Search in sources :

Example 1 with GroovyLexer

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Lexer(com.intellij.lexer.Lexer) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer)

Example 2 with GroovyLexer

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());
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) ASTNode(com.intellij.lang.ASTNode)

Example 3 with 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();
}
Also used : Project(com.intellij.openapi.project.Project) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) PsiBuilder(com.intellij.lang.PsiBuilder) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 4 with GroovyLexer

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);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer)

Example 5 with GroovyLexer

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();
}
Also used : GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer)

Aggregations

GroovyLexer (org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer)9 IElementType (com.intellij.psi.tree.IElementType)6 Lexer (com.intellij.lexer.Lexer)3 Project (com.intellij.openapi.project.Project)2 SyncIssue (com.android.builder.model.SyncIssue)1 TYPE_UNRESOLVED_DEPENDENCY (com.android.builder.model.SyncIssue.TYPE_UNRESOLVED_DEPENDENCY)1 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 SdkMavenRepository (com.android.ide.common.repository.SdkMavenRepository)1 ProgressIndicator (com.android.repository.api.ProgressIndicator)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoPackage (com.android.repository.api.RepoPackage)1 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 IdeInfo (com.android.tools.idea.IdeInfo)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 com.android.tools.idea.gradle.project.sync.hyperlink (com.android.tools.idea.gradle.project.sync.hyperlink)1 ERROR (com.android.tools.idea.gradle.project.sync.messages.MessageType.ERROR)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1