Search in sources :

Example 6 with GroovyLexer

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;
}
Also used : PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) StudioSdkUtil.reloadRemoteSdkWithModalProgress(com.android.tools.idea.sdk.StudioSdkUtil.reloadRemoteSdkWithModalProgress) NonNavigatable(com.intellij.pom.NonNavigatable) IElementType(com.intellij.psi.tree.IElementType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) SyncIssue(com.android.builder.model.SyncIssue) TYPE_UNRESOLVED_DEPENDENCY(com.android.builder.model.SyncIssue.TYPE_UNRESOLVED_DEPENDENCY) RemotePackage(com.android.repository.api.RemotePackage) ArrayList(java.util.ArrayList) RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) com.android.tools.idea.gradle.project.sync.hyperlink(com.android.tools.idea.gradle.project.sync.hyperlink) Project(com.intellij.openapi.project.Project) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) Projects.isOfflineBuildModeEnabled(com.android.tools.idea.gradle.util.Projects.isOfflineBuildModeEnabled) IdeInfo(com.android.tools.idea.IdeInfo) AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) ERROR(com.android.tools.idea.gradle.project.sync.messages.MessageType.ERROR) GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) RepoPackage(com.android.repository.api.RepoPackage) Collection(java.util.Collection) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) TextRange(com.intellij.openapi.util.TextRange) ProgressIndicator(com.android.repository.api.ProgressIndicator) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Nullable(org.jetbrains.annotations.Nullable) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) Function(com.intellij.util.Function) Pair(com.intellij.openapi.util.Pair) SdkMavenRepository(com.android.ide.common.repository.SdkMavenRepository) GroovyTokenTypes.mSTRING_LITERAL(org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mSTRING_LITERAL) NotNull(org.jetbrains.annotations.NotNull) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) StringUtil.unquoteString(com.intellij.openapi.util.text.StringUtil.unquoteString) IElementType(com.intellij.psi.tree.IElementType) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) TextRange(com.intellij.openapi.util.TextRange) StringUtil.unquoteString(com.intellij.openapi.util.text.StringUtil.unquoteString) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GroovyLexer

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);
    }
}
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) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GroovyLexer

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

Example 9 with GroovyLexer

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) 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