use of org.jetbrains.plugins.groovy.lang.psi.api.SpreadState 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.api.SpreadState in project intellij-community by JetBrains.
the class ResolverProcessorImpl method execute.
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof PsiLocalVariableImpl) {
// the debugger creates a Java code block context and our expressions to evaluate resolve there
return true;
}
if (myResolveTargetKinds == null || myResolveTargetKinds.contains(getDeclarationKind(element))) {
//don't check field for name because they can be aliased imported
if (element instanceof PsiVariable && !(element instanceof PsiField) && myName != null && !myName.equals(((PsiVariable) element).getName())) {
return true;
}
PsiNamedElement namedElement = (PsiNamedElement) element;
PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
if (substitutor == null)
substitutor = PsiSubstitutor.EMPTY;
if (myTypeArguments.length > 0 && namedElement instanceof PsiClass) {
substitutor = substitutor.putAll((PsiClass) namedElement, myTypeArguments);
}
if (namedElement instanceof PsiClass && !(namedElement instanceof PsiTypeParameter)) {
final PsiClass aClass = (PsiClass) namedElement;
if (myProcessedClasses == null)
myProcessedClasses = new HashSet<>();
if (!myProcessedClasses.add(aClass.getQualifiedName())) {
return true;
}
}
boolean isAccessible = isAccessible(namedElement);
final PsiElement resolveContext = state.get(RESOLVE_CONTEXT);
final SpreadState spreadState = state.get(SpreadState.SPREAD_STATE);
boolean isStaticsOK = isStaticsOK(namedElement, resolveContext, false);
addCandidate(new GroovyResolveResultImpl(namedElement, resolveContext, spreadState, substitutor, isAccessible, isStaticsOK));
return !(isAccessible && isStaticsOK);
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.SpreadState 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.api.SpreadState 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