Search in sources :

Example 16 with GrArgumentList

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

the class AndroidDslContributor method getContributingMethod.

@Nullable
private static PsiMethod getContributingMethod(PsiElement place, PsiClass contributorClass, String methodName) {
    GrMethodCall call = PsiTreeUtil.getParentOfType(place, GrMethodCall.class);
    if (call == null) {
        return null;
    }
    GrArgumentList args = call.getArgumentList();
    int argsCount = GradleResolverUtil.getGrMethodArumentsCount(args);
    PsiMethod[] methodsByName = findMethodByName(contributorClass, methodName);
    // first check to see if we can narrow down by # of arguments
    for (PsiMethod method : methodsByName) {
        if (method.getParameterList().getParametersCount() == argsCount) {
            return method;
        }
    }
    // if we couldn't narrow down by # of arguments, just use the first one
    return methodsByName.length > 0 ? methodsByName[0] : null;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with GrArgumentList

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

the class GroovyAnnotator method visitConstructorInvocation.

@Override
public void visitConstructorInvocation(@NotNull GrConstructorInvocation invocation) {
    final GroovyResolveResult resolveResult = invocation.advancedResolve();
    if (resolveResult.getElement() == null) {
        final GroovyResolveResult[] results = invocation.multiResolve(false);
        final GrArgumentList argList = invocation.getArgumentList();
        if (results.length > 0) {
            String message = GroovyBundle.message("ambiguous.constructor.call");
            myHolder.createWarningAnnotation(argList, message);
        } else {
            final PsiClass clazz = invocation.getDelegatedClass();
            if (clazz != null) {
                //default constructor invocation
                PsiType[] argumentTypes = PsiUtil.getArgumentTypes(invocation.getInvokedExpression(), true);
                if (argumentTypes != null && argumentTypes.length > 0) {
                    String message = GroovyBundle.message("cannot.apply.default.constructor", clazz.getName());
                    myHolder.createWarningAnnotation(argList, message);
                }
            }
        }
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)

Example 18 with GrArgumentList

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

the class GrEnumConstantInfo method getElementToHighlight.

@NotNull
@Override
public PsiElement getElementToHighlight() {
    GrEnumConstant constant = getCall();
    GrArgumentList argList = constant.getArgumentList();
    if (argList != null)
        return argList;
    return constant.getNameIdentifierGroovy();
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrEnumConstant(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with GrArgumentList

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

the class GroovyDslDefaultMembers method enclosingCall.

/**
   * Returns enclosing method call of a given context's place
   */
@Nullable
public GrCall enclosingCall(String name, GdslMembersHolderConsumer consumer) {
    final PsiElement place = consumer.getPlace();
    if (place == null)
        return null;
    GrCall call = PsiTreeUtil.getParentOfType(place, GrCall.class, true);
    if (call == null)
        return null;
    while (call != null && !name.equals(getInvokedMethodName(call))) {
        call = PsiTreeUtil.getParentOfType(call, GrCall.class, true);
    }
    if (call == null)
        return null;
    final GrArgumentList argumentList = call.getArgumentList();
    if (argumentList != null) {
        for (GrExpression arg : argumentList.getExpressionArguments()) {
            if (arg instanceof GrClosableBlock && PsiTreeUtil.findCommonParent(place, arg) == arg) {
                return call;
            }
        }
    }
    if (call instanceof GrMethodCallExpression) {
        for (GrExpression arg : call.getClosureArguments()) {
            if (arg instanceof GrClosableBlock && PsiTreeUtil.findCommonParent(place, arg) == arg) {
                return call;
            }
        }
    }
    return null;
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with GrArgumentList

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

the class EquivalenceChecker method applicationStatementsAreEquivalent.

private static boolean applicationStatementsAreEquivalent(GrApplicationStatement statement1, GrApplicationStatement statement2) {
    final GrExpression funExpression1 = statement1.getInvokedExpression();
    final GrExpression funExpression2 = statement2.getInvokedExpression();
    if (!expressionsAreEquivalent(funExpression1, funExpression2)) {
        return false;
    }
    final GrArgumentList argumentList1 = statement1.getArgumentList();
    final GrArgumentList argumentList2 = statement2.getArgumentList();
    final GrExpression[] args1 = argumentList1.getExpressionArguments();
    final GrExpression[] args2 = argumentList2.getExpressionArguments();
    if (!expressionListsAreEquivalent(args1, args2)) {
        return false;
    }
    final GrNamedArgument[] namedArgs1 = argumentList1.getNamedArguments();
    final GrNamedArgument[] namedArgs2 = argumentList2.getNamedArguments();
    if (!namedArgumentListsAreEquivalent(namedArgs1, namedArgs2)) {
        return false;
    }
    return true;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)

Aggregations

GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)80 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)26 PsiElement (com.intellij.psi.PsiElement)21 Nullable (org.jetbrains.annotations.Nullable)20 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)18 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)15 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)14 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)14 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)14 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)14 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)12 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)9 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)8 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)8 NotNull (org.jetbrains.annotations.NotNull)7 GrCommandArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList)6 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)6 GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)6 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)6 ASTNode (com.intellij.lang.ASTNode)5