langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
changeset 18393 3672b286337e
parent 18389 a425d0819f36
child 18395 d56a5fbf0b32
equal deleted inserted replaced
18392:de0ad9c84ce8 18393:3672b286337e
  2312 
  2312 
  2313             Type lambdaType;
  2313             Type lambdaType;
  2314             if (pt() != Type.recoveryType) {
  2314             if (pt() != Type.recoveryType) {
  2315                 target = targetChecker.visit(target, that);
  2315                 target = targetChecker.visit(target, that);
  2316                 lambdaType = types.findDescriptorType(target);
  2316                 lambdaType = types.findDescriptorType(target);
  2317                 chk.checkFunctionalInterface(that, target);
       
  2318             } else {
  2317             } else {
  2319                 target = Type.recoveryType;
  2318                 target = Type.recoveryType;
  2320                 lambdaType = fallbackDescriptorType(that);
  2319                 lambdaType = fallbackDescriptorType(that);
  2321             }
  2320             }
  2322 
  2321 
  2323             setFunctionalInfo(that, pt(), lambdaType, target, resultInfo.checkContext.inferenceContext());
  2322             setFunctionalInfo(localEnv, that, pt(), lambdaType, target, resultInfo.checkContext);
  2324 
  2323 
  2325             if (lambdaType.hasTag(FORALL)) {
  2324             if (lambdaType.hasTag(FORALL)) {
  2326                 //lambda expression target desc cannot be a generic method
  2325                 //lambda expression target desc cannot be a generic method
  2327                 resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target",
  2326                 resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target",
  2328                         lambdaType, kindName(target.tsym), target.tsym));
  2327                         lambdaType, kindName(target.tsym), target.tsym));
  2660             Type target;
  2659             Type target;
  2661             Type desc;
  2660             Type desc;
  2662             if (pt() != Type.recoveryType) {
  2661             if (pt() != Type.recoveryType) {
  2663                 target = targetChecker.visit(pt(), that);
  2662                 target = targetChecker.visit(pt(), that);
  2664                 desc = types.findDescriptorType(target);
  2663                 desc = types.findDescriptorType(target);
  2665                 chk.checkFunctionalInterface(that, target);
       
  2666             } else {
  2664             } else {
  2667                 target = Type.recoveryType;
  2665                 target = Type.recoveryType;
  2668                 desc = fallbackDescriptorType(that);
  2666                 desc = fallbackDescriptorType(that);
  2669             }
  2667             }
  2670 
  2668 
  2671             setFunctionalInfo(that, pt(), desc, target, resultInfo.checkContext.inferenceContext());
  2669             setFunctionalInfo(localEnv, that, pt(), desc, target, resultInfo.checkContext);
  2672             List<Type> argtypes = desc.getParameterTypes();
  2670             List<Type> argtypes = desc.getParameterTypes();
  2673 
  2671 
  2674             Pair<Symbol, Resolve.ReferenceLookupHelper> refResult =
  2672             Pair<Symbol, Resolve.ReferenceLookupHelper> refResult =
  2675                     rs.resolveMemberReference(that.pos(), localEnv, that,
  2673                     rs.resolveMemberReference(that.pos(), localEnv, that,
  2676                         that.expr.type, that.name, argtypes, typeargtypes, true, rs.resolveMethodCheck);
  2674                         that.expr.type, that.name, argtypes, typeargtypes, true, rs.resolveMethodCheck);
  2868     /**
  2866     /**
  2869      * Set functional type info on the underlying AST. Note: as the target descriptor
  2867      * Set functional type info on the underlying AST. Note: as the target descriptor
  2870      * might contain inference variables, we might need to register an hook in the
  2868      * might contain inference variables, we might need to register an hook in the
  2871      * current inference context.
  2869      * current inference context.
  2872      */
  2870      */
  2873     private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt,
  2871     private void setFunctionalInfo(final Env<AttrContext> env, final JCFunctionalExpression fExpr,
  2874             final Type descriptorType, final Type primaryTarget, InferenceContext inferenceContext) {
  2872             final Type pt, final Type descriptorType, final Type primaryTarget, final CheckContext checkContext) {
  2875         if (inferenceContext.free(descriptorType)) {
  2873         if (checkContext.inferenceContext().free(descriptorType)) {
  2876             inferenceContext.addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() {
  2874             checkContext.inferenceContext().addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() {
  2877                 public void typesInferred(InferenceContext inferenceContext) {
  2875                 public void typesInferred(InferenceContext inferenceContext) {
  2878                     setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType),
  2876                     setFunctionalInfo(env, fExpr, pt, inferenceContext.asInstType(descriptorType),
  2879                             inferenceContext.asInstType(primaryTarget), inferenceContext);
  2877                             inferenceContext.asInstType(primaryTarget), checkContext);
  2880                 }
  2878                 }
  2881             });
  2879             });
  2882         } else {
  2880         } else {
  2883             ListBuffer<TypeSymbol> targets = ListBuffer.lb();
  2881             ListBuffer<Type> targets = ListBuffer.lb();
  2884             if (pt.hasTag(CLASS)) {
  2882             if (pt.hasTag(CLASS)) {
  2885                 if (pt.isCompound()) {
  2883                 if (pt.isCompound()) {
  2886                     targets.append(primaryTarget.tsym); //this goes first
  2884                     targets.append(types.removeWildcards(primaryTarget)); //this goes first
  2887                     for (Type t : ((IntersectionClassType)pt()).interfaces_field) {
  2885                     for (Type t : ((IntersectionClassType)pt()).interfaces_field) {
  2888                         if (t != primaryTarget) {
  2886                         if (t != primaryTarget) {
  2889                             targets.append(t.tsym);
  2887                             targets.append(types.removeWildcards(t));
  2890                         }
  2888                         }
  2891                     }
  2889                     }
  2892                 } else {
  2890                 } else {
  2893                     targets.append(pt.tsym);
  2891                     targets.append(types.removeWildcards(primaryTarget));
  2894                 }
  2892                 }
  2895             }
  2893             }
  2896             fExpr.targets = targets.toList();
  2894             fExpr.targets = targets.toList();
  2897             fExpr.descriptorType = descriptorType;
  2895             if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
       
  2896                     pt != Type.recoveryType) {
       
  2897                 //check that functional interface class is well-formed
       
  2898                 ClassSymbol csym = types.makeFunctionalInterfaceClass(env,
       
  2899                         names.empty, List.of(fExpr.targets.head), ABSTRACT);
       
  2900                 chk.checkImplementations(env.tree, csym, csym);
       
  2901             }
  2898         }
  2902         }
  2899     }
  2903     }
  2900 
  2904 
  2901     public void visitParens(JCParens tree) {
  2905     public void visitParens(JCParens tree) {
  2902         Type owntype = attribTree(tree.expr, env, resultInfo);
  2906         Type owntype = attribTree(tree.expr, env, resultInfo);
  4548         }
  4552         }
  4549 
  4553 
  4550         @Override
  4554         @Override
  4551         public void visitLambda(JCLambda that) {
  4555         public void visitLambda(JCLambda that) {
  4552             super.visitLambda(that);
  4556             super.visitLambda(that);
  4553             if (that.descriptorType == null) {
       
  4554                 that.descriptorType = syms.unknownType;
       
  4555             }
       
  4556             if (that.targets == null) {
  4557             if (that.targets == null) {
  4557                 that.targets = List.nil();
  4558                 that.targets = List.nil();
  4558             }
  4559             }
  4559         }
  4560         }
  4560 
  4561 
  4562         public void visitReference(JCMemberReference that) {
  4563         public void visitReference(JCMemberReference that) {
  4563             super.visitReference(that);
  4564             super.visitReference(that);
  4564             if (that.sym == null) {
  4565             if (that.sym == null) {
  4565                 that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol);
  4566                 that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol);
  4566             }
  4567             }
  4567             if (that.descriptorType == null) {
       
  4568                 that.descriptorType = syms.unknownType;
       
  4569             }
       
  4570             if (that.targets == null) {
  4568             if (that.targets == null) {
  4571                 that.targets = List.nil();
  4569                 that.targets = List.nil();
  4572             }
  4570             }
  4573         }
  4571         }
  4574     }
  4572     }