From 9ba225cde5dd09367a0be75db8af8297a6b4b845 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 23 Nov 2015 16:59:10 +0300 Subject: [PATCH] type migration: do not migrate super method if return-type isn't same --- .../refactoring/typeMigration/Util.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/Util.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/Util.java index 43175d7d7c6e..b779fb6e5645 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/Util.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/Util.java @@ -17,8 +17,12 @@ package com.intellij.refactoring.typeMigration; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.SmartList; +import com.intellij.util.containers.Queue; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** * @author db * Date: Nov 4, 2004 @@ -39,9 +43,25 @@ public class Util { @Nullable public static PsiElement normalizeElement(final PsiElement element) { if (element instanceof PsiMethod) { - final PsiMethod superMethod = ((PsiMethod)element).findDeepestSuperMethod(); - - return superMethod == null ? element : superMethod; + final PsiMethod method = (PsiMethod)element; + final PsiType initialMethodReturnType = method.getReturnType(); + if (initialMethodReturnType == null) { + return null; + } + final List normalized = new SmartList(); + final Queue queue = new Queue(1); + queue.addLast(method); + while (!queue.isEmpty()) { + final PsiMethod currentMethod = queue.pullFirst(); + if (initialMethodReturnType.equals(currentMethod.getReturnType())) { + for (PsiMethod toConsume : currentMethod.findSuperMethods(false)) { + queue.addLast(toConsume); + } + normalized.add(currentMethod); + } + } + //TODO Dmitry Batkovich multiple result is possible + return normalized.isEmpty() ? element : normalized.get(normalized.size() - 1); } else if (element instanceof PsiParameter && element.getParent() instanceof PsiParameterList) { final PsiElement declarationScope = ((PsiParameter)element).getDeclarationScope();