/** * Lambda body to use for a 'new'. */ private JCExpression expressionNew() { if (tree.kind == ReferenceKind.ARRAY_CTOR) { //create the array creation expression JCNewArray newArr = make.NewArray( make.Type(types.elemtype(tree.getQualifierExpression().type)), List.of(make.Ident(params.first())), null); newArr.type = tree.getQualifierExpression().type; return newArr; } else { //create the instance creation expression //note that method reference syntax does not allow an explicit //enclosing class (so the enclosing class is null) JCNewClass newClass = make.NewClass(null, List.<JCExpression>nil(), make.Type(tree.getQualifierExpression().type), convertArgs(tree.sym, args.toList(), tree.varargsElement), null); newClass.constructor = tree.sym; newClass.constructorType = tree.sym.erasure(types); newClass.type = tree.getQualifierExpression().type; setVarargsIfNeeded(newClass, tree.varargsElement); return newClass; } }
/** * Erasure destroys the implementation parameter subtype * relationship for intersection types */ boolean interfaceParameterIsIntersectionType() { List<Type> tl = tree.getDescriptorType(types).getParameterTypes(); if (tree.kind == ReferenceKind.UNBOUND) { tl = tl.tail; } for (; tl.nonEmpty(); tl = tl.tail) { Type pt = tl.head; if (pt.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) pt; if (tv.bound.getKind() == TypeKind.INTERSECTION) { return true; } } } return false; }
/** * Lambda body to use for a 'new'. */ private JCExpression expressionNew() { if (tree.kind == ReferenceKind.ARRAY_CTOR) { //create the array creation expression JCNewArray newArr = make.NewArray( make.Type(types.elemtype(tree.getQualifierExpression().type)), List.of(make.Ident(params.first())), null); newArr.type = tree.getQualifierExpression().type; return newArr; } else { //create the instance creation expression //note that method reference syntax does not allow an explicit //enclosing class (so the enclosing class is null) JCNewClass newClass = make.NewClass(null, List.nil(), make.Type(tree.getQualifierExpression().type), convertArgs(tree.sym, args.toList(), tree.varargsElement), null); newClass.constructor = tree.sym; newClass.constructorType = tree.sym.erasure(types); newClass.type = tree.getQualifierExpression().type; setVarargsIfNeeded(newClass, tree.varargsElement); return newClass; } }
ReferenceTranslationContext(JCMemberReference tree) { super(tree); this.isSuper = tree.hasKind(ReferenceKind.SUPER); this.bridgeSym = needsBridge() ? makePrivateSyntheticMethod(isSuper ? 0 : STATIC, referenceBridgeName(), null, owner.enclClass()) : null; this.sigPolySym = isSignaturePolymorphic() ? makePrivateSyntheticMethod(tree.sym.flags(), tree.sym.name, bridgedRefSig(), tree.sym.enclClass()) : null; if (dumpLambdaToMethodStats) { String key = bridgeSym == null ? "mref.stat" : "mref.stat.1"; log.note(tree, key, needsAltMetafactory(), bridgeSym); } }
@Override ReferenceKind referenceKind(Symbol sym) { if (sym.isStatic()) { return ReferenceKind.STATIC; } else { Name selName = TreeInfo.name(referenceTree.getQualifierExpression()); return selName != null && selName == names._super ? ReferenceKind.SUPER : ReferenceKind.BOUND; } }
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; }
/** * Does this reference need to be converted to a lambda * (i.e. var args need to be expanded or "super" is used) */ final boolean needsConversionToLambda() { return interfaceParameterIsIntersectionType() || isSuper || needsVarArgsConversion() || isArrayOp() || isPrivateInOtherClass() || !receiverAccessible() || (tree.getMode() == ReferenceMode.NEW && tree.kind != ReferenceKind.ARRAY_CTOR && (tree.sym.owner.isLocal() || tree.sym.owner.isInner())); }
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; }
/** * Does this reference need to be converted to a lambda * (i.e. var args need to be expanded or "super" is used) */ final boolean needsConversionToLambda() { return interfaceParameterIsIntersectionType() || isSuper || needsVarArgsConversion() || isArrayOp() || isPrivateInOtherClass() || isProtectedInSuperClassOfEnclosingClassInOtherPackage() || !receiverAccessible() || (tree.getMode() == ReferenceMode.NEW && tree.kind != ReferenceKind.ARRAY_CTOR && (tree.sym.owner.isLocal() || tree.sym.owner.isInner())); }
/** * the enclosing expression is either 'null' (no enclosing type) or set * to the first bridge synthetic parameter */ private JCExpression bridgeExpressionNew() { if (tree.kind == ReferenceKind.ARRAY_CTOR) { //create the array creation expression JCNewArray newArr = make.NewArray( make.Type(types.elemtype(tree.getQualifierExpression().type)), List.of(make.Ident(params.first())), null); newArr.type = tree.getQualifierExpression().type; return newArr; } else { JCExpression encl = null; switch (tree.kind) { case UNBOUND: case IMPLICIT_INNER: encl = make.Ident(params.first()); } //create the instance creation expression JCNewClass newClass = make.NewClass(encl, List.<JCExpression>nil(), make.Type(tree.getQualifierExpression().type), convertArgs(tree.sym, args.toList(), tree.varargsElement), null); newClass.constructor = tree.sym; newClass.constructorType = tree.sym.erasure(types); newClass.type = tree.getQualifierExpression().type; setVarargsIfNeeded(newClass, tree.varargsElement); return newClass; } }
@Override ReferenceKind referenceKind(Symbol sym) { return ReferenceKind.UNBOUND; }
@Override ReferenceKind referenceKind(Symbol sym) { return ReferenceKind.ARRAY_CTOR; }
@Override ReferenceKind referenceKind(Symbol sym) { return site.getEnclosingType().hasTag(NONE) ? ReferenceKind.TOPLEVEL : ReferenceKind.IMPLICIT_INNER; }