mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-69972 Smart Complete Statement: Leave code block if the action is called for the complete statement
Don't leave method code block on smart completion
This commit is contained in:
+22
-7
@@ -51,7 +51,12 @@ public class LeaveCodeBlockEnterProcessor implements EnterProcessor {
|
||||
if (!(parent instanceof PsiCodeBlock)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
final ASTNode node = psiElement.getNode();
|
||||
if (node != null && CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean leaveCodeBlock = isControlFlowBreak(psiElement) || isValidStatementInsideControlFlowOperator(psiElement, isModified);
|
||||
if (!leaveCodeBlock) {
|
||||
return false;
|
||||
@@ -106,15 +111,25 @@ public class LeaveCodeBlockEnterProcessor implements EnterProcessor {
|
||||
return element instanceof PsiReturnStatement || element instanceof PsiThrowStatement;
|
||||
}
|
||||
|
||||
private static boolean isValidStatementInsideControlFlowOperator(@Nullable PsiElement element, boolean modified) {
|
||||
private static boolean isValidStatementInsideControlFlowOperator(final @Nullable PsiElement element, boolean modified) {
|
||||
if (modified || element == null || PsiTreeUtil.hasErrorElements(element)) {
|
||||
return false;
|
||||
}
|
||||
final ASTNode node = element.getNode();
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (PsiElement e = element; e != null; e = e.getParent()) {
|
||||
final ASTNode node = e.getNode();
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType());
|
||||
if (node.getElementType() == JavaElementType.METHOD) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CONTROL_FLOW_ELEMENT_TYPES.contains(node.getElementType())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
public class Foo {
|
||||
{
|
||||
foo(x);
|
||||
<caret>
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
public class Foo {
|
||||
public void foo() {
|
||||
String s = "abcdef";
|
||||
<caret>
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
@@ -2,6 +2,6 @@
|
||||
public class Test {
|
||||
public void foo() {
|
||||
int x = 2;
|
||||
<caret>
|
||||
}
|
||||
<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user