com.intellij.lang.LanguageParserDefinitions Java Examples
The following examples show how to use
com.intellij.lang.LanguageParserDefinitions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilteredIndentsHighlightingPass.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example #2
Source File: FilteredIndentsHighlightingPass.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example #3
Source File: TextOccurrencesUtil.java From consulo with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: StubVersionMap.java From consulo with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: CSharpFileStubElementType.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Override protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull PsiElement psi) { final Project project = psi.getProject(); final Language languageForParser = getLanguageForParser(psi); final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY); final CSharpLanguageVersionWrapper languageVersion = (CSharpLanguageVersionWrapper) (tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion); Set<String> defVariables = getStableDefines((PsiFile) psi); final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars()); builder.putUserData(PREPROCESSOR_VARIABLES, defVariables); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #6
Source File: StubUpdatingIndex.java From consulo with Apache License 2.0 | 6 votes |
public static boolean canHaveStub(@Nonnull ProjectLocator projectLocator, @Nullable Project project, @Nonnull VirtualFile file) { FileType fileType = SubstitutedFileType.substituteFileType(file, file.getFileType(), project == null ? projectLocator.guessProjectForFile(file) : project); 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); }
Example #7
Source File: IgnoreFile.java From idea-gitignore with MIT License | 6 votes |
/** 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); }
Example #8
Source File: IndentsPass.java From consulo with Apache License 2.0 | 6 votes |
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); }
Example #9
Source File: LightApplicationBuilder.java From consulo with Apache License 2.0 | 6 votes |
@Override public void registerExtensionPointsAndExtensions(@Nonnull ExtensionsAreaImpl area) { registerExtensionPoint(area, ASTLazyFactory.EP.getExtensionPointName(), ASTLazyFactory.class); registerExtension(area, ASTLazyFactory.EP.getExtensionPointName(), new DefaultASTLazyFactory()); registerExtensionPoint(area, ASTLeafFactory.EP.getExtensionPointName(), ASTLeafFactory.class); registerExtension(area, ASTLeafFactory.EP.getExtensionPointName(), new DefaultASTLeafFactory()); registerExtensionPoint(area, ASTCompositeFactory.EP.getExtensionPointName(), ASTCompositeFactory.class); registerExtension(area, ASTCompositeFactory.EP.getExtensionPointName(), new DefaultASTCompositeFactory()); registerExtensionPoint(area, LanguageParserDefinitions.INSTANCE.getExtensionPointName(), LanguageExtensionPoint.class); registerExtensionPoint(area, LanguageSubstitutors.INSTANCE.getExtensionPointName(), LanguageExtensionPoint.class); registerExtensionPoint(area, LanguageVersionResolvers.INSTANCE.getExtensionPointName(), LanguageExtensionPoint.class); registerExtensionPoint(area, LanguageVersionDefines.INSTANCE.getExtensionPointName(), LanguageExtensionPoint.class); registerExtensionPoint(area, LanguageFileViewProviders.INSTANCE.getExtensionPointName(), LanguageExtensionPoint.class); registerExtensionPoint(area, PathMacroFilter.EP_NAME, PathMacroFilter.class); registerExtensionPoint(area, ExtensionExtender.EP_NAME, KeyedLazyInstanceEP.class); }
Example #10
Source File: FluidFileViewProvider.java From idea-php-typo3-plugin with MIT License | 6 votes |
@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 == FluidLanguage.INSTANCE) { return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); } else { return null; } }
Example #11
Source File: CacheUtil.java From consulo with Apache License 2.0 | 6 votes |
public static boolean isInComments(final IElementType tokenType, LanguageVersion languageVersion) { final Language language = tokenType.getLanguage(); //for (CommentTokenSetProvider provider : CommentTokenSetProvider.EXTENSION.allForLanguage(language)) { // if (provider.isInComments(tokenType)) { // return true; // } //} boolean inComments = false; final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language); if (parserDefinition != null) { final TokenSet commentTokens = parserDefinition.getCommentTokens(languageVersion); if (commentTokens.contains(tokenType)) { inComments = true; } } return inComments; }
Example #12
Source File: DefaultASTLeafFactory.java From consulo with Apache License 2.0 | 6 votes |
@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); }
Example #13
Source File: CoreStubTreeLoader.java From consulo with Apache License 2.0 | 6 votes |
@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 #14
Source File: PlatformIdTableBuilding.java From consulo with Apache License 2.0 | 5 votes |
@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; }
Example #15
Source File: DustFileViewProvider.java From Intellij-Dust with MIT License | 5 votes |
@Override protected PsiFile createFile(Language lang) { // creating file for main lang (HTML) if (lang == myTemplateDataLanguage) { PsiFileImpl file = (PsiFileImpl) LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); file.setContentElementType(templateDataElementType); return file; } else if (lang == DustLanguage.INSTANCE) { return LanguageParserDefinitions.INSTANCE.forLanguage(lang).createFile(this); } else { return null; } }
Example #16
Source File: FindManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private static TokenSet addTokenTypesForLanguage(FindModel model, Language lang, TokenSet tokensOfInterest) { ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (definition != null) { for (LanguageVersion languageVersion : lang.getVersions()) { tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInCommentsOnly() ? definition.getCommentTokens(languageVersion) : TokenSet.EMPTY); tokensOfInterest = TokenSet.orSet(tokensOfInterest, model.isInStringLiteralsOnly() ? definition.getStringLiteralElements(languageVersion) : TokenSet.EMPTY); } } return tokensOfInterest; }
Example #17
Source File: AbstractFileViewProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nullable protected PsiFile createFile(@Nonnull Language lang) { if (lang != getBaseLanguage()) return null; final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (parserDefinition != null) { return parserDefinition.createFile(this); } return null; }
Example #18
Source File: SkipAutopopupInStrings.java From consulo with Apache License 2.0 | 5 votes |
public static boolean isInStringLiteral(PsiElement element) { LanguageVersion languageVersion = PsiUtilCore.findLanguageVersionFromElement(element); ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(languageVersion.getLanguage()); if (definition == null) { return false; } return isStringLiteral(element, definition, languageVersion) || isStringLiteral(element.getParent(), definition, languageVersion) || isStringLiteralWithError(element, definition, languageVersion) || isStringLiteralWithError(element.getParent(), definition, languageVersion); }
Example #19
Source File: CSharpDocElements.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredReadAction protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull final PsiElement psi) { final Project project = psi.getProject(); CSharpDocLanguage docLanguage = CSharpDocLanguage.INSTANCE; final LanguageVersion languageVersion = LanguageVersionUtil.findDefaultVersion(docLanguage); DeprecatedCSharpDocLexer docLexer = new DeprecatedCSharpDocLexer(); final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, docLexer, docLanguage, languageVersion, chameleon.getChars()); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(docLanguage).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #20
Source File: CSharpPreprocessorElements.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull PsiElement psi) { final Project project = psi.getProject(); final Language languageForParser = getLanguageForParser(psi); final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY); final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion; final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new _CSharpMacroLexer(), languageForParser, languageVersion, chameleon.getChars()); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #21
Source File: LatteFileViewProvider.java From intellij-latte with MIT License | 5 votes |
@Nullable protected PsiFile createFile(@NotNull Language lang) { ParserDefinition parser = LanguageParserDefinitions.INSTANCE.forLanguage(lang); if (parser == null) { return null; } else if (lang == XMLLanguage.INSTANCE || lang == HTMLLanguage.INSTANCE) { PsiFileImpl file = (PsiFileImpl) parser.createFile(this); file.setContentElementType(templateDataElement); return file; } else { return lang == this.getBaseLanguage() ? parser.createFile(this) : null; } }
Example #22
Source File: HaxeProjectStructureDetector.java From intellij-haxe with Apache License 2.0 | 4 votes |
public String fun(final CharSequence charSequence) { Lexer lexer = LanguageParserDefinitions.INSTANCE.forLanguage(HaxeLanguage.INSTANCE).createLexer(null); lexer.start(charSequence); return readPackageName(charSequence, lexer); }
Example #23
Source File: TemplateDataElementType.java From consulo with Apache License 2.0 | 4 votes |
protected Lexer createBaseLexer(PsiFile file, TemplateLanguageFileViewProvider viewProvider) { final Language baseLanguage = viewProvider.getBaseLanguage(); final LanguageVersion languageVersion = LanguageVersionResolvers.INSTANCE.forLanguage(baseLanguage).getLanguageVersion(baseLanguage, file); return LanguageParserDefinitions.INSTANCE.forLanguage(viewProvider.getBaseLanguage()).createLexer(languageVersion); }
Example #24
Source File: BashEvalElementType.java From BashSupport with Apache License 2.0 | 4 votes |
@Override protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) { Project project = psi.getProject(); boolean supportEvalEscapes = BashProjectSettings.storedSettings(project).isEvalEscapesEnabled(); String originalText = chameleon.getChars().toString(); ParserDefinition def = LanguageParserDefinitions.INSTANCE.forLanguage(BashFileType.BASH_LANGUAGE); boolean isDoubleQuoted = originalText.startsWith("\"") && originalText.endsWith("\""); boolean isSingleQuoted = originalText.startsWith("'") && originalText.endsWith("'"); boolean isEscapingSingleQuoted = originalText.startsWith("$'") && originalText.endsWith("'"); boolean isUnquoted = !isDoubleQuoted && !isSingleQuoted && !isEscapingSingleQuoted; String prefix = isUnquoted ? "" : originalText.subSequence(0, isEscapingSingleQuoted ? 2 : 1).toString(); String content = isUnquoted ? originalText : originalText.subSequence(isEscapingSingleQuoted ? 2 : 1, originalText.length() - 1).toString(); String suffix = isUnquoted ? "" : originalText.subSequence(originalText.length() - 1, originalText.length()).toString(); TextPreprocessor textProcessor; if (supportEvalEscapes) { if (isEscapingSingleQuoted) { textProcessor = new BashEnhancedTextPreprocessor(TextRange.from(prefix.length(), content.length())); } else if (isSingleQuoted) { //no escape handling for single-quoted strings textProcessor = new BashIdentityTextPreprocessor(TextRange.from(prefix.length(), content.length())); } else { //fallback to simple escape handling textProcessor = new BashSimpleTextPreprocessor(TextRange.from(prefix.length(), content.length())); } } else { textProcessor = new BashIdentityTextPreprocessor(TextRange.from(prefix.length(), content.length())); } StringBuilder unescapedContent = new StringBuilder(content.length()); textProcessor.decode(content, unescapedContent); Lexer lexer = isUnquoted ? def.createLexer(project) : new PrefixSuffixAddingLexer(def.createLexer(project), prefix, TokenType.WHITE_SPACE, suffix, TokenType.WHITE_SPACE); PsiBuilder psiBuilder = new UnescapingPsiBuilder(project, def, lexer, chameleon, originalText, prefix + unescapedContent + suffix, textProcessor); return def.createParser(project).parse(this, psiBuilder).getFirstChildNode(); }
Example #25
Source File: SoyFileViewProvider.java From bamboo-soy with Apache License 2.0 | 4 votes |
private ParserDefinition getDefinition(Language lang) { return LanguageParserDefinitions.INSTANCE.forLanguage(lang); }