CodeEditUtil#removeChildren: fixed nextLeaf determination

Before when removing more than one element, nextLeaf was invalid as well. The invalidation check below did not work as parent might still exist (element might be relinked to dummy file)

Fixes IDEA-187531 "Add on demand static import" with intervening comment and an empty line breaks code
This commit is contained in:
Tagir Valeev
2018-03-03 15:47:21 +07:00
parent 48848a8a7b
commit 43b86a988e
51 changed files with 77 additions and 63 deletions

View File

@@ -3,6 +3,6 @@ import java.lang.invoke.*;
public class Main {
void foo() throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();
lookup.findVarHandle(Types.class, "str",String.class);
lookup.findVarHandle(Types.class, "str", String.class);
}
}

View File

@@ -0,0 +1,9 @@
// "Add on demand static import for 'java.lang.annotation.ElementType'" "true"
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
@Target({//simple end comment
METHOD})
@interface F {}

View File

@@ -0,0 +1,8 @@
// "Add on demand static import for 'java.lang.annotation.ElementType'" "true"
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({Element<caret>Type.//simple end comment
METHOD})
@interface F {}

View File

@@ -2,7 +2,7 @@
abstract class AsyncTask<A, B, C> {
abstract C doin(A... a);
}
class AAsync extends AsyncTask<String,Integer,Integer> {
class AAsync extends AsyncTask<String, Integer, Integer> {
@Override
Integer doin(String... a) {
return 1;

View File

@@ -4,7 +4,7 @@ interface Main<A, B> {
List<A> foo();
}
class MainImpl implements Main<Integer,String> {
class MainImpl implements Main<Integer, String> {
@Override
public List<Integer> foo() {
return bar();

View File

@@ -3,7 +3,6 @@ class Test {
{
// This is comment"
int i = 1;
}<caret>
}
}
}

View File

@@ -1,6 +1,6 @@
class A{
{
long x; // comment
long x; // comment
long y;
}
}

View File

@@ -3,7 +3,7 @@ class Test {
for(int i = 0; i < ss.length; i++) {
newMethod(ss[i], bb[i]);
}
}

View File

@@ -5,7 +5,7 @@ class X {
for (Object o : l) {
Object x = newMethod(o);
if (x == null) continue;
System.out.println(x);
System.out.println(x);
}
}

View File

@@ -5,7 +5,7 @@ class Test {
String a = "A";
newMethod(a);
ArrayList<String> listB = new ArrayList<String>();
ArrayList<String> listB = new ArrayList<String>();
ArrayList<String> listC = new ArrayList<String>();
listB.add("B");
listC.add("C");

View File

@@ -5,7 +5,7 @@ class X {
for (String psiMethod : methods) {
String strings = newMethod(method, testName);
if (strings != null) return strings;
}
return null;
}

View File

@@ -3,7 +3,6 @@ class Test {
if (true) {
newMethod();
} else {
}

View File

@@ -1,7 +1,7 @@
class Test {
void h(int i, String[] s, String[] t) {
final String s1 = newMethod(t[i], s[t[i].length()]);
System.out.println(s1);
System.out.println(s1);
}
private String newMethod(String s, String s11) {

View File

@@ -5,7 +5,7 @@ class X {
for (Object o : l) {
Object x = newMethod(o);
if (x == null) continue;
System.out.println(x);
System.out.println(x);
}
}

View File

@@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull;
class X {
public static String main(String[] args) {
return newMethod();
}
@NotNull

View File

@@ -1,7 +1,7 @@
class Test {
void foo() {
int i = newMethod();
System.out.println(i);
System.out.println(i);
}
private int newMethod() {

View File

@@ -1,7 +1,7 @@
class X {
void foo() {
newMethod();
}
private int newMethod() {

View File

@@ -2,7 +2,6 @@ public class ExtractMethods {
public void processLine(String line) {
newMethod(line);
}
private void newMethod(String line) {

View File

@@ -1,7 +1,7 @@
class X {
void foo() {
newMethod();
}
private int newMethod() {

View File

@@ -5,8 +5,8 @@ class Test {
String xxx = newMethod(i, flag);
if (xxx == null) return null;
System.out.println(xxx);
System.out.println(xxx);
return null;
}

View File

@@ -8,8 +8,8 @@ class Test {
void foo() {
while(true) {
Pojo x = newMethod();
if (x == null) break;
System.out.println(x.it);
if (x == null) break;
System.out.println(x.it);
}
}

View File

@@ -4,7 +4,7 @@ class Test {
void foo() {
final String str = newMethod();
if (str == null) return;
new Runnable() {
new Runnable() {
public void run() {
System.out.println(str);
}

View File

@@ -4,7 +4,7 @@ class Test {
void foo() {
Object o = newMethod();
if (o == null) return;
System.out.println(o);
System.out.println(o);
}
@Nullable

View File

@@ -4,7 +4,7 @@ class Test {
Object foo() {
Object o = newMethod();
if (o == null) return null;
System.out.println(o);
System.out.println(o);
return o;
}

View File

@@ -3,9 +3,9 @@ import java.util.*;
class Test {
public void foo() {
List trades = newMethod();
//probably not assigned !!!
//probably not assigned !!!
if (trades.isEmpty()) {
}
}

View File

@@ -4,7 +4,7 @@ class X {
public X() {
i = newMethod();
}
private int newMethod() {

View File

@@ -10,7 +10,7 @@ class A {
newMethod(allStats[i], sb, statMember);
}
}

View File

@@ -4,8 +4,8 @@ class Test {
private String getRevenue() {
final String revenue = newMethod("revenues");
return revenue;
return revenue;
}
@NotNull
@@ -20,7 +20,7 @@ class Test {
public String getExpense() {
final String expense = newMethod("expenses");
return expense;
return expense;
}
private String createNamedQuery(String expenses) {

View File

@@ -2,7 +2,7 @@ class Test {
public static void main(String[] args) {
newMethod();
System.out.println("hello");
System.out.println("hello");
}
private static void newMethod() {

View File

@@ -3,7 +3,7 @@ class Test {
for(int i = 0; i < ss.length; i++) {
newMethod(ss, i);
}
}

View File

@@ -3,7 +3,7 @@ class Foo {
Inner inner = new Inner().invoke();
if (inner.is()) return "";
String var = inner.getVar();
System.out.println(var);
System.out.println(var);
}
private class Inner {

View File

@@ -5,7 +5,7 @@ class Test {
if (inner.is()) continue;
boolean a = inner.isA();
System.out.println(aArg + a);
System.out.println(aArg + a);
}
}

View File

@@ -5,7 +5,7 @@ class Test {
Inner inner = new Inner().invoke();
int i = inner.getI();
int j = inner.getJ();
System.out.println(i + j);
System.out.println(i + j);
}
}
}

View File

@@ -16,7 +16,7 @@ class ExtractMethodObjectFail {
String parm14 = inner.getParm14();
String parm15 = inner.getParm15();
System.out.println(parm1 + parm2 + parm3 + parm4 + parm5 + parm6 + parm7 + parm8 + param9 + parm10 + parm11 + parm12 + parm13 + parm14 + parm15);
System.out.println(parm1 + parm2 + parm3 + parm4 + parm5 + parm6 + parm7 + parm8 + param9 + parm10 + parm11 + parm12 + parm13 + parm14 + parm15);
}
private class Inner {

View File

@@ -6,8 +6,8 @@ class Test {
Inner inner = new Inner(i, j).invoke();
j = inner.getJ();
int k = inner.getK();
int n = i+j;
int n = i+j;
int m = k;
}

View File

@@ -3,7 +3,7 @@ class Test {
Inner inner = new Inner().invoke();
int i = inner.getI();
int j = inner.getJ();
System.out.println(MessageFormat.format("i: {0}", i));
System.out.println(MessageFormat.format("k: {0}", j));
}

View File

@@ -3,7 +3,7 @@ class Foo {
Inner inner = new Inner().invoke();
String var = inner.getVar();
if (var == null) return null;
System.out.println(var);
System.out.println(var);
}
private class Inner {

View File

@@ -20,7 +20,7 @@ class Test {
Inner inner = new Inner(cur, prev, total).invoke();
cur = inner.getCur();
total = inner.getTotal();
return cur != null ? total + cur.x : total;
return cur != null ? total + cur.x : total;
}
}
return total;

View File

@@ -4,7 +4,7 @@ public class RenameInInitializer {
int aValue = inner.getValue();
int result = inner.getResult();
int a = inner.getA();
System.out.println(aValue + result + a);
System.out.println(aValue + result + a);
}
private static class Inner {

View File

@@ -4,7 +4,7 @@ public class SameFieldsWithPrefix {
int aValue = inner.getValue();
int bValue = inner.getBValue();
System.out.println(aValue + bValue);
System.out.println(aValue + bValue);
}
private static class Inner {

View File

@@ -5,8 +5,8 @@ class Test {
Inner inner = new Inner(i).invoke();
int j = inner.getJ();
int k = inner.getK();
int m = k + j;
int m = k + j;
}
private class Inner {

View File

@@ -6,7 +6,7 @@ public class Demo {
Inner inner = new Inner().invoke();
Pojo1 p1 = inner.getP1();
Pojo2 p2 = inner.getP2();
System.out.println(p1.getContent() + p2.getContent());

View File

@@ -1,7 +1,7 @@
class Test {
public final Integer integer = new Integer(0);
void foo() {
void foo() {
Integer i = integer;
}
}

View File

@@ -8,7 +8,7 @@ class Test {
System.out.println();
};
stringConsumer.accept(s);
System.out.println();
}
}

View File

@@ -11,6 +11,6 @@ class IdentityComplete {
public void context(boolean bp) {
/* before fragment */
method(bp);
// after fragment
// after fragment
}
}

View File

@@ -9,7 +9,7 @@ class Post {
public void contextVarFree(int param) {
int varFree = 1;
int var = method(param, varFree);
int varPost = varFree;
int varPost = varFree;
}
public void contextVarIncapsulated(int param) {
@@ -22,18 +22,18 @@ class Post {
public void contextParam(int param) {
int varFree = 1;
int var = method(param, varFree);
int varPost = param;
int varPost = param;
}
public void contextField(int param) {
int varFree = 1;
int var = method(param, varFree);
int varPost = myField;
int varPost = myField;
}
public void contextThis(int param) {
int varFree = 1;
int var = method(param, varFree);
int varPost = this.hashCode();
int varPost = this.hashCode();
}
}

View File

@@ -10,7 +10,7 @@ class Return {
public void contextLValue() {
myReturn = method();
myReturn = null;
myReturn = null;
}
public void contextNoUsage() {
@@ -19,11 +19,11 @@ class Return {
public void contextRValue() {
myReturn = method();
Return r = myReturn;
Return r = myReturn;
}
public void contextRValueQualified() {
myReturn = method();
Return r = this.myReturn;
Return r = this.myReturn;
}
}

View File

@@ -10,7 +10,7 @@ class Return {
public void contextLValue() {
Return r = method();
r = null;
r = null;
}
public void contextNoUsage() {
@@ -19,6 +19,6 @@ class Return {
public void contextRValue() {
Return r = method();
Return r2 = r;
Return r2 = r;
}
}

View File

@@ -8,7 +8,7 @@ class Return {
public void context() {
Return r = method();
// Currently the statement below could be replaced, but it's not. Nobody has requested this.
// Currently the statement below could be replaced, but it's not. Nobody has requested this.
myInt++;
}
}

View File

@@ -11,7 +11,7 @@ class Test {
private double ss2(int index, double compVal, int numDays) {
double aveSlope = dd1(index, compVal, numDays);
return aveSlope;
return aveSlope;
}
private boolean condition(int idx, int n, int i){return false;}

View File

@@ -142,7 +142,7 @@ public class CodeEditUtil {
assert child == last : last + " is not a successor of " + first + " in the .getTreeNext() chain";
final ASTNode prevLeaf = TreeUtil.prevLeaf(first);
final ASTNode nextLeaf = TreeUtil.nextLeaf(first);
final ASTNode nextLeaf = TreeUtil.nextLeaf(last);
parent.removeRange(first, last.getTreeNext());
ASTNode nextLeafToAdjust = nextLeaf;
if (nextLeafToAdjust != null && prevLeaf != null && nextLeafToAdjust.getTreeParent() == null) {