Search in sources :

Example 1 with GrTraitMethod

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod in project intellij-community by JetBrains.

the class GroovyOverrideImplementExploreUtil method getMapToOverrideImplement.

@NotNull
public static Map<MethodSignature, CandidateInfo> getMapToOverrideImplement(GrTypeDefinition aClass, boolean toImplement, boolean skipImplemented) {
    Map<MethodSignature, PsiMethod> abstracts = ContainerUtil.newLinkedHashMap();
    Map<MethodSignature, PsiMethod> finals = ContainerUtil.newLinkedHashMap();
    Map<MethodSignature, PsiMethod> concretes = ContainerUtil.newLinkedHashMap();
    PsiUtilCore.ensureValid(aClass);
    Collection<HierarchicalMethodSignature> allMethodSignatures = aClass.getVisibleSignatures();
    PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(aClass.getProject()).getResolveHelper();
    for (HierarchicalMethodSignature signature : allMethodSignatures) {
        PsiMethod method = signature.getMethod();
        if (method instanceof GrTraitMethod) {
            for (HierarchicalMethodSignature superSignature : signature.getSuperSignatures()) {
                processMethod(aClass, skipImplemented, abstracts, finals, concretes, resolveHelper, superSignature, superSignature.getMethod());
            }
        } else {
            processMethod(aClass, skipImplemented, abstracts, finals, concretes, resolveHelper, signature, method);
        }
    }
    final Map<MethodSignature, CandidateInfo> result = new TreeMap<>(new OverrideImplementExploreUtil.MethodSignatureComparator());
    if (toImplement || aClass.isInterface()) {
        collectMethodsToImplement(aClass, abstracts, finals, concretes, result);
    } else {
        for (Map.Entry<MethodSignature, PsiMethod> entry : concretes.entrySet()) {
            MethodSignature signature = entry.getKey();
            PsiMethod concrete = entry.getValue();
            if (finals.get(signature) == null) {
                PsiMethod abstractOne = abstracts.get(signature);
                if (abstractOne == null || !abstractOne.getContainingClass().isInheritor(concrete.getContainingClass(), true) || CommonClassNames.JAVA_LANG_OBJECT.equals(concrete.getContainingClass().getQualifiedName())) {
                    PsiSubstitutor subst = OverrideImplementExploreUtil.correctSubstitutor(concrete, signature.getSubstitutor());
                    CandidateInfo info = new CandidateInfo(concrete, subst);
                    result.put(signature, info);
                }
            }
        }
    }
    return result;
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) CandidateInfo(com.intellij.psi.infos.CandidateInfo) TreeMap(java.util.TreeMap) OverrideImplementExploreUtil(com.intellij.codeInsight.generation.OverrideImplementExploreUtil) GrTraitMethod(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod) TreeMap(java.util.TreeMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GrTraitMethod

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod in project intellij-community by JetBrains.

the class ClashingTraitMethodsInspectionBase method collectClassingMethods.

@NotNull
protected static List<ClashingMethod> collectClassingMethods(@NotNull GrTypeDefinition typeDefinition) {
    Collection<HierarchicalMethodSignature> visibleSignatures = typeDefinition.getVisibleSignatures();
    List<ClashingMethod> clashingMethods = ContainerUtil.newArrayList();
    for (HierarchicalMethodSignature signature : visibleSignatures) {
        PsiMethod method = signature.getMethod();
        if (method instanceof GrTraitMethod && method.getContainingClass() == typeDefinition) {
            List<HierarchicalMethodSignature> superSignatures = signature.getSuperSignatures();
            if (superSignatures.size() > 1) {
                List<GrTypeDefinition> traits = ContainerUtil.newArrayList();
                for (HierarchicalMethodSignature superSignature : superSignatures) {
                    PsiMethod superMethod = superSignature.getMethod();
                    PsiClass superClass = superMethod.getContainingClass();
                    if (GrTraitUtil.isTrait(superClass) && !superMethod.getModifierList().hasExplicitModifier(PsiModifier.ABSTRACT)) {
                        traits.add((GrTypeDefinition) superClass);
                    }
                }
                if (traits.size() > 1) {
                    clashingMethods.add(new ClashingMethod(signature, traits));
                }
            }
        }
    }
    return clashingMethods;
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) HierarchicalMethodSignature(com.intellij.psi.HierarchicalMethodSignature) GrTraitMethod(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GrTraitMethod

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod in project intellij-community by JetBrains.

the class TraitMethodImplementor method createImplementationPrototypes.

@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
    if (!(inClass instanceof GrTypeDefinition && method instanceof GrTraitMethod))
        return PsiMethod.EMPTY_ARRAY;
    final PsiClass containingClass = method.getContainingClass();
    PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true) ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY) : PsiSubstitutor.EMPTY;
    return new GrMethod[] { GroovyOverrideImplementUtil.generateTraitMethodPrototype((GrTypeDefinition) inClass, (GrTraitMethod) method, substitutor) };
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) GrTraitMethod(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)3 GrTraitMethod (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod)3 PsiClass (com.intellij.psi.PsiClass)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 OverrideImplementExploreUtil (com.intellij.codeInsight.generation.OverrideImplementExploreUtil)1 HierarchicalMethodSignature (com.intellij.psi.HierarchicalMethodSignature)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiSubstitutor (com.intellij.psi.PsiSubstitutor)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1