Search in sources :

Example 66 with GrArgumentList

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

the class GroovyIntroduceParameterObjectDelegate method createNewParameterInitializerAtCallSite.

@Override
public PsiElement createNewParameterInitializerAtCallSite(PsiElement callExpression, IntroduceParameterObjectClassDescriptor descriptor, List<? extends ParameterInfo> oldMethodParameters, Object substitutor) {
    if (callExpression instanceof GrCallExpression) {
        final GrArgumentList list = ((GrCallExpression) callExpression).getArgumentList();
        if (list == null) {
            return null;
        }
        final GrExpression[] args = list.getExpressionArguments();
        final String qualifiedName = StringUtil.getQualifiedName(descriptor.getPackageName(), descriptor.getClassName());
        String newExpression = "new " + qualifiedName + '(' + JavaIntroduceParameterObjectDelegate.getMergedArgs(descriptor, oldMethodParameters, args) + ')';
        GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(callExpression.getProject());
        return factory.createExpressionFromText(newExpression, callExpression);
    }
    return null;
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Example 67 with GrArgumentList

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

the class JavaStylePropertiesUtil method isSetterInvocation.

private static boolean isSetterInvocation(GrMethodCall call) {
    GrExpression expr = call.getInvokedExpression();
    if (!(expr instanceof GrReferenceExpression))
        return false;
    GrReferenceExpression refExpr = (GrReferenceExpression) expr;
    PsiMethod method;
    if (call instanceof GrApplicationStatement) {
        PsiElement element = refExpr.resolve();
        if (!(element instanceof PsiMethod) || !GroovyPropertyUtils.isSimplePropertySetter(((PsiMethod) element)))
            return false;
        method = (PsiMethod) element;
    } else {
        method = call.resolveMethod();
        if (!GroovyPropertyUtils.isSimplePropertySetter(method))
            return false;
        LOG.assertTrue(method != null);
    }
    if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameBySetterName(method.getName()), ((GrReferenceExpression) expr).getQualifier() != null, call.getProject())) {
        return false;
    }
    GrArgumentList args = call.getArgumentList();
    if (args.getExpressionArguments().length != 1 || PsiImplUtil.hasNamedArguments(args)) {
        return false;
    }
    GrAssignmentExpression assignment = genRefForSetter(call, refExpr.getReferenceName());
    if (assignment != null) {
        GrExpression value = assignment.getLValue();
        if (value instanceof GrReferenceExpression && call.getManager().areElementsEquivalent(((GrReferenceExpression) value).resolve(), method)) {
            return true;
        }
    }
    return false;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) PsiElement(com.intellij.psi.PsiElement)

Example 68 with GrArgumentList

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

the class GroovyTargetElementEvaluator method getElementByReference.

@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
    PsiElement sourceElement = ref.getElement();
    if (sourceElement instanceof GrCodeReferenceElement) {
        GrNewExpression newExpr;
        if (sourceElement.getParent() instanceof GrNewExpression) {
            newExpr = (GrNewExpression) sourceElement.getParent();
        } else if (sourceElement.getParent().getParent() instanceof GrNewExpression) {
            //anonymous class declaration
            newExpr = (GrNewExpression) sourceElement.getParent().getParent();
        } else {
            return null;
        }
        final PsiMethod constructor = newExpr.resolveMethod();
        final GrArgumentList argumentList = newExpr.getArgumentList();
        if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
            if (constructor.getParameterList().getParametersCount() == 0)
                return constructor.getContainingClass();
        }
        return constructor;
    }
    if (sourceElement instanceof GrReferenceExpression) {
        PsiElement resolved = ((GrReferenceExpression) sourceElement).resolve();
        if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) {
            return correctSearchTargets(resolved);
        }
        return resolved;
    }
    return null;
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) PsiMethod(com.intellij.psi.PsiMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrRenameableLightElement(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrRenameableLightElement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 69 with GrArgumentList

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

the class PsiImplUtil method getRuntimeQualifier.

@Nullable
public static GrExpression getRuntimeQualifier(@NotNull GrReferenceExpression refExpr) {
    GrExpression qualifier = refExpr.getQualifierExpression();
    if (qualifier != null)
        return qualifier;
    for (GrClosableBlock closure = PsiTreeUtil.getParentOfType(refExpr, GrClosableBlock.class); closure != null; closure = PsiTreeUtil.getParentOfType(closure, GrClosableBlock.class)) {
        PsiElement parent = closure.getParent();
        if (parent instanceof GrArgumentList)
            parent = parent.getParent();
        if (!(parent instanceof GrMethodCall))
            continue;
        GrExpression funExpr = ((GrMethodCall) parent).getInvokedExpression();
        if (!(funExpr instanceof GrReferenceExpression))
            return funExpr;
        final PsiElement resolved = ((GrReferenceExpression) funExpr).resolve();
        if (!(resolved instanceof PsiMethod))
            return funExpr;
        if (resolved instanceof GrGdkMethod && isFromDGM((GrGdkMethod) resolved) && !GdkMethodUtil.isWithName(((GrGdkMethod) resolved).getStaticMethod().getName())) {
            continue;
        }
        qualifier = ((GrReferenceExpression) funExpr).getQualifierExpression();
        if (qualifier != null)
            return qualifier;
    }
    return null;
}
Also used : GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with GrArgumentList

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

the class IndexedExpressionConversionIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final GrIndexProperty arrayIndexExpression = (GrIndexProperty) element;
    final GrArgumentList argList = (GrArgumentList) arrayIndexExpression.getLastChild();
    assert argList != null;
    final GrExpression[] arguments = argList.getExpressionArguments();
    final PsiElement parent = element.getParent();
    final GrExpression arrayExpression = arrayIndexExpression.getInvokedExpression();
    if (!(parent instanceof GrAssignmentExpression)) {
        rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
        return;
    }
    final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) parent;
    final GrExpression rhs = assignmentExpression.getRValue();
    if (rhs.equals(element)) {
        rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
    } else {
        rewriteAsSetAt(assignmentExpression, arrayExpression, arguments[0], rhs);
    }
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrIndexProperty(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement)

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