inplace rename: prefer reference to be primary rename variable (DEA-100018)

(cherry picked from commit 56fafe3ecec9c3504e23b976633b7d05f83f53c9)
This commit is contained in:
anna
2013-03-26 21:43:01 +01:00
parent 8350906a1b
commit a33bf81ad2
5 changed files with 30 additions and 2 deletions
@@ -268,11 +268,16 @@ public abstract class InplaceRefactoring {
int offset = myEditor.getCaretModel().getOffset();
PsiElement selectedElement = getSelectedInEditorElement(nameIdentifier, refs, stringUsages, offset);
if (nameIdentifier != null) addVariable(nameIdentifier, selectedElement, builder);
boolean subrefOnPrimaryElement = false;
for (PsiReference ref : refs) {
if (nameIdentifier != null && ref.getElement() == nameIdentifier.getParent()) continue;
if (nameIdentifier != null && ref.getElement() == nameIdentifier.getParent()) {
builder.replaceElement(ref, PRIMARY_VARIABLE_NAME, createLookupExpression(), true);
subrefOnPrimaryElement = true;
continue;
}
addVariable(ref, selectedElement, builder, offset);
}
if (nameIdentifier != null && !subrefOnPrimaryElement) addVariable(nameIdentifier, selectedElement, builder);
for (Pair<PsiElement, TextRange> usage : stringUsages) {
addVariable(usage.first, usage.second, selectedElement, builder);
}
@@ -38,6 +38,10 @@ public class JavaFXRenameTest extends DaemonAnalyzerTestCase {
doTest("newFieldName");
}
public void testHandler() throws Exception {
doTest("newHandlerName");
}
public void testCustomComponentTag() throws Exception {
doTest("Foo");
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
fx:controller="Handler">
<Button onAction="#fo<caret>o"
</AnchorPane>
@@ -0,0 +1,3 @@
public class Handler {
public void foo() {}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
fx:controller="Handler">
<Button onAction="#newHandlerName"
</AnchorPane>