本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer类的典型用法代码示例。如果您正苦于以下问题:Java GroovyLexer类的具体用法?Java GroovyLexer怎么用?Java GroovyLexer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GroovyLexer类属于org.jetbrains.plugins.groovy.lang.lexer包,在下文中一共展示了GroovyLexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateGradleDependencyVersion
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
/**
* Updates the version of a Gradle dependency used in a build.gradle file.
*
* @param project the project containing the build.gradle file.
* @param buildFileDocument document of the build.gradle file, which declares the version of the dependency.
* @param dependencyName the name of the dependency to look for.
* @param versionTask returns the version of the dependency to update the file to.
* @return {@code true} if the build.gradle file was updated; {@code false} otherwise.
*/
public static boolean updateGradleDependencyVersion(@NotNull Project project,
@NotNull final Document buildFileDocument,
@NotNull final String dependencyName,
@NotNull final Computable<String> versionTask) {
String contents = buildFileDocument.getText();
final TextRange range = findStringLiteral(dependencyName, contents, new Function<Pair<String, GroovyLexer>, TextRange>() {
@Override
public TextRange fun(Pair<String, GroovyLexer> pair) {
GroovyLexer lexer = pair.getSecond();
return TextRange.create(lexer.getTokenStart() + 1 + dependencyName.length(), lexer.getTokenEnd() - 1);
}
});
if (range != null) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
buildFileDocument.replaceString(range.getStartOffset(), range.getEndOffset(), versionTask.compute());
}
});
return true;
}
return false;
}
示例2: 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;
}
示例3: getErrorsCount
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@Override
public int getErrorsCount(final CharSequence seq, Language fileLanguage, final Project project) {
final Lexer lexer = new GroovyLexer();
lexer.start(seq);
if (lexer.getTokenType() != GroovyTokenTypes.mLCURLY) return FATAL_ERROR;
lexer.advance();
int balance = 1;
while (true) {
IElementType type = lexer.getTokenType();
if (type == null) break;
if (balance == 0) return FATAL_ERROR;
if (type == GroovyTokenTypes.mLCURLY) {
balance++;
}
else if (type == GroovyTokenTypes.mRCURLY) {
balance--;
}
lexer.advance();
}
return balance;
}
示例4: parseImpl
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
private ASTNode parseImpl(ASTNode chameleon) {
final PsiElement parentElement = chameleon.getTreeParent().getPsi();
final Project project = parentElement.getProject();
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), getLanguage(), chameleon.getText());
PsiBuilder.Marker rootMarker = builder.mark();
if (BUILT_IN_TYPES.contains(chameleon.getText())) {
builder.advanceLexer();
} else {
ReferenceElement.parse(builder, false, false, false, false, false);
while (!builder.eof()) {
builder.advanceLexer();
}
}
rootMarker.done(this);
return builder.getTreeBuilt().getFirstChildNode();
}
示例5: 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;
}
示例6: parseContents
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@Override
public ASTNode parseContents(ASTNode chameleon)
{
Project project = chameleon.getTreeParent().getPsi().getProject();
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), GroovyFileType.GROOVY_LANGUAGE,
LanguageVersionUtil.findDefaultVersion(GroovyFileType.GROOVY_LANGUAGE), chameleon.getText());
PsiBuilder.Marker mark = builder.mark();
GroovyParser.parseExpression(builder);
if(!builder.eof())
{
builder.error("expression expected");
while(!builder.eof())
{
builder.advanceLexer();
}
}
mark.done(GroovyParserDefinition.GROOVY_FILE);
return builder.getTreeBuilt().getFirstChildNode();
}
示例7: 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;
}
示例8: getPluginDefinition
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
/**
* Returns target plugin's definition.
*
* @param fileContents target Gradle build file contents
* @param pluginName target plugin's name in a form {@code group-id:artifact-id:}
* @return target plugin's definition if found; {@code null} otherwise
*/
@Nullable
public static GradleCoordinate getPluginDefinition(@NotNull String fileContents, @NotNull String pluginName) {
String definition = findStringLiteral(pluginName, fileContents, new Function<Pair<String, GroovyLexer>, String>() {
@Override
public String fun(Pair<String, GroovyLexer> pair) {
return pair.getFirst();
}
});
return isNotEmpty(definition) ? parseCoordinateString(definition) : null;
}
示例9: findDependency
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@Nullable
public static TextRange findDependency(@NotNull final String dependency, @NotNull String contents) {
return findStringLiteral(dependency, contents, new Function<Pair<String, GroovyLexer>, TextRange>() {
@Override
public TextRange fun(Pair<String, GroovyLexer> pair) {
GroovyLexer lexer = pair.getSecond();
return TextRange.create(lexer.getTokenStart() + 1, lexer.getTokenEnd() - 1);
}
});
}
示例10: getPluginDefinitionString
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
/**
* Delegates to the {@link #forPluginDefinition(String, String, Function)} and just returns target plugin's definition string (unquoted).
*
* @param fileContents target gradle config text
* @param pluginName target plugin's name in a form <code>'group-id:artifact-id:'</code>
* @return target plugin's definition string if found (unquoted); <code>null</code> otherwise
* @see #forPluginDefinition(String, String, Function)
*/
@Nullable
public static String getPluginDefinitionString(@NotNull String fileContents, @NotNull String pluginName) {
return forPluginDefinition(fileContents, pluginName, new Function<Pair<String, GroovyLexer>, String>() {
@Override
public String fun(Pair<String, GroovyLexer> pair) {
return pair.getFirst();
}
});
}
示例11: GroovyHighlightingLexer
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
private GroovyHighlightingLexer() {
super(new GroovyLexer());
registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, GroovyTokenTypes.mSTRING_LITERAL, true, "$"),
new IElementType[]{GroovyTokenTypes.mSTRING_LITERAL}, IElementType.EMPTY_ARRAY);
registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, GroovyTokenTypes.mGSTRING_LITERAL, true, "$"),
new IElementType[]{GroovyTokenTypes.mGSTRING_LITERAL}, IElementType.EMPTY_ARRAY);
registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, GroovyTokenTypes.mGSTRING_CONTENT, true, "$"),
new IElementType[]{GroovyTokenTypes.mGSTRING_CONTENT}, IElementType.EMPTY_ARRAY);
registerSelfStoppingLayer(new GroovySlashyStringLexer(), new IElementType[]{GroovyTokenTypes.mREGEX_CONTENT}, IElementType.EMPTY_ARRAY);
registerSelfStoppingLayer(new GroovyDollarSlashyStringLexer(), new IElementType[]{GroovyTokenTypes.mDOLLAR_SLASH_REGEX_CONTENT}, IElementType.EMPTY_ARRAY);
}
示例12: spaceExistanceTypeBetweenTokens
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@Override
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
final IElementType lType = left.getElementType();
final IElementType rType = right.getElementType();
if (rType == GroovyTokenTypes.kIMPORT && lType != TokenType.WHITE_SPACE) {
return SpaceRequirements.MUST_LINE_BREAK;
}
else if (lType == MODIFIERS && rType == MODIFIERS) {
return SpaceRequirements.MUST;
}
if (lType == GroovyTokenTypes.mSEMI || lType == GroovyTokenTypes.mSL_COMMENT) {
return SpaceRequirements.MUST_LINE_BREAK;
}
if (lType == GroovyTokenTypes.mNLS || lType == GroovyDocTokenTypes.mGDOC_COMMENT_START) {
return SpaceRequirements.MAY;
}
if (lType == GroovyTokenTypes.mGT) return SpaceRequirements.MUST;
if (rType == GroovyTokenTypes.mLT) return SpaceRequirements.MUST;
final ASTNode parent = TreeUtil.findCommonParent(left, right);
if (parent == null || ArrayUtil.contains(parent.getElementType(), STRINGS)) {
return SpaceRequirements.MUST_NOT;
}
return LanguageUtil.canStickTokensTogetherByLexer(left, right, new GroovyLexer());
}
示例13: isIdentifier
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
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;
}
示例14: getIndexingLexer
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@Override
public Lexer getIndexingLexer(@NotNull PsiFile file) {
if (file instanceof GroovyFile) {
return new GroovyLexer();
}
return null;
}
示例15: getPackageName
import org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer; //导入依赖的package包/类
@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);
}
}