mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
+14
-17
@@ -277,29 +277,26 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
if (body != null) {
|
||||
body.accept(new PsiRecursiveElementVisitor() {
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
if (qualifier == null || qualifier instanceof PsiThisExpression) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiMember &&
|
||||
((PsiMember)resolved).getContainingClass().equals(methodCopy.getContainingClass())) {
|
||||
try {
|
||||
try {
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
if (qualifier == null || qualifier instanceof PsiThisExpression) {
|
||||
final PsiElement resolved = expression.resolve();
|
||||
if (resolved instanceof PsiMember && ((PsiMember)resolved).getContainingClass().equals(methodCopy.getContainingClass())) {
|
||||
PsiReferenceExpression qualified = (PsiReferenceExpression)factory.createExpressionFromText(myOldClassParameterName + ".f", null);
|
||||
qualified.getReferenceNameElement().replace(expression.getReferenceNameElement());
|
||||
expression.replace(qualified);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
else if (variableCopy.equals(resolved)) {
|
||||
PsiThisExpression thisExpression = (PsiThisExpression)factory.createExpressionFromText("this", null);
|
||||
expression.replace(thisExpression);
|
||||
}
|
||||
}
|
||||
} else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).isReferenceTo(variableCopy)) {
|
||||
try {
|
||||
qualifier.delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
} else if (qualifier instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifier).isReferenceTo(variableCopy)) {
|
||||
qualifier.delete(); }
|
||||
super.visitReferenceExpression(expression);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
super.visitReferenceExpression(expression);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class MoveMethodTest {
|
||||
void <caret>foo (MoveMethodTest f) {
|
||||
f.foo(f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class MoveMethodTest {
|
||||
|
||||
void foo(MoveMethodTest moveMethodTest) {
|
||||
foo(this);
|
||||
}
|
||||
}
|
||||
@@ -13,19 +13,21 @@ import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
*/
|
||||
public class MoveInstanceMethodTest extends LightCodeInsightTestCase {
|
||||
|
||||
public void testSimple() throws Exception { doTestForTargetParameter(true, 0); }
|
||||
public void testSimple() throws Exception { doTest(true, 0); }
|
||||
|
||||
public void testSimpleWithTargetField() throws Exception { doTestForTargetParameter(false, 1); }
|
||||
public void testSimpleWithTargetField() throws Exception { doTest(false, 1); }
|
||||
|
||||
public void testInterface() throws Exception { doTestForTargetParameter(true, 0); }
|
||||
public void testInterface() throws Exception { doTest(true, 0); }
|
||||
|
||||
public void testWithInner() throws Exception { doTestForTargetParameter(true, 0); }
|
||||
public void testWithInner() throws Exception { doTest(true, 0); }
|
||||
|
||||
public void testJavadoc() throws Exception { doTestForTargetParameter(true, 0); }
|
||||
public void testJavadoc() throws Exception { doTest(true, 0); }
|
||||
|
||||
public void testRecursive() throws Exception { doTest(true, 0); }
|
||||
|
||||
|
||||
|
||||
private void doTestForTargetParameter(boolean isTargetParameter, final int targetIndex) throws Exception {
|
||||
private void doTest(boolean isTargetParameter, final int targetIndex) throws Exception {
|
||||
final String filePath = "/refactoring/moveInstanceMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(filePath);
|
||||
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
|
||||
Reference in New Issue
Block a user