move method tests. To be continued...

This commit is contained in:
Eugene Vigdorchik
2005-01-31 13:14:16 +03:00
parent 3950838b00
commit c648ba6381
6 changed files with 46 additions and 2 deletions
@@ -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)) {
@@ -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" +
@@ -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);
@@ -0,0 +1,15 @@
class Foreign {
class Inner {}
}
public abstract class Test1 {
void <caret>foo (Foreign f, Inner i) {
}
class Inner {}
void bar () {
foo(new Foreign(), new Inner());
}
}
@@ -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);
}
}
@@ -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 {