Search in sources :

Example 1 with GrImmediateTupleType

use of org.jetbrains.plugins.groovy.lang.psi.impl.GrImmediateTupleType in project intellij-community by JetBrains.

the class GrIndexPropertyImpl method resolveImpl.

private GroovyResolveResult[] resolveImpl(boolean incompleteCode, @Nullable GrExpression upToArgument, @Nullable Boolean isSetter) {
    if (isSetter == null)
        isSetter = PsiUtil.isLValue(this);
    GrExpression invoked = getInvokedExpression();
    PsiType thisType = invoked.getType();
    if (thisType == null) {
        thisType = TypesUtil.getJavaLangObject(this);
    }
    GrArgumentList argList = getArgumentList();
    //don't use short PsiUtil.getArgumentTypes(...) because it use incorrect 'isSetter' value
    PsiType[] argTypes = PsiUtil.getArgumentTypes(argList.getNamedArguments(), argList.getExpressionArguments(), GrClosableBlock.EMPTY_ARRAY, true, upToArgument);
    if (argTypes == null)
        return GroovyResolveResult.EMPTY_ARRAY;
    final GlobalSearchScope resolveScope = getResolveScope();
    if (argTypes.length == 0) {
        PsiType arrType = null;
        if (invoked instanceof GrBuiltinTypeClassExpression) {
            arrType = ((GrBuiltinTypeClassExpression) invoked).getPrimitiveType();
        }
        if (invoked instanceof GrReferenceExpression) {
            final PsiElement resolved = ((GrReferenceExpression) invoked).resolve();
            if (resolved instanceof PsiClass) {
                String qname = ((PsiClass) resolved).getQualifiedName();
                if (qname != null) {
                    arrType = TypesUtil.createTypeByFQClassName(qname, this);
                }
            }
        }
        if (arrType != null) {
            return GroovyResolveResult.EMPTY_ARRAY;
        }
    }
    GroovyResolveResult[] candidates;
    final String name = isSetter ? "putAt" : "getAt";
    if (isSetter && !incompleteCode) {
        argTypes = ArrayUtil.append(argTypes, TypeInferenceHelper.getInitializerTypeFor(this), PsiType.class);
    }
    if (PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, this, isSetter)) {
        return GroovyResolveResult.EMPTY_ARRAY;
    }
    candidates = ResolveUtil.getMethodCandidates(thisType, name, invoked, true, incompleteCode, argTypes);
    //hack for remove DefaultGroovyMethods.getAt(Object, ...)
    if (candidates.length == 2) {
        for (int i = 0; i < candidates.length; i++) {
            GroovyResolveResult candidate = candidates[i];
            final PsiElement element = candidate.getElement();
            if (element instanceof GrGdkMethod) {
                final PsiMethod staticMethod = ((GrGdkMethod) element).getStaticMethod();
                final PsiParameter param = staticMethod.getParameterList().getParameters()[0];
                if (param.getType().equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
                    return new GroovyResolveResult[] { candidates[1 - i] };
                }
            }
        }
    }
    if (candidates.length != 1) {
        final GrTupleType tupleType = new GrImmediateTupleType(argTypes, JavaPsiFacade.getInstance(getProject()), resolveScope);
        final GroovyResolveResult[] tupleCandidates = ResolveUtil.getMethodCandidates(thisType, name, invoked, tupleType);
        if (incompleteCode) {
            candidates = ArrayUtil.mergeArrays(candidates, tupleCandidates, count -> new GroovyResolveResult[count]);
        } else {
            candidates = tupleCandidates;
        }
    }
    return candidates;
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) ArrayUtil(com.intellij.util.ArrayUtil) PsiImplUtil(org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) ResolveUtil(org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil) ResolveUtil.getClassReferenceFromExpression(org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil.getClassReferenceFromExpression) GrBuiltinTypeClassExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBuiltinTypeClassExpression) GroovyElementVisitor(org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor) GrIndexProperty(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty) TypeInferenceHelper(org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper) GrThrowStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) ResolveCache(com.intellij.psi.impl.source.resolve.ResolveCache) IncorrectOperationException(com.intellij.util.IncorrectOperationException) NullableFunction(com.intellij.util.NullableFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TextRange(com.intellij.openapi.util.TextRange) TypesUtil(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) GrImmediateTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrImmediateTupleType) Function(com.intellij.util.Function) GrTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) GrExpressionImpl(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl) PsiUtil(org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType) GrBuiltinTypeClassExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBuiltinTypeClassExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) 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) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GrImmediateTupleType(org.jetbrains.plugins.groovy.lang.psi.impl.GrImmediateTupleType)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 com.intellij.psi (com.intellij.psi)1 ResolveCache (com.intellij.psi.impl.source.resolve.ResolveCache)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 InheritanceUtil (com.intellij.psi.util.InheritanceUtil)1 ArrayUtil (com.intellij.util.ArrayUtil)1 Function (com.intellij.util.Function)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NullableFunction (com.intellij.util.NullableFunction)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 GroovyElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)1 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrThrowStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrThrowStatement)1 GrBuiltinTypeClassExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBuiltinTypeClassExpression)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1