Search in sources :

Example 26 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class TransformationContextImpl method doAddMethod.

private void doAddMethod(@NotNull PsiMethod method, boolean prepend) {
    if (method instanceof GrLightMethodBuilder) {
        ((GrLightMethodBuilder) method).setContainingClass(myCodeClass);
    } else if (method instanceof LightMethodBuilder) {
        ((LightMethodBuilder) method).setContainingClass(myCodeClass);
    }
    MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
    Set<MethodSignature> signatures = mySignaturesCache.get(method.getName());
    if (signatures.add(signature)) {
        if (prepend) {
            myMethods.addFirst(method);
        } else {
            myMethods.addLast(method);
        }
    }
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 27 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.

private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
    final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
    final String name = prototype.getName();
    if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
        return;
    final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
    final PsiType returnType;
    if (getter instanceof GrMethod) {
        returnType = ((GrMethod) getter).getInferredReturnType();
    } else if (getter instanceof GrAccessorMethod) {
        returnType = ((GrAccessorMethod) getter).getInferredReturnType();
    } else {
        return;
    }
    if (!(returnType instanceof GrClosureType))
        return;
    final GrSignature signature = ((GrClosureType) returnType).getSignature();
    signature.accept(new GrRecursiveSignatureVisitor() {

        @Override
        public void visitClosureSignature(GrClosureSignature signature) {
            NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
                final GrClosureParameter[] params = signature.getParameters();
                final PsiType[] types = prototypeSignature.getParameterTypes();
                if (types.length != params.length)
                    continue;
                for (int i = 0; i < types.length; i++) {
                    if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
                        continue NextSignature;
                    }
                }
                conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
            }
        }
    });
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) GrRecursiveSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature) GrClosureType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)

Example 28 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class GrMethodConflictUtil method checkForMethodSignatureOverload.

private static void checkForMethodSignatureOverload(PsiClass clazz, GrMethod prototype, GrMethod refactoredMethod, MultiMap<PsiElement, String> conflicts, boolean excludeJavaConflicts, List<MethodSignature> prototypeSignatures) {
    if (excludeJavaConflicts) {
        prototypeSignatures.remove(prototype.getSignature(PsiSubstitutor.EMPTY));
    }
    String newName = prototype.getName();
    PsiMethod[] methods = clazz.findMethodsByName(newName, false);
    MultiMap<MethodSignature, PsiMethod> signatures = GrClosureSignatureUtil.findRawMethodSignatures(methods, clazz);
    for (MethodSignature prototypeSignature : prototypeSignatures) {
        for (PsiMethod method : signatures.get(prototypeSignature)) {
            if (method != refactoredMethod) {
                String signaturePresentation = GroovyPresentationUtil.getSignaturePresentation(prototypeSignature);
                conflicts.putValue(method, GroovyRefactoringBundle.message("method.duplicate", signaturePresentation, RefactoringUIUtil.getDescription(clazz, false)));
                break;
            }
        }
    }
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature)

Example 29 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class GroovyOverrideImplementExploreUtil method collectMethodsToImplement.

public static void collectMethodsToImplement(PsiClass aClass, Map<MethodSignature, PsiMethod> abstracts, Map<MethodSignature, PsiMethod> finals, Map<MethodSignature, PsiMethod> concretes, Map<MethodSignature, CandidateInfo> result) {
    for (Map.Entry<MethodSignature, PsiMethod> entry : abstracts.entrySet()) {
        MethodSignature signature = entry.getKey();
        PsiMethod abstractOne = entry.getValue();
        PsiMethod concrete = concretes.get(signature);
        if (concrete == null || PsiUtil.getAccessLevel(concrete.getModifierList()) < PsiUtil.getAccessLevel(abstractOne.getModifierList()) || !abstractOne.getContainingClass().isInterface() && abstractOne.getContainingClass().isInheritor(concrete.getContainingClass(), true) || isDefaultMethod(abstractOne)) {
            if (finals.get(signature) == null) {
                PsiSubstitutor subst = OverrideImplementExploreUtil.correctSubstitutor(abstractOne, signature.getSubstitutor());
                CandidateInfo info = new CandidateInfo(abstractOne, subst);
                result.put(signature, info);
            }
        }
    }
    for (final PsiMethod method : new GroovyMethodImplementor().getMethodsToImplement(aClass)) {
        MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), method.getTypeParameterList(), PsiSubstitutor.EMPTY, method.isConstructor());
        CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY);
        result.put(signature, info);
    }
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) CandidateInfo(com.intellij.psi.infos.CandidateInfo) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 30 with MethodSignature

use of com.intellij.psi.util.MethodSignature in project intellij-community by JetBrains.

the class ClosureToSamConverter method doFindSingleAbstractMethodClass.

@Nullable
private static MethodSignature doFindSingleAbstractMethodClass(@NotNull PsiClass aClass) {
    Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(aClass);
    if (toImplement.size() > 1)
        return null;
    MethodSignature abstractSignature = toImplement.isEmpty() ? null : toImplement.iterator().next();
    for (PsiMethod method : aClass.getMethods()) {
        if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
            if (abstractSignature != null)
                return null;
            abstractSignature = method.getSignature(PsiSubstitutor.EMPTY);
        }
    }
    return abstractSignature;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) Nullable(org.jetbrains.annotations.Nullable)

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