|
10 | 10 | *******************************************************************************/ |
11 | 11 | package org.eclipse.jdt.internal.javac; |
12 | 12 |
|
| 13 | +import java.util.function.Predicate; |
| 14 | + |
13 | 15 | import com.sun.tools.javac.code.Symbol; |
14 | 16 | import com.sun.tools.javac.code.Symbol.MethodSymbol; |
15 | 17 | 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; |
16 | 21 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
17 | 22 | 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; |
19 | 25 | import com.sun.tools.javac.util.Context; |
20 | 26 | import com.sun.tools.javac.util.Context.Factory; |
21 | 27 |
|
@@ -46,27 +52,53 @@ private boolean hasErrors(JCClassDecl def) { |
46 | 52 |
|
47 | 53 | @Override |
48 | 54 | 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; |
68 | 73 | } |
69 | 74 | super.visitApply(tree); |
70 | 75 | } |
71 | 76 |
|
| 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 | + } |
72 | 104 | } |
0 commit comments