use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class StubUpdatingIndex method canHaveStub.
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;
}
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);
}
use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class StubVersionMap method getVersionOwner.
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;
}
use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class CoreStubTreeLoader method canHaveStub.
@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;
}
use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class ConvertToEntityFix method invoke.
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final XmlAttribute attribute = PsiTreeUtil.getContextOfType(myToken.getContainingFile(), XmlAttribute.class, true);
assert attribute != null;
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(myToken.getLanguage());
assert parserDefinition != null;
final PsiFile f = XPathChangeUtil.createXPathFile(myToken, "1 " + myValue + " 2");
final PsiElement firstChild = f.getFirstChild();
assert firstChild != null;
//
final XPathToken child = PsiTreeUtil.getChildOfType(firstChild, XPathToken.class);
assert child != null;
myToken.replace(child);
}
use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class IndexPatternSearcher method findCommentTokenRanges.
private static void findCommentTokenRanges(final PsiFile file, final CharSequence chars, final TextRange range, final TIntArrayList commentStarts, final TIntArrayList commentEnds) {
if (file instanceof PsiPlainTextFile) {
FileType fType = file.getFileType();
if (fType instanceof CustomSyntaxTableFileType) {
Lexer lexer = SyntaxHighlighterFactory.getSyntaxHighlighter(fType, file.getProject(), file.getVirtualFile()).getHighlightingLexer();
findComments(lexer, chars, range, COMMENT_TOKENS, commentStarts, commentEnds, null);
} else {
commentStarts.add(0);
commentEnds.add(file.getTextLength());
}
} else {
final FileViewProvider viewProvider = file.getViewProvider();
final Set<Language> relevantLanguages = viewProvider.getLanguages();
for (Language lang : relevantLanguages) {
final TIntArrayList commentStartsList = new TIntArrayList();
final TIntArrayList commentEndsList = new TIntArrayList();
final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(lang, file.getProject(), file.getVirtualFile());
Lexer lexer = syntaxHighlighter.getHighlightingLexer();
TokenSet commentTokens = null;
IndexPatternBuilder builderForFile = null;
for (IndexPatternBuilder builder : Extensions.getExtensions(IndexPatternBuilder.EP_NAME)) {
Lexer lexerFromBuilder = builder.getIndexingLexer(file);
if (lexerFromBuilder != null) {
lexer = lexerFromBuilder;
commentTokens = builder.getCommentTokenSet(file);
builderForFile = builder;
}
}
if (builderForFile == null) {
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
if (parserDefinition != null) {
commentTokens = parserDefinition.getCommentTokens();
}
}
if (commentTokens != null) {
findComments(lexer, chars, range, commentTokens, commentStartsList, commentEndsList, builderForFile);
mergeCommentLists(commentStarts, commentEnds, commentStartsList, commentEndsList);
}
}
}
}
Aggregations