com.sun.tools.javac.tree.TreeCopier Java Examples
The following examples show how to use
com.sun.tools.javac.tree.TreeCopier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
<Z> JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, TreeCopier<Z> deferredCopier, Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator, LocalCacheContext localCache) { final JCTree newTree = deferredCopier.copy(tree); Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner))); speculativeEnv.info.isSpeculative = true; Log.DeferredDiagnosticHandler deferredDiagnosticHandler = diagHandlerCreator.apply(newTree); try { attr.attribTree(newTree, speculativeEnv, resultInfo); return newTree; } finally { new UnenterScanner(env.toplevel.modle).scan(newTree); log.popDiagnosticHandler(deferredDiagnosticHandler); if (localCache != null) { localCache.leave(); } } }
Example #2
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected DeferredAttr(Context context) { context.put(deferredAttrKey, this); attr = Attr.instance(context); argumentAttr = ArgumentAttr.instance(context); chk = Check.instance(context); diags = JCDiagnostic.Factory.instance(context); enter = Enter.instance(context); infer = Infer.instance(context); rs = Resolve.instance(context); log = Log.instance(context); syms = Symtab.instance(context); make = TreeMaker.instance(context); types = Types.instance(context); flow = Flow.instance(context); names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); typeEnvs = TypeEnvs.instance(context); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override void addDeferredAttrNode(DeferredType dt, ResultInfo ri, DeferredStuckPolicy deferredStuckPolicy) { Assert.error("Empty deferred context!"); } @Override void complete() { Assert.error("Empty deferred context!"); } @Override public String toString() { return "Empty deferred context!"; } }; // For speculative attribution, skip the class definition in <>. treeCopier = new TreeCopier<Void>(make) { @Override @DefinedBy(Api.COMPILER_TREE) public JCTree visitNewClass(NewClassTree node, Void p) { JCNewClass t = (JCNewClass) node; if (TreeInfo.isDiamond(t)) { JCExpression encl = copy(t.encl, p); List<JCExpression> typeargs = copy(t.typeargs, p); JCExpression clazz = copy(t.clazz, p); List<JCExpression> args = copy(t.args, p); JCClassDecl def = null; return make.at(t.pos).NewClass(encl, typeargs, clazz, args, def); } else { return super.visitNewClass(node, p); } } @Override @DefinedBy(Api.COMPILER_TREE) public JCTree visitMemberReference(MemberReferenceTree node, Void p) { JCMemberReference t = (JCMemberReference) node; JCExpression expr = copy(t.expr, p); List<JCExpression> typeargs = copy(t.typeargs, p); /** once the value for overloadKind is determined for a copy, it can be safely forwarded to * the copied tree, we want to profit from that */ JCMemberReference result = new JCMemberReference(t.mode, t.name, expr, typeargs) { @Override public void setOverloadKind(OverloadKind overloadKind) { super.setOverloadKind(overloadKind); if (t.getOverloadKind() == null) { t.setOverloadKind(overloadKind); } } }; result.pos = t.pos; return result; } }; deferredCopier = new TypeMapping<Void> () { @Override public Type visitType(Type t, Void v) { if (t.hasTag(DEFERRED)) { DeferredType dt = (DeferredType) t; return new DeferredType(treeCopier.copy(dt.tree), dt.env); } return t; } }; }