@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 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; }
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; }
private boolean isComment(int offset) { final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset); IElementType tokenType = it.getTokenType(); Language language = tokenType.getLanguage(); TokenSet comments = myComments.get(language); if (comments == null) { ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language); if (definition != null) { comments = definition.getCommentTokens(); } if (comments == null) { return false; } else { myComments.put(language, comments); } } return comments.contains(tokenType); }
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); }
@Override @NotNull public MultiHostRegistrar startInjecting(@NotNull Language language) { escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>(); shreds = new SmartList<PsiLanguageInjectionHost.Shred>(); outChars = new StringBuilder(); if (!cleared) { clear(); throw new IllegalStateException("Seems you haven't called doneInjecting()"); } if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) { ReferenceInjector injector = ReferenceInjector.findById(language.getID()); if (injector == null) { throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null"); } myLanguage = null; myReferenceInjector = injector; } myLanguage = language; return this; }
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) { TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() { @Override public boolean execute(@NotNull PsiElement element, int offsetInElement) { final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); final ASTNode node = element.getNode(); if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) { return processor.process(element); } return true; } }; return helper.processElementsWithWord(occurenceProcessor, searchScope, identifier, UsageSearchContext.IN_STRINGS, true); }
private static void registerProblemStart(@NotNull final AnnotationHolder holder, @NotNull final XmlTag tag, @NotNull final XmlToken start, @NotNull final XmlToken end) { PsiElement context = tag.getContainingFile().getContext(); if (context != null) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage()); if (parserDefinition != null) { ASTNode contextNode = context.getNode(); if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) { // TODO: we should check for concatenations here return; } } } final String tagName = tag.getName(); final String endTokenText = end.getText(); final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false); final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true); final Annotation annotation = holder.createErrorAnnotation(start, XmlErrorMessages.message("tag.has.wrong.closing.tag.name")); annotation.registerFix(renameEndAction); annotation.registerFix(renameStartAction); }
private static void registerProblemEnd(@NotNull final AnnotationHolder holder, @NotNull final XmlTag tag, @NotNull final XmlToken end) { PsiElement context = tag.getContainingFile().getContext(); if (context != null) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage()); if (parserDefinition != null) { ASTNode contextNode = context.getNode(); if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) { // TODO: we should check for concatenations here return; } } } final String tagName = tag.getName(); final String endTokenText = end.getText(); final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false); final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true); final Annotation annotation = holder.createErrorAnnotation(end, XmlErrorMessages.message("wrong.closing.tag.name")); annotation.registerFix(new RemoveExtraClosingTagIntentionAction()); annotation.registerFix(renameEndAction); annotation.registerFix(renameStartAction); }
public DtdParsing(CharSequence chars, final IElementType type, final XmlEntityDecl.EntityContextType contextType, PsiFile contextFile ) { this( type, contextType, PsiBuilderFactory.getInstance().createBuilder( LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE), new DtdLexer(false) { final int myInitialState = getLexerInitialState(type, contextType); @Override public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { super.start(buffer, startOffset, endOffset, myInitialState); } }, chars ) ); if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile); }
private static boolean isInsideStringLiteral(final Editor editor, final PsiFile file) { int offset = editor.getCaretModel().getOffset(); PsiElement element = file.findElementAt(offset); if (element == null) return false; final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); if (definition != null) { final TokenSet stringLiteralElements = definition.getStringLiteralElements(); final ASTNode node = element.getNode(); if (node == null) return false; final IElementType elementType = node.getElementType(); if (stringLiteralElements.contains(elementType)) { return true; } PsiElement parent = element.getParent(); if (parent != null) { ASTNode parentNode = parent.getNode(); if (parentNode != null && stringLiteralElements.contains(parentNode.getElementType())) { return true; } } } return false; }
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); }
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; }
@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; }
@Override @NotNull public MultiHostRegistrar startInjecting(@NotNull Language language) { escapers = new SmartList<LiteralTextEscaper<? extends PsiLanguageInjectionHost>>(); shreds = new SmartList<PsiLanguageInjectionHost.Shred>(); outChars = new StringBuilder(); if (!cleared) { clear(); throw new IllegalStateException("Seems you haven't called doneInjecting()"); } if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) { throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null"); } myLanguage = language; return this; }
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) { TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() { @Override public boolean execute(PsiElement element, int offsetInElement) { final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); final ASTNode node = element.getNode(); if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) { return processor.process(element); } return true; } }; return helper.processElementsWithWord(occurenceProcessor, searchScope, identifier, UsageSearchContext.IN_STRINGS, true); }
public DtdParsing(CharSequence chars, final IElementType type, final XmlEntityDecl.EntityContextType contextType, PsiFile contextFile ) { this( type, contextType, PsiBuilderFactory.getInstance().createBuilder( LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE), new DtdLexer(false) { final int myInitialState = getLexerInitialState(type, contextType); @Override public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { super.start(buffer, startOffset, endOffset, myInitialState); } }, chars ) ); if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile); }
/** Builds a new instance of {@link IgnoreFile}. */ public IgnoreFile(@NotNull FileViewProvider viewProvider, @NotNull IgnoreFileType fileType) { super(viewProvider); this.fileType = fileType; this.language = findLanguage(fileType.getLanguage(), viewProvider); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(this.language); if (parserDefinition == null) { throw new RuntimeException( "PsiFileBase: language.getParserDefinition() returned null for: " + this.language ); } this.parserDefinition = parserDefinition; final IFileElementType nodeType = parserDefinition.getFileNodeType(); init(nodeType, nodeType); }
@Override protected PsiFile createFile(@NotNull Language lang) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (parserDefinition == null) { return null; } Language templateDataLanguage = getTemplateDataLanguage(myManager, myFile); if (lang == templateDataLanguage) { PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this); file.setContentElementType(new TemplateDataElementType("Dot_TEMPLATE_DATA", templateDataLanguage, DotTokenTypes.CONTENT, DotTokenTypes.OUTER_ELEMENT_TYPE)); return file; } else if (lang == DotLanguage.INSTANCE) { return parserDefinition.createFile(this); } else { return null; } }
@Nullable @Override protected PsiFile createFile(@NotNull final Language lang) { if(lang == getBaseLanguage()) { return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); } if(lang == JavaLanguage.INSTANCE) { return new JspJavaFileImpl(this); } if(lang == getTemplateDataLanguage()) { PsiFileImpl file = (PsiFileImpl) LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); file.setContentElementType(JspTemplateTokens.HTML_TEMPLATE_DATA); return file; } return null; }
@Nonnull @Override public LeafElement createLeaf(@Nonnull IElementType type, @Nonnull LanguageVersion languageVersion, @Nonnull CharSequence text) { final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(type.getLanguage()); if(parserDefinition != null) { if(parserDefinition.getCommentTokens(languageVersion).contains(type)) { return new PsiCoreCommentImpl(type, text); } } // this is special case, then type is WHITE_SPACE, but no parser definition if(type == TokenType.WHITE_SPACE) { return new PsiWhiteSpaceImpl(text); } if (type instanceof ILeafElementType) { return (LeafElement)((ILeafElementType)type).createLeafNode(text); } return new LeafPsiElement(type, text); }
private boolean isComment(int offset) { final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset); IElementType tokenType = it.getTokenType(); Language language = tokenType.getLanguage(); TokenSet comments = myComments.get(language); if (comments == null) { ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language); if (definition != null) { comments = definition.getCommentTokens(LanguageVersionUtil.findLanguageVersion(language, myFile)); } if (comments == null) { return false; } else { myComments.put(language, comments); } } return comments.contains(tokenType); }
public static boolean canHaveStub(@Nonnull 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; } FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); if (file instanceof NewVirtualFile && fileBasedIndex instanceof FileBasedIndexImpl && ((FileBasedIndexImpl)fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile)file).getId(), file)) { return true; } } } final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); return builder != null && builder.acceptsFile(file); }
private static Object getVersionOwner(FileType fileType) { Object owner = null; 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) { owner = type; } } } BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType); if (builder != null) { owner = builder; } return owner; }
private static boolean processStringLiteralsContainingIdentifier(@Nonnull String identifier, @Nonnull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) { TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() { @Override public boolean execute(PsiElement element, int offsetInElement) { final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); final ASTNode node = element.getNode(); if (definition != null && node != null && definition.getStringLiteralElements(element.getLanguageVersion()).contains(node.getElementType())) { return processor.process(element); } return true; } }; return helper.processElementsWithWord(occurenceProcessor, searchScope, identifier, UsageSearchContext.IN_STRINGS, true); }
public DtdParsing(CharSequence chars, final IElementType type, final XmlEntityDecl.EntityContextType contextType, PsiFile contextFile ) { this( type, contextType, PsiBuilderFactory.getInstance().createBuilder( LanguageParserDefinitions.INSTANCE.forLanguage(DTDLanguage.INSTANCE), new DtdLexer(false) { final int myInitialState = getLexerInitialState(type, contextType); @Override public void start(CharSequence buffer, int startOffset, int endOffset, int initialState) { super.start(buffer, startOffset, endOffset, myInitialState); } }, LanguageVersionUtil.findDefaultVersion(DTDLanguage.INSTANCE), chars ) ); if (contextFile != null) myBuilder.putUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY, contextFile); }
private static ASTNode insertWhitespaceIfNeeded(ASTNode anchorNode, final ASTNode elementNode, final ASTNode parentNode, final ASTNode insertionPlaceNode) throws IncorrectOperationException { ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(parentNode.getPsi().getLanguage()); final TokenSet comments = parserDef.getCommentTokens(parentNode.getPsi().getLanguage().getVersions()[0]); final TokenSet whitespaces = parserDef.getWhitespaceTokens(parentNode.getPsi().getLanguage().getVersions()[0]); if(anchorNode != null && ((!whitespaces.contains(anchorNode.getElementType()) && !whitespaces.contains(elementNode.getElementType())) || comments.contains(anchorNode.getElementType()) || comments.contains(elementNode.getElementType()) || elementNode.getPsi() instanceof PsiComment)) { String commentString = " "; if(comments.contains(anchorNode.getElementType()) || comments.contains(elementNode.getElementType()) || elementNode.getPsi() instanceof PsiComment) { commentString = "\n"; } final ASTNode wsNode = PsiParserFacade.SERVICE.getInstance(parentNode.getPsi().getProject()).createWhiteSpaceFromText(commentString).getNode(); parentNode.addChild(wsNode, insertionPlaceNode); anchorNode = wsNode; } return anchorNode; }
private ParserDefinition getDefinition(Language lang) { ParserDefinition parserDefinition; if (lang.isKindOf(getBaseLanguage())) { parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang.is(getBaseLanguage()) ? lang : getBaseLanguage()); } else { parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); } return parserDefinition; }
@Nullable @Override protected PsiFile createFile(@NotNull Language lang) { if (lang == myTemplateDataLanguage) { PsiFileImpl file = (PsiFileImpl) LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); file.setContentElementType(TEMPLATE_DATA); return file; } else if (lang == JetLanguage.INSTANCE) { return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); } else { return null; } }
@Override public TokenSet getCommentTokenSet(@NotNull final PsiFile file) { final JspFile jspFile = JspPsiUtil.getJspFile(file); TokenSet commentTokens = TokenSet.orSet(JavaIndexPatternBuilder.XML_COMMENT_BIT_SET, StdTokenSets.COMMENT_BIT_SET); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(jspFile.getViewProvider().getTemplateDataLanguage()); if (parserDefinition != null) { commentTokens = TokenSet.orSet(commentTokens, parserDefinition.getCommentTokens()); } return commentTokens; }
private static boolean isComment(final ASTNode node) { final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node); if (psiElement instanceof PsiComment) return true; final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage()); if (parserDefinition == null) return false; final TokenSet commentTokens = parserDefinition.getCommentTokens(); return commentTokens.contains(node.getElementType()); }
@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; }
public static boolean isInStringLiteral(PsiElement element) { ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(PsiUtilCore.findLanguageFromElement(element)); if (definition == null) { return false; } return isStringLiteral(element, definition) || isStringLiteral(element.getParent(), definition) || isStringLiteralWithError(element, definition) || isStringLiteralWithError(element.getParent(), definition); }
protected boolean isStringLiteral(PsiElement element) { if (element == null) return false; final ASTNode astNode = element.getNode(); if (astNode == null) { return false; } final IElementType elementType = astNode.getElementType(); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); if (parserDefinition != null) { final TokenSet literals = parserDefinition.getStringLiteralElements(); return literals.contains(elementType); } return false; }
private void doVisitElement(PsiElement element) { CompiledPattern pattern = myGlobalVisitor.getContext().getPattern(); if (myGlobalVisitor.getCodeBlockLevel() == 0) { initTopLevelElement(element); return; } if (canBePatternVariable(element) && pattern.isRealTypedVar(element)) { myGlobalVisitor.handle(element); final MatchingHandler handler = pattern.getHandler(element); handler.setFilter(new NodeFilter() { public boolean accepts(PsiElement other) { return canBePatternVariableValue(other); } }); super.visitElement(element); return; } super.visitElement(element); if (myGlobalVisitor.getContext().getSearchHelper().doOptimizing() && element instanceof LeafElement) { ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage()); if (parserDefinition != null) { String text = element.getText(); // todo: support variables inside comments boolean flag = true; if (StringUtil.isJavaIdentifier(text) && flag) { myGlobalVisitor.processTokenizedName(text, true, GlobalCompilingVisitor.OccurenceKind.CODE); } } } }
@Nullable protected PsiFile createFile(@NotNull Language lang) { if (lang != getBaseLanguage()) return null; final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (parserDefinition != null) { return parserDefinition.createFile(this); } return null; }
public static boolean isInComments(final IElementType tokenType) { final Language language = tokenType.getLanguage(); boolean inComments = false; final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language); if (parserDefinition != null) { final TokenSet commentTokens = parserDefinition.getCommentTokens(); if (commentTokens.contains(tokenType)) { inComments = true; } } return inComments; }
private static TokenSet addTokenTypesForLanguage(FindModel model, Language lang, TokenSet tokensOfInterest) { ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (definition != null) { tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens(): TokenSet.EMPTY); tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements() : TokenSet.EMPTY); } return tokensOfInterest; }