Search in sources :

Example 46 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class ImportMavenRepositoriesTask method findMavenRemoteRepositories.

@NotNull
private Collection<? extends MavenRemoteRepository> findMavenRemoteRepositories(@Nullable GrClosableBlock repositoriesBlock) {
    Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
    for (GrMethodCall repo : PsiTreeUtil.getChildrenOfTypeAsList(repositoriesBlock, GrMethodCall.class)) {
        final String expressionText = repo.getInvokedExpression().getText();
        if ("mavenCentral".equals(expressionText)) {
            myRemoteRepositories.add(mavenCentralRemoteRepository);
        } else if ("mavenRepo".equals(expressionText)) {
            for (GrNamedArgument namedArgument : repo.getNamedArguments()) {
                if ("url".equals(namedArgument.getLabelName())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(namedArgument.getExpression());
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                    break;
                }
            }
        } else if ("maven".equals(expressionText) && repo.getClosureArguments().length > 0) {
            List<GrApplicationStatement> applicationStatementList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrApplicationStatement.class);
            if (!applicationStatementList.isEmpty()) {
                GrApplicationStatement statement = applicationStatementList.get(0);
                if (statement == null)
                    continue;
                GrExpression expression = statement.getInvokedExpression();
                if ("url".equals(expression.getText())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getExpressionArguments()[0]);
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                }
            }
            List<GrAssignmentExpression> assignmentExpressionList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrAssignmentExpression.class);
            if (!assignmentExpressionList.isEmpty()) {
                GrAssignmentExpression statement = assignmentExpressionList.get(0);
                if (statement == null)
                    continue;
                GrExpression expression = statement.getLValue();
                if ("url".equals(expression.getText())) {
                    URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getRValue());
                    if (urlArgumentValue != null) {
                        String textUri = urlArgumentValue.toString();
                        myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
                    }
                }
            }
        }
    }
    return myRemoteRepositories;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) URI(java.net.URI) GrApplicationStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.

the class GradleGroovyFile method getValueStatic.

/**
   * Returns the value in the file for the given key, or null if not present.
   */
@Nullable
static Object getValueStatic(@NotNull GrStatementOwner root, @NotNull BuildFileKey key) {
    GrMethodCall method = getMethodCallByPath(root, key.getPath());
    if (method == null) {
        return null;
    }
    GroovyPsiElement arg = key.getType() == BuildFileKeyType.CLOSURE ? getMethodClosureArgument(method) : getFirstArgument(method);
    if (arg == null) {
        return null;
    }
    return key.getValue(arg);
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.

the class GradleBuildFile method getPlugins.

/**
   * Returns a list of all the plugins used by the given build file.
   */
@NotNull
public static List<String> getPlugins(GroovyFile buildScript) {
    List<String> plugins = Lists.newArrayListWithExpectedSize(1);
    for (GrMethodCall methodCall : getMethodCalls(buildScript, "apply")) {
        Map<String, Object> values = getNamedArgumentValues(methodCall);
        Object plugin = values.get("plugin");
        if (plugin != null) {
            plugins.add(plugin.toString());
        }
    }
    return plugins;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.

the class GradleGroovyFile method setValueStatic.

/**
   * Sets the value for the given key
   */
static void setValueStatic(@NotNull GrStatementOwner root, @NotNull BuildFileKey key, @NotNull Object value, boolean reformatClosure, @Nullable ValueFactory.KeyFilter filter) {
    if (value == GradleBuildFile.UNRECOGNIZED_VALUE) {
        return;
    }
    GrMethodCall method = getMethodCallByPath(root, key.getPath());
    if (method == null) {
        method = createNewValue(root, key, value, reformatClosure);
        if (key.getType() != BuildFileKeyType.CLOSURE) {
            return;
        }
    }
    if (method != null) {
        GroovyPsiElement arg = key.getType() == BuildFileKeyType.CLOSURE ? getMethodClosureArgument(method) : getFirstArgument(method);
        if (arg == null) {
            return;
        }
        key.setValue(arg, value, filter);
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)

Example 50 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-plugins by JetBrains.

the class GrStepDefinitionCreator method buildStepDefinitionByStep.

private static GrMethodCall buildStepDefinitionByStep(@NotNull final GherkinStep step) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(step.getProject());
    final Step cucumberStep = new Step(Collections.emptyList(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
    SnippetGenerator generator = new SnippetGenerator(new GroovySnippet());
    final String fqnPendingException;
    if (GrCucumberUtil.isCucumber_1_1_orAbove(step)) {
        fqnPendingException = "cucumber.api.PendingException";
    } else {
        fqnPendingException = "cucumber.runtime.PendingException";
    }
    String snippet = generator.getSnippet(cucumberStep, null).replace("PendingException", fqnPendingException);
    return (GrMethodCall) factory.createStatementFromText(snippet, step);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) SnippetGenerator(cucumber.runtime.snippets.SnippetGenerator) Step(gherkin.formatter.model.Step) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) GroovySnippet(cucumber.runtime.groovy.GroovySnippet)

Aggregations

GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)51 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)23 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)22 Nullable (org.jetbrains.annotations.Nullable)18 PsiElement (com.intellij.psi.PsiElement)17 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)13 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)9 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 NotNull (org.jetbrains.annotations.NotNull)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 PsiMethod (com.intellij.psi.PsiMethod)3 PsiType (com.intellij.psi.PsiType)3 ArrayList (java.util.ArrayList)3 GroovyMapContentProvider (org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider)3 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)3 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)3