use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GrCodeBlockElementType method getErrorsCount.
@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;
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovyParserDefinition method spaceExistanceTypeBetweenTokens.
@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) {
return SpaceRequirements.MAY;
}
if (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());
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovyDocTagValueTokenType method parseImpl.
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();
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class GroovyNamesUtil method isKeyword.
public static boolean isKeyword(@NotNull String name) {
final GroovyLexer lexer = new GroovyLexer();
lexer.start(name);
final IElementType type = lexer.getTokenType();
return TokenSets.KEYWORDS.contains(type);
}
use of org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer in project intellij-community by JetBrains.
the class PsiUtil method isValidReferenceName.
public static boolean isValidReferenceName(@NotNull String text) {
final GroovyLexer lexer = new GroovyLexer();
lexer.start(text);
return TokenSets.REFERENCE_NAMES_WITHOUT_NUMBERS.contains(lexer.getTokenType()) && lexer.getTokenEnd() == text.length();
}
Aggregations