@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; }
@Override public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) { final PsiClass parentClass = queryParameters.getPsiClass(); final PsiMethod method = queryParameters.getMethod(); return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature(); final boolean checkBases = queryParameters.isCheckBases(); final boolean allowStaticMethod = queryParameters.isAllowStaticMethod(); final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures(); for(HierarchicalMethodSignature superSignature : supers) { if(MethodSignatureUtil.isSubsignature(superSignature, signature)) { if(!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) { return false; } } } return true; } }); }
private static boolean addSuperMethods(final HierarchicalMethodSignature signature, final PsiMethod method, final PsiClass parentClass, final boolean allowStaticMethod, final boolean checkBases, final Processor<MethodSignatureBackedByPsiMethod> consumer) { PsiMethod signatureMethod = signature.getMethod(); PsiClass hisClass = signatureMethod.getContainingClass(); if(parentClass == null || InheritanceUtil.isInheritorOrSelf(parentClass, hisClass, true)) { if(isAcceptable(signatureMethod, method, allowStaticMethod)) { if(parentClass != null && !parentClass.equals(hisClass) && !checkBases) { return true; } LOG.assertTrue(signatureMethod != method, method); // method != method.getsuper() return consumer.process(signature); //no need to check super classes } } for(HierarchicalMethodSignature superSignature : signature.getSuperSignatures()) { if(MethodSignatureUtil.isSubsignature(superSignature, signature)) { addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer); } } return true; }
@Nullable private static PsiMethod checkPackageLocalInSuperClass(@NotNull PsiClass aClass) { // super class can have package local abstract methods not accessible for overriding PsiClass superClass = aClass.getSuperClass(); if (superClass == null) return null; if (CommonClassNames.JAVA_LANG_OBJECT.equals(aClass.getQualifiedName())) return null; if (JavaPsiFacade.getInstance(aClass.getProject()).arePackagesTheSame(aClass, superClass)) return null; for (HierarchicalMethodSignature methodSignature : superClass.getVisibleSignatures()) { PsiMethod method = methodSignature.getMethod(); if (method.hasModifierProperty(PsiModifier.ABSTRACT) && method.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) return method; } return null; }
public void addSuperSignature(@NotNull HierarchicalMethodSignature superSignatureHierarchical) { if (mySupers == null) mySupers = new SmartList<HierarchicalMethodSignature>(); mySupers.add(superSignatureHierarchical); }
@Override @NotNull public List<HierarchicalMethodSignature> getSuperSignatures() { return mySupers == null ? Collections.<HierarchicalMethodSignature>emptyList() : mySupers; }
public ClashingMethod(@NotNull HierarchicalMethodSignature signature, @NotNull List<GrTypeDefinition> superTraits) { mySignature = signature; mySuperTraits = superTraits; }
@NotNull public HierarchicalMethodSignature getSignature() { return mySignature; }