diff --git a/source/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java b/source/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java index c10853feb2d0..33b84db4fd86 100644 --- a/source/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java +++ b/source/com/intellij/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java @@ -60,7 +60,7 @@ public class ConvertToInstanceMethodHandler implements RefactoringActionHandler for (int i = 0; i < parameters.length; i++) { final PsiParameter parameter = parameters[i]; final PsiType type = parameter.getType(); - if (type instanceof PsiClassType && !((PsiClassType)type).hasParameters()) { + if (type instanceof PsiClassType) { classTypesFound = true; final PsiClass psiClass = ((PsiClassType)type).resolve(); if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) { diff --git a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodHandler.java b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodHandler.java index 2fadbb248c39..60a14d18ac7f 100644 --- a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodHandler.java +++ b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodHandler.java @@ -11,6 +11,7 @@ import com.intellij.psi.codeStyle.SuggestedNameInfo; import com.intellij.psi.codeStyle.VariableKind; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiSuperMethodUtil; +import com.intellij.psi.util.PsiUtil; import com.intellij.refactoring.HelpID; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.util.RefactoringMessageUtil; @@ -59,6 +60,13 @@ public class MoveInstanceMethodHandler implements RefactoringActionHandler { return; } + if (PsiUtil.typeParametersIterator(method.getContainingClass()).hasNext()) { + String message = "Cannot perform the refactoring.\n" + + "Move method is not supported for generic classes"; + RefactoringMessageUtil.showErrorMessage(REFACTORING_NAME, message, HelpID.MOVE_INSTANCE_METHOD, project); + return; + } + if (PsiSuperMethodUtil.findSuperMethods(method).length > 0 || method.getManager().getSearchHelper().findOverridingMethods(method, GlobalSearchScope.allScope(project), true).length > 0) { String message = "Cannot perform the refactoring.\n" + diff --git a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java index 06385fd1416f..f13f2437bfb6 100644 --- a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java +++ b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java @@ -17,6 +17,7 @@ import com.intellij.usageView.FindUsagesCommand; import com.intellij.usageView.UsageInfo; import com.intellij.usageView.UsageViewDescriptor; import com.intellij.util.IncorrectOperationException; +import com.intellij.codeInsight.ChangeContextUtil; import java.util.*; @@ -227,7 +228,8 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ private void addMethodToClass(final PsiClass aClass, final PsiMethod patternMethod) { try { - aClass.add(patternMethod); + final PsiElement method = aClass.add(patternMethod); + ChangeContextUtil.decodeContextInfo(method, null, null); } catch (IncorrectOperationException e) { LOG.error(e); @@ -235,6 +237,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ } private PsiMethod createPatternMethod () { + ChangeContextUtil.encodeContextInfo(myMethod, true); final PsiMethod methodCopy = (PsiMethod)myMethod.copy(); final PsiElement elementAt = methodCopy.getContainingFile().findElementAt(myTargetVariable.getTextRange().getStartOffset()); final PsiVariable variableCopy = PsiTreeUtil.getParentOfType(elementAt, PsiVariable.class); diff --git a/testData/refactoring/moveInstanceMethod/WithInner.java b/testData/refactoring/moveInstanceMethod/WithInner.java new file mode 100644 index 000000000000..415ce95e2872 --- /dev/null +++ b/testData/refactoring/moveInstanceMethod/WithInner.java @@ -0,0 +1,15 @@ +class Foreign { + class Inner {} +} + + +public abstract class Test1 { + void foo (Foreign f, Inner i) { + } + + class Inner {} + + void bar () { + foo(new Foreign(), new Inner()); + } +} \ No newline at end of file diff --git a/testData/refactoring/moveInstanceMethod/WithInner.java.after b/testData/refactoring/moveInstanceMethod/WithInner.java.after new file mode 100644 index 000000000000..efa97cfb8450 --- /dev/null +++ b/testData/refactoring/moveInstanceMethod/WithInner.java.after @@ -0,0 +1,16 @@ +class Foreign { + void foo(Test1.Inner i, Test1 test1) { + } + + class Inner {} +} + + +public abstract class Test1 { + + class Inner {} + + void bar () { + new Foreign().foo(new Inner(), this); + } +} \ No newline at end of file diff --git a/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java b/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java index c04d26800f2f..3765bdae3146 100644 --- a/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java +++ b/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java @@ -19,6 +19,8 @@ public class MoveInstanceMethodTest extends LightCodeInsightTestCase { public void testInterface() throws Exception { doTestForTargetParameter(true, 0); } + public void testWithInner() throws Exception { doTestForTargetParameter(true, 0); } + private void doTestForTargetParameter(boolean isTargetParameter, final int targetIndex) throws Exception {