introduce constant: add constant to destination class (IDEA-146787)

This commit is contained in:
Anna Kozlova
2015-10-29 19:40:10 +01:00
parent 8a96f088f1
commit 2f4fddec5a
4 changed files with 33 additions and 6 deletions
@@ -894,13 +894,10 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
return field;
}
else {
if (forwardReference != null ) {
return forwardReference.getParent() == destClass ?
(PsiField)destClass.addAfter(psiField, forwardReference) :
(PsiField)forwardReference.getParent().addAfter(psiField, forwardReference);
} else {
return (PsiField)destClass.add(psiField);
if (forwardReference != null &&forwardReference.getParent() == destClass) {
return (PsiField)destClass.addAfter(psiField, forwardReference);
}
return (PsiField)destClass.add(psiField);
}
}
@@ -0,0 +1,10 @@
class Test {
public String getString() {
return <selection>StaticInner.STRING</selection>;
}
static class StaticInner {
public static String STRING = "aaaa";
}
}
@@ -0,0 +1,12 @@
class Test {
public static final String xxx = StaticInner.STRING;
public String getString() {
return xxx;
}
static class StaticInner {
public static String STRING = "aaaa";
}
}
@@ -116,11 +116,19 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
}
public void testComments() throws Exception {
doTestExpr();
}
private void doTestExpr() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
checkDefaultType(CommonClassNames.JAVA_LANG_STRING);
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
public void testContainingClass() throws Exception {
doTestExpr();
}
public void testEscalateVisibility() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final PsiClass[] classes = ((PsiJavaFile)getFile()).getClasses();