Skip to content

Commit 4516c31

Browse files
mickaelistriaRob Stryker
authored andcommitted
Improve some proceedOnError generation
1 parent 9455994 commit 4516c31

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/ProceedOnErrorGen.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.sun.tools.javac.tree.TreeMaker;
2020
import com.sun.tools.javac.tree.JCTree.JCArrayAccess;
2121
import com.sun.tools.javac.tree.JCTree.JCAssign;
22+
import com.sun.tools.javac.tree.JCTree.JCBinary;
2223
import com.sun.tools.javac.tree.JCTree.JCErroneous;
2324
import com.sun.tools.javac.tree.JCTree.JCExpression;
2425
import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
@@ -28,6 +29,7 @@
2829
import com.sun.tools.javac.tree.JCTree.JCLiteral;
2930
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
3031
import com.sun.tools.javac.tree.JCTree.JCNewClass;
32+
import com.sun.tools.javac.tree.JCTree.JCParens;
3133
import com.sun.tools.javac.tree.JCTree.JCThrow;
3234
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
3335
import com.sun.tools.javac.util.Context;
@@ -82,7 +84,7 @@ public void visitLiteral(JCLiteral tree) {
8284

8385
@Override
8486
public void visitNewClass(JCNewClass tree) {
85-
if (tree.type == null || tree.type.isErroneous()) {
87+
if (tree.type == null || tree.type.isErroneous() || tree.args.stream().anyMatch(arg -> arg.type == null || arg.type.isErroneous())) {
8688
visitErroneous(null);
8789
} else {
8890
super.visitNewClass(tree);
@@ -91,7 +93,7 @@ public void visitNewClass(JCNewClass tree) {
9193

9294
@Override
9395
public void visitApply(JCMethodInvocation tree) {
94-
if (tree.type.isErroneous()) {
96+
if (tree.type.isErroneous() || tree.args.stream().anyMatch(arg -> arg.type == null || arg.type.isErroneous())) {
9597
visitErroneous(null);
9698
} else {
9799
super.visitApply(tree);
@@ -118,7 +120,7 @@ public void visitExec(JCExpressionStatement tree) {
118120

119121
@Override
120122
public void visitAssign(JCAssign tree) {
121-
if (tree.lhs.type.isErroneous()) {
123+
if (tree.lhs.type.isErroneous() || tree.rhs == null || tree.rhs.type == null || tree.rhs.type.isErroneous()) {
122124
visitErroneous(null);
123125
} else {
124126
super.visitAssign(tree);
@@ -127,7 +129,7 @@ public void visitAssign(JCAssign tree) {
127129

128130
@Override
129131
public void visitIndexed(JCArrayAccess tree) {
130-
if (tree.type.isErroneous() || tree.getIndex() == null) {
132+
if (tree.type.isErroneous() || tree.getIndex() == null || tree.getIndex().type == null || tree.getIndex().type.isErroneous()) {
131133
visitErroneous(null);
132134
} else {
133135
super.visitIndexed(tree);
@@ -165,4 +167,22 @@ public void visitVarDef(JCVariableDecl varDef) {
165167
super.visitVarDef(varDef);
166168
}
167169
}
170+
171+
@Override
172+
public void visitBinary(JCBinary binary) {
173+
if (!isValid(binary.lhs) || !isValid(binary.rhs)) {
174+
visitErroneous(null);
175+
} else {
176+
super.visitBinary(binary);
177+
}
178+
}
179+
180+
@Override
181+
public void visitParens(JCParens parens) {
182+
if (!isValid(parens) || !isValid(parens.expr)) {
183+
visitErroneous(null);
184+
} else {
185+
super.visitParens(parens);
186+
}
187+
}
168188
}

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/ProceedOnErrorTransTypes.java

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
*******************************************************************************/
1111
package org.eclipse.jdt.internal.javac;
1212

13+
import java.util.function.Predicate;
14+
1315
import com.sun.tools.javac.code.Symbol;
1416
import com.sun.tools.javac.code.Symbol.MethodSymbol;
1517
import com.sun.tools.javac.comp.TransTypes;
18+
import com.sun.tools.javac.tree.JCTree;
19+
import com.sun.tools.javac.tree.TreeInfo;
20+
import com.sun.tools.javac.tree.JCTree.JCAssign;
1621
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
1722
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
18-
import com.sun.tools.javac.tree.TreeInfo;
23+
import com.sun.tools.javac.tree.JCTree.JCParens;
24+
import com.sun.tools.javac.tree.JCTree.JCTypeCast;
1925
import com.sun.tools.javac.util.Context;
2026
import com.sun.tools.javac.util.Context.Factory;
2127

@@ -46,27 +52,53 @@ private boolean hasErrors(JCClassDecl def) {
4652

4753
@Override
4854
public void visitApply(JCMethodInvocation tree) {
49-
if (this.needsProceedOnError) {
50-
// The next lines of code should allow to generate
51-
// classes with errors, but they are sometimes
52-
// causing infinite processing for files that
53-
// have no errors (eg with XLargeTests).
54-
// So at the moment we guard them by `needProceedOnError`
55-
// but those lines must be considered fragile and made
56-
// more bullet proof; concretely then need to work with
57-
// XLargeTest.
58-
// Cf https://github.com/eclipse-jdtls/eclipse-jdt-core-incubator/issues/1008
59-
if (tree.type.isErroneous()) {
60-
return;
61-
}
62-
tree.meth = translate(tree.meth, null);
63-
Symbol meth = TreeInfo.symbol(tree.meth);
64-
if (!(meth.baseSymbol() instanceof MethodSymbol)) {
65-
//workaround: guard against ClassCastException when referencing non existing member
66-
return;
67-
}
55+
if (!isValid(tree) || tree.args.stream().anyMatch(Predicate.not(this::isValid))) {
56+
return;
57+
}
58+
// The next lines of code should allow to generate
59+
// classes with errors, but they are sometimes
60+
// causing infinite processing for files that
61+
// have no errors (eg with XLargeTests).
62+
// So at the moment we guard them by `needProceedOnError`
63+
// but those lines must be considered fragile and made
64+
// more bullet proof; concretely then need to work with
65+
// XLargeTest.
66+
// Cf https://github.com/eclipse-jdtls/eclipse-jdt-core-incubator/issues/1008
67+
68+
tree.meth = translate(tree.meth, null);
69+
Symbol meth = TreeInfo.symbol(tree.meth);
70+
if (!(meth.baseSymbol() instanceof MethodSymbol)) {
71+
//workaround: guard against ClassCastException when referencing non existing member
72+
return;
6873
}
6974
super.visitApply(tree);
7075
}
7176

77+
@Override
78+
public void visitAssign(JCAssign tree) {
79+
if (!isValid(tree.lhs) || !isValid(tree.rhs)) {
80+
return;
81+
}
82+
super.visitAssign(tree);
83+
}
84+
85+
@Override
86+
public void visitTypeCast(JCTypeCast tree) {
87+
if (!isValid(tree) || !isValid(tree.expr)) {
88+
return;
89+
}
90+
super.visitTypeCast(tree);
91+
}
92+
93+
@Override
94+
public void visitParens(JCParens tree) {
95+
if (!isValid(tree)) {
96+
return;
97+
}
98+
super.visitParens(tree);
99+
}
100+
101+
private boolean isValid(JCTree tree) {
102+
return tree != null && tree.type != null && !tree.type.isErroneous();
103+
}
72104
}

0 commit comments

Comments
 (0)