introduce variable: ensure initialize conflict resolver over code ready to rename (IDEA-141634)

This commit is contained in:
Anna Kozlova
2015-06-18 17:54:25 +03:00
parent 30a12275a2
commit eaa9b80df1
5 changed files with 41 additions and 0 deletions
@@ -109,6 +109,10 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer
}
}
super.beforeTemplateStart();
}
@Override
protected void onRenameTemplateStarted() {
final ResolveSnapshotProvider resolveSnapshotProvider = VariableInplaceRenamer.INSTANCE.forLanguage(myScope.getLanguage());
myConflictResolver = resolveSnapshotProvider != null ? resolveSnapshotProvider.createSnapshot(myScope) : null;
}
@@ -0,0 +1,12 @@
import javax.swing.*;
import java.awt.*;
class OuterClass {
private MyComp myComp;
private class MyComp extends JPanel {
@Override
public void paint(Graphics g) {
int a = myComp.get<caret>Height();
}
}
}
@@ -0,0 +1,13 @@
import javax.swing.*;
import java.awt.*;
class OuterClass {
private MyComp myComp;
private class MyComp extends JPanel {
@Override
public void paint(Graphics g) {
int height = myComp.getHeight();
int a = height;
}
}
}
@@ -82,6 +82,15 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
});
}
public void testConflictWithField() throws Exception {
doTest(new Pass<AbstractInplaceIntroducer>() {
@Override
public void pass(AbstractInplaceIntroducer introducer) {
type("height");
}
});
}
public void testCast() throws Exception {
doTestTypeChange("Integer");
}
@@ -230,6 +230,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
updateTitle(getVariable());
started = AbstractInplaceIntroducer.super.performInplaceRefactoring(nameSuggestions);
if (started) {
onRenameTemplateStarted();
myDocumentAdapter = new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
@@ -260,6 +261,8 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
return result.get();
}
protected void onRenameTemplateStarted() {}
protected int getCaretOffset() {
RangeMarker r;
if (myLocalMarker != null) {