mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ChainCallJoinLinesHandler: disable when builder variable is self-referenced
This commit is contained in:
+3
@@ -4,6 +4,8 @@ package com.intellij.codeInsight.editorActions;
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -53,6 +55,7 @@ public class ChainCallJoinLinesHandler implements JoinLinesHandlerDelegate {
|
||||
if (!ExpressionUtils.isReferenceTo(qualifier, var)) return false;
|
||||
PsiType type = nextCall.getType();
|
||||
if (type == null || !type.equals(initializer.getType())) return false;
|
||||
if (ReferencesSearch.search(var, new LocalSearchScope(nextCall)).findAll().size() > 1) return false;
|
||||
qualifier.replace(initializer);
|
||||
initializer.replace(nextCall);
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
void test() {
|
||||
<caret>StringBuilder sb = new StringBuilder();
|
||||
sb.append(sb);
|
||||
sb.append("bar");
|
||||
sb.append("baz");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
void test() {
|
||||
StringBuilder sb = new StringBuilder();<caret>sb.append(sb);
|
||||
sb.append("bar");
|
||||
sb.append("baz");
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ public class JoinLinesTest extends LightCodeInsightTestCase {
|
||||
public void testCallChain2() { doTest(); }
|
||||
public void testCallChainWrong() { doTest(); }
|
||||
public void testDeclarationAndCall() { doTest(); }
|
||||
public void testDeclarationAndCallSelfRef() { doTest(); }
|
||||
public void testAssignmentAndCall() { doTest(); }
|
||||
|
||||
public void testSCR3493() {
|
||||
|
||||
Reference in New Issue
Block a user