use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project android by JetBrains.
the class UnresolvedDependenciesReporter method findDependency.
@Nullable
private static TextRange findDependency(@NotNull String dependency, @NotNull Document buildFile) {
Function<Pair<String, GroovyLexer>, TextRange> consumer = pair -> {
GroovyLexer lexer = pair.getSecond();
return TextRange.create(lexer.getTokenStart() + 1, lexer.getTokenEnd() - 1);
};
GroovyLexer lexer = new GroovyLexer();
lexer.start(buildFile.getText());
while (lexer.getTokenType() != null) {
IElementType type = lexer.getTokenType();
if (type == mSTRING_LITERAL) {
String text = unquoteString(lexer.getTokenText());
if (text.startsWith(dependency)) {
return consumer.fun(Pair.create(text, lexer));
}
}
lexer.advance();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovySourceRootDetector method getPackageName.
@Nullable
public static String getPackageName(CharSequence text) {
Lexer lexer = new GroovyLexer();
lexer.start(text);
skipWhitespacesAndComments(lexer);
final IElementType firstToken = lexer.getTokenType();
if (firstToken != GroovyTokenTypes.kPACKAGE) {
return "";
}
lexer.advance();
skipWhitespacesAndComments(lexer);
final StringBuilder buffer = StringBuilderSpinAllocator.alloc();
try {
while (true) {
if (lexer.getTokenType() != GroovyTokenTypes.mIDENT)
break;
buffer.append(text, lexer.getTokenStart(), lexer.getTokenEnd());
lexer.advance();
skipWhitespacesAndComments(lexer);
if (lexer.getTokenType() != GroovyTokenTypes.mDOT)
break;
buffer.append('.');
lexer.advance();
skipWhitespacesAndComments(lexer);
}
String packageName = buffer.toString();
if (packageName.isEmpty() || StringUtil.endsWithChar(packageName, '.'))
return null;
return packageName;
} finally {
StringBuilderSpinAllocator.dispose(buffer);
}
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovyNamesUtil method isIdentifier.
public static boolean isIdentifier(@Nullable String text) {
if (text == null)
return false;
Lexer lexer = new GroovyLexer();
lexer.start(text);
if (lexer.getTokenType() != GroovyTokenTypes.mIDENT)
return false;
lexer.advance();
return lexer.getTokenType() == null;
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovyEnterHandler method checkStringApplicable.
private static boolean checkStringApplicable(Editor editor, int caret) {
final GroovyLexer lexer = new GroovyLexer();
lexer.start(editor.getDocument().getText());
while (lexer.getTokenEnd() < caret) {
lexer.advance();
}
final IElementType leftToken = lexer.getTokenType();
if (lexer.getTokenEnd() <= caret)
lexer.advance();
final IElementType rightToken = lexer.getTokenType();
if (!(ALL_STRINGS.contains(leftToken))) {
return false;
}
if (BEFORE_DOLLAR.contains(leftToken) && !AFTER_DOLLAR.contains(rightToken)) {
return false;
}
if (EXPR_END.contains(leftToken) && !AFTER_EXPR_END.contains(rightToken)) {
return false;
}
if (STRING_END.contains(leftToken) && !STRING_END.contains(rightToken)) {
return false;
}
return true;
}
Aggregations