diff --git a/java/java-tests/testData/refactoring/introduceVariable/EnumValues.after.java b/java/java-tests/testData/refactoring/introduceVariable/EnumValues.after.java new file mode 100644 index 000000000000..552581e5af9e --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceVariable/EnumValues.after.java @@ -0,0 +1,11 @@ + +enum E { + ; + + public static void m() { + E[] vs = values(); + for (E value : vs) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceVariable/EnumValues.java b/java/java-tests/testData/refactoring/introduceVariable/EnumValues.java new file mode 100644 index 000000000000..81cba8358323 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceVariable/EnumValues.java @@ -0,0 +1,10 @@ + +enum E { + ; + + public static void m() { + for (E value : values()) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java index 61900f9f8ddb..81c0c3906d26 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/IntroduceVariableTest.java @@ -242,7 +242,8 @@ public class IntroduceVariableTest extends LightJavaCodeInsightTestCase { public void testPolyadic() { doTest("b1", true, true, true, "boolean"); } public void testAssignmentToUnresolvedReference() { doTest("collection", true, true, true, "java.util.List>"); } public void testSubstringInSwitch() { doTest("ba", false, false, false, JAVA_LANG_STRING);} - + public void testEnumValues() { doTest("vs", false, false, false, "E[]"); } + public void testNameSuggestion() { String expectedTypeName = "Path"; doTest(new MockIntroduceVariableHandler("path", true, false, false, expectedTypeName) { diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java index 8c23fac6bd4e..331fd6b4ca67 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/BaseRefactoringAction.java @@ -212,7 +212,7 @@ public abstract class BaseRefactoringAction extends AnAction implements UpdateIn PsiFile file = dataContext.getData(CommonDataKeys.PSI_FILE); PsiElement element = dataContext.getData(CommonDataKeys.PSI_ELEMENT); Language[] languages = dataContext.getData(LangDataKeys.CONTEXT_LANGUAGES); - if (element == null || !isAvailableForLanguage(element.getLanguage())) { + if (element == null|| element instanceof SyntheticElement || !isAvailableForLanguage(element.getLanguage())) { if (file == null || editor == null) { return null; }