24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.comp; |
26 package com.sun.tools.javac.comp; |
27 |
27 |
28 import com.sun.source.tree.LambdaExpressionTree.BodyKind; |
28 import com.sun.source.tree.LambdaExpressionTree.BodyKind; |
|
29 import com.sun.source.tree.NewClassTree; |
29 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.*; |
30 import com.sun.tools.javac.code.Type.TypeMapping; |
31 import com.sun.tools.javac.code.Type.TypeMapping; |
31 import com.sun.tools.javac.comp.Resolve.ResolveError; |
32 import com.sun.tools.javac.comp.Resolve.ResolveError; |
32 import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
33 import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
33 import com.sun.tools.javac.tree.*; |
34 import com.sun.tools.javac.tree.*; |
123 @Override |
126 @Override |
124 public String toString() { |
127 public String toString() { |
125 return "Empty deferred context!"; |
128 return "Empty deferred context!"; |
126 } |
129 } |
127 }; |
130 }; |
|
131 |
|
132 // For speculative attribution, skip the class definition in <>. |
|
133 treeCopier = |
|
134 new TreeCopier<Void>(make) { |
|
135 @Override @DefinedBy(Api.COMPILER_TREE) |
|
136 public JCTree visitNewClass(NewClassTree node, Void p) { |
|
137 JCNewClass t = (JCNewClass) node; |
|
138 if (TreeInfo.isDiamond(t)) { |
|
139 JCExpression encl = copy(t.encl, p); |
|
140 List<JCExpression> typeargs = copy(t.typeargs, p); |
|
141 JCExpression clazz = copy(t.clazz, p); |
|
142 List<JCExpression> args = copy(t.args, p); |
|
143 JCClassDecl def = null; |
|
144 return make.at(t.pos).NewClass(encl, typeargs, clazz, args, def); |
|
145 } else { |
|
146 return super.visitNewClass(node, p); |
|
147 } |
|
148 } |
|
149 }; |
|
150 deferredCopier = new TypeMapping<Void> () { |
|
151 @Override |
|
152 public Type visitType(Type t, Void v) { |
|
153 if (t.hasTag(DEFERRED)) { |
|
154 DeferredType dt = (DeferredType) t; |
|
155 return new DeferredType(treeCopier.copy(dt.tree), dt.env); |
|
156 } |
|
157 return t; |
|
158 } |
|
159 }; |
128 } |
160 } |
129 |
161 |
130 /** shared tree for stuck expressions */ |
162 /** shared tree for stuck expressions */ |
131 final JCTree stuckTree; |
163 final JCTree stuckTree; |
132 |
164 |
362 * cloned (to avoid side-effects cause by Attr) and compiler state is |
394 * cloned (to avoid side-effects cause by Attr) and compiler state is |
363 * restored after type-checking. All diagnostics (but critical ones) are |
395 * restored after type-checking. All diagnostics (but critical ones) are |
364 * disabled during speculative type-checking. |
396 * disabled during speculative type-checking. |
365 */ |
397 */ |
366 JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
398 JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
367 return attribSpeculative(tree, env, resultInfo, new TreeCopier<>(make), |
399 return attribSpeculative(tree, env, resultInfo, treeCopier, |
368 (newTree)->new DeferredAttrDiagHandler(log, newTree)); |
400 (newTree)->new DeferredAttrDiagHandler(log, newTree)); |
369 } |
401 } |
370 |
402 |
371 <Z> JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, TreeCopier<Z> deferredCopier, |
403 <Z> JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, TreeCopier<Z> deferredCopier, |
372 Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator) { |
404 Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator) { |