mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce variable placed inside lambda body: ensure initializer not changed (IDEA-142361)
This commit is contained in:
+6
-3
@@ -288,7 +288,7 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer
|
||||
LOG.assertTrue(expression.isValid(), expression.getText());
|
||||
stringUsages.add(Pair.<PsiElement, TextRange>create(expression, new TextRange(0, expression.getTextLength())));
|
||||
}
|
||||
} else if (getExpr() != null && !myReplaceSelf) {
|
||||
} else if (getExpr() != null && !myReplaceSelf && getExpr().getParent() != getVariable()) {
|
||||
final PsiExpression expr = getExpr();
|
||||
LOG.assertTrue(expr.isValid(), expr.getText());
|
||||
stringUsages.add(Pair.<PsiElement, TextRange>create(expr, new TextRange(0, expr.getTextLength())));
|
||||
@@ -297,8 +297,11 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer
|
||||
|
||||
@Override
|
||||
protected void addReferenceAtCaret(Collection<PsiReference> refs) {
|
||||
if (!isReplaceAllOccurrences() && getExpr() == null && !myReplaceSelf) {
|
||||
return;
|
||||
if (!isReplaceAllOccurrences()) {
|
||||
final PsiExpression expr = getExpr();
|
||||
if (expr == null && !myReplaceSelf || expr != null && expr.getParent() == getVariable()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.addReferenceAtCaret(refs);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
public void test(final DocumentDataHookUp hookUp) {
|
||||
Runnable r = () -> hookUp.getDocument().replace("".leng<caret>th());
|
||||
}
|
||||
private class DocumentDataHookUp {
|
||||
public String replace(int i1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
public void test(final DocumentDataHookUp hookUp) {
|
||||
Runnable r = () -> {
|
||||
int expr = "".length();
|
||||
hookUp.getDocument().replace(expr);
|
||||
};
|
||||
}
|
||||
private class DocumentDataHookUp {
|
||||
public String replace(int i1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,15 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
});
|
||||
}
|
||||
|
||||
public void testPlaceInsideLambda() throws Exception {
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
type("expr");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testRanges() throws Exception {
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user