CodeEditUtil.addChildren: avoid returning invalid AST

This commit is contained in:
peter
2017-11-24 16:48:30 +01:00
parent 2dd6a4a053
commit 4d005013e6
3 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
// "Remove 'if' statement extracting side effects" "true"
import org.jetbrains.annotations.NotNull;
class X {
public String getRole(Object parent) {
if (parent instanceof Foo) {
((Foo) parent).getBar();
}
return null;
}
}
interface Foo {
@NotNull
Integer getBar();
}

View File

@@ -0,0 +1,17 @@
// "Remove 'if' statement extracting side effects" "true"
import org.jetbrains.annotations.NotNull;
class X {
public String getRole(Object parent) {
if (parent instan<caret>ceof Foo && ((Foo)parent).getBar() == null) {
return "a";
}
else {
}
return null;
}
}
interface Foo {
@NotNull
Integer getBar();
}

View File

@@ -70,7 +70,7 @@ public class CodeEditUtil {
ASTNode result = first;
if (firstAddedLeaf != null) {
ASTNode placeHolderEnd = makePlaceHolderBetweenTokens(prevLeaf, firstAddedLeaf, isFormattingRequired(prevLeaf, first), false);
if (placeHolderEnd != prevLeaf && first == firstAddedLeaf) {
if (placeHolderEnd != prevLeaf && first == firstAddedLeaf || result.getTreeParent() != parent) {
result = placeHolderEnd;
}
ASTNode lastAddedLeaf = findLastLeaf(first, last);