mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline constant field: preserve qualifiers
This commit is contained in:
@@ -161,6 +161,16 @@ class InlineConstantFieldProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
myField.normalizeDeclaration();
|
||||
ChangeContextUtil.encodeContextInfo(initializer1, true);
|
||||
if (expr instanceof PsiReferenceExpression) {
|
||||
PsiExpression qExpression = ((PsiReferenceExpression)expr).getQualifierExpression();
|
||||
if (qExpression != null) {
|
||||
if (initializer1 instanceof PsiMethodCallExpression) {
|
||||
((PsiMethodCallExpression)initializer1).getMethodExpression().setQualifierExpression(qExpression);
|
||||
} else if (initializer1 instanceof PsiReferenceExpression) {
|
||||
((PsiReferenceExpression)initializer1).setQualifierExpression(qExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
PsiElement element = expr.replace(initializer1);
|
||||
ChangeContextUtil.decodeContextInfo(element, null, null);
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class QTest {
|
||||
final int myI = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new QTest().my<caret>I);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class QTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class QTest {
|
||||
final int myI = foo();
|
||||
int foo(){return 0;}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new QTest().my<caret>I);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class QTest {
|
||||
int foo(){return 0;}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new QTest().foo());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.intellij.refactoring.inline;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
public class InlineConstantFieldTest extends LightCodeInsightTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testQualifiedExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testQualifiedConstantExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JavaSdkImpl.getMockJdk15("java 1.5");
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
String name = getTestName(false);
|
||||
@NonNls String fileName = "/refactoring/inlineConstantField/" + name + ".java";
|
||||
configureByFile(fileName);
|
||||
performAction();
|
||||
checkResultByFile(fileName + ".after");
|
||||
}
|
||||
|
||||
private void performAction() {
|
||||
PsiElement element = TargetElementUtilBase
|
||||
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
|
||||
final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
|
||||
PsiReferenceExpression refExpr = ref instanceof PsiReferenceExpression ? (PsiReferenceExpression)ref : null;
|
||||
assertTrue(element instanceof PsiField);
|
||||
PsiField field = (PsiField)element;
|
||||
new InlineConstantFieldProcessor(field, getProject(), refExpr, false).run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user