mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract constant: allow class-constants to be used from enum constant initializer outside argument list (IDEA-161237)
This commit is contained in:
+2
-1
@@ -737,7 +737,8 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
|
||||
}
|
||||
PsiMember anchorMember = finalAnchorElement instanceof PsiMember ? (PsiMember)finalAnchorElement : null;
|
||||
|
||||
if (anchorMember instanceof PsiEnumConstant && destClass == anchorMember.getContainingClass()) {
|
||||
if (anchorMember instanceof PsiEnumConstant && destClass == anchorMember.getContainingClass() &&
|
||||
PsiTreeUtil.isAncestor(((PsiEnumConstant)anchorMember).getArgumentList(), initializer, false)) {
|
||||
final String initialName = "Constants";
|
||||
String constantsClassName = initialName;
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
|
||||
enum Foo {
|
||||
|
||||
FOO1 {
|
||||
public String bar() {
|
||||
return <selection>"bar"</selection>;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
|
||||
enum Foo {
|
||||
|
||||
FOO1 {
|
||||
public String bar() {
|
||||
return xxx;
|
||||
}
|
||||
};
|
||||
public static final String xxx = "bar";
|
||||
}
|
||||
@@ -48,6 +48,12 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testFromEnumConstantInitializer2() throws Exception {
|
||||
configureByFile(BASE_PATH + getTestName(false) + ".java");
|
||||
new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testEnumConstant() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user