Search in sources :

Example 6 with MethodResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.

the class GrDocMethodReferenceImpl method resolve.

@Override
public PsiElement resolve() {
    String name = getReferenceName();
    GrDocReferenceElement holder = getReferenceHolder();
    PsiElement resolved;
    if (holder != null) {
        GrCodeReferenceElement referenceElement = holder.getReferenceElement();
        resolved = referenceElement != null ? referenceElement.resolve() : null;
    } else {
        resolved = PsiUtil.getContextClass(this);
    }
    if (resolved instanceof PsiClass) {
        PsiType[] parameterTypes = getParameterList().getParameterTypes();
        PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
        MethodResolverProcessor processor = new MethodResolverProcessor(name, this, false, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
        resolved.processDeclarations(processor, ResolveState.initial(), resolved, this);
        if (processor.hasApplicableCandidates()) {
            return processor.getCandidates()[0].getElement();
        }
        MethodResolverProcessor constructorProcessor = new MethodResolverProcessor(name, this, true, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
        resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this);
        if (constructorProcessor.hasApplicableCandidates()) {
            return constructorProcessor.getCandidates()[0].getElement();
        }
    }
    return null;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) MethodResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)

Example 7 with MethodResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.

the class GrDocMethodReferenceImpl method multiResolveImpl.

@Override
protected ResolveResult[] multiResolveImpl() {
    String name = getReferenceName();
    GrDocReferenceElement holder = getReferenceHolder();
    PsiElement resolved;
    if (holder != null) {
        GrCodeReferenceElement referenceElement = holder.getReferenceElement();
        resolved = referenceElement != null ? referenceElement.resolve() : null;
    } else {
        resolved = PsiUtil.getContextClass(this);
    }
    if (resolved instanceof PsiClass) {
        PsiType[] parameterTypes = getParameterList().getParameterTypes();
        PsiType thisType = JavaPsiFacade.getInstance(getProject()).getElementFactory().createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
        MethodResolverProcessor processor = new MethodResolverProcessor(name, this, false, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
        MethodResolverProcessor constructorProcessor = new MethodResolverProcessor(name, this, true, thisType, parameterTypes, PsiType.EMPTY_ARRAY);
        resolved.processDeclarations(processor, ResolveState.initial(), resolved, this);
        resolved.processDeclarations(constructorProcessor, ResolveState.initial(), resolved, this);
        return ArrayUtil.mergeArrays(processor.getCandidates(), constructorProcessor.getCandidates());
    }
    return ResolveResult.EMPTY_ARRAY;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) MethodResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)

Example 8 with MethodResolverProcessor

use of org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor in project intellij-community by JetBrains.

the class PsiUtil method isRawIndexPropertyAccess.

private static boolean isRawIndexPropertyAccess(GrIndexProperty expr) {
    final GrExpression qualifier = expr.getInvokedExpression();
    final PsiType qualifierType = qualifier.getType();
    if (qualifierType instanceof PsiClassType) {
        if (InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_LIST)) {
            return com.intellij.psi.util.PsiUtil.extractIterableTypeParameter(qualifierType, false) == null;
        }
        if (InheritanceUtil.isInheritor(qualifierType, CommonClassNames.JAVA_UTIL_MAP)) {
            return com.intellij.psi.util.PsiUtil.substituteTypeParameter(qualifierType, CommonClassNames.JAVA_UTIL_MAP, 1, false) == null;
        }
        PsiClassType classType = (PsiClassType) qualifierType;
        final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
        GrExpression[] arguments = expr.getArgumentList().getExpressionArguments();
        PsiType[] argTypes = PsiType.createArray(arguments.length);
        for (int i = 0; i < arguments.length; i++) {
            PsiType argType = arguments[i].getType();
            if (argType == null)
                argType = TypesUtil.getJavaLangObject(expr);
            argTypes[i] = argType;
        }
        MethodResolverProcessor processor = new MethodResolverProcessor("getAt", expr, false, qualifierType, argTypes, PsiType.EMPTY_ARRAY);
        final PsiClass qClass = resolveResult.getElement();
        final ResolveState state = ResolveState.initial().put(PsiSubstitutor.KEY, PsiSubstitutor.EMPTY);
        if (qClass != null) {
            qClass.processDeclarations(processor, state, null, expr);
        }
        ResolveUtil.processNonCodeMembers(qualifierType, processor, qualifier, state);
        final GroovyResolveResult[] candidates = processor.getCandidates();
        PsiType type = null;
        if (candidates.length == 1) {
            final PsiElement element = candidates[0].getElement();
            if (element instanceof PsiMethod) {
                type = getSmartReturnType((PsiMethod) element);
            }
        }
        return isRawType(type, resolveResult.getSubstitutor());
    }
    return false;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) MethodResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)

Aggregations

MethodResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor)8 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)3 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)3 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 com.intellij.psi (com.intellij.psi)1 SuperMethodsSearch (com.intellij.psi.search.searches.SuperMethodsSearch)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 MethodSignatureBackedByPsiMethod (com.intellij.psi.util.MethodSignatureBackedByPsiMethod)1 TypeConversionUtil (com.intellij.psi.util.TypeConversionUtil)1 UnresolvableCollisionUsageInfo (com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo)1 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)1 UsageInfo (com.intellij.usageView.UsageInfo)1 Processor (com.intellij.util.Processor)1 QueryExecutor (com.intellij.util.QueryExecutor)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1