equal
deleted
inserted
replaced
61 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
61 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
62 import com.sun.tools.javac.util.List; |
62 import com.sun.tools.javac.util.List; |
63 import com.sun.tools.javac.util.ListBuffer; |
63 import com.sun.tools.javac.util.ListBuffer; |
64 import com.sun.tools.javac.util.Log; |
64 import com.sun.tools.javac.util.Log; |
65 import com.sun.tools.javac.util.Options; |
65 import com.sun.tools.javac.util.Options; |
|
66 import com.sun.tools.javac.util.Position; |
66 |
67 |
67 import java.util.EnumSet; |
68 import java.util.EnumSet; |
68 import java.util.HashMap; |
69 import java.util.HashMap; |
69 import java.util.Map; |
70 import java.util.Map; |
70 import java.util.function.Predicate; |
71 import java.util.function.Predicate; |
303 @Override |
304 @Override |
304 List<JCLambda> rewrite(JCNewClass oldTree){ |
305 List<JCLambda> rewrite(JCNewClass oldTree){ |
305 JCMethodDecl md = (JCMethodDecl)decls(oldTree.def).head; |
306 JCMethodDecl md = (JCMethodDecl)decls(oldTree.def).head; |
306 List<JCVariableDecl> params = md.params; |
307 List<JCVariableDecl> params = md.params; |
307 JCBlock body = md.body; |
308 JCBlock body = md.body; |
308 JCLambda newTree = make.Lambda(params, body); |
309 JCLambda newTree = make.at(oldTree).Lambda(params, body); |
309 return List.of(newTree); |
310 return List.of(newTree); |
310 } |
311 } |
311 |
312 |
312 @Override |
313 @Override |
313 void process (JCNewClass oldTree, JCLambda newTree, boolean hasErrors){ |
314 void process (JCNewClass oldTree, JCLambda newTree, boolean hasErrors){ |
416 } |
417 } |
417 @Override |
418 @Override |
418 List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) { |
419 List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) { |
419 JCEnhancedForLoop newTree = copier.copy(oldTree); |
420 JCEnhancedForLoop newTree = copier.copy(oldTree); |
420 newTree.var = rewriteVarType(oldTree.var); |
421 newTree.var = rewriteVarType(oldTree.var); |
421 newTree.body = make.Block(0, List.nil()); |
422 newTree.body = make.at(oldTree.body).Block(0, List.nil()); |
422 return List.of(newTree); |
423 return List.of(newTree); |
423 } |
424 } |
424 @Override |
425 @Override |
425 void process(JCEnhancedForLoop oldTree, JCEnhancedForLoop newTree, boolean hasErrors){ |
426 void process(JCEnhancedForLoop oldTree, JCEnhancedForLoop newTree, boolean hasErrors){ |
426 processVar(oldTree.var, newTree.var, hasErrors); |
427 processVar(oldTree.var, newTree.var, hasErrors); |
549 log.useSource(rewriting.env.toplevel.getSourceFile()); |
550 log.useSource(rewriting.env.toplevel.getSourceFile()); |
550 |
551 |
551 JCStatement treeToAnalyze = (JCStatement)rewriting.originalTree; |
552 JCStatement treeToAnalyze = (JCStatement)rewriting.originalTree; |
552 if (rewriting.env.info.scope.owner.kind == Kind.TYP) { |
553 if (rewriting.env.info.scope.owner.kind == Kind.TYP) { |
553 //add a block to hoist potential dangling variable declarations |
554 //add a block to hoist potential dangling variable declarations |
554 treeToAnalyze = make.Block(Flags.SYNTHETIC, List.of((JCStatement)rewriting.originalTree)); |
555 treeToAnalyze = make.at(Position.NOPOS) |
|
556 .Block(Flags.SYNTHETIC, List.of((JCStatement)rewriting.originalTree)); |
555 } |
557 } |
556 |
558 |
557 //TODO: to further refine the analysis, try all rewriting combinations |
559 //TODO: to further refine the analysis, try all rewriting combinations |
558 deferredAttr.attribSpeculative(treeToAnalyze, rewriting.env, attr.statInfo, new TreeRewriter(rewriting), |
560 deferredAttr.attribSpeculative(treeToAnalyze, rewriting.env, attr.statInfo, new TreeRewriter(rewriting), |
559 t -> rewriting.diagHandler(), argumentAttr.withLocalCacheContext()); |
561 t -> rewriting.diagHandler(), argumentAttr.withLocalCacheContext()); |