Search in sources :

Example 11 with MethodSignature

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;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)

Example 12 with MethodSignature

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;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) GrRecursiveSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)

Example 13 with MethodSignature

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;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with MethodSignature

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;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) GrSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature) GrClosureType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)

Example 15 with MethodSignature

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);
                }
            }
        }
    };
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) IntArrayList(com.intellij.util.containers.IntArrayList) ArrayList(java.util.ArrayList) IntArrayList(com.intellij.util.containers.IntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MethodSignature (com.intellij.psi.util.MethodSignature)31 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 com.intellij.psi (com.intellij.psi)3 List (java.util.List)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 TextRange (com.intellij.openapi.util.TextRange)2 CandidateInfo (com.intellij.psi.infos.CandidateInfo)2 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)2 Processor (com.intellij.util.Processor)2 GrSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature)2 GrClosureType (org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)2 OverrideImplementExploreUtil (com.intellij.codeInsight.generation.OverrideImplementExploreUtil)1 RedundantLambdaCodeBlockInspection (com.intellij.codeInspection.RedundantLambdaCodeBlockInspection)1 FindBundle (com.intellij.find.FindBundle)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1