use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult in project intellij-community by JetBrains.
the class ResolveUtil method filterSameSignatureCandidates.
/**
* The point is that we do not want to see repeating methods in completion.
* Candidates can have multiple toString() methods (e.g. from Object and from some inheritor) and we want to show only one.
*/
public static GroovyResolveResult[] filterSameSignatureCandidates(Collection<? extends GroovyResolveResult> candidates) {
if (candidates.size() == 0)
return GroovyResolveResult.EMPTY_ARRAY;
if (candidates.size() == 1)
return candidates.toArray(new GroovyResolveResult[candidates.size()]);
final List<GroovyResolveResult> result = new ArrayList<>();
final Iterator<? extends GroovyResolveResult> allIterator = candidates.iterator();
result.add(allIterator.next());
Outer: while (allIterator.hasNext()) {
final GroovyResolveResult currentResult = allIterator.next();
final PsiMethod currentMethod;
final PsiSubstitutor currentSubstitutor;
if (currentResult instanceof GroovyMethodResult) {
final GroovyMethodResult currentMethodResult = (GroovyMethodResult) currentResult;
currentMethod = currentMethodResult.getElement();
currentSubstitutor = currentMethodResult.getSubstitutor(false);
} else if (currentResult.getElement() instanceof PsiMethod) {
currentMethod = (PsiMethod) currentResult.getElement();
currentSubstitutor = currentResult.getSubstitutor();
} else {
result.add(currentResult);
continue;
}
Inner: for (Iterator<GroovyResolveResult> resultIterator = result.iterator(); resultIterator.hasNext(); ) {
final GroovyResolveResult otherResult = resultIterator.next();
final PsiMethod otherMethod;
final PsiSubstitutor otherSubstitutor;
if (otherResult instanceof GroovyMethodResult) {
final GroovyMethodResult otherMethodResult = (GroovyMethodResult) otherResult;
otherMethod = otherMethodResult.getElement();
otherSubstitutor = otherMethodResult.getSubstitutor(false);
} else if (otherResult.getElement() instanceof PsiMethod) {
otherMethod = (PsiMethod) otherResult.getElement();
otherSubstitutor = otherResult.getSubstitutor();
} else {
continue Inner;
}
if (dominated(currentMethod, currentSubstitutor, otherMethod, otherSubstitutor)) {
// then do not add current method to result and skip rest other methods
continue Outer;
} else if (dominated(otherMethod, otherSubstitutor, currentMethod, currentSubstitutor)) {
// if other method is dominated by current method
// then remove other from result
resultIterator.remove();
}
}
result.add(currentResult);
}
return result.toArray(new GroovyResolveResult[result.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult in project intellij-community by JetBrains.
the class GroovyResolverProcessor method execute.
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (!(element instanceof PsiNamedElement))
return true;
final PsiNamedElement namedElement = (PsiNamedElement) element;
final PsiElement resolveContext = state.get(ClassHint.RESOLVE_CONTEXT);
final GroovyResolveKind kind = computeKindAndCheckName(namedElement, resolveContext);
if (!myAcceptableKinds.contains(kind))
return true;
if (kind == GroovyResolveKind.METHOD && myStopExecutingMethods) {
return true;
} else if (kind != GroovyResolveKind.PROPERTY && kind != GroovyResolveKind.METHOD) {
if (!myCandidates.get(kind).isEmpty())
return true;
}
final GroovyResolveResultImpl candidate;
{
final PsiSubstitutor substitutor = getSubstitutor(state);
final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
final boolean isAccessible = isAccessible(myRef, namedElement);
final boolean isStaticsOK = isStaticsOK(myRef, namedElement, resolveContext, false);
if (kind == GroovyResolveKind.METHOD || kind == GroovyResolveKind.PROPERTY) {
final PsiMethod method = (PsiMethod) namedElement;
final boolean isApplicable = kind == GroovyResolveKind.PROPERTY && !myIsLValue || isApplicable(myArgumentTypes.getValue(), method, substitutor, myRef, true);
final NotNullComputable<PsiSubstitutor> substitutorComputer;
if (kind == GroovyResolveKind.METHOD) {
substitutorComputer = () -> myMethodSubstitutorComputer.getValue().obtainSubstitutor(substitutor, method, resolveContext);
} else {
substitutorComputer = () -> myPropertySubstitutorComputer.getValue().obtainSubstitutor(substitutor, method, resolveContext);
}
candidate = new GroovyMethodResult(method, resolveContext, spreadState, substitutor, substitutorComputer, kind == GroovyResolveKind.PROPERTY, isAccessible, isStaticsOK, isApplicable);
} else {
candidate = new GroovyResolveResultImpl(namedElement, resolveContext, spreadState, substitutor, isAccessible, isStaticsOK, false, true);
}
}
(candidate.isValidResult() ? myCandidates : myInapplicableCandidates).putValue(kind, candidate);
if (candidate.isValidResult() && kind == GroovyResolveKind.VARIABLE) {
myStopExecutingMethods = true;
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult 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);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult in project intellij-community by JetBrains.
the class AccessorResolverProcessor method addAccessor.
private boolean addAccessor(final PsiMethod method, ResolveState state) {
final PsiSubstitutor substitutor = getSubstitutor(state);
final PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
final NotNullComputable<PsiSubstitutor> substitutorComputer = () -> mySubstitutorComputer.obtainSubstitutor(substitutor, method, resolveContext);
boolean isAccessible = isAccessible(method);
final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
boolean isStaticsOK = isStaticsOK(method, resolveContext, false);
final GroovyMethodResult candidate = new GroovyMethodResult(method, resolveContext, spreadState, substitutor, substitutorComputer, isAccessible, isStaticsOK);
if (isAccessible && isStaticsOK) {
addCandidate(candidate);
//don't stop searching if we found only gdk method
return method instanceof GrGdkMethod;
} else {
addInapplicableCandidate(candidate);
return true;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GroovyMethodResult in project intellij-community by JetBrains.
the class MethodResolverProcessor method execute.
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (myStopExecuting) {
return false;
}
if (element instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) element;
if (method.isConstructor() != myIsConstructor)
return true;
final PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
final PsiSubstitutor partialSubstitutor = getSubstitutor(state);
final NotNullComputable<PsiSubstitutor> substitutorComputer = () -> mySubstitutorComputer.obtainSubstitutor(partialSubstitutor, method, resolveContext);
boolean isAccessible = isAccessible(method);
boolean isStaticsOK = isStaticsOK(method, resolveContext, false);
boolean isApplicable = PsiUtil.isApplicable(myArgumentTypes, method, partialSubstitutor, myPlace, true);
boolean isValidResult = isStaticsOK && isAccessible && isApplicable;
GroovyMethodResult candidate = new GroovyMethodResult(method, resolveContext, spreadState, partialSubstitutor, substitutorComputer, isAccessible, isStaticsOK, isValidResult);
if (!myAllVariants && isValidResult) {
addCandidate(candidate);
} else {
addInapplicableCandidate(candidate);
}
}
return true;
}
Aggregations