Java 类com.intellij.openapi.fileTypes.LanguageFileType 实例源码

项目:idea-php-typo3-plugin    文件:ExtensionFileGenerationUtil.java   
/**
 * @param templateFile        Name of the generated file
 * @param destinationPath     Relative path to the target file system entry
 * @param extensionDefinition Extension definition containing all relevant metadata
 * @param context             Template Context variables
 * @param project             Project in context
 */
public static PsiElement fromTemplate(@NotNull String templateFile, @NotNull String destinationPath, @NotNull String destinationFileName, @NotNull TYPO3ExtensionDefinition extensionDefinition, @NotNull Map<String, String> context, Project project) {
    String template = readTemplateToString(templateFile, context);

    VirtualFile targetDirectory = getOrCreateDestinationPath(extensionDefinition.getRootDirectory(), destinationPath);

    LanguageFileType fileType = FileTypes.PLAIN_TEXT;
    if (templateFile.endsWith(".php")) {
        fileType = PhpFileType.INSTANCE;
    }

    PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText(destinationFileName, fileType, template);
    CodeStyleManager.getInstance(project).reformat(fileFromText);
    return PsiDirectoryFactory
            .getInstance(project)
            .createDirectory(targetDirectory)
            .add(fileFromText);
}
项目:idea-php-typo3-plugin    文件:ExtensionFileGenerationUtil.java   
/**
 * @param templateFile           Name of the generated file
 * @param destinationPath        Relative path to the target file system entry
 * @param extensionRootDirectory Extension definition containing all relevant metadata
 * @param context                Template Context variables
 * @param project                Project in context
 */
public static PsiElement fromTemplate(@NotNull String templateFile, @NotNull String destinationPath, @NotNull String destinationFileName, @NotNull PsiDirectory extensionRootDirectory, @NotNull Map<String, String> context, Project project) {
    String template = readTemplateToString(templateFile, context);

    VirtualFile targetDirectory = getOrCreateDestinationPath(extensionRootDirectory.getVirtualFile(), destinationPath);

    LanguageFileType fileType = FileTypes.PLAIN_TEXT;
    if (templateFile.endsWith(".php")) {
        fileType = PhpFileType.INSTANCE;
    }

    PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText(destinationFileName, fileType, template);
    CodeStyleManager.getInstance(project).reformat(fileFromText);
    return PsiDirectoryFactory
            .getInstance(project)
            .createDirectory(targetDirectory)
            .add(fileFromText);
}
项目:educational-plugin    文件:EduIntellijUtils.java   
@NotNull
private static String publicClassName(@NotNull Project project, @NotNull TaskFile taskFile, @NotNull LanguageFileType fileType) {
  String fileName = "Main";
  PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(taskFile.name, fileType, taskFile.text);
  if (file instanceof PsiClassOwner) {
    PsiClassOwner fileFromText = (PsiClassOwner) file;
    PsiClass[] classes = fileFromText.getClasses();
    for (PsiClass aClass : classes) {
      boolean isPublic = aClass.hasModifierProperty(PsiModifier.PUBLIC);
      if (isPublic && aClass.getName() != null) {
        fileName = aClass.getName();
        break;
      }
    }
  }

  return fileName;
}
项目:idea-php-behat-plugin    文件:BehatLightCodeInsightFixtureTestCase.java   
public void assertIntentionIsAvailable(LanguageFileType languageFileType, String configureByText, String intentionText) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    Set<String> items = new HashSet<>();

    for (IntentionAction intentionAction : IntentionManager.getInstance().getIntentionActions()) {
        if(!intentionAction.isAvailable(getProject(), getEditor(), psiElement.getContainingFile())) {
            continue;
        }

        String text = intentionAction.getText();
        items.add(text);

        if(!text.equals(intentionText)) {
            continue;
        }

        return;
    }

    fail(String.format("Fail intention action '%s' is available in element '%s' with '%s'", intentionText, psiElement.getText(), items));
}
项目:rythm_plugin    文件:RythmFileType.java   
private static LanguageFileType getAssociatedFileType(VirtualFile file, Project project) {
    if (project == null) {
        return null;
    }
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(file);

    LanguageFileType associatedFileType = null;
    if (language != null) {
        associatedFileType = language.getAssociatedFileType();
    }

    if (language == null || associatedFileType == null) {
        associatedFileType = RythmLanguage.getDefaultTemplateLang();
    }
    return associatedFileType;
}
项目:GoJetPlugin    文件:JetFileType.java   
private static LanguageFileType getAssociatedFileType(VirtualFile file, Project project) {
    if (project == null) {
        return null;
    }
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(file);

    LanguageFileType associatedFileType = null;
    if (language != null) {
        associatedFileType = language.getAssociatedFileType();
    }

    if (language == null || associatedFileType == null) {
        associatedFileType = JetLanguage.getDefaultTemplateLang();
    }
    return associatedFileType;
}
项目:intellij-ce-playground    文件:JSR45PositionManager.java   
public JSR45PositionManager(DebugProcess debugProcess, Scope scope, final String stratumId, final LanguageFileType[] acceptedFileTypes,
                            final SourcesFinder<Scope> sourcesFinder) {
  myDebugProcess = debugProcess;
  myScope = scope;
  myStratumId = stratumId;
  myFileTypes = Collections.unmodifiableSet(new HashSet<LanguageFileType>(Arrays.asList(acceptedFileTypes)));
  mySourcesFinder = sourcesFinder;
  String generatedClassPattern = getGeneratedClassesPackage();
  if(generatedClassPattern.length() == 0) {
    generatedClassPattern = getGeneratedClassesNamePattern();
  }
  else {
    generatedClassPattern = generatedClassPattern + "." + getGeneratedClassesNamePattern();
  }
  GENERATED_CLASS_PATTERN = generatedClassPattern;
  myGeneratedClassPatternMatcher = Pattern.compile(generatedClassPattern.replaceAll("\\*", ".*")).matcher("");
}
项目:intellij-ce-playground    文件:TodoIndex.java   
@Override
public boolean acceptInput(@NotNull final VirtualFile file) {
  if (!file.isInLocalFileSystem()) {
    return false; // do not index TODOs in library sources
  }

  final FileType fileType = file.getFileType();

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    return commentTokens != null;
  }

  return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
         fileType instanceof CustomSyntaxTableFileType;
}
项目:intellij-ce-playground    文件:MatcherImplUtil.java   
public static PsiElement[] createTreeFromText(String text,
                                              PatternTreeContext context,
                                              FileType fileType,
                                              Language language,
                                              String contextName,
                                              Project project,
                                              boolean physical) throws IncorrectOperationException {
  if (language == null && fileType instanceof LanguageFileType) {
    language = ((LanguageFileType)fileType).getLanguage();
  }
  if (language != null) {
    StructuralSearchProfile profile = StructuralSearchUtil.getProfileByLanguage(language);
    if (profile != null) {
      return profile.createPatternTree(text, context, fileType, language, contextName, null, project, physical);
    }
  }
  return PsiElement.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:CoreStubTreeLoader.java   
@Override
public boolean canHaveStub(VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) return false;
    final IFileElementType elementType = parserDefinition.getFileNodeType();
    return elementType instanceof IStubFileElementType && ((IStubFileElementType)elementType).shouldBuildStubFor(file);
  }
  else if (fileType.isBinary()) {
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
  }
  return false;
}
项目:intellij-ce-playground    文件:CumulativeStubVersion.java   
public static int getCumulativeVersion() {
  int version = VERSION;
  for (final FileType fileType : FileTypeRegistry.getInstance().getRegisteredFileTypes()) {
    if (fileType instanceof LanguageFileType) {
      Language l = ((LanguageFileType)fileType).getLanguage();
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
      if (parserDefinition != null) {
        final IFileElementType type = parserDefinition.getFileNodeType();
        if (type instanceof IStubFileElementType) {
          version += ((IStubFileElementType)type).getStubVersion();
        }
      }
    }

    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
      version += builder.getStubVersion();
    }
  }
  return version;
}
项目:intellij-ce-playground    文件:SingleRootFileViewProvider.java   
private static Language calcBaseLanguage(@NotNull VirtualFile file, @NotNull Project project, @NotNull final FileType fileType) {
  if (file instanceof LightVirtualFile) {
    final Language language = ((LightVirtualFile)file).getLanguage();
    if (language != null) {
      return language;
    }
  }

  if (fileType.isBinary()) return Language.ANY;
  if (isTooLargeForIntelligence(file)) return PlainTextLanguage.INSTANCE;

  if (fileType instanceof LanguageFileType) {
    return LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, project);
  }

  return PlainTextLanguage.INSTANCE;
}
项目:intellij-ce-playground    文件:PsiFileFactoryImpl.java   
@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name,
                                  @NotNull FileType fileType,
                                  @NotNull CharSequence text,
                                  long modificationStamp,
                                  final boolean eventSystemEnabled,
                                  boolean markAsCopy) {
  final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
  if(fileType instanceof LanguageFileType){
    final Language language =
        LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
    final PsiFile file = trySetupPsiForFile(virtualFile, language, eventSystemEnabled, markAsCopy);
    if (file != null) return file;
  }
  final SingleRootFileViewProvider singleRootFileViewProvider =
    new SingleRootFileViewProvider(myManager, virtualFile, eventSystemEnabled);
  final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
  if(markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
  return plainTextFile;
}
项目:intellij-ce-playground    文件:SubstitutedFileType.java   
@NotNull
public static FileType substituteFileType(@NotNull VirtualFile file, @NotNull FileType fileType, Project project) {
  if (project == null) {
    return fileType;
  }
  if (fileType instanceof LanguageFileType) {
    final Language language = ((LanguageFileType)fileType).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
    LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
    if (!substitutedLanguage.equals(language) && substFileType != null) {
      return new SubstitutedFileType(fileType, substFileType, substitutedLanguage);
    }
  }

  return fileType;
}
项目:intellij-ce-playground    文件:StubUpdatingIndex.java   
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      if (IndexingStamp.isFileIndexedStateCurrent(file, INDEX_ID)) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
项目:intellij-ce-playground    文件:FindDialog.java   
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
  final Component editorComponent = inputComboBox.getEditor().getEditorComponent();

  if (editorComponent instanceof EditorTextField) {
    boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable();
    FileType fileType = PlainTextFileType.INSTANCE;
    if (isRegexp) {
      Language regexpLanguage = Language.findLanguageByID("RegExp");
      if (regexpLanguage != null) {
        LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType();
        if (regexpFileType != null) {
          fileType = regexpFileType;
        }
      }
    }
    String fileName = isRegexp ? "a.regexp" : "a.txt";
    final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true);

    ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
  }
}
项目:intellij-ce-playground    文件:ScanSourceCommentsAction.java   
private void scanCommentsInFile(final Project project, final VirtualFile vFile) {
  if (!vFile.isDirectory() && vFile.getFileType() instanceof LanguageFileType) {
    ApplicationManager.getApplication().runReadAction(new Runnable() {
      @Override
      public void run() {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
        if (psiFile == null) return;

        for (PsiFile root : psiFile.getViewProvider().getAllFiles()) {
          root.accept(new PsiRecursiveElementWalkingVisitor() {
            @Override
            public void visitComment(PsiComment comment) {
              commentFound(vFile, comment.getText());
            }
          });
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:NodeSpecificHasherBase.java   
@Override
public void visitNode(@NotNull PsiElement node) {
  Language language = null;
  if (node instanceof PsiFile) {
    FileType fileType = ((PsiFile)node).getFileType();
    if (fileType instanceof LanguageFileType) {
      language = ((LanguageFileType)fileType).getLanguage();
    }
  }
  if (language == null) language = node.getLanguage();
  if ((myForIndexing || mySettings.SELECTED_PROFILES.contains(language.getDisplayName())) &&
      myDuplicatesProfile.isMyLanguage(language)) {

    myTreeHasher.hash(node, this);
  }
}
项目:intellij-ce-playground    文件:LanguageResolvingUtil.java   
private static List<LanguageDefinition> collectLibraryLanguages(final ConvertContext context,
                                                                final Collection<PsiClass> allLanguages) {
  return ContainerUtil.mapNotNull(Language.getRegisteredLanguages(), new NullableFunction<Language, LanguageDefinition>() {
    @Override
    public LanguageDefinition fun(Language language) {
      if (language.getID().isEmpty() ||
          language instanceof DependentLanguage) {
        return null;
      }
      final PsiClass psiClass = DomJavaUtil.findClass(language.getClass().getName(), context.getInvocationElement());
      if (psiClass == null) {
        return null;
      }

      if (!allLanguages.contains(psiClass)) {
        return null;
      }

      final LanguageFileType type = language.getAssociatedFileType();
      final Icon icon = type != null ? type.getIcon() : null;
      return new LanguageDefinition(language.getID(),
                                    psiClass,
                                    icon, language.getDisplayName());
    }
  });
}
项目:idea-php-toolbox    文件:SymfonyLightCodeInsightFixtureTestCase.java   
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {

        myFixture.configureByText(languageFileType, configureByText);
        PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

        Set<String> targetStrings = new HashSet<>();

        for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {

            PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
            if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
                continue;
            }

            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                targetStrings.add(gotoDeclarationTarget.toString());
                if(pattern.accepts(gotoDeclarationTarget)) {
                    return;
                }
            }
        }

        fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
    }
项目:idea-php-toolbox    文件:SymfonyLightCodeInsightFixtureTestCase.java   
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (psiElement == null) {
        fail("Element is not PhpReference.");
    }

    PsiElement resolve = ((PhpReference) psiElement).resolve();
    if(!pattern.accepts(resolve)) {
        fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString()));
    }

    assertTrue(pattern.accepts(resolve));
}
项目:silex-idea-plugin    文件:CodeInsightFixtureTestCase.java   
protected void assertCompletionEquals(LanguageFileType languageFileType, String configureByText, String... lookupStrings) {

        myFixture.configureByText(languageFileType, configureByText);
        myFixture.completeBasic();

        List<String> lookupElements = myFixture.getLookupElementStrings();
        if (lookupElements == null) {
            return;
        }

        if (lookupElements.size() != lookupStrings.length) {
            fail(String.format("completion %s have to contain only %s", lookupElements.toString(), Arrays.toString(lookupStrings)));
        }

        completionContainsAssert(lookupStrings);
    }
项目:silex-idea-plugin    文件:CodeInsightFixtureTestCase.java   
protected void assertSignatureEquals(LanguageFileType languageFileType, @NotNull Class aClass, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, aClass);

    PhpTypeProvider2[] typeAnalyser = Extensions.getExtensions(PhpTypeProvider2.EP_NAME);

    for (PhpTypeProvider2 provider : typeAnalyser) {

        if (provider instanceof PimplePhpTypeProvider) {

            String providerType = provider.getType(psiElement);
            if (providerType != null) {
                providerType = "#" + provider.getKey() + providerType;
            }

            assertEquals(typeSignature, providerType);
        }
    }
}
项目:silex-idea-plugin    文件:CodeInsightFixtureTestCase.java   
protected void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, @NotNull Class aClass, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, aClass);

    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    PhpIndex phpIndex = PhpIndex.getInstance(myFixture.getProject());
    Collection<? extends PhpNamedElement> collection = phpIndex.getBySignature(((PhpReference)psiElement).getSignature(), null, 0);
    assertNotEmpty(collection);

    for (String type : collection.iterator().next().getType().getTypes()) {
        if (type.equals(typeSignature)) {
            return;
        }
    }

    fail("Can't find type: "+typeSignature+", found:"+collection.iterator().next().getType().toString());
}
项目:idea-php-shopware-plugin    文件:ShopwareLightCodeInsightFixtureTestCase.java   
public void assertCompletionLookupContainsPresentableItem(LanguageFileType languageFileType, String configureByText, LookupElementPresentationAssert.Assert presentationAssert) {

        myFixture.configureByText(languageFileType, configureByText);
        myFixture.completeBasic();

        LookupElement[] lookupElements = myFixture.getLookupElements();
        if(lookupElements == null) {
            fail("failed to find lookup presentable on empty collection");
        }

        for (LookupElement lookupElement : lookupElements) {
            LookupElementPresentation presentation = new LookupElementPresentation();
            lookupElement.renderElement(presentation);

            if(presentationAssert.match(presentation)) {
                return;
            }
        }

        fail("failed to find lookup presentable");
    }
项目:idea-php-shopware-plugin    文件:ShopwareLightCodeInsightFixtureTestCase.java   
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (psiElement == null) {
        fail("Element is not PhpReference.");
    }

    PsiElement resolve = ((PhpReference) psiElement).resolve();
    if(!pattern.accepts(resolve)) {
        fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString()));
    }

    assertTrue(pattern.accepts(resolve));
}
项目:idea-php-drupal-symfony2-bridge    文件:DrupalLightCodeInsightFixtureTestCase.java   
public void assertCompletionLookupContainsPresentableItem(LanguageFileType languageFileType, String configureByText, LookupElementPresentationAssert.Assert presentationAssert) {

        myFixture.configureByText(languageFileType, configureByText);
        myFixture.completeBasic();

        LookupElement[] lookupElements = myFixture.getLookupElements();
        if(lookupElements == null) {
            fail("failed to find lookup presentable on empty collection");
        }

        for (LookupElement lookupElement : lookupElements) {
            LookupElementPresentation presentation = new LookupElementPresentation();
            lookupElement.renderElement(presentation);

            if(presentationAssert.match(presentation)) {
                return;
            }
        }

        fail("failed to find lookup presentable");
    }
项目:idea-php-drupal-symfony2-bridge    文件:DrupalLightCodeInsightFixtureTestCase.java   
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (psiElement == null) {
        fail("Element is not PhpReference.");
    }

    PsiElement resolve = ((PhpReference) psiElement).resolve();
    if(!pattern.accepts(resolve)) {
        fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString()));
    }

    assertTrue(pattern.accepts(resolve));
}
项目:idea-php-toolbox    文件:SymfonyLightCodeInsightFixtureTestCase.java   
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {

        myFixture.configureByText(languageFileType, configureByText);
        PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

        Set<String> targetStrings = new HashSet<>();

        for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {

            PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
            if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
                continue;
            }

            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                targetStrings.add(gotoDeclarationTarget.toString());
                if(pattern.accepts(gotoDeclarationTarget)) {
                    return;
                }
            }
        }

        fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
    }
项目:idea-php-toolbox    文件:SymfonyLightCodeInsightFixtureTestCase.java   
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (psiElement == null) {
        fail("Element is not PhpReference.");
    }

    PsiElement resolve = ((PhpReference) psiElement).resolve();
    if(!pattern.accepts(resolve)) {
        fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString()));
    }

    assertTrue(pattern.accepts(resolve));
}
项目:tools-idea    文件:JSR45PositionManager.java   
public JSR45PositionManager(DebugProcess debugProcess, Scope scope, final String stratumId, final LanguageFileType[] acceptedFileTypes,
                            final SourcesFinder<Scope> sourcesFinder) {
  myDebugProcess = debugProcess;
  myScope = scope;
  myStratumId = stratumId;
  myFileTypes = Collections.unmodifiableSet(new HashSet<LanguageFileType>(Arrays.asList(acceptedFileTypes)));
  mySourcesFinder = sourcesFinder;
  String generatedClassPattern = getGeneratedClassesPackage();
  if(generatedClassPattern.length() == 0) {
    generatedClassPattern = getGeneratedClassesNamePattern();
  }
  else {
    generatedClassPattern = generatedClassPattern + "." + getGeneratedClassesNamePattern();
  }
  GENERATED_CLASS_PATTERN = generatedClassPattern;
  myGeneratedClassPatternMatcher = Pattern.compile(generatedClassPattern.replaceAll("\\*", ".*")).matcher("");
}
项目:tools-idea    文件:TabPostFormatProcessor.java   
@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
  ASTNode node = source.getNode();
  if (node == null) {
    return range;
  }

  Language language = source.getLanguage();
  if (language != JavaLanguage.INSTANCE) {
    // We had the only complaint for tabs not being converted to spaces for now. It was for the java code which has
    // a single block for the multi-line comment. This check should be removed if it is decided to generalize
    // this logic to other languages as well.
    return range;
  }

  LanguageFileType fileType = language.getAssociatedFileType();
  if (fileType == null) {
    return range;
  }

  boolean useTabs = settings.useTabCharacter(fileType);
  boolean smartTabs = settings.isSmartTabs(fileType);
  int tabWidth = settings.getTabSize(fileType);
  return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}
项目:tools-idea    文件:CodeStyleSettings.java   
private void copyOldIndentOptions(@NonNls final String extension, final IndentOptions options) {
  final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(extension);
  if (fileType != FileTypes.UNKNOWN && fileType != FileTypes.PLAIN_TEXT && !myAdditionalIndentOptions.containsKey(fileType) &&
      !fileType.getDefaultExtension().isEmpty()) {
    registerAdditionalIndentOptions(fileType, options);
    //
    // Upgrade to version 11
    //
    if (fileType instanceof LanguageFileType) {
      Language lang = ((LanguageFileType)fileType).getLanguage();
      CommonCodeStyleSettings langSettings = myCommonSettingsManager.getCommonSettings(lang);
      if (langSettings != this && langSettings.getIndentOptions() != null) {
        langSettings.importOldIndentOptions(this);
      }
    }
  }
}
项目:tools-idea    文件:PsiParserFacadeImpl.java   
@Override
@NotNull
public PsiComment createLineCommentFromText(@NotNull final LanguageFileType fileType,
                                            @NotNull final String text) throws IncorrectOperationException {
  Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(fileType.getLanguage());
  assert commenter != null;
  String prefix = commenter.getLineCommentPrefix();
  if (prefix == null) {
    throw new IncorrectOperationException("No line comment prefix defined for language " + fileType.getLanguage().getID());
  }

  PsiFile aFile = createDummyFile(prefix + text, fileType);
  PsiElement[] children = aFile.getChildren();
  for (PsiElement aChildren : children) {
    if (aChildren instanceof PsiComment) {
      PsiComment comment = (PsiComment)aChildren;
      DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), null);
      return comment;
    }
  }
  throw new IncorrectOperationException("Incorrect comment \"" + text + "\".");
}
项目:tools-idea    文件:FileManagerImpl.java   
@Nullable
private Language getLanguage(final VirtualFile file) {
  final FileType fileType = file.getFileType();
  Project project = myManager.getProject();
  if (fileType instanceof LanguageFileType) {
    return LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, project);
  }
  // Define language for binary file
  final ContentBasedFileSubstitutor[] processors = Extensions.getExtensions(ContentBasedFileSubstitutor.EP_NAME);
  for (ContentBasedFileSubstitutor processor : processors) {
    Language language = processor.obtainLanguageForFile(file);
    if (language != null) {
      return language;
    }
  }

  return null;
}
项目:tools-idea    文件:PsiFileFactoryImpl.java   
@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name,
                                  @NotNull FileType fileType,
                                  @NotNull CharSequence text,
                                  long modificationStamp,
                                  final boolean physical,
                                  boolean markAsCopy) {
  final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
  if(fileType instanceof LanguageFileType){
    final Language language =
        LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
    final PsiFile file = trySetupPsiForFile(virtualFile, language, physical, markAsCopy);
    if (file != null) return file;
  }
  final SingleRootFileViewProvider singleRootFileViewProvider =
    new SingleRootFileViewProvider(myManager, virtualFile, physical);
  final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
  if(markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
  return plainTextFile;
}
项目:tools-idea    文件:SubstitutedFileType.java   
@NotNull
public static FileType substituteFileType(VirtualFile file, @NotNull FileType fileType, Project project) {
  if (project == null) {
    return fileType;
  }
  if (fileType instanceof LanguageFileType) {
    final Language language = ((LanguageFileType)fileType).getLanguage();
    final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
    LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
    if (!substitutedLanguage.equals(language) && substFileType != null && !substFileType.equals(fileType)) {
      return new SubstitutedFileType(fileType, substFileType);
    }
  }

  return fileType;
}
项目:tools-idea    文件:OtherTabsAndIndentsPanel.java   
@Nullable
private Language getSelectedLanguage() {
  int selectedIndex = myIndentOptionsTabs.getSelectedIndex();
  int i = 0;
  for (Map.Entry<FileType, IndentOptionsEditor> entry : myAdditionalIndentOptions.entrySet()) {
    if (i == selectedIndex) {
      FileType ft = entry.getKey();
      if (ft instanceof LanguageFileType) {
        return ((LanguageFileType)ft).getLanguage();
      }
      return null;
    }
    i++;
  }
  return null;
}
项目:tools-idea    文件:StubUpdatingIndex.java   
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      final ID indexId = IndexInfrastructure.getStubId(INDEX_ID, file.getFileType());
      if (IndexingStamp.isFileIndexed(file, indexId, IndexInfrastructure.getIndexCreationStamp(indexId))) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
项目:tools-idea    文件:StubUpdatingIndex.java   
private static Map<FileType, Integer> computeVersionMap() {
  Map<FileType, Integer> map = new HashMap<FileType, Integer>();
  for (final FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) {
    if (fileType instanceof LanguageFileType) {
      Language l = ((LanguageFileType)fileType).getLanguage();
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
      if (parserDefinition != null) {
        final IFileElementType type = parserDefinition.getFileNodeType();
        if (type instanceof IStubFileElementType) {
          map.put(fileType, ((IStubFileElementType)type).getStubVersion());
        }
      }
    }
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
      map.put(fileType, builder.getStubVersion());
    }
  }
  return map;
}