diff --git a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java index 99e7e2e50661..7f8718d2cbe6 100644 --- a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java +++ b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodDialog.java @@ -30,7 +30,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase { protected JComponent createCenterPanel() { JPanel mainPanel = new JPanel(new GridBagLayout()); - final JLabel jLabel = new JLabel("Select an instance parameter:"); + final JLabel jLabel = new JLabel("Select an instance variable:"); jLabel.setDisplayedMnemonic('i'); mainPanel.add(jLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0,0)); diff --git a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java index f13f2437bfb6..175e411c2840 100644 --- a/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java +++ b/source/com/intellij/refactoring/move/moveInstanceMethod/MoveInstanceMethodProcessor.java @@ -173,6 +173,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ protected void performRefactoring(UsageInfo[] usages) { PsiMethod patternMethod = createPatternMethod(); + final List docRefs = new ArrayList(); for (int i = 0; i < usages.length; i++) { UsageInfo usage = usages[i]; if (usage instanceof InheritorUsageInfo) { @@ -181,15 +182,19 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ } else if (usage instanceof MethodCallUsageInfo) { correctMethodCall (((MethodCallUsageInfo)usage).getMethodCallExpression()); } else if (usage instanceof JavadocUsageInfo) { - //TODO:!!! + docRefs.add(usage.getElement().getReference()); } } try { if (myTargetClass.isInterface()) patternMethod.getBody().delete(); - addMethodToClass(myTargetClass, patternMethod); + final PsiMethod method = addMethodToClass(myTargetClass, patternMethod); myMethod.delete(); + for (Iterator it = docRefs.iterator(); it.hasNext();) { + PsiReference reference = it.next(); + reference.bindToElement(method); + } } catch (IncorrectOperationException e) { LOG.error(e); @@ -226,14 +231,17 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ } } - private void addMethodToClass(final PsiClass aClass, final PsiMethod patternMethod) { + private PsiMethod addMethodToClass(final PsiClass aClass, final PsiMethod patternMethod) { try { - final PsiElement method = aClass.add(patternMethod); + final PsiMethod method = (PsiMethod)aClass.add(patternMethod); ChangeContextUtil.decodeContextInfo(method, null, null); + return method; } catch (IncorrectOperationException e) { LOG.error(e); } + + return null; } private PsiMethod createPatternMethod () { @@ -295,6 +303,9 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{ final PsiClassType type = factory.createType(myMethod.getContainingClass()); final PsiParameter parameter = factory.createParameter(myOldClassParameterName, type); methodCopy.getParameterList().add(parameter); + + final List newParameters = Arrays.asList(methodCopy.getParameterList().getParameters()); + RefactoringUtil.fixJavadocsForParams(methodCopy, new HashSet(newParameters)); } catch (IncorrectOperationException e) { LOG.error(e); diff --git a/testData/refactoring/moveInstanceMethod/Javadoc.java b/testData/refactoring/moveInstanceMethod/Javadoc.java new file mode 100644 index 000000000000..939179184b11 --- /dev/null +++ b/testData/refactoring/moveInstanceMethod/Javadoc.java @@ -0,0 +1,17 @@ +class Foreign { +} + +public abstract class Test1 { + + /** + * @param f + */ + void foo (Foreign f) { + } + + /** + * @see #foo(Foreign) + */ + void bar () { + } +} \ No newline at end of file diff --git a/testData/refactoring/moveInstanceMethod/Javadoc.java.after b/testData/refactoring/moveInstanceMethod/Javadoc.java.after new file mode 100644 index 000000000000..57696496dbe6 --- /dev/null +++ b/testData/refactoring/moveInstanceMethod/Javadoc.java.after @@ -0,0 +1,16 @@ +class Foreign { + /** + * @param test1 + */ + void foo(Test1 test1) { + } +} + +public abstract class Test1 { + + /** + * @see Foreign#foo(Test1) + */ + void bar () { + } +} \ 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 3765bdae3146..30e492e4ddbd 100644 --- a/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java +++ b/testSource/com/intellij/refactoring/moveMethod/MoveInstanceMethodTest.java @@ -21,6 +21,8 @@ public class MoveInstanceMethodTest extends LightCodeInsightTestCase { public void testWithInner() throws Exception { doTestForTargetParameter(true, 0); } + public void testJavadoc() throws Exception { doTestForTargetParameter(true, 0); } + private void doTestForTargetParameter(boolean isTargetParameter, final int targetIndex) throws Exception {