mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-25441 flex: invoking inline on unused variable silently deletes it
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user