use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyIntroduceParameterUtil method removeParametersFromCall.
private static void removeParametersFromCall(GrMethodCallExpression methodCall, GrIntroduceParameterSettings settings) {
final GroovyResolveResult resolveResult = methodCall.advancedResolve();
final PsiElement resolved = resolveResult.getElement();
LOG.assertTrue(resolved instanceof PsiMethod);
final GrClosureSignature signature = GrClosureSignatureUtil.createSignature((PsiMethod) resolved, resolveResult.getSubstitutor());
final GrClosureSignatureUtil.ArgInfo<PsiElement>[] argInfos = GrClosureSignatureUtil.mapParametersToArguments(signature, methodCall);
LOG.assertTrue(argInfos != null);
settings.parametersToRemove().forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
final List<PsiElement> args = argInfos[value].args;
for (PsiElement arg : args) {
arg.delete();
}
return true;
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class OldReferencesResolver method getQualifierFromGetterCall.
/**
* checks for the case: qualifier.getFoo()(args)
* @param methodExpression
*/
@Nullable
private static GrExpression getQualifierFromGetterCall(GrMethodCall methodExpression) {
final GroovyResolveResult result = methodExpression.advancedResolve();
if (!(result.getElement() instanceof GrAccessorMethod) || result.isInvokedOnProperty())
return null;
final GrExpression invoked = methodExpression.getInvokedExpression();
if (invoked instanceof GrReferenceExpression)
return ((GrReferenceExpression) invoked).getQualifier();
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyAnnotator method visitTypeArgumentList.
@Override
public void visitTypeArgumentList(@NotNull GrTypeArgumentList typeArgumentList) {
PsiElement parent = typeArgumentList.getParent();
if (!(parent instanceof GrReferenceElement))
return;
final GroovyResolveResult resolveResult = ((GrReferenceElement) parent).advancedResolve();
final PsiElement resolved = resolveResult.getElement();
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
if (resolved == null)
return;
if (!(resolved instanceof PsiTypeParameterListOwner)) {
myHolder.createWarningAnnotation(typeArgumentList, GroovyBundle.message("type.argument.list.is.not.allowed.here"));
return;
}
if (parent instanceof GrCodeReferenceElement) {
if (!checkDiamonds((GrCodeReferenceElement) parent, myHolder))
return;
}
final PsiTypeParameter[] parameters = ((PsiTypeParameterListOwner) resolved).getTypeParameters();
final GrTypeElement[] arguments = typeArgumentList.getTypeArgumentElements();
if (arguments.length != parameters.length) {
myHolder.createWarningAnnotation(typeArgumentList, GroovyBundle.message("wrong.number.of.type.arguments", arguments.length, parameters.length));
return;
}
for (int i = 0; i < parameters.length; i++) {
PsiTypeParameter parameter = parameters[i];
final PsiClassType[] superTypes = parameter.getExtendsListTypes();
final PsiType argType = arguments[i].getType();
for (PsiClassType superType : superTypes) {
final PsiType substitutedSuper = substitutor.substitute(superType);
if (substitutedSuper != null && !substitutedSuper.isAssignableFrom(argType)) {
myHolder.createWarningAnnotation(arguments[i], GroovyBundle.message("type.argument.0.is.not.in.its.bound.should.extend.1", argType.getCanonicalText(), superType.getCanonicalText()));
break;
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyAnnotator method visitConstructorInvocation.
@Override
public void visitConstructorInvocation(@NotNull GrConstructorInvocation invocation) {
final GroovyResolveResult resolveResult = invocation.advancedResolve();
if (resolveResult.getElement() == null) {
final GroovyResolveResult[] results = invocation.multiResolve(false);
final GrArgumentList argList = invocation.getArgumentList();
if (results.length > 0) {
String message = GroovyBundle.message("ambiguous.constructor.call");
myHolder.createWarningAnnotation(argList, message);
} else {
final PsiClass clazz = invocation.getDelegatedClass();
if (clazz != null) {
//default constructor invocation
PsiType[] argumentTypes = PsiUtil.getArgumentTypes(invocation.getInvokedExpression(), true);
if (argumentTypes != null && argumentTypes.length > 0) {
String message = GroovyBundle.message("cannot.apply.default.constructor", clazz.getName());
myHolder.createWarningAnnotation(argList, message);
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method checkMethodApplicability.
private <T extends GroovyPsiElement> boolean checkMethodApplicability(@NotNull final GroovyResolveResult methodResolveResult, boolean checkUnknownArgs, @NotNull final CallInfo<T> info) {
final PsiElement element = methodResolveResult.getElement();
if (!(element instanceof PsiMethod))
return true;
if (element instanceof GrBuilderMethod)
return true;
final PsiMethod method = (PsiMethod) element;
if ("call".equals(method.getName()) && info.getInvokedExpression() instanceof GrReferenceExpression) {
final GrExpression qualifierExpression = ((GrReferenceExpression) info.getInvokedExpression()).getQualifierExpression();
if (qualifierExpression != null) {
final PsiType type = qualifierExpression.getType();
if (type instanceof GrClosureType) {
GrClosureSignatureUtil.ApplicabilityResult result = PsiUtil.isApplicableConcrete(info.getArgumentTypes(), (GrClosureType) type, info.getInvokedExpression());
switch(result) {
case inapplicable:
highlightInapplicableMethodUsage(methodResolveResult, info, method);
return false;
case //q(1,2)
canBeApplicable:
if (checkUnknownArgs) {
highlightUnknownArgs(info);
}
return !checkUnknownArgs;
default:
return true;
}
}
}
}
if (method instanceof GrGdkMethod && info.getInvokedExpression() instanceof GrReferenceExpression) {
final GrReferenceExpression invoked = (GrReferenceExpression) info.getInvokedExpression();
final GrExpression qualifier = PsiImplUtil.getRuntimeQualifier(invoked);
if (qualifier == null && method.getName().equals("call")) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(invoked.getProject());
final GrReferenceExpression callRef = factory.createReferenceExpressionFromText("qualifier.call", invoked);
callRef.setQualifier(invoked);
return checkMethodApplicability(methodResolveResult, checkUnknownArgs, new DelegatingCallInfo<T>(info) {
@Nullable
@Override
public GrExpression getInvokedExpression() {
return callRef;
}
@NotNull
@Override
public GroovyResolveResult advancedResolve() {
return methodResolveResult;
}
@NotNull
@Override
public GroovyResolveResult[] multiResolve() {
return new GroovyResolveResult[] { methodResolveResult };
}
@Nullable
@Override
public PsiType getQualifierInstanceType() {
return info.getInvokedExpression().getType();
}
});
}
final PsiMethod staticMethod = ((GrGdkMethod) method).getStaticMethod();
PsiType qualifierType = info.getQualifierInstanceType();
if (method.hasModifierProperty(PsiModifier.STATIC)) {
qualifierType = ResolveUtil.unwrapClassType(qualifierType);
}
//check methods processed by @Category(ClassWhichProcessMethod) annotation
if (qualifierType != null && !GdkMethodUtil.isCategoryMethod(staticMethod, qualifierType, qualifier, methodResolveResult.getSubstitutor()) && !checkCategoryQualifier(invoked, qualifier, staticMethod, methodResolveResult.getSubstitutor())) {
registerError(info.getHighlightElementForCategoryQualifier(), ProblemHighlightType.GENERIC_ERROR, GroovyInspectionBundle.message("category.method.0.cannot.be.applied.to.1", method.getName(), qualifierType.getCanonicalText()));
return false;
}
}
if (info.getArgumentTypes() == null)
return true;
GrClosureSignatureUtil.ApplicabilityResult applicable = PsiUtil.isApplicableConcrete(info.getArgumentTypes(), method, methodResolveResult.getSubstitutor(), info.getCall(), false);
switch(applicable) {
case inapplicable:
highlightInapplicableMethodUsage(methodResolveResult, info, method);
return false;
case canBeApplicable:
if (checkUnknownArgs) {
highlightUnknownArgs(info);
}
return !checkUnknownArgs;
default:
return true;
}
}
Aggregations