Search in sources :

Example 91 with GrReferenceExpression

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

the class ResolveUtil method getCallVariants.

public static GroovyResolveResult[] getCallVariants(GroovyPsiElement place) {
    final PsiElement parent = place.getParent();
    GroovyResolveResult[] variants = GroovyResolveResult.EMPTY_ARRAY;
    if (parent instanceof GrCallExpression) {
        variants = ((GrCallExpression) parent).getCallVariants(place instanceof GrExpression ? (GrExpression) place : null);
    } else if (parent instanceof GrConstructorInvocation) {
        final PsiClass clazz = ((GrConstructorInvocation) parent).getDelegatedClass();
        if (clazz != null) {
            final PsiMethod[] constructors = clazz.getConstructors();
            variants = getConstructorResolveResult(constructors, place);
        }
    } else if (parent instanceof GrAnonymousClassDefinition) {
        final PsiElement element = ((GrAnonymousClassDefinition) parent).getBaseClassReferenceGroovy().resolve();
        if (element instanceof PsiClass) {
            final PsiMethod[] constructors = ((PsiClass) element).getConstructors();
            variants = getConstructorResolveResult(constructors, place);
        }
    } else if (place instanceof GrReferenceExpression) {
        variants = ((GrReferenceExpression) place).getSameNameVariants();
    }
    return variants;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression) GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 92 with GrReferenceExpression

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

the class GradleFilePsiMerger method pullDependenciesIntoMap.

/**
   * Looks for statements adding dependencies to different configurations (which look like 'configurationName "dependencyCoordinate"')
   * and tries to parse them into Gradle coordinates. If successful, adds the new coordinate to the map and removes the corresponding
   * PsiElement from the tree.
   *
   * @return true if new items were added to the map
   */
private static boolean pullDependenciesIntoMap(@NotNull PsiElement root, @NotNull Map<String, Multimap<String, GradleCoordinate>> allConfigurations, @Nullable List<String> unparsedDependencies) {
    boolean wasMapUpdated = false;
    for (PsiElement existingElem : root.getChildren()) {
        if (existingElem instanceof GrCall) {
            PsiElement reference = existingElem.getFirstChild();
            if (reference instanceof GrReferenceExpression) {
                final String configurationName = reference.getText();
                boolean parsed = false;
                GrCall call = (GrCall) existingElem;
                GrArgumentList arguments = call.getArgumentList();
                // Don't try merging dependencies if one of them has a closure block attached.
                if (arguments != null && call.getClosureArguments().length == 0) {
                    GrExpression[] expressionArguments = arguments.getExpressionArguments();
                    if (expressionArguments.length == 1 && expressionArguments[0] instanceof GrLiteral) {
                        Object value = ((GrLiteral) expressionArguments[0]).getValue();
                        if (value instanceof String) {
                            String coordinateText = (String) value;
                            GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(coordinateText);
                            if (coordinate != null) {
                                parsed = true;
                                Multimap<String, GradleCoordinate> map = allConfigurations.get(configurationName);
                                if (map == null) {
                                    map = LinkedListMultimap.create();
                                    allConfigurations.put(configurationName, map);
                                }
                                if (!map.get(coordinate.getId()).contains(coordinate)) {
                                    map.put(coordinate.getId(), coordinate);
                                    existingElem.delete();
                                    wasMapUpdated = true;
                                }
                            }
                        }
                    }
                    if (!parsed && unparsedDependencies != null) {
                        unparsedDependencies.add(existingElem.getText());
                    }
                }
            }
        }
    }
    return wasMapUpdated;
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 93 with GrReferenceExpression

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

the class AndroidDslContributor method resolveToMethodWithClosure.

private static void resolveToMethodWithClosure(PsiElement place, PsiElement resolveToElement, String closureTypeFqcn, PsiScopeProcessor processor, ResolveState state) {
    if (place.getParent() instanceof GrMethodCallExpression) {
        GrLightMethodBuilder methodWithClosure = GradleResolverUtil.createMethodWithClosure(place.getText(), closureTypeFqcn, null, place);
        if (methodWithClosure != null) {
            processor.execute(methodWithClosure, state);
            methodWithClosure.setNavigationElement(resolveToElement);
        }
    } else if (place.getParent() instanceof GrReferenceExpression) {
        GrLightVariable variable = new GrLightVariable(place.getManager(), place.getText(), closureTypeFqcn, place);
        processor.execute(variable, state);
    }
}
Also used : GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) GrLightVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightVariable) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 94 with GrReferenceExpression

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

the class GradleEditorValueExtractor method extractMethodName.

@Nullable
public static Pair<String, TextRange> extractMethodName(@NotNull PsiElement methodCall) {
    GrReferenceExpression methodNameRef = PsiTreeUtil.findChildOfType(methodCall, GrReferenceExpression.class);
    if (methodNameRef == null || methodNameRef.getParent() != methodCall) {
        return null;
    }
    String methodName = methodNameRef.getReferenceName();
    if (methodName == null) {
        return null;
    }
    return Pair.create(methodName, methodNameRef.getTextRange());
}
Also used : GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with GrReferenceExpression

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

the class CustomWorldContributor method isWorldDeclaration.

private static boolean isWorldDeclaration(@NotNull GrMethodCall methodCall) {
    final GrExpression invoked = methodCall.getInvokedExpression();
    if (invoked instanceof GrReferenceExpression) {
        final PsiMethod method = methodCall.resolveMethod();
        final PsiClass clazz = method == null ? null : method.getContainingClass();
        final String qname = clazz == null ? null : clazz.getQualifiedName();
        return method != null && "World".equals(method.getName()) && GrCucumberCommonClassNames.isHookClassName(qname);
    }
    return false;
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)177 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)92 PsiElement (com.intellij.psi.PsiElement)56 Nullable (org.jetbrains.annotations.Nullable)28 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)27 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)26 NotNull (org.jetbrains.annotations.NotNull)25 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)22 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)22 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)21 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)17 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)16 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)15 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)14 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)14 PsiType (com.intellij.psi.PsiType)13 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)12 Project (com.intellij.openapi.project.Project)11 ArrayList (java.util.ArrayList)11 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)11