com.sun.tools.javac.tree.JCTree.JCMemberReference Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCMemberReference.
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 |
@Override public void visitReference(JCMemberReference tree) { scan(tree.expr); if (inferenceContext.inferenceVars().contains(pt)) { stuckVars.add(pt); return; } if (!types.isFunctionalInterface(pt)) { return; } Type descType = types.findDescriptorType(pt); List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); if (freeArgVars.nonEmpty() && tree.getOverloadKind() == JCMemberReference.OverloadKind.OVERLOADED) { stuckVars.addAll(freeArgVars); depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); } }
Example #2
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Method references to local class constructors, may, if the local * class references local variables, have implicit constructor * parameters added in Lower; As a result, the invokedynamic bootstrap * information added in the LambdaToMethod pass will have the wrong * signature. Hooks between Lower and LambdaToMethod have been added to * handle normal "new" in this case. This visitor converts potentially * affected method references into a lambda containing a normal * expression. * * @param tree */ @Override public void visitReference(JCMemberReference tree) { ReferenceTranslationContext rcontext = new ReferenceTranslationContext(tree); contextMap.put(tree, rcontext); if (rcontext.needsConversionToLambda()) { // Convert to a lambda, and process as such MemberReferenceToLambda conv = new MemberReferenceToLambda(tree, rcontext, owner()); analyzeLambda(conv.lambda(), conv.getReceiverExpression()); } else { super.visitReference(tree); if (dumpLambdaToMethodStats) { log.note(tree, Notes.MrefStat(rcontext.needsAltMetafactory(), null)); } } }
Example #3
Source File: FieldOverloadKindNotAssignedTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { Context context = new Context(); JavacFileManager.preRegister(context); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(new JavaSource())); Iterable<? extends CompilationUnitTree> elements = ct.parse(); ct.analyze(); Assert.check(elements.iterator().hasNext()); JCTree topLevel = (JCTree)elements.iterator().next(); new TreeScanner() { @Override public void visitReference(JCMemberReference tree) { Assert.check(tree.getOverloadKind() != null); } }.scan(topLevel); }
Example #4
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitReference(JCMemberReference tree) { Type t = types.skipTypeVars(tree.expr.type, false); Type receiverTarget = t.isCompound() ? erasure(tree.sym.owner.type) : erasure(t); if (tree.kind == ReferenceKind.UNBOUND) { tree.expr = make.Type(receiverTarget); } else { tree.expr = translate(tree.expr, receiverTarget); } tree.type = erasure(tree.type); if (tree.varargsElement != null) tree.varargsElement = erasure(tree.varargsElement); result = tree; }
Example #5
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitReference(JCMemberReference tree) { super.visitReference(tree); if (tree.getOverloadKind() == JCMemberReference.OverloadKind.OVERLOADED) { stuck = true; } }
Example #6
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
ReferenceTranslationContext(JCMemberReference tree) { super(tree); this.isSuper = tree.hasKind(ReferenceKind.SUPER); this.sigPolySym = isSignaturePolymorphic() ? makePrivateSyntheticMethod(tree.sym.flags(), tree.sym.name, bridgedRefSig(), tree.sym.enclClass()) : null; }
Example #7
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 5 votes |
private TreeNode convertMethodReference( MemberReferenceTree node, TreePath parent, MethodReference newNode) { TreePath path = getTreePath(parent, node); convertFunctionalExpression((JCMemberReference) node, parent, newNode); if (node.getTypeArguments() != null) { for (ExpressionTree typeArg : node.getTypeArguments()) { newNode.addTypeArgument(Type.newType(((JCExpression) typeArg).type)); } } return newNode .setExecutableElement((ExecutableElement) getElement(path)) .setVarargsType(((JCMemberReference) node).varargsElement); }
Example #8
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; } }; }
Example #9
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Translate a method reference into an invokedynamic call to the * meta-factory. * @param tree */ @Override public void visitReference(JCMemberReference tree) { ReferenceTranslationContext localContext = (ReferenceTranslationContext)context; //first determine the method symbol to be used to generate the sam instance //this is either the method reference symbol, or the bridged reference symbol Symbol refSym = localContext.isSignaturePolymorphic() ? localContext.sigPolySym : tree.sym; //the qualifying expression is treated as a special captured arg JCExpression init; switch(tree.kind) { case IMPLICIT_INNER: /** Inner :: new */ case SUPER: /** super :: instMethod */ init = makeThis( localContext.owner.enclClass().asType(), localContext.owner.enclClass()); break; case BOUND: /** Expr :: instMethod */ init = tree.getQualifierExpression(); init = attr.makeNullCheck(init); break; case UNBOUND: /** Type :: instMethod */ case STATIC: /** Type :: staticMethod */ case TOPLEVEL: /** Top level :: new */ case ARRAY_CTOR: /** ArrayType :: new */ init = null; break; default: throw new InternalError("Should not have an invalid kind"); } List<JCExpression> indy_args = init==null? List.nil() : translate(List.of(init), localContext.prev); //build a sam instance using an indy call to the meta-factory result = makeMetafactoryIndyCall(localContext, localContext.referenceKind(), refSym, indy_args); }
Example #10
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
MemberReferenceToLambda(JCMemberReference tree, ReferenceTranslationContext localContext, Symbol owner) { this.tree = tree; this.localContext = localContext; this.owner = owner; }