本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer.advance方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyLexer.advance方法的具体用法?Java GroovyLexer.advance怎么用?Java GroovyLexer.advance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer
的用法示例。
在下文中一共展示了GroovyLexer.advance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findStringLiteral
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入方法依赖的package包/类
@Nullable
private static <T> T findStringLiteral(@NotNull String textToSearchPrefix,
@NotNull String fileContents,
@NotNull Function<Pair<String, GroovyLexer>, T> consumer) {
GroovyLexer lexer = new GroovyLexer();
lexer.start(fileContents);
while (lexer.getTokenType() != null) {
IElementType type = lexer.getTokenType();
if (type == GroovyTokenTypes.mSTRING_LITERAL) {
String text = unquoteString(lexer.getTokenText());
if (text.startsWith(textToSearchPrefix)) {
return consumer.fun(Pair.create(text, lexer));
}
}
lexer.advance();
}
return null;
}
示例2: checkStringApplicable
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入方法依赖的package包/类
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;
}
示例3: findCompileSdkVersionValueOffset
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入方法依赖的package包/类
@VisibleForTesting
static int findCompileSdkVersionValueOffset(@NotNull String buildFileContents) {
GroovyLexer lexer = new GroovyLexer();
lexer.start(buildFileContents);
int end = -1;
while (lexer.getTokenType() != null) {
IElementType type = lexer.getTokenType();
String text = lexer.getTokenText();
if (type == GroovyTokenTypes.mIDENT) {
if ("compileSdkVersion".equals(text)) {
end = lexer.getTokenEnd();
}
else if (end > -1) {
return end;
}
}
else if (type == TokenType.WHITE_SPACE && end > -1) {
end++;
}
else if (end > -1) {
return end;
}
lexer.advance();
}
return -1;
}
示例4: forPluginDefinition
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入方法依赖的package包/类
/**
* Checks given file contents (assuming that it's build.gradle config) and finds target plugin's definition (given the plugin
* name in a form <code>'group-id:artifact-id:'</code>. Supplies given callback with the plugin definition string (unquoted) and
* a {@link GroovyLexer} which state points to the plugin definition string (quoted).
* <p/>
* Example:
* <pre>
* buildscript {
* repositories {
* mavenCentral()
* }
* dependencies {
* classpath 'com.google.appengine:gradle-appengine-plugin:1.9.4'
* }
* }
* </pre>
* Suppose that this method is called for the given build script content and
* <code>'com.google.appengine:gradle-appengine-plugin:'</code> as a plugin name argument. Given callback is supplied by a
* string <code>'com.google.appengine:gradle-appengine-plugin:1.9.4'</code> (without quotes) and a {@link GroovyLexer} which
* {@link GroovyLexer#getTokenStart() points} to the string <code>'com.google.appengine:gradle-appengine-plugin:1.9.4'</code>
* (with quotes), i.e. we can get exact text range for the target string in case we need to do something like replacing plugin's
* version.
*
* @param fileContents target gradle config text
* @param pluginName target plugin's name in a form <code>'group-id:artifact-id:'</code>
* @param consumer a callback to be notified for the target plugin's definition string
* @param <T> given callback's return type
* @return given callback's call result if target plugin definition is found; <code>null</code> otherwise
*/
@Nullable
public static <T> T forPluginDefinition(@NotNull String fileContents,
@NotNull String pluginName,
@NotNull Function<Pair<String, GroovyLexer>, T> consumer) {
GroovyLexer lexer = new GroovyLexer();
lexer.start(fileContents);
while (lexer.getTokenType() != null) {
IElementType type = lexer.getTokenType();
if (type == GroovyTokenTypes.mSTRING_LITERAL) {
String text = unquoteString(lexer.getTokenText());
if (text.startsWith(pluginName)) {
return consumer.fun(Pair.create(text, lexer));
}
}
lexer.advance();
}
return null;
}