introduce constant: do not delete self if it is still needed
authorAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 12:08:29 +0000 (16:08 +0400)
committerAnna Kozlova <Anna.Kozlova@jetbrains.com>
Wed, 16 Sep 2009 12:08:29 +0000 (16:08 +0400)
java/java-impl/src/com/intellij/refactoring/introduceField/BaseExpressionToFieldHandler.java
java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription.java [new file with mode: 0644]
java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription_after.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/refactoring/IntroduceConstantTest.java

index 62bf188ef677ae71bf915a45bdecfc25e46f7e41..6dcb94df9e927490a31db838f8e73d525777597a 100644 (file)
@@ -147,7 +147,7 @@ public abstract class BaseExpressionToFieldHandler extends IntroduceHandlerBase
 
     PsiElement anchor = getNormalizedAnchor(anchorElement);
 
-    boolean tempDeleteSelf = anchorElement == null;
+    boolean tempDeleteSelf = false;
     if (element.getParent() instanceof PsiExpressionStatement && anchor.equals(anchorElement)) {
       PsiStatement statement = (PsiStatement)element.getParent();
       if (statement.getParent() instanceof PsiCodeBlock) {
diff --git a/java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription.java b/java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription.java
new file mode 100644 (file)
index 0000000..e2317b7
--- /dev/null
@@ -0,0 +1,4 @@
+@SuppressWarnings(<selection>"CONST"</selection>)
+class Me {
+
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription_after.java b/java/java-tests/testData/refactoring/introduceConstant/AnnotationDescription_after.java
new file mode 100644 (file)
index 0000000..a4f3852
--- /dev/null
@@ -0,0 +1,5 @@
+@SuppressWarnings(Me.xxx)
+class Me {
+
+    public static final String xxx = "CONST";
+}
\ No newline at end of file
index 7b4690103a4bacaaaba804500bae08d6f34992c2..ff168460789c452d580c710555afa4d41a8c26c6 100644 (file)
@@ -36,6 +36,12 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
     doTest(true);    
   }
 
+  public void testAnnotationDescription() throws Exception {
+    configureByFile(BASE_PATH + getTestName(false) + ".java");
+    new MockIntroduceConstantHandler(null).invoke(getProject(), getEditor(), getFile(), null);
+    checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
+  }
+
   private static void convertLocal(final boolean makeEnumConstant) {
     PsiLocalVariable local = PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
     new MockLocalToFieldHandler(getProject(), true, makeEnumConstant).convertLocalToField(local, getEditor());