IDEA-25441 flex: invoking inline on unused variable silently deletes it
authorMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Tue, 3 Nov 2009 17:15:38 +0000 (20:15 +0300)
committerMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Tue, 3 Nov 2009 17:15:38 +0000 (20:15 +0300)
platform/lang-api/src/com/intellij/lang/refactoring/InlineHandler.java
platform/lang-impl/src/com/intellij/refactoring/inline/GenericInlineHandler.java
plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/inline/GroovyInlineHandler.java

index 5cc16068e48032d756ed74030f08b8d3d9a8bb25..dfc2fba37a4c1dbfc4ab14d29da1b5b24e9ecff8 100644 (file)
@@ -41,6 +41,15 @@ public interface InlineHandler {
      * was triggered should be inlined.
      */
     boolean isOnlyOneReferenceToInline();
+
+    /**
+     * Special settings for the case when inline cannot be performed due to already reported (by error hint) problem
+     */
+    Settings CANNOT_INLINE_SETTINGS = new Settings() {
+      public boolean isOnlyOneReferenceToInline() {
+        return false;
+      }
+    };
   }
 
   /**
@@ -55,7 +64,7 @@ public interface InlineHandler {
   /**
    * @param element inlined element
    */
-  void removeDefinition(PsiElement element);
+  void removeDefinition(PsiElement element, Settings settings);
 
   /**
    * @param element inlined element
index ed13b39c80319a7706910acdba72ef94aa96cc05..f64c066f82521fc28e4b36ca81561e804f6cb053 100644 (file)
@@ -17,6 +17,7 @@
 package com.intellij.refactoring.inline;
 
 import com.intellij.codeInsight.TargetElementUtilBase;
+import com.intellij.codeInsight.hint.HintManager;
 import com.intellij.lang.Language;
 import com.intellij.lang.refactoring.InlineHandler;
 import com.intellij.lang.refactoring.InlineHandlers;
@@ -48,7 +49,9 @@ public class GenericInlineHandler {
   public static boolean invoke(final PsiElement element, final Editor editor, final InlineHandler languageSpecific) {
     final PsiReference invocationReference = TargetElementUtilBase.findReference(editor);
     final InlineHandler.Settings settings = languageSpecific.prepareInlineElement(element, editor, invocationReference != null);
-    if (settings == null) return false;
+    if (settings == null || settings == InlineHandler.Settings.CANNOT_INLINE_SETTINGS) {
+      return settings != null;
+    }
 
     final Collection<PsiReference> allReferences =
       settings.isOnlyOneReferenceToInline() ? Collections.singleton(invocationReference) : ReferencesSearch.search(element).findAll();
@@ -123,7 +126,7 @@ public class GenericInlineHandler {
             }
 
             if (!settings.isOnlyOneReferenceToInline()) {
-              languageSpecific.removeDefinition(element);
+              languageSpecific.removeDefinition(element, settings);
             }
           }
         }, RefactoringBundle.message("inline.command", subj), null);
index 6a911c0d287c2a2577bba32afe6da0c948622ae9..8e0e3d0816c5babe23e955095f2fcce57a2978cd 100644 (file)
@@ -63,7 +63,7 @@ public class GroovyInlineHandler implements InlineHandler {
     return null;
   }
 
-  public void removeDefinition(final PsiElement element) {
+  public void removeDefinition(final PsiElement element, Settings settings) {
     final PsiElement owner = element.getParent().getParent();
     if (element instanceof GrVariable &&
         owner instanceof GrVariableDeclarationOwner) {