use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class StructuralSearchProfileBase method isStringLiteral.
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;
}
use of com.intellij.lang.ParserDefinition in project android by JetBrains.
the class GradleEditorValueExtractor method visitReferenceExpression.
@Override
public void visitReferenceExpression(GrReferenceExpression expression) {
if (expression.getParent() instanceof GrMethodCallExpression) {
// This is a reference expression which points to the method name. We're not interested in it, so, just return.
return;
}
GrExpression qualifier = expression.getQualifierExpression();
if (qualifier == null) {
myContext.addCachedVariable(expression.getText(), expression.getTextRange());
return;
}
myContext.rememberVariableQualifier(qualifier.getText());
PsiElement dotToken = expression.getDotToken();
if (dotToken == null) {
return;
}
ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.findSingle(GroovyLanguage.INSTANCE);
for (PsiElement e = dotToken.getNextSibling(); e != null; e = e.getNextSibling()) {
ASTNode node = e.getNode();
if (node == null) {
if (e instanceof PsiWhiteSpace) {
continue;
}
e.accept(myVisitor);
return;
}
IElementType type = node.getElementType();
if (type == GroovyTokenTypes.mIDENT) {
myContext.addCachedVariable(e.getText(), e.getTextRange());
} else if (parserDefinition.getWhitespaceTokens().contains(type) || parserDefinition.getCommentTokens().contains(type)) {
continue;
} else {
e.accept(myVisitor);
}
return;
}
}
use of com.intellij.lang.ParserDefinition in project intellij-plugins by JetBrains.
the class HbFileViewProvider method createFile.
@Override
protected PsiFile createFile(@NotNull Language lang) {
ParserDefinition parserDefinition = getDefinition(lang);
if (parserDefinition == null) {
return null;
}
if (lang.is(getTemplateDataLanguage())) {
PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
return file;
} else if (lang.isKindOf(getBaseLanguage())) {
return parserDefinition.createFile(this);
} else {
return null;
}
}
use of com.intellij.lang.ParserDefinition in project intellij-community by JetBrains.
the class RegExpElementImpl method isLiteralExpression.
public static boolean isLiteralExpression(@Nullable PsiElement context) {
if (context == null)
return false;
final ASTNode astNode = context.getNode();
if (astNode == null) {
return false;
}
final IElementType elementType = astNode.getElementType();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
return parserDefinition.getStringLiteralElements().contains(elementType);
}
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