Java Code Examples for com.intellij.openapi.fileTypes.LanguageFileType

The following are top voted examples for showing how to use com.intellij.openapi.fileTypes.LanguageFileType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: idea-php-typo3-plugin   File: ExtensionFileGenerationUtil.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
}
 
Example 2
Project: idea-php-typo3-plugin   File: ExtensionFileGenerationUtil.java   Source Code and License 6 votes vote down vote up
/**
 * @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);
}
 
Example 3
Project: educational-plugin   File: EduIntellijUtils.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 4
Project: idea-php-behat-plugin   File: BehatLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 5
Project: rythm_plugin   File: RythmFileType.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 6
Project: GoJetPlugin   File: JetFileType.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 7
Project: intellij-ce-playground   File: JSR45PositionManager.java   Source Code and License 6 votes vote down vote up
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("");
}
 
Example 8
Project: intellij-ce-playground   File: TodoIndex.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 9
Project: intellij-ce-playground   File: MatcherImplUtil.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 10
Project: intellij-ce-playground   File: CoreStubTreeLoader.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 11
Project: intellij-ce-playground   File: CumulativeStubVersion.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 12
Project: intellij-ce-playground   File: SingleRootFileViewProvider.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 13
Project: intellij-ce-playground   File: PsiFileFactoryImpl.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 14
Project: intellij-ce-playground   File: SubstitutedFileType.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 15
Project: intellij-ce-playground   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 16
Project: intellij-ce-playground   File: FindDialog.java   Source Code and License 6 votes vote down vote up
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));
  }
}
 
Example 17
Project: intellij-ce-playground   File: ScanSourceCommentsAction.java   Source Code and License 6 votes vote down vote up
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());
            }
          });
        }
      }
    });
  }
}
 
Example 18
Project: intellij-ce-playground   File: NodeSpecificHasherBase.java   Source Code and License 6 votes vote down vote up
@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);
  }
}
 
Example 19
Project: intellij-ce-playground   File: LanguageResolvingUtil.java   Source Code and License 6 votes vote down vote up
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());
    }
  });
}
 
Example 20
Project: idea-php-toolbox   File: SymfonyLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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()));
    }
 
Example 21
Project: idea-php-toolbox   File: SymfonyLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 22
Project: silex-idea-plugin   File: CodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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);
    }
 
Example 23
Project: silex-idea-plugin   File: CodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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);
        }
    }
}
 
Example 24
Project: silex-idea-plugin   File: CodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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());
}
 
Example 25
Project: idea-php-shopware-plugin   File: ShopwareLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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");
    }
 
Example 26
Project: idea-php-shopware-plugin   File: ShopwareLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 27
Project: idea-php-drupal-symfony2-bridge   File: DrupalLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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");
    }
 
Example 28
Project: idea-php-drupal-symfony2-bridge   File: DrupalLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 29
Project: idea-php-toolbox   File: SymfonyLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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()));
    }
 
Example 30
Project: idea-php-toolbox   File: SymfonyLightCodeInsightFixtureTestCase.java   Source Code and License 6 votes vote down vote up
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));
}
 
Example 31
Project: tools-idea   File: JSR45PositionManager.java   Source Code and License 6 votes vote down vote up
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("");
}
 
Example 32
Project: tools-idea   File: TabPostFormatProcessor.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 33
Project: tools-idea   File: CodeStyleSettings.java   Source Code and License 6 votes vote down vote up
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);
      }
    }
  }
}
 
Example 34
Project: tools-idea   File: PsiParserFacadeImpl.java   Source Code and License 6 votes vote down vote up
@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 + "\".");
}
 
Example 35
Project: tools-idea   File: FileManagerImpl.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 36
Project: tools-idea   File: PsiFileFactoryImpl.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 37
Project: tools-idea   File: SubstitutedFileType.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 38
Project: tools-idea   File: OtherTabsAndIndentsPanel.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 39
Project: tools-idea   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 40
Project: tools-idea   File: StubUpdatingIndex.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 41
Project: tools-idea   File: TodoIndex.java   Source Code and License 6 votes vote down vote up
@Override
public boolean acceptInput(final VirtualFile file) {
  if (!(file.getFileSystem() instanceof LocalFileSystem)) {
    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;
}
 
Example 42
Project: bamboo-soy   File: SoyTypingTest.java   Source Code and License 5 votes vote down vote up
private void doTypingTest(
    @NotNull final LanguageFileType fileType,
    final char charToType,
    @NotNull final String textBefore,
    @NotNull final String textAfter) {
  myFixture.configureByText(fileType, textBefore);
  myFixture.type(charToType);
  myFixture.checkResult(textAfter);
}
 
Example 43
Project: idea-php-dotenv-plugin   File: DotEnvLightCodeInsightFixtureTestCase.java   Source Code and License 5 votes vote down vote up
public void assertNavigationContainsFile(LanguageFileType languageFileType, String configureByText, String targetShortcut) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

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

    for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
        PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
        if (gotoDeclarationTargets != null && gotoDeclarationTargets.length > 0) {
            for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
                if(gotoDeclarationTarget instanceof PsiFile) {
                    targets.add(((PsiFile) gotoDeclarationTarget).getVirtualFile().getUrl());
                }
            }
        }
    }

    // its possible to have memory fields,
    // so simple check for ending conditions
    // temp:///src/interchange.en.xlf
    for (String target : targets) {
        if(target.endsWith(targetShortcut)) {
            return;
        }
    }

    fail(String.format("failed that PsiElement (%s) navigate to file %s", psiElement.toString(), targetShortcut));
}
 
Example 44
Project: idea-php-dotenv-plugin   File: DotEnvLightCodeInsightFixtureTestCase.java   Source Code and License 5 votes vote down vote up
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.");
    }

    assertTrue(pattern.accepts(((PhpReference) psiElement).resolve()));
}
 
Example 45
Project: idea-php-dotenv-plugin   File: DotEnvLightCodeInsightFixtureTestCase.java   Source Code and License 5 votes vote down vote up
public void assertPhpReferenceNotResolveTo(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.");
    }

    assertFalse(pattern.accepts(((PhpReference) psiElement).resolve()));
}
 
Example 46
Project: idea-php-dotenv-plugin   File: DotEnvLightCodeInsightFixtureTestCase.java   Source Code and License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

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

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example 47
Project: idea-php-dotenv-plugin   File: DotEnvLightCodeInsightFixtureTestCase.java   Source Code and License 5 votes vote down vote up
public void assertIntentionIsAvailable(LanguageFileType languageFileType, String configureByText, String intentionText) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    for (IntentionAction intentionAction : IntentionManager.getInstance().getIntentionActions()) {
        if(intentionAction.isAvailable(getProject(), getEditor(), psiElement.getContainingFile()) && intentionAction.getText().equals(intentionText)) {
            return;
        }
    }

    fail(String.format("Fail intention action '%s' is available in element '%s'", intentionText, psiElement.getText()));
}
 
Example 48
Project: educational-plugin   File: EduAdaptiveStepicConnector.java   Source Code and License 5 votes vote down vote up
@Nullable
private static String getTaskFileName(@NotNull Language language) {
  // This is a hacky way to how we should name task file.
  // It's assumed that if test's name is capitalized we need to capitalize task file name too.
  String testFileName = EduPluginConfigurator.INSTANCE.forLanguage(language).getTestFileName();
  boolean capitalize = !testFileName.isEmpty() && Character.isUpperCase(testFileName.charAt(0));

  LanguageFileType type = language.getAssociatedFileType();
  if (type == null) {
    LOG.warn("Failed to create task file name: associated file type for " + language + " is null");
    return null;
  }

  return (capitalize ? StringUtil.capitalize(TASK_NAME) : TASK_NAME) + "." + type.getDefaultExtension();
}
 
Example 49
Project: CodeGen   File: AbstractFileProvider.java   Source Code and License 5 votes vote down vote up
protected PsiFile createFile(Project project, @NotNull PsiDirectory psiDirectory, String fileName, String context, LanguageFileType fileType) {
    PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(fileName, fileType, context);
    // reformat class
    CodeStyleManager.getInstance(project).reformat(psiFile);
    if (psiFile instanceof PsiJavaFile) {
        JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
        styleManager.optimizeImports(psiFile);
        styleManager.shortenClassReferences(psiFile);
    }
    psiDirectory.add(psiFile);
    return psiFile;
}
 
Example 50
Project: rythm_plugin   File: RythmFileType.java   Source Code and License 5 votes vote down vote up
public Charset extractCharsetFromFileContent(@org.jetbrains.annotations.Nullable final Project project,
                                             @org.jetbrains.annotations.Nullable final VirtualFile file,
                                             @org.jetbrains.annotations.NotNull final CharSequence content) {
    LanguageFileType associatedFileType = getAssociatedFileType(file, project);

    if (associatedFileType == null) {
        return null;
    }

    return CharsetUtil.extractCharsetFromFileContent(project, file, associatedFileType, content);
}
 
Example 51
Project: GoJetPlugin   File: JetFileType.java   Source Code and License 5 votes vote down vote up
public Charset extractCharsetFromFileContent(@Nullable final Project project,
                                             @Nullable final VirtualFile file,
                                             @NotNull final CharSequence content) {
    LanguageFileType associatedFileType = getAssociatedFileType(file, project);

    if (associatedFileType == null) {
        return null;
    }

    return CharsetUtil.extractCharsetFromFileContent(project, file, associatedFileType, content);
}
 
Example 52
Project: intellij-ce-playground   File: JavaOutOfSourcesResolveScopeProvider.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
  // For java only! For other languages resolve may be implemented with different rules, requiring larger scope.
  final FileType type = file.getFileType();
  if (type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() == JavaLanguage.INSTANCE) {
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    if (index.isInContent(file) && !index.isInSource(file)) {
      return GlobalSearchScope.fileScope(project, file);
    }
  }
  return null;
}
 
Example 53
Project: intellij-ce-playground   File: DebuggerUtils.java   Source Code and License 5 votes vote down vote up
private static boolean isDebugAware(@NotNull PsiFile file, boolean breakpointAware) {
  FileType fileType = file.getFileType();
  //noinspection deprecation
  if (fileType instanceof LanguageFileType && ((LanguageFileType)fileType).isJVMDebuggingSupported()) {
    return true;
  }

  for (JavaDebugAware provider : JavaDebugAware.EP_NAME.getExtensions()) {
    if (breakpointAware ? provider.isBreakpointAware(file) : provider.isActionAware(file)) {
      return true;
    }
  }
  return false;
}
 
Example 54
Project: intellij-ce-playground   File: LanguageFileTypeStructureViewBuilderProvider.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public StructureViewBuilder getStructureViewBuilder(@NotNull final FileType fileType, @NotNull final VirtualFile file, @NotNull final Project project) {
  if (!(fileType instanceof LanguageFileType)) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null) return null;

  final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage());
  return factory == null ?  null : factory.getStructureViewBuilder(psiFile);
}
 
Example 55
Project: intellij-ce-playground   File: PlatformIdTableBuilding.java   Source Code and License 5 votes vote down vote up
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  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;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
  }

  return null;
}
 
Example 56
Project: intellij-ce-playground   File: LanguageUtil.java   Source Code and License 5 votes vote down vote up
public static boolean isFileLanguage(@NotNull Language language) {
  if (language instanceof DependentLanguage || language instanceof InjectableLanguage) return false;
  if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) return false;
  LanguageFileType type = language.getAssociatedFileType();
  if (type == null || StringUtil.isEmpty(type.getDefaultExtension())) return false;
  String name = language.getDisplayName();
  if (StringUtil.isEmpty(name) || name.startsWith("<") || name.startsWith("[")) return false;
  return StringUtil.isNotEmpty(type.getDefaultExtension());
}
 
Example 57
Project: intellij-ce-playground   File: XDebuggerEditorsProvider.java   Source Code and License 5 votes vote down vote up
@NotNull
public Collection<Language> getSupportedLanguages(@NotNull Project project, @Nullable XSourcePosition sourcePosition) {
  FileType type = getFileType();
  if (type instanceof LanguageFileType) {
    return Collections.singleton(((LanguageFileType)type).getLanguage());
  }
  return Collections.emptyList();
}
 
Example 58
Project: intellij-ce-playground   File: IdTableBuilding.java   Source Code and License 5 votes vote down vote up
@Nullable
public static FileTypeIdIndexer getFileTypeIndexer(FileType fileType) {
  final FileTypeIdIndexer idIndexer = ourIdIndexers.get(fileType);

  if (idIndexer != null) {
    return idIndexer;
  }

  final FileTypeIdIndexer extIndexer = IdIndexers.INSTANCE.forFileType(fileType);
  if (extIndexer != null) {
    return extIndexer;
  }

  final WordsScanner customWordsScanner = CacheBuilderRegistry.getInstance().getCacheBuilder(fileType);
  if (customWordsScanner != null) {
    return new WordsScannerFileTypeIdIndexerAdapter(customWordsScanner);
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final FindUsagesProvider findUsagesProvider = LanguageFindUsages.INSTANCE.forLanguage(lang);
    WordsScanner scanner = findUsagesProvider == null ? null : findUsagesProvider.getWordsScanner();
    if (scanner == null) {
      scanner = new SimpleWordsScanner();
    }
    return new WordsScannerFileTypeIdIndexerAdapter(scanner);
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new WordsScannerFileTypeIdIndexerAdapter(createCustomFileTypeScanner(((CustomSyntaxTableFileType)fileType).getSyntaxTable()));
  }

  return null;
}
 
Example 59
Project: intellij-ce-playground   File: CodeSamplesCorrectnessTest.java   Source Code and License 5 votes vote down vote up
@NotNull
private Collection<PsiErrorElement> getErrorsForText(@NotNull LanguageCodeStyleSettingsProvider provider, @NotNull String sample) {
  PsiFile file = provider.createFileFromText(getProject(), sample);
  if (file == null) {
    Language language = provider.getLanguage();
    LanguageFileType type = language.getAssociatedFileType();
    if (type == null) return ContainerUtil.newArrayList();
    file = myFixture.configureByText(type, sample);
  }

  return PsiTreeUtil.collectElementsOfType(file, PsiErrorElement.class);
}
 
Example 60
Project: intellij-ce-playground   File: CodeStyleSettings.java   Source Code and License 5 votes vote down vote up
@Nullable
private IndentOptions getLanguageIndentOptions(@Nullable FileType fileType) {
  if (fileType == null || !(fileType instanceof LanguageFileType)) return null;
  Language lang = ((LanguageFileType)fileType).getLanguage();
  CommonCodeStyleSettings langSettings = getCommonSettings(lang);
  return langSettings == this ? null : langSettings.getIndentOptions();
}