move method tests.

This commit is contained in:
Eugene Vigdorchik
2005-01-31 13:44:48 +03:00
parent c648ba6381
commit 2da790170c
5 changed files with 51 additions and 5 deletions
@@ -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));
@@ -173,6 +173,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
protected void performRefactoring(UsageInfo[] usages) {
PsiMethod patternMethod = createPatternMethod();
final List<PsiReference> docRefs = new ArrayList<PsiReference>();
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<PsiReference> 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<PsiParameter> newParameters = Arrays.asList(methodCopy.getParameterList().getParameters());
RefactoringUtil.fixJavadocsForParams(methodCopy, new HashSet<PsiParameter>(newParameters));
}
catch (IncorrectOperationException e) {
LOG.error(e);
@@ -0,0 +1,17 @@
class Foreign {
}
public abstract class Test1 {
/**
* @param f
*/
void <caret>foo (Foreign f) {
}
/**
* @see #foo(Foreign)
*/
void bar () {
}
}
@@ -0,0 +1,16 @@
class Foreign {
/**
* @param test1
*/
void foo(Test1 test1) {
}
}
public abstract class Test1 {
/**
* @see Foreign#foo(Test1)
*/
void bar () {
}
}
@@ -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 {