Set<RefOverridable> (RefMethod method) { final Set<RefOverridable> siblingReferences = new HashSet<>(); final Stack<RefOverridable> pendingReferences = new Stack<>(); pendingReferences.add(method); while (!pendingReferences.isEmpty()) { final RefOverridable referenceToAnalyze = pendingReferences.pop(); siblingReferences.add(referenceToAnalyze); final Collection<? extends RefOverridable> overridingReferences = referenceToAnalyze.getDerivedReferences(); for (RefOverridable overridingReference : overridingReferences) { if (!siblingReferences.contains(overridingReference) && !pendingReferences.contains(overridingReference)) { pendingReferences.add(overridingReference); } } if (referenceToAnalyze instanceof RefMethod) { final Collection<RefMethod> superMethods = ((RefMethod)referenceToAnalyze).getSuperMethods(); for (RefMethod superMethod : superMethods) { if (!siblingReferences.contains(superMethod) && !pendingReferences.contains(superMethod)) { pendingReferences.add(superMethod); } } } } return siblingReferences; }