Search in sources :

Example 21 with GrGdkMethod

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.

the class ExpressionGenerator method visitIndexProperty.

@Override
public void visitIndexProperty(@NotNull GrIndexProperty expression) {
    final GrExpression selectedExpression = expression.getInvokedExpression();
    final PsiType thisType = selectedExpression.getType();
    final GrArgumentList argList = expression.getArgumentList();
    if (argList.getAllArguments().length == 0) {
        // int[] or String[]
        if (selectedExpression instanceof GrBuiltinTypeClassExpression) {
            selectedExpression.accept(this);
            return;
        } else if (selectedExpression instanceof GrReferenceExpression) {
            PsiElement resolved = ((GrReferenceExpression) selectedExpression).resolve();
            if (resolved instanceof PsiClass) {
                builder.append(((PsiClass) resolved).getQualifiedName());
                builder.append("[].class");
                return;
            }
        }
    }
    final PsiType[] argTypes = PsiUtil.getArgumentTypes(argList);
    final GrExpression[] exprArgs = argList.getExpressionArguments();
    final GrNamedArgument[] namedArgs = argList.getNamedArguments();
    if (!PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, expression, PsiUtil.isLValue(expression))) {
        final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(expression.multiResolve(false));
        PsiElement element = candidate.getElement();
        if (element != null || !PsiUtil.isLValue(expression)) {
            //see the case of l-value in assignment expression
            if (element instanceof GrGdkMethod && ((GrGdkMethod) element).getStaticMethod().getParameterList().getParameters()[0].getType().equalsToText("java.util.Map<K,V>")) {
                PsiClass map = JavaPsiFacade.getInstance(context.project).findClass(CommonClassNames.JAVA_UTIL_MAP, expression.getResolveScope());
                if (map != null) {
                    PsiMethod[] gets = map.findMethodsByName("get", false);
                    invokeMethodOn(gets[0], selectedExpression, exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, PsiSubstitutor.EMPTY, expression);
                    return;
                }
            } else if (element instanceof GrGdkMethod && ((GrGdkMethod) element).getStaticMethod().getParameterList().getParameters()[0].getType().equalsToText("java.util.List<T>")) {
                PsiClass list = JavaPsiFacade.getInstance(context.project).findClass(CommonClassNames.JAVA_UTIL_LIST, expression.getResolveScope());
                if (list != null) {
                    PsiMethod[] gets = list.findMethodsByName("get", false);
                    invokeMethodOn(gets[0], selectedExpression, exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, PsiSubstitutor.EMPTY, expression);
                    return;
                }
            }
            GenerationUtil.invokeMethodByResolveResult(selectedExpression, candidate, "getAt", exprArgs, namedArgs, GrClosableBlock.EMPTY_ARRAY, this, expression);
            return;
        }
    }
    selectedExpression.accept(this);
    builder.append('[');
    final GrExpression arg = exprArgs[0];
    arg.accept(this);
    builder.append(']');
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 22 with GrGdkMethod

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod in project intellij-community by JetBrains.

the class SetterWriter method inferActualParameters.

@NotNull
private PsiParameter[] inferActualParameters(boolean aStatic, @NotNull PsiParameter[] parameters, @NotNull PsiParameter parameter) {
    //parameters
    parameters[parameters.length - 1] = parameter;
    PsiParameter[] actual;
    if (aStatic) {
        actual = parameters;
    } else {
        final String typeText;
        final PsiClass containingClass = mySetter.getContainingClass();
        if (containingClass == null) {
            if (mySetter instanceof GrGdkMethod) {
                typeText = ((GrGdkMethod) mySetter).getStaticMethod().getParameterList().getParameters()[0].getType().getCanonicalText();
            } else {
                typeText = CommonClassNames.JAVA_LANG_OBJECT;
            }
        } else {
            typeText = containingClass.getQualifiedName();
        }
        final GrParameter propOwner = GroovyPsiElementFactory.getInstance(myContext.project).createParameter("propOwner", typeText, null);
        actual = new PsiParameter[parameters.length + 1];
        actual[0] = propOwner;
        System.arraycopy(parameters, 0, actual, 1, parameters.length);
    }
    return actual;
}
Also used : GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)22 Nullable (org.jetbrains.annotations.Nullable)8 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)6 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)6 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)6 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)5 NotNull (org.jetbrains.annotations.NotNull)4 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)4 PsiMethod (com.intellij.psi.PsiMethod)3 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)3 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)3 NameHint (com.intellij.psi.scope.NameHint)2 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)2 GrTupleType (org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType)2 ASTNode (com.intellij.lang.ASTNode)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 com.intellij.psi (com.intellij.psi)1