introduce variable: case with unresolved reference and replace all

EA-90834 - AIOOBE: AbstractInplaceIntroducer.lambda$restoreState$
This commit is contained in:
Anna Kozlova
2017-06-15 20:51:20 +03:00
parent 0f39932f41
commit 1298560a61
5 changed files with 30 additions and 1 deletions
@@ -405,6 +405,7 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer
occurrences.add(createMarker(reference.getElement()));
});
setOccurrenceMarkers(occurrences);
myOccurrences = new PsiExpression[occurrences.size()];
}
final PsiIdentifier identifier = variable.getNameIdentifier();
@@ -0,0 +1,9 @@
class Demo {
void d(String s){
System.out.println(<caret>s);
System.out.println(s);
System.out.println(s1);
}
}
@@ -0,0 +1,10 @@
class Demo {
void d(String s){
String expr = s;
System.out.println(expr);
System.out.println(expr);
System.out.println(expr);
}
}
@@ -125,6 +125,15 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
});
}
public void testReplaceAllOnDummyCodeWithSameNameAsGenerated() throws Exception {
doTestReplaceChoice(IntroduceVariableBase.JavaReplaceChoice.ALL, new Pass<AbstractInplaceIntroducer>() {
@Override
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
type("expr");
}
});
}
public void testRanges() throws Exception {
doTest(new Pass<AbstractInplaceIntroducer>() {
@Override
@@ -451,7 +451,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
}
}
final List<RangeMarker> occurrenceMarkers = getOccurrenceMarkers();
for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) {
for (int i = 0; i < occurrenceMarkers.size(); i++) {
RangeMarker marker = occurrenceMarkers.get(i);
if (getExprMarker() != null && marker.getStartOffset() == getExprMarker().getStartOffset() && myExpr != null) {
myOccurrences[i] = myExpr;