use of com.intellij.psi.HierarchicalMethodSignature in project intellij-community by JetBrains.
the class ClashingTraitMethodsInspectionBase method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
super.visitTypeDefinition(typeDefinition);
List<PsiClass> superTraits = collectImplementedTraits(typeDefinition);
if (superTraits.size() < 2)
return;
List<ClashingMethod> clashingMethods = collectClassingMethods(typeDefinition);
for (ClashingMethod clashing : clashingMethods) {
registerError(typeDefinition.getNameIdentifierGroovy(), buildWarning(clashing), new LocalQuickFix[] { getFix() }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
@NotNull
private String buildWarning(@NotNull ClashingMethod entry) {
return "Traits " + buildTraitString(entry) + " contain clashing methods with signature " + buildSignatureString(entry);
}
@NotNull
private String buildSignatureString(@NotNull ClashingMethod entry) {
HierarchicalMethodSignature signature = entry.getSignature();
return PsiFormatUtil.formatMethod(signature.getMethod(), signature.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
}
@NotNull
private String buildTraitString(@NotNull ClashingMethod entry) {
return StringUtil.join(entry.getSuperTraits(), tr -> tr.getName(), ", ");
}
};
}
use of com.intellij.psi.HierarchicalMethodSignature 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;
}
Aggregations