Search in sources :

Example 76 with GroovyResolveResult

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

the class ResolveUtil method collectExpectedParamsByArg.

@NotNull
public static List<Pair<PsiParameter, PsiType>> collectExpectedParamsByArg(@NotNull PsiElement place, @NotNull GroovyResolveResult[] variants, @NotNull GrNamedArgument[] namedArguments, @NotNull GrExpression[] expressionArguments, @NotNull GrClosableBlock[] closureArguments, @NotNull GrExpression arg) {
    List<Pair<PsiParameter, PsiType>> expectedParams = ContainerUtil.newArrayList();
    for (GroovyResolveResult variant : variants) {
        final Map<GrExpression, Pair<PsiParameter, PsiType>> map = GrClosureSignatureUtil.mapArgumentsToParameters(variant, place, true, true, namedArguments, expressionArguments, closureArguments);
        if (map != null) {
            final Pair<PsiParameter, PsiType> pair = map.get(arg);
            ContainerUtil.addIfNotNull(expectedParams, pair);
        }
    }
    return expectedParams;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with GroovyResolveResult

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

the class GroovyResolverProcessor method getCandidatesArray.

public final GroovyResolveResult[] getCandidatesArray() {
    final List<GroovyResolveResult> candidates = getCandidates();
    final int size = candidates.size();
    if (size == 0)
        return GroovyResolveResult.EMPTY_ARRAY;
    if (size == 1)
        return new GroovyResolveResult[] { candidates.get(0) };
    return candidates.toArray(new GroovyResolveResult[size]);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 78 with GroovyResolveResult

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

the class GroovyResolverProcessorImpl method filterCorrectParameterCount.

private List<GroovyResolveResult> filterCorrectParameterCount(Collection<GroovyResolveResult> candidates) {
    PsiType[] argumentTypes = myArgumentTypes.getValue();
    if (argumentTypes == null)
        return ContainerUtil.newArrayList(candidates);
    final List<GroovyResolveResult> result = ContainerUtil.newSmartList();
    for (GroovyResolveResult candidate : candidates) {
        if (candidate instanceof GroovyMethodResult) {
            if (((GroovyMethodResult) candidate).getElement().getParameterList().getParametersCount() == argumentTypes.length) {
                result.add(candidate);
            }
        } else {
            result.add(candidate);
        }
    }
    if (!result.isEmpty())
        return result;
    return ContainerUtil.newArrayList(candidates);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyMethodResult(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult)

Example 79 with GroovyResolveResult

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

the class GroovyResolverProcessorImpl method collapseReflectedMethods.

private static List<GroovyResolveResult> collapseReflectedMethods(Collection<GroovyResolveResult> candidates) {
    Set<GrMethod> visited = ContainerUtil.newHashSet();
    List<GroovyResolveResult> collapsed = ContainerUtil.newArrayList();
    for (GroovyResolveResult result : candidates) {
        PsiElement element = result.getElement();
        if (element instanceof GrReflectedMethod) {
            GrMethod baseMethod = ((GrReflectedMethod) element).getBaseMethod();
            if (visited.add(baseMethod)) {
                collapsed.add(PsiImplUtil.reflectedToBase(result, baseMethod, (GrReflectedMethod) element));
            }
        } else {
            collapsed.add(result);
        }
    }
    return collapsed;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrReflectedMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)

Example 80 with GroovyResolveResult

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

the class PropertyResolverProcessor method getCandidates.

@NotNull
@Override
public GroovyResolveResult[] getCandidates() {
    //do not have more than one correct result. And if it exists it is the last
    final List<GroovyResolveResult> candidates = getCandidatesInternal();
    final int size = candidates.size();
    if (size == 0)
        return GroovyResolveResult.EMPTY_ARRAY;
    GroovyResolveResult last = candidates.get(size - 1);
    if (last.getElement() instanceof GrBindingVariable && size > 1) {
        last = candidates.get(size - 2);
    }
    if (isCorrectLocalVarOrParam(last)) {
        return new GroovyResolveResult[] { last };
    }
    for (GroovyResolveResult candidate : candidates) {
        if (candidate.isStaticsOK()) {
            return new GroovyResolveResult[] { candidate };
        }
    }
    return candidates.toArray(new GroovyResolveResult[candidates.size()]);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)132 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)33 Nullable (org.jetbrains.annotations.Nullable)29 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)29 NotNull (org.jetbrains.annotations.NotNull)25 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)23 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)17 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)14 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)13 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)12 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)11 PsiElement (com.intellij.psi.PsiElement)10 ArrayList (java.util.ArrayList)8 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)8 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)8 IElementType (com.intellij.psi.tree.IElementType)7 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)7 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)7 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)7 Project (com.intellij.openapi.project.Project)6