mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
introduce parameter: fix getter call
This commit is contained in:
@@ -227,10 +227,9 @@ public class OldReferenceResolver {
|
||||
if (JavaPsiFacade.getInstance(psiField.getProject()).getResolveHelper().isAccessible(getter, newExpr, null)) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(newExpr.getProject()).getElementFactory();
|
||||
String id = getter.getName();
|
||||
final PsiElement parent = newExpr.getParent();
|
||||
String qualifier = null;
|
||||
if (parent instanceof PsiReferenceExpression) {
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)parent).getQualifierExpression();
|
||||
if (newExpr instanceof PsiReferenceExpression) {
|
||||
final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
qualifier = qualifierExpression.getText();
|
||||
}
|
||||
@@ -238,8 +237,8 @@ public class OldReferenceResolver {
|
||||
PsiMethodCallExpression getterCall =
|
||||
(PsiMethodCallExpression)factory.createExpressionFromText((qualifier != null ? qualifier + "." : "") + id + "()", null);
|
||||
getterCall = (PsiMethodCallExpression)CodeStyleManager.getInstance(myProject).reformat(getterCall);
|
||||
if (parent != null) {
|
||||
newExpr = parent.replace(getterCall);
|
||||
if (newExpr.getParent() != null) {
|
||||
newExpr = newExpr.replace(getterCall);
|
||||
}
|
||||
else {
|
||||
newExpr = getterCall;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
public class R {
|
||||
private static int ourInt;
|
||||
|
||||
public static int getOurInt() {
|
||||
return ourInt;
|
||||
}
|
||||
|
||||
public static void doSmth(final int anObject) {
|
||||
System.out.println(anObject);
|
||||
}
|
||||
}
|
||||
|
||||
class Usage {
|
||||
void foo() {
|
||||
R.doSmth(R.getOurInt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
public class R {
|
||||
private static int ourInt;
|
||||
|
||||
public static int getOurInt() {
|
||||
return ourInt;
|
||||
}
|
||||
|
||||
public static void doSmth() {
|
||||
System.out.println(<selection>ourInt</selection>);
|
||||
}
|
||||
}
|
||||
|
||||
class Usage {
|
||||
void foo() {
|
||||
R.doSmth();
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,10 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
"Incomplete call(Root()): expected to delete the 1 parameter but only 0 parameters found");
|
||||
}
|
||||
|
||||
public void testStaticFieldWithGetterReplacement() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
|
||||
}
|
||||
|
||||
private void doTestThroughHandler() throws Exception {
|
||||
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
|
||||
new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() {
|
||||
|
||||
Reference in New Issue
Block a user