use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method generateAllSignaturesForMethod.
public static List<MethodSignature> generateAllSignaturesForMethod(GrMethod method, PsiSubstitutor substitutor) {
GrClosureSignature signature = createSignature(method, substitutor);
String name = method.getName();
PsiTypeParameter[] typeParameters = method.getTypeParameters();
final ArrayList<MethodSignature> result = new ArrayList<>();
generateAllMethodSignaturesByClosureSignature(name, signature, typeParameters, substitutor, result);
return result;
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class GrClosureSignatureUtil method generateAllMethodSignaturesBySignature.
public static List<MethodSignature> generateAllMethodSignaturesBySignature(@NotNull final String name, @NotNull final GrSignature signature) {
final ArrayList<MethodSignature> result = new ArrayList<>();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
generateAllMethodSignaturesByClosureSignature(name, signature, PsiTypeParameter.EMPTY_ARRAY, PsiSubstitutor.EMPTY, result);
}
});
return result;
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class ClosureToSamConverter method findSingleAbstractMethod.
@Nullable
public static MethodSignature findSingleAbstractMethod(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor) {
MethodSignature signature;
Ref<MethodSignature> cached = SAM_SIGNATURE_LIGHT_CACHE_KEY.getCachedValue(aClass);
if (cached != null) {
signature = cached.get();
} else {
Ref<MethodSignature> newCached = Ref.create(doFindSingleAbstractMethodClass(aClass));
signature = SAM_SIGNATURE_LIGHT_CACHE_KEY.putCachedValue(aClass, newCached).get();
}
return signature != null ? substitute(signature, substitutor) : null;
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class ClosureToSamConverter method isConvertible.
@Override
public Boolean isConvertible(@NotNull PsiType ltype, @NotNull PsiType rtype, @NotNull final GroovyPsiElement context) {
if (rtype instanceof GrClosureType && ltype instanceof PsiClassType && isSamConversionAllowed(context) && !TypesUtil.isClassType(ltype, GroovyCommonClassNames.GROOVY_LANG_CLOSURE)) {
MethodSignature signature = findSAMSignature(ltype);
if (signature != null) {
final PsiType[] samParameterTypes = signature.getParameterTypes();
GrSignature closureSignature = ((GrClosureType) rtype).getSignature();
boolean raw = ((PsiClassType) ltype).isRaw();
if (raw)
return true;
if (GrClosureSignatureUtil.isSignatureApplicable(closureSignature, samParameterTypes, context)) {
return true;
}
}
}
return null;
}
use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.
the class SuspiciousCollectionsMethodCallsInspection method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final List<PsiMethod> patternMethods = new ArrayList<>();
final IntArrayList indices = new IntArrayList();
return new JavaElementVisitor() {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression methodCall) {
final String message = getSuspiciousMethodCallMessage(methodCall, REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, indices);
if (message != null) {
holder.registerProblem(methodCall.getArgumentList().getExpressions()[0], message);
}
}
@Override
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
final PsiClassType.ClassResolveResult functionalInterfaceResolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType);
if (interfaceMethod != null && interfaceMethod.getParameterList().getParametersCount() == 1) {
final PsiSubstitutor psiSubstitutor = LambdaUtil.getSubstitutor(interfaceMethod, functionalInterfaceResolveResult);
final MethodSignature signature = interfaceMethod.getSignature(psiSubstitutor);
String message = SuspiciousMethodCallUtil.getSuspiciousMethodCallMessage(expression, signature.getParameterTypes()[0], REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, indices);
if (message != null) {
holder.registerProblem(ObjectUtils.notNull(expression.getReferenceNameElement(), expression), message);
}
}
}
};
}
Aggregations