This commit is contained in:
Alexey Kudravtsev
2016-04-01 14:37:47 +03:00
parent ab23f498d1
commit a9deb438f6
2 changed files with 39 additions and 42 deletions
@@ -248,10 +248,10 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
range = aClass;
}
MarkerType type = MarkerType.SUBCLASSED_CLASS;
LineMarkerInfo info = new LineMarkerInfo<PsiElement>(range, range.getTextRange(),
icon, Pass.UPDATE_OVERRIDDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
LineMarkerInfo info = new LineMarkerInfo<>(range, range.getTextRange(),
icon, Pass.UPDATE_OVERRIDDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
NavigateAction.setNavigateAction(info, aClass.isInterface() ? "Go to implementation(s)" : "Go to subclass(es)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
result.add(info);
}
@@ -260,16 +260,16 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
private void collectOverridingMethods(@NotNull final Collection<PsiMethod> methods, @NotNull Collection<LineMarkerInfo> result) {
if (!myOverriddenOption.isEnabled() && !myImplementedOption.isEnabled()) return;
final Set<PsiMethod> overridden = new HashSet<>();
Set<PsiClass> classes = new THashSet<>();
Set<PsiClass> methodContainingClasses = new THashSet<>();
for (PsiMethod method : methods) {
ProgressManager.checkCanceled();
final PsiClass parentClass = method.getContainingClass();
if (!CommonClassNames.JAVA_LANG_OBJECT.equals(parentClass.getQualifiedName())) {
classes.add(parentClass);
PsiClass containingClass = method.getContainingClass();
if (containingClass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
methodContainingClasses.add(containingClass);
}
}
for (final PsiClass aClass : classes) {
for (final PsiClass aClass : methodContainingClasses) {
AllOverridingMethodsSearch.search(aClass).forEach(pair -> {
ProgressManager.checkCanceled();
@@ -282,7 +282,7 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
}
if (!methods.isEmpty()) {
for (PsiClass aClass : classes) {
for (PsiClass aClass : methodContainingClasses) {
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass);
if (interfaceMethod != null) {
if (FunctionalExpressionSearch.search(aClass).findFirst() != null) {
@@ -304,10 +304,10 @@ public class JavaLineMarkerProvider extends LineMarkerProviderDescriptor {
PsiElement range = getMethodRange(method);
final MarkerType type = MarkerType.OVERRIDDEN_METHOD;
final Icon icon = overrides ? AllIcons.Gutter.OverridenMethod : AllIcons.Gutter.ImplementedMethod;
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<PsiElement>(range, range.getTextRange(),
icon, Pass.UPDATE_OVERRIDDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(range, range.getTextRange(),
icon, Pass.UPDATE_OVERRIDDEN_MARKERS, type.getTooltip(),
type.getNavigationHandler(),
GutterIconRenderer.Alignment.RIGHT);
NavigateAction.setNavigateAction(info, overrides ? "Go to overriding methods" : "Go to implementation(s)", IdeActions.ACTION_GOTO_IMPLEMENTATION);
result.add(info);
}
@@ -52,44 +52,41 @@ public class JavaAllOverridingMethodsSearcher implements QueryExecutor<Pair<PsiM
final SearchScope scope = p.getScope();
Processor<PsiClass> inheritorsProcessor = new Processor<PsiClass>() {
@Override
public boolean process(PsiClass inheritor) {
PsiSubstitutor substitutor = null;
Processor<PsiClass> inheritorsProcessor = inheritor -> {
PsiSubstitutor substitutor = null;
for (String name : potentials.keySet()) {
if (inheritor.findMethodsByName(name, true).length == 0) continue;
for (String name : potentials.keySet()) {
if (inheritor.findMethodsByName(name, true).length == 0) continue;
for (PsiMethod superMethod : potentials.get(name)) {
if (superMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) &&
!JavaPsiFacade.getInstance(inheritor.getProject()).arePackagesTheSame(psiClass, inheritor)) continue;
for (PsiMethod superMethod : potentials.get(name)) {
if (superMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) &&
!JavaPsiFacade.getInstance(inheritor.getProject()).arePackagesTheSame(psiClass, inheritor)) continue;
if (substitutor == null) {
//could be null if not java inheritor, TODO only JavaClassInheritors are needed
substitutor = TypeConversionUtil.getClassSubstitutor(psiClass, inheritor, PsiSubstitutor.EMPTY);
if (substitutor == null) return true;
}
if (substitutor == null) {
//could be null if not java inheritor, TODO only JavaClassInheritors are needed
substitutor = TypeConversionUtil.getClassSubstitutor(psiClass, inheritor, PsiSubstitutor.EMPTY);
if (substitutor == null) return true;
}
MethodSignature superSignature = superMethod.getSignature(substitutor);
PsiMethod inInheritor = MethodSignatureUtil.findMethodBySuperSignature(inheritor, superSignature, false);
if (inInheritor != null && !inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (!consumer.process(Pair.create(superMethod, inInheritor))) return false;
}
MethodSignature superSignature = superMethod.getSignature(substitutor);
PsiMethod inInheritor = MethodSignatureUtil.findMethodBySuperSignature(inheritor, superSignature, false);
if (inInheritor != null && !inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (!consumer.process(Pair.create(superMethod, inInheritor))) return false;
}
if (psiClass.isInterface() && !inheritor.isInterface()) { //check for sibling implementation
final PsiClass superClass = inheritor.getSuperClass();
if (superClass != null && !superClass.isInheritor(psiClass, true)) {
inInheritor = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(inheritor, superClass, superSignature, true);
if (inInheritor != null && !inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (!consumer.process(Pair.create(superMethod, inInheritor))) return false;
}
if (psiClass.isInterface() && !inheritor.isInterface()) { //check for sibling implementation
final PsiClass superClass = inheritor.getSuperClass();
if (superClass != null && !superClass.isInheritor(psiClass, true)) {
inInheritor = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(inheritor, superClass, superSignature, true);
if (inInheritor != null && !inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (!consumer.process(Pair.create(superMethod, inInheritor))) return false;
}
}
}
}
return true;
}
return true;
};
return ClassInheritorsSearch.search(psiClass, scope, true).forEach(inheritorsProcessor);