@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; }
@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; }
private static boolean mayContainClassName(CompletionParameters parameters) { PsiElement position = parameters.getPosition(); PsiFile file = position.getContainingFile(); if(file instanceof PsiPlainTextFile || file.getFileType() instanceof CustomSyntaxTableFileType) { return true; } if(SkipAutopopupInStrings.isInStringLiteral(position)) { return true; } PsiComment comment = PsiTreeUtil.getParentOfType(position, PsiComment.class, false); if(comment != null && !(comment instanceof PsiDocComment)) { return true; } return false; }
private static boolean mayContainClassName(CompletionParameters parameters) { PsiElement position = parameters.getPosition(); PsiFile file = position.getContainingFile(); if (file instanceof PsiPlainTextFile || file.getFileType() instanceof CustomSyntaxTableFileType) { return true; } if (SkipAutopopupInStrings.isInStringLiteral(position)) { return true; } if (PsiTreeUtil.getParentOfType(position, PsiComment.class, false) != null) { return true; } return false; }
@NotNull public Tokenizer getTokenizer(PsiElement element) { if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element)) { return EMPTY_TOKENIZER; } if (element instanceof PsiNameIdentifierOwner) return new PsiIdentifierOwnerTokenizer(); if (element instanceof PsiComment) { if (SuppressionUtil.isSuppressionComment(element)) { return EMPTY_TOKENIZER; } return myCommentTokenizer; } if (element instanceof XmlAttributeValue) return myXmlAttributeTokenizer; if (element instanceof XmlText) return myXmlTextTokenizer; if (element instanceof PsiPlainText) { PsiFile file = element.getContainingFile(); FileType fileType = file == null ? null : file.getFileType(); if (fileType instanceof CustomSyntaxTableFileType) { return new CustomFileTypeTokenizer(((CustomSyntaxTableFileType)fileType).getSyntaxTable()); } return TEXT_TOKENIZER; } if (element instanceof XmlToken) { if (((XmlToken)element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) { PsiElement injection = InjectedLanguageManager.getInstance(element.getProject()).findInjectedElementAt(element.getContainingFile(), element.getTextOffset()); if (injection == null) { return TEXT_TOKENIZER; } } } return EMPTY_TOKENIZER; }
@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; }
@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; }
public CustomFileTypeCompletionContributor() { extend(CompletionType.BASIC, psiElement().inFile(psiFile().withFileType(instanceOf(CustomSyntaxTableFileType.class))), new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { if (inCommentOrLiteral(parameters)) { return; } FileType fileType = parameters.getOriginalFile().getFileType(); if (!(fileType instanceof CustomSyntaxTableFileType)) { return; } SyntaxTable syntaxTable = ((CustomSyntaxTableFileType)fileType).getSyntaxTable(); String prefix = findPrefix(parameters.getPosition(), parameters.getOffset()); CompletionResultSet resultSetWithPrefix = result.withPrefixMatcher(prefix); addVariants(resultSetWithPrefix, syntaxTable.getKeywords1()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords2()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords3()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords4()); WordCompletionContributor.addWordCompletionVariants(resultSetWithPrefix, parameters, Collections.<String>emptySet()); } }); }
@Override protected void buildLanguageFoldRegions(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root, @NotNull Document document, boolean quick) { FileType fileType = root.getContainingFile().getFileType(); if (!(fileType instanceof CustomSyntaxTableFileType)) { return; } CustomFileHighlighter highlighter = new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); buildBraceMatcherBasedFolding(descriptors, root, document, highlighter); }
@Override @Nullable public SyntaxHighlighter create(@NotNull final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
@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(createWordScanner((CustomSyntaxTableFileType)fileType)); } return null; }
private static WordsScanner createWordScanner(final CustomSyntaxTableFileType customSyntaxTableFileType) { return new DefaultWordsScanner(new CustomFileTypeLexer(customSyntaxTableFileType.getSyntaxTable(), true), TokenSet.create(CustomHighlighterTokenType.IDENTIFIER), TokenSet.create(CustomHighlighterTokenType.LINE_COMMENT, CustomHighlighterTokenType.MULTI_LINE_COMMENT), TokenSet.create(CustomHighlighterTokenType.STRING, CustomHighlighterTokenType.SINGLE_QUOTED_STRING)); }
@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 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; }
@Override @Nullable public SyntaxHighlighter create(final FileType fileType, @Nullable final Project project, @Nullable final VirtualFile file) { if (fileType instanceof AbstractFileType) { return new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable()); } return null; }
@javax.annotation.Nullable public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, final VirtualFile virtualFile) { final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer; if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) { SubstitutedFileType sft = (SubstitutedFileType)fileType; extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, 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); LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile); final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null; if (commentTokens != null) { return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project); } } if (fileType instanceof CustomSyntaxTableFileType) { return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project); } return null; }
@javax.annotation.Nullable public static IdIndexer getFileTypeIndexer(FileType fileType) { final IdIndexer idIndexer = ourIdIndexers.get(fileType); if (idIndexer != null) { return idIndexer; } final IdIndexer 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(createWordScanner((CustomSyntaxTableFileType)fileType)); } return null; }
public CustomFileTypeCompletionContributor() { extend(CompletionType.BASIC, psiElement().inFile(psiFile().withFileType(instanceOf(CustomSyntaxTableFileType.class))), new CompletionProvider() { @RequiredReadAction @Override public void addCompletions(@Nonnull CompletionParameters parameters, ProcessingContext context, @Nonnull CompletionResultSet result) { if (inCommentOrLiteral(parameters)) { return; } FileType fileType = parameters.getOriginalFile().getFileType(); if (!(fileType instanceof CustomSyntaxTableFileType)) { return; } SyntaxTable syntaxTable = ((CustomSyntaxTableFileType)fileType).getSyntaxTable(); String prefix = findPrefix(parameters.getPosition(), parameters.getOffset()); CompletionResultSet resultSetWithPrefix = result.withPrefixMatcher(prefix); addVariants(resultSetWithPrefix, syntaxTable.getKeywords1()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords2()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords3()); addVariants(resultSetWithPrefix, syntaxTable.getKeywords4()); WordCompletionContributor.addWordCompletionVariants(resultSetWithPrefix, parameters, Collections.<String>emptySet()); } }); }
public static boolean isIndexable(FileType fileType) { return fileType instanceof LanguageFileType || fileType instanceof CustomSyntaxTableFileType || IdTableBuilding.isIdIndexerRegistered(fileType) || CacheBuilderRegistry.getInstance().getCacheBuilder(fileType) != null; }
@Override public boolean canSelect(PsiElement e) { return (e instanceof PsiPlainText || e instanceof PsiComment) && !(e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType); }
@Override public boolean canSelect(PsiElement e) { return e.getContainingFile().getFileType() instanceof CustomSyntaxTableFileType; }
private static boolean isIndexable(FileType fileType) { return fileType instanceof LanguageFileType || fileType instanceof CustomSyntaxTableFileType || IdTableBuilding.isIdIndexerRegistered(fileType) || CacheBuilderRegistry.getInstance().getCacheBuilder(fileType) != null; }
@Nullable private TextRange findCommentedRange(final Commenter commenter) { final CharSequence text = myDocument.getCharsSequence(); final FileType fileType = myFile.getFileType(); if (fileType instanceof CustomSyntaxTableFileType) { Lexer lexer = new CustomFileTypeLexer(((CustomSyntaxTableFileType)fileType).getSyntaxTable()); final int caretOffset = myEditor.getCaretModel().getOffset(); int commentStart = CharArrayUtil.lastIndexOf(text, commenter.getBlockCommentPrefix(), caretOffset); if (commentStart == -1) return null; lexer.start(text, commentStart, text.length()); if (lexer.getTokenType() == CustomHighlighterTokenType.MULTI_LINE_COMMENT && lexer.getTokenEnd() >= caretOffset) { return new TextRange(commentStart, lexer.getTokenEnd()); } return null; } final String prefix; final String suffix; final SelectionModel selectionModel = myEditor.getSelectionModel(); if (commenter instanceof SelfManagingCommenter) { SelfManagingCommenter selfManagingCommenter = (SelfManagingCommenter)commenter; prefix = selfManagingCommenter.getBlockCommentPrefix( selectionModel.getSelectionStart(), myDocument, mySelfManagedCommenterData ); suffix = selfManagingCommenter.getBlockCommentSuffix( selectionModel.getSelectionEnd(), myDocument, mySelfManagedCommenterData ); } else { prefix = trim(commenter.getBlockCommentPrefix()); suffix = trim(commenter.getBlockCommentSuffix()); } if (prefix == null || suffix == null) return null; TextRange commentedRange; if (commenter instanceof SelfManagingCommenter) { commentedRange = ((SelfManagingCommenter)commenter).getBlockCommentRange( selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), myDocument, mySelfManagedCommenterData ); } else { if (!testSelectionForNonComments()) { return null; } commentedRange = getSelectedComments(text, prefix, suffix); if (commentedRange == null) { PsiElement comment = findCommentAtCaret(); if (comment != null) { String commentText = comment.getText(); if (commentText.startsWith(prefix) && commentText.endsWith(suffix)) { commentedRange = comment.getTextRange(); } } } } return commentedRange; }
public MyCommenter(final CustomSyntaxTableFileType abstractFileType) { myAbstractFileType = abstractFileType; }