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;
}
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;
}
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) };
}
Aggregations