Thu, 20 Nov 2014 11:27:57 -0800
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Wed Nov 19 11:29:47 2014 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Nov 20 11:27:57 2014 -0800 1.3 @@ -242,9 +242,15 @@ 1.4 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); 1.5 try { 1.6 new AssignAnalyzer() { 1.7 + Scope enclosedSymbols = new Scope(env.enclClass.sym); 1.8 + @Override 1.9 + public void visitVarDef(JCVariableDecl tree) { 1.10 + enclosedSymbols.enter(tree.sym); 1.11 + super.visitVarDef(tree); 1.12 + } 1.13 @Override 1.14 protected boolean trackable(VarSymbol sym) { 1.15 - return !env.info.scope.includes(sym) && 1.16 + return enclosedSymbols.includes(sym) && 1.17 sym.owner.kind == MTH; 1.18 } 1.19 }.analyzeTree(env, that);
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed Nov 19 11:29:47 2014 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Thu Nov 20 11:27:57 2014 -0800 2.3 @@ -321,7 +321,9 @@ 2.4 2.5 ListBuffer<JCExpression> syntheticInits = new ListBuffer<>(); 2.6 2.7 - if (!sym.isStatic()) { 2.8 + if (localContext.methodReferenceReceiver != null) { 2.9 + syntheticInits.append(localContext.methodReferenceReceiver); 2.10 + } else if (!sym.isStatic()) { 2.11 syntheticInits.append(makeThis( 2.12 sym.owner.enclClass().asType(), 2.13 localContext.owner.enclClass())); 2.14 @@ -364,17 +366,10 @@ 2.15 2.16 //first determine the method symbol to be used to generate the sam instance 2.17 //this is either the method reference symbol, or the bridged reference symbol 2.18 - Symbol refSym = localContext.needsBridge() 2.19 - ? localContext.bridgeSym 2.20 - : localContext.isSignaturePolymorphic() 2.21 + Symbol refSym = localContext.isSignaturePolymorphic() 2.22 ? localContext.sigPolySym 2.23 : tree.sym; 2.24 2.25 - //build the bridge method, if needed 2.26 - if (localContext.needsBridge()) { 2.27 - bridgeMemberReference(tree, localContext); 2.28 - } 2.29 - 2.30 //the qualifying expression is treated as a special captured arg 2.31 JCExpression init; 2.32 switch(tree.kind) { 2.33 @@ -744,54 +739,51 @@ 2.34 // </editor-fold> 2.35 2.36 /** 2.37 - * Generate an adapter method "bridge" for a method reference which cannot 2.38 - * be used directly. 2.39 + * Converts a method reference which cannot be used directly into a lambda 2.40 */ 2.41 - private class MemberReferenceBridger { 2.42 + private class MemberReferenceToLambda { 2.43 2.44 private final JCMemberReference tree; 2.45 private final ReferenceTranslationContext localContext; 2.46 + private final Symbol owner; 2.47 private final ListBuffer<JCExpression> args = new ListBuffer<>(); 2.48 private final ListBuffer<JCVariableDecl> params = new ListBuffer<>(); 2.49 2.50 - MemberReferenceBridger(JCMemberReference tree, ReferenceTranslationContext localContext) { 2.51 + private JCExpression receiverExpression = null; 2.52 + 2.53 + MemberReferenceToLambda(JCMemberReference tree, ReferenceTranslationContext localContext, Symbol owner) { 2.54 this.tree = tree; 2.55 this.localContext = localContext; 2.56 + this.owner = owner; 2.57 } 2.58 2.59 - /** 2.60 - * Generate the bridge 2.61 - */ 2.62 - JCMethodDecl bridge() { 2.63 + JCLambda lambda() { 2.64 int prevPos = make.pos; 2.65 try { 2.66 make.at(tree); 2.67 Type samDesc = localContext.bridgedRefSig(); 2.68 List<Type> samPTypes = samDesc.getParameterTypes(); 2.69 2.70 - //an extra argument is prepended to the signature of the bridge in case 2.71 - //the member reference is an instance method reference (in which case 2.72 - //the receiver expression is passed to the bridge itself). 2.73 - Type recType = null; 2.74 + // an extra argument is prepended in the case where the member 2.75 + // reference is an unbound instance method reference (in which 2.76 + // case the receiver expression in passed. 2.77 + VarSymbol rcvr; 2.78 switch (tree.kind) { 2.79 - case IMPLICIT_INNER: 2.80 - recType = tree.sym.owner.type.getEnclosingType(); 2.81 - break; 2.82 case BOUND: 2.83 - recType = tree.getQualifierExpression().type; 2.84 + rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); 2.85 + receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); 2.86 break; 2.87 case UNBOUND: 2.88 - recType = samPTypes.head; 2.89 + rcvr = addParameter("rec$", samPTypes.head, false); 2.90 samPTypes = samPTypes.tail; 2.91 break; 2.92 + default: 2.93 + rcvr = null; 2.94 + break; 2.95 } 2.96 2.97 - //generate the parameter list for the bridged member reference - the 2.98 - //bridge signature will match the signature of the target sam descriptor 2.99 - 2.100 - VarSymbol rcvr = (recType == null) 2.101 - ? null 2.102 - : addParameter("rec$", recType, false); 2.103 + // generate the parameter list for the coverted member reference. 2.104 + // the signature will match the signature of the target sam descriptor 2.105 2.106 List<Type> refPTypes = tree.sym.type.getParameterTypes(); 2.107 int refSize = refPTypes.size(); 2.108 @@ -810,64 +802,50 @@ 2.109 addParameter("xva$" + i, tree.varargsElement, true); 2.110 } 2.111 2.112 - //generate the bridge method declaration 2.113 - JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()), 2.114 - localContext.bridgeSym.name, 2.115 - make.QualIdent(samDesc.getReturnType().tsym), 2.116 - List.<JCTypeParameter>nil(), 2.117 - params.toList(), 2.118 - tree.sym.type.getThrownTypes() == null 2.119 - ? List.<JCExpression>nil() 2.120 - : make.Types(tree.sym.type.getThrownTypes()), 2.121 - null, 2.122 - null); 2.123 - bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym; 2.124 - bridgeDecl.type = localContext.bridgeSym.type = 2.125 - types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList())); 2.126 + //body generation - this can be either a method call or a 2.127 + //new instance creation expression, depending on the member reference kind 2.128 + JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE) 2.129 + ? expressionInvoke(rcvr) 2.130 + : expressionNew(); 2.131 2.132 - //bridge method body generation - this can be either a method call or a 2.133 - //new instance creation expression, depending on the member reference kind 2.134 - JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE) 2.135 - ? bridgeExpressionInvoke(makeReceiver(rcvr)) 2.136 - : bridgeExpressionNew(); 2.137 - 2.138 - //the body is either a return expression containing a method call, 2.139 - //or the method call itself, depending on whether the return type of 2.140 - //the bridge is non-void/void. 2.141 - bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl); 2.142 - 2.143 - return bridgeDecl; 2.144 + JCLambda slam = make.Lambda(params.toList(), expr); 2.145 + slam.targets = tree.targets; 2.146 + slam.type = tree.type; 2.147 + slam.pos = tree.pos; 2.148 + return slam; 2.149 } finally { 2.150 make.at(prevPos); 2.151 } 2.152 } 2.153 - //where 2.154 - private JCExpression makeReceiver(VarSymbol rcvr) { 2.155 - if (rcvr == null) return null; 2.156 - JCExpression rcvrExpr = make.Ident(rcvr); 2.157 - Type rcvrType = tree.sym.enclClass().type; 2.158 - if (rcvrType == syms.arrayClass.type) { 2.159 - // Map the receiver type to the actually type, not just "array" 2.160 - rcvrType = tree.getQualifierExpression().type; 2.161 - } 2.162 - if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { 2.163 - rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); 2.164 - } 2.165 - return rcvrExpr; 2.166 + 2.167 + JCExpression getReceiverExpression() { 2.168 + return receiverExpression; 2.169 + } 2.170 + 2.171 + private JCExpression makeReceiver(VarSymbol rcvr) { 2.172 + if (rcvr == null) return null; 2.173 + JCExpression rcvrExpr = make.Ident(rcvr); 2.174 + Type rcvrType = tree.sym.enclClass().type; 2.175 + if (rcvrType == syms.arrayClass.type) { 2.176 + // Map the receiver type to the actually type, not just "array" 2.177 + rcvrType = tree.getQualifierExpression().type; 2.178 } 2.179 + if (!rcvr.type.tsym.isSubClass(rcvrType.tsym, types)) { 2.180 + rcvrExpr = make.TypeCast(make.Type(rcvrType), rcvrExpr).setType(rcvrType); 2.181 + } 2.182 + return rcvrExpr; 2.183 + } 2.184 2.185 /** 2.186 - * determine the receiver of the bridged method call - the receiver can 2.187 - * be either the synthetic receiver parameter or a type qualifier; the 2.188 - * original qualifier expression is never used here, as it might refer 2.189 - * to symbols not available in the static context of the bridge 2.190 + * determine the receiver of the method call - the receiver can 2.191 + * be a type qualifier, the synthetic receiver parameter or 'super'. 2.192 */ 2.193 - private JCExpression bridgeExpressionInvoke(JCExpression rcvr) { 2.194 + private JCExpression expressionInvoke(VarSymbol rcvr) { 2.195 JCExpression qualifier = 2.196 tree.sym.isStatic() ? 2.197 make.Type(tree.sym.owner.type) : 2.198 (rcvr != null) ? 2.199 - rcvr : 2.200 + makeReceiver(rcvr) : 2.201 tree.getQualifierExpression(); 2.202 2.203 //create the qualifier expression 2.204 @@ -886,10 +864,9 @@ 2.205 } 2.206 2.207 /** 2.208 - * the enclosing expression is either 'null' (no enclosing type) or set 2.209 - * to the first bridge synthetic parameter 2.210 + * Lambda body to use for a 'new'. 2.211 */ 2.212 - private JCExpression bridgeExpressionNew() { 2.213 + private JCExpression expressionNew() { 2.214 if (tree.kind == ReferenceKind.ARRAY_CTOR) { 2.215 //create the array creation expression 2.216 JCNewArray newArr = make.NewArray( 2.217 @@ -899,15 +876,10 @@ 2.218 newArr.type = tree.getQualifierExpression().type; 2.219 return newArr; 2.220 } else { 2.221 - JCExpression encl = null; 2.222 - switch (tree.kind) { 2.223 - case UNBOUND: 2.224 - case IMPLICIT_INNER: 2.225 - encl = make.Ident(params.first()); 2.226 - } 2.227 - 2.228 //create the instance creation expression 2.229 - JCNewClass newClass = make.NewClass(encl, 2.230 + //note that method reference syntax does not allow an explicit 2.231 + //enclosing class (so the enclosing class is null) 2.232 + JCNewClass newClass = make.NewClass(null, 2.233 List.<JCExpression>nil(), 2.234 make.Type(tree.getQualifierExpression().type), 2.235 convertArgs(tree.sym, args.toList(), tree.varargsElement), 2.236 @@ -921,7 +893,8 @@ 2.237 } 2.238 2.239 private VarSymbol addParameter(String name, Type p, boolean genArg) { 2.240 - VarSymbol vsym = new VarSymbol(0, names.fromString(name), p, localContext.bridgeSym); 2.241 + VarSymbol vsym = new VarSymbol(PARAMETER | SYNTHETIC, names.fromString(name), p, owner); 2.242 + vsym.pos = tree.pos; 2.243 params.append(make.VarDef(vsym, null)); 2.244 if (genArg) { 2.245 args.append(make.Ident(vsym)); 2.246 @@ -930,15 +903,6 @@ 2.247 } 2.248 } 2.249 2.250 - /** 2.251 - * Bridges a member reference - this is needed when: 2.252 - * * Var args in the referenced method need to be flattened away 2.253 - * * super is used 2.254 - */ 2.255 - private void bridgeMemberReference(JCMemberReference tree, ReferenceTranslationContext localContext) { 2.256 - kInfo.addMethod(new MemberReferenceBridger(tree, localContext).bridge()); 2.257 - } 2.258 - 2.259 private MethodType typeToMethodType(Type mt) { 2.260 Type type = types.erasure(mt); 2.261 return new MethodType(type.getParameterTypes(), 2.262 @@ -1258,9 +1222,25 @@ 2.263 2.264 @Override 2.265 public void visitLambda(JCLambda tree) { 2.266 + analyzeLambda(tree, "lambda.stat"); 2.267 + } 2.268 + 2.269 + private void analyzeLambda(JCLambda tree, JCExpression methodReferenceReceiver) { 2.270 + // Translation of the receiver expression must occur first 2.271 + JCExpression rcvr = translate(methodReferenceReceiver); 2.272 + LambdaTranslationContext context = analyzeLambda(tree, "mref.stat.1"); 2.273 + if (rcvr != null) { 2.274 + context.methodReferenceReceiver = rcvr; 2.275 + } 2.276 + } 2.277 + 2.278 + private LambdaTranslationContext analyzeLambda(JCLambda tree, String statKey) { 2.279 List<Frame> prevStack = frameStack; 2.280 try { 2.281 - LambdaTranslationContext context = (LambdaTranslationContext)makeLambdaContext(tree); 2.282 + LambdaTranslationContext context = new LambdaTranslationContext(tree); 2.283 + if (dumpLambdaToMethodStats) { 2.284 + log.note(tree, statKey, context.needsAltMetafactory(), context.translatedSym); 2.285 + } 2.286 frameStack = frameStack.prepend(new Frame(tree)); 2.287 for (JCVariableDecl param : tree.params) { 2.288 context.addSymbol(param.sym, PARAM); 2.289 @@ -1269,6 +1249,7 @@ 2.290 contextMap.put(tree, context); 2.291 super.visitLambda(tree); 2.292 context.complete(); 2.293 + return context; 2.294 } 2.295 finally { 2.296 frameStack = prevStack; 2.297 @@ -1357,47 +1338,24 @@ 2.298 * information added in the LambdaToMethod pass will have the wrong 2.299 * signature. Hooks between Lower and LambdaToMethod have been added to 2.300 * handle normal "new" in this case. This visitor converts potentially 2.301 - * effected method references into a lambda containing a normal "new" of 2.302 - * the class. 2.303 + * affected method references into a lambda containing a normal 2.304 + * expression. 2.305 * 2.306 * @param tree 2.307 */ 2.308 @Override 2.309 public void visitReference(JCMemberReference tree) { 2.310 - if (tree.getMode() == ReferenceMode.NEW 2.311 - && tree.kind != ReferenceKind.ARRAY_CTOR 2.312 - && tree.sym.owner.isLocal()) { 2.313 - MethodSymbol consSym = (MethodSymbol) tree.sym; 2.314 - List<Type> ptypes = ((MethodType) consSym.type).getParameterTypes(); 2.315 - Type classType = consSym.owner.type; 2.316 - 2.317 - // Build lambda parameters 2.318 - // partially cloned from TreeMaker.Params until 8014021 is fixed 2.319 - Symbol owner = owner(); 2.320 - ListBuffer<JCVariableDecl> paramBuff = new ListBuffer<JCVariableDecl>(); 2.321 - int i = 0; 2.322 - for (List<Type> l = ptypes; l.nonEmpty(); l = l.tail) { 2.323 - JCVariableDecl param = make.Param(make.paramName(i++), l.head, owner); 2.324 - param.sym.pos = tree.pos; 2.325 - paramBuff.append(param); 2.326 - } 2.327 - List<JCVariableDecl> params = paramBuff.toList(); 2.328 - 2.329 - // Make new-class call 2.330 - JCNewClass nc = makeNewClass(classType, make.Idents(params)); 2.331 - nc.pos = tree.pos; 2.332 - 2.333 - // Make lambda holding the new-class call 2.334 - JCLambda slam = make.Lambda(params, nc); 2.335 - slam.targets = tree.targets; 2.336 - slam.type = tree.type; 2.337 - slam.pos = tree.pos; 2.338 - 2.339 - // Now it is a lambda, process as such 2.340 - visitLambda(slam); 2.341 + ReferenceTranslationContext rcontext = new ReferenceTranslationContext(tree); 2.342 + contextMap.put(tree, rcontext); 2.343 + if (rcontext.needsConversionToLambda()) { 2.344 + // Convert to a lambda, and process as such 2.345 + MemberReferenceToLambda conv = new MemberReferenceToLambda(tree, rcontext, owner()); 2.346 + analyzeLambda(conv.lambda(), conv.getReceiverExpression()); 2.347 } else { 2.348 super.visitReference(tree); 2.349 - contextMap.put(tree, makeReferenceContext(tree)); 2.350 + if (dumpLambdaToMethodStats) { 2.351 + log.note(tree, "mref.stat", rcontext.needsAltMetafactory(), null); 2.352 + } 2.353 } 2.354 } 2.355 2.356 @@ -1652,14 +1610,6 @@ 2.357 } 2.358 } 2.359 2.360 - private TranslationContext<JCLambda> makeLambdaContext(JCLambda tree) { 2.361 - return new LambdaTranslationContext(tree); 2.362 - } 2.363 - 2.364 - private TranslationContext<JCMemberReference> makeReferenceContext(JCMemberReference tree) { 2.365 - return new ReferenceTranslationContext(tree); 2.366 - } 2.367 - 2.368 private class Frame { 2.369 final JCTree tree; 2.370 List<Symbol> locals; 2.371 @@ -1779,6 +1729,13 @@ 2.372 */ 2.373 final Set<Symbol> freeVarProcessedLocalClasses; 2.374 2.375 + /** 2.376 + * For method references converted to lambdas. The method 2.377 + * reference receiver expression. Must be treated like a captured 2.378 + * variable. 2.379 + */ 2.380 + JCExpression methodReferenceReceiver; 2.381 + 2.382 LambdaTranslationContext(JCLambda tree) { 2.383 super(tree); 2.384 Frame frame = frameStack.head; 2.385 @@ -1798,9 +1755,6 @@ 2.386 // This symbol will be filled-in in complete 2.387 this.translatedSym = makePrivateSyntheticMethod(0, null, null, owner.enclClass()); 2.388 2.389 - if (dumpLambdaToMethodStats) { 2.390 - log.note(tree, "lambda.stat", needsAltMetafactory(), translatedSym); 2.391 - } 2.392 translatedSymbols = new EnumMap<>(LambdaSymbolKind.class); 2.393 2.394 translatedSymbols.put(PARAM, new LinkedHashMap<Symbol, Symbol>()); 2.395 @@ -2017,6 +1971,13 @@ 2.396 for (Symbol thisSym : getSymbolMap(CAPTURED_VAR).values()) { 2.397 params.append(make.VarDef((VarSymbol) thisSym, null)); 2.398 } 2.399 + if (methodReferenceReceiver != null) { 2.400 + params.append(make.VarDef( 2.401 + make.Modifiers(PARAMETER|FINAL), 2.402 + names.fromString("$rcvr$"), 2.403 + make.Type(methodReferenceReceiver.type), 2.404 + null)); 2.405 + } 2.406 for (Symbol thisSym : getSymbolMap(PARAM).values()) { 2.407 params.append(make.VarDef((VarSymbol) thisSym, null)); 2.408 } 2.409 @@ -2044,40 +2005,27 @@ 2.410 * and the used by the main translation routines in order to adjust method 2.411 * references (i.e. in case a bridge is needed) 2.412 */ 2.413 - private class ReferenceTranslationContext extends TranslationContext<JCMemberReference> { 2.414 + private final class ReferenceTranslationContext extends TranslationContext<JCMemberReference> { 2.415 2.416 final boolean isSuper; 2.417 - final Symbol bridgeSym; 2.418 final Symbol sigPolySym; 2.419 2.420 ReferenceTranslationContext(JCMemberReference tree) { 2.421 super(tree); 2.422 this.isSuper = tree.hasKind(ReferenceKind.SUPER); 2.423 - this.bridgeSym = needsBridge() 2.424 - ? makePrivateSyntheticMethod(isSuper ? 0 : STATIC, 2.425 - referenceBridgeName(), null, 2.426 - owner.enclClass()) 2.427 - : null; 2.428 this.sigPolySym = isSignaturePolymorphic() 2.429 ? makePrivateSyntheticMethod(tree.sym.flags(), 2.430 tree.sym.name, 2.431 bridgedRefSig(), 2.432 tree.sym.enclClass()) 2.433 : null; 2.434 - if (dumpLambdaToMethodStats) { 2.435 - String key = bridgeSym == null ? 2.436 - "mref.stat" : "mref.stat.1"; 2.437 - log.note(tree, key, needsAltMetafactory(), bridgeSym); 2.438 - } 2.439 } 2.440 2.441 /** 2.442 * Get the opcode associated with this method reference 2.443 */ 2.444 int referenceKind() { 2.445 - return LambdaToMethod.this.referenceKind(needsBridge() 2.446 - ? bridgeSym 2.447 - : tree.sym); 2.448 + return LambdaToMethod.this.referenceKind(tree.sym); 2.449 } 2.450 2.451 boolean needsVarArgsConversion() { 2.452 @@ -2085,62 +2033,6 @@ 2.453 } 2.454 2.455 /** 2.456 - * Generate a disambiguating string to increase stability (important 2.457 - * if serialized) 2.458 - * 2.459 - * @return String to differentiate synthetic lambda method names 2.460 - */ 2.461 - private String referenceBridgeDisambiguation() { 2.462 - StringBuilder buf = new StringBuilder(); 2.463 - // Append the enclosing method signature to differentiate 2.464 - // overloaded enclosing methods. 2.465 - if (owner.type != null) { 2.466 - buf.append(typeSig(owner.type)); 2.467 - buf.append(":"); 2.468 - } 2.469 - 2.470 - // Append qualifier type 2.471 - buf.append(classSig(tree.sym.owner.type)); 2.472 - 2.473 - // Note static/instance 2.474 - buf.append(tree.sym.isStatic()? " S " : " I "); 2.475 - 2.476 - // Append referenced signature 2.477 - buf.append(typeSig(tree.sym.erasure(types))); 2.478 - 2.479 - return buf.toString(); 2.480 - } 2.481 - 2.482 - /** 2.483 - * Construct a unique stable name for the method reference bridge 2.484 - * 2.485 - * @return Name to use for the synthetic method name 2.486 - */ 2.487 - private Name referenceBridgeName() { 2.488 - StringBuilder buf = new StringBuilder(); 2.489 - // Append lambda ID, this is semantically significant 2.490 - buf.append(names.lambda); 2.491 - // Note that it is a method reference bridge 2.492 - buf.append("MR$"); 2.493 - // Append the enclosing method name 2.494 - buf.append(enclosingMethodName()); 2.495 - buf.append('$'); 2.496 - // Append the referenced method name 2.497 - buf.append(syntheticMethodNameComponent(tree.sym.name)); 2.498 - buf.append('$'); 2.499 - // Append a hash of the disambiguating string : enclosing method 2.500 - // signature, etc. 2.501 - String disam = referenceBridgeDisambiguation(); 2.502 - buf.append(Integer.toHexString(disam.hashCode())); 2.503 - buf.append('$'); 2.504 - // The above appended name components may not be unique, append 2.505 - // a count based on the above name components. 2.506 - buf.append(syntheticMethodNameCounts.getIndex(buf)); 2.507 - String result = buf.toString(); 2.508 - return names.fromString(result); 2.509 - } 2.510 - 2.511 - /** 2.512 * @return Is this an array operation like clone() 2.513 */ 2.514 boolean isArrayOp() { 2.515 @@ -2175,13 +2067,16 @@ 2.516 } 2.517 2.518 /** 2.519 - * Does this reference needs a bridge (i.e. var args need to be 2.520 - * expanded or "super" is used) 2.521 + * Does this reference need to be converted to a lambda 2.522 + * (i.e. var args need to be expanded or "super" is used) 2.523 */ 2.524 - final boolean needsBridge() { 2.525 + final boolean needsConversionToLambda() { 2.526 return isSuper || needsVarArgsConversion() || isArrayOp() || 2.527 isPrivateInOtherClass() || 2.528 - !receiverAccessible(); 2.529 + !receiverAccessible() || 2.530 + (tree.getMode() == ReferenceMode.NEW && 2.531 + tree.kind != ReferenceKind.ARRAY_CTOR && 2.532 + (tree.sym.owner.isLocal() || tree.sym.owner.isInner())); 2.533 } 2.534 2.535 Type generatedRefSig() {
3.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler_ja.properties Wed Nov 19 11:29:47 2014 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler_ja.properties Thu Nov 20 11:27:57 2014 -0800 3.3 @@ -1534,7 +1534,7 @@ 3.4 compiler.warn.override.unchecked.thrown={0}\n\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3055\u308C\u305F\u30E1\u30BD\u30C3\u30C9\u306F{1}\u3092\u30B9\u30ED\u30FC\u3057\u307E\u305B\u3093 3.5 3.6 # 0: symbol 3.7 -compiler.warn.override.equals.but.not.hashcode=\u30AF\u30E9\u30B9{0}\u306F\u7B49\u53F7\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3057\u307E\u3059\u304C\u3001\u3053\u306E\u30AF\u30E9\u30B9\u3082\u30B9\u30FC\u30D1\u30FC\u30AF\u30E9\u30B9\u3082hashCode\u30E1\u30BD\u30C3\u30C9\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3057\u307E\u305B\u3093 3.8 +compiler.warn.override.equals.but.not.hashcode=\u30AF\u30E9\u30B9{0}\u306Fequals\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3057\u307E\u3059\u304C\u3001\u3053\u306E\u30AF\u30E9\u30B9\u3082\u3001\u307E\u305F\u3001\u3044\u304B\u306A\u308B\u30B9\u30FC\u30D1\u30FC\u30AF\u30E9\u30B9\u3082\u3001hashCode\u30E1\u30BD\u30C3\u30C9\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3057\u307E\u305B\u3093 3.9 3.10 ## The following are all possible strings for the first argument ({0}) of the 3.11 ## above strings.
4.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties Wed Nov 19 11:29:47 2014 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties Thu Nov 20 11:27:57 2014 -0800 4.3 @@ -1534,7 +1534,7 @@ 4.4 compiler.warn.override.unchecked.thrown={0}\n\u88AB\u8986\u76D6\u7684\u65B9\u6CD5\u672A\u629B\u51FA{1} 4.5 4.6 # 0: symbol 4.7 -compiler.warn.override.equals.but.not.hashcode=\u7C7B{0}\u8986\u76D6\u4E86\u7B49\u53F7, \u4F46\u8BE5\u7C7B\u6216\u4EFB\u4F55\u8D85\u7C7B\u90FD\u672A\u8986\u76D6 hashCode \u65B9\u6CD5 4.8 +compiler.warn.override.equals.but.not.hashcode=\u7C7B{0}\u8986\u76D6\u4E86 equals, \u4F46\u8BE5\u7C7B\u6216\u4EFB\u4F55\u8D85\u7C7B\u90FD\u672A\u8986\u76D6 hashCode \u65B9\u6CD5 4.9 4.10 ## The following are all possible strings for the first argument ({0}) of the 4.11 ## above strings.
5.1 --- a/test/tools/javac/T8019486/WrongLNTForLambdaTest.java Wed Nov 19 11:29:47 2014 -0800 5.2 +++ b/test/tools/javac/T8019486/WrongLNTForLambdaTest.java Thu Nov 20 11:27:57 2014 -0800 5.3 @@ -138,7 +138,7 @@ 5.4 checkClassFile(new File(Paths.get(System.getProperty("user.dir"), 5.5 "Foo.class").toUri()), "$deserializeLambda$", deserializeExpectedLNT); 5.6 checkClassFile(new File(Paths.get(System.getProperty("user.dir"), 5.7 - "Foo.class").toUri()), "lambda$MR$variablesInLambdas$notify$8bc4f5bd$1", lambdaBridgeExpectedLNT); 5.8 + "Foo.class").toUri()), "lambda$variablesInLambdas$3", lambdaBridgeExpectedLNT); 5.9 checkClassFile(new File(Paths.get(System.getProperty("user.dir"), 5.10 "Foo.class").toUri()), "assignLambda", assignmentExpectedLNT); 5.11 checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/flow/T8062747.java Thu Nov 20 11:27:57 2014 -0800 6.3 @@ -0,0 +1,24 @@ 6.4 +/** 6.5 + * @test 6.6 + * @bug 8062747 6.7 + * @summary Avoiding an error for lambdas with thrown types inference inside an anonymous class. 6.8 + * @compile T8062747.java 6.9 + */ 6.10 +public class T8062747 { 6.11 + 6.12 + public interface Throwing<Y extends Exception> { 6.13 + void canThrow() throws Y; 6.14 + } 6.15 + 6.16 + public static <Y extends Exception> void wrap(Throwing<Y> action) { 6.17 + } 6.18 + 6.19 + public static void invoke(String a) { 6.20 + Runnable r = new Runnable() { 6.21 + @Override 6.22 + public void run() { 6.23 + wrap(() -> System.out.println(a)); 6.24 + } 6.25 + }; 6.26 + } 6.27 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerBootstrap.java Thu Nov 20 11:27:57 2014 -0800 7.3 @@ -0,0 +1,72 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +/** 7.28 + * @test 7.29 + * @bug 8044748 7.30 + * @summary JVM cannot access constructor though ::new reference although can call it directly 7.31 + */ 7.32 + 7.33 +public class MethodRefNewInnerBootstrap { 7.34 + 7.35 + interface Constructor { 7.36 + public MyTest execute(int i); 7.37 + } 7.38 + 7.39 + public class MyTest { 7.40 + public MyTest(int i) { System.out.println("Constructor executed " + i); } 7.41 + } 7.42 + 7.43 + public Constructor getConstructor() { 7.44 + return MyTest::new; 7.45 + } 7.46 + 7.47 + public static void main(String argv[]) { 7.48 + new MethodRefNewInnerBootstrap().call(); 7.49 + } 7.50 + 7.51 + public void call() { 7.52 + MyTest mt = new MyTest(0); 7.53 + 7.54 + Constructor c1 = MyTest::new; 7.55 + c1.execute(1); 7.56 + 7.57 + Constructor c2 = getConstructor(); 7.58 + c2.execute(2); 7.59 + 7.60 + Constructor c3 = new Constructor() { 7.61 + public MyTest execute(int i) { 7.62 + return new MyTest(3); 7.63 + } 7.64 + }; 7.65 + c3.execute(3); 7.66 + 7.67 + Constructor c4 = new Constructor() { 7.68 + public MyTest execute(int i) { 7.69 + Constructor c = MyTest::new; 7.70 + return c.execute(i); 7.71 + } 7.72 + }; 7.73 + c4.execute(4); 7.74 + } 7.75 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerInLambdaNPE1.java Thu Nov 20 11:27:57 2014 -0800 8.3 @@ -0,0 +1,48 @@ 8.4 +/* 8.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + */ 8.26 + 8.27 +/** 8.28 + * @test 8.29 + * @bug 8037404 8.30 + * @summary javac NPE or VerifyError for code with constructor reference of inner class 8.31 + */ 8.32 + 8.33 +import java.util.function.Supplier; 8.34 +import java.util.stream.Stream; 8.35 + 8.36 +public class MethodRefNewInnerInLambdaNPE1 { 8.37 + public static void main(String[] args) { 8.38 + if (new MethodRefNewInnerInLambdaNPE1().getList().get().getClass() != TT.class) 8.39 + throw new AssertionError("sanity failed"); 8.40 + } 8.41 + 8.42 + Supplier<TT> getList() { 8.43 + return () -> Stream.of(1).map(TT::new).findFirst().get(); 8.44 + } 8.45 + 8.46 + class TT { 8.47 + public TT(int i) { 8.48 + 8.49 + } 8.50 + } 8.51 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerInLambdaNPE2.java Thu Nov 20 11:27:57 2014 -0800 9.3 @@ -0,0 +1,57 @@ 9.4 +/* 9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/** 9.28 + * @test 9.29 + * @bug 8044737 9.30 + * @summary Lambda: NPE while obtaining method reference through lambda expression 9.31 + * @compile MethodRefNewInnerInLambdaNPE2.java 9.32 + */ 9.33 + 9.34 +public class MethodRefNewInnerInLambdaNPE2 { 9.35 + 9.36 + interface Constructor { 9.37 + MyTest execute(); 9.38 + } 9.39 + 9.40 + class MyTest { 9.41 + MyTest() { System.out.println("Constructor executed"); } 9.42 + } 9.43 + 9.44 + public Constructor getConstructor() { 9.45 + return getConstructor(() -> { return MyTest::new; }); 9.46 + } 9.47 + 9.48 + public static void main(String argv[]) { 9.49 + MethodRefNewInnerInLambdaNPE2 t = new MethodRefNewInnerInLambdaNPE2(); 9.50 + MyTest mytest = t.getConstructor().execute(); 9.51 + } 9.52 + 9.53 + Constructor getConstructor(Wrapper arg) { 9.54 + return arg.unwrap(); 9.55 + } 9.56 + 9.57 + interface Wrapper { 9.58 + Constructor unwrap(); 9.59 + } 9.60 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerInLambdaVerify1.java Thu Nov 20 11:27:57 2014 -0800 10.3 @@ -0,0 +1,48 @@ 10.4 +/* 10.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +/** 10.28 + * @test 10.29 + * @bug 8037404 10.30 + * @summary javac NPE or VerifyError for code with constructor reference of inner class 10.31 + */ 10.32 + 10.33 +import java.util.function.Function; 10.34 +import java.util.stream.Stream; 10.35 + 10.36 +public class MethodRefNewInnerInLambdaVerify1 { 10.37 + public static void main(String[] args) { 10.38 + if (new MethodRefNewInnerInLambdaVerify1().map().apply(1).getClass() != TT.class) 10.39 + throw new AssertionError("sanity failed"); 10.40 + } 10.41 + 10.42 + Function<Integer,TT> map() { 10.43 + return (i) -> Stream.of(i).map(TT::new).findFirst().get(); 10.44 + } 10.45 + 10.46 + class TT { 10.47 + public TT(int i) { 10.48 + 10.49 + } 10.50 + } 10.51 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerInLambdaVerify2.java Thu Nov 20 11:27:57 2014 -0800 11.3 @@ -0,0 +1,62 @@ 11.4 +/* 11.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/** 11.28 + * @test 11.29 + * @bug 8038776 11.30 + * @summary VerifyError when running successfully compiled java class 11.31 + */ 11.32 + 11.33 +import java.util.function.Function; 11.34 + 11.35 +/** 11.36 + * Derived from code by: 11.37 + * @author Yawkat 11.38 + */ 11.39 +public class MethodRefNewInnerInLambdaVerify2 { 11.40 + public static void main(String[] args) { new MethodRefNewInnerInLambdaVerify2().runTest(); } 11.41 + 11.42 + private void runTest() { 11.43 + Worker worker = new Worker(); 11.44 + run(() -> worker.check(field -> new SomeClass(field))); 11.45 + run(() -> worker.check(SomeClass::new)); 11.46 + } 11.47 + 11.48 + private void run(Runnable runnable) { 11.49 + runnable.run(); 11.50 + } 11.51 + 11.52 + private class SomeClass { 11.53 + final Object field; 11.54 + 11.55 + SomeClass(Object field) { 11.56 + this.field = field; 11.57 + } 11.58 + } 11.59 + 11.60 + private static class Worker { 11.61 + void check(Function<Object, SomeClass> i) { 11.62 + if (!i.apply("frank").field.equals("frank")) throw new AssertionError("sanity failed"); 11.63 + } 11.64 + } 11.65 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefNewInnerInLambdaVerify2simple.java Thu Nov 20 11:27:57 2014 -0800 12.3 @@ -0,0 +1,50 @@ 12.4 +/* 12.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/** 12.28 + * @test 12.29 + * @bug 8038776 12.30 + * @summary VerifyError when running successfully compiled java class 12.31 + */ 12.32 + 12.33 +import java.util.function.Function; 12.34 + 12.35 +/** 12.36 + * Derived from code by: 12.37 + * @author Yawkat 12.38 + */ 12.39 +public class MethodRefNewInnerInLambdaVerify2simple { 12.40 + public static void main(String[] args) { new MethodRefNewInnerInLambdaVerify2simple().runTest(); } 12.41 + 12.42 + private void runTest() { 12.43 + Runnable r = (() -> { Sup w = SomeClass::new; } ); 12.44 + } 12.45 + 12.46 + private class SomeClass { 12.47 + SomeClass() { } 12.48 + } 12.49 +} 12.50 + 12.51 +interface Sup { 12.52 + Object get(); 12.53 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefQualifier1.java Thu Nov 20 11:27:57 2014 -0800 13.3 @@ -0,0 +1,62 @@ 13.4 +/* 13.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/** 13.28 + * @test 13.29 + * @bug 8048121 13.30 + * @summary javac complex method references: revamp and simplify 13.31 + */ 13.32 + 13.33 +public class MethodRefQualifier1 { 13.34 + 13.35 + interface SAM { 13.36 + void m(); 13.37 + } 13.38 + 13.39 + static int count = 0; 13.40 + 13.41 + static void assertTrue(boolean cond, String msg) { 13.42 + if (!cond) 13.43 + throw new AssertionError(msg); 13.44 + } 13.45 + 13.46 + MethodRefQualifier1 check() { 13.47 + count++; 13.48 + return this; 13.49 + } 13.50 + 13.51 + void ido(Object... args) { } 13.52 + 13.53 + public static void main(String[] args) { 13.54 + new MethodRefQualifier1().test(); 13.55 + } 13.56 + 13.57 + void test() { 13.58 + count = 0; 13.59 + SAM s = check()::ido; 13.60 + assertTrue(count == 1, "creation: unexpected: " + count); 13.61 + count = 0; 13.62 + s.m(); 13.63 + assertTrue(count == 0, "evaluation: unexpected: " + count); 13.64 + } 13.65 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefSingleRefEvalBridge.java Thu Nov 20 11:27:57 2014 -0800 14.3 @@ -0,0 +1,70 @@ 14.4 +/* 14.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/** 14.28 + * @test 14.29 + * @bug 8048121 14.30 + * @summary javac complex method references: revamp and simplify 14.31 + * 14.32 + * Make sure that the method reference receiver is evaluated exactly once 14.33 + * even in this bridging case. 14.34 + */ 14.35 + 14.36 + public class MethodRefSingleRefEvalBridge { 14.37 + 14.38 + interface SAM { 14.39 + int m(); 14.40 + } 14.41 + 14.42 + class ZZ { 14.43 + // private to force bridging 14.44 + private int four() { return 4; } 14.45 + } 14.46 + 14.47 + static int count = 0; 14.48 + ZZ azz = new ZZ(); 14.49 + 14.50 + static void assertEqual(int expected, int got) { 14.51 + if (got != expected) 14.52 + throw new AssertionError("Expected " + expected + " got " + got); 14.53 + } 14.54 + 14.55 + public static void main(String[] args) { 14.56 + new MethodRefSingleRefEvalBridge().test(); 14.57 + } 14.58 + 14.59 + ZZ check() { 14.60 + count++; 14.61 + return azz; 14.62 + } 14.63 + 14.64 + void test() { 14.65 + count = 0; 14.66 + SAM s = check()::four; 14.67 + assertEqual(1, count); 14.68 + 14.69 + count = 0; 14.70 + assertEqual(4, s.m()); 14.71 + assertEqual(0, count); 14.72 + } 14.73 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/lambda/methodReference/MethodRefToInner.java Thu Nov 20 11:27:57 2014 -0800 15.3 @@ -0,0 +1,52 @@ 15.4 +/* 15.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/** 15.28 + * @test 15.29 + * @bug 8047341 15.30 + * @summary lambda reference to inner class in base class causes LambdaConversionException 15.31 + */ 15.32 + 15.33 +import java.util.List; 15.34 +import java.util.ArrayList; 15.35 + 15.36 +class MethodRefToInnerBase { 15.37 + class TestString { 15.38 + String str; 15.39 + TestString(String strin) { 15.40 + str = strin; 15.41 + } 15.42 + } 15.43 +} 15.44 +public class MethodRefToInner extends MethodRefToInnerBase { 15.45 + public static void main(String[] args) { 15.46 + new MethodRefToInner().run(); 15.47 + } 15.48 + MethodRefToInner() { 15.49 + super(); 15.50 + } 15.51 + void run() { 15.52 + List<String> list = new ArrayList<>(); 15.53 + list.stream().forEach(TestString::new); 15.54 + } 15.55 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/lambda/methodReference/MethodReferenceComplexNullCheckTest.java Thu Nov 20 11:27:57 2014 -0800 16.3 @@ -0,0 +1,54 @@ 16.4 +/* 16.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. Oracle designates this 16.11 + * particular file as subject to the "Classpath" exception as provided 16.12 + * by Oracle in the LICENSE file that accompanied this code. 16.13 + * 16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.17 + * version 2 for more details (a copy is included in the LICENSE file that 16.18 + * accompanied this code). 16.19 + * 16.20 + * You should have received a copy of the GNU General Public License version 16.21 + * 2 along with this work; if not, write to the Free Software Foundation, 16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.23 + * 16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.25 + * or visit www.oracle.com if you need additional information or have any 16.26 + * questions. 16.27 + */ 16.28 + 16.29 +/** 16.30 + * @test 16.31 + * @bug 8048121 16.32 + * @summary javac complex method references: revamp and simplify 16.33 + * 16.34 + * Make sure NPE check is done even in the convert to Lambda case 16.35 + */ 16.36 + 16.37 +public class MethodReferenceComplexNullCheckTest { 16.38 + public static void main(String[] args) { 16.39 + F fr = null; 16.40 + boolean npeFired = false; 16.41 + try { 16.42 + IForm frf = fr::doit; 16.43 + } catch (NullPointerException npe) { 16.44 + npeFired = true; 16.45 + } finally { 16.46 + if (!npeFired) throw new AssertionError( "NPE should have been thrown"); 16.47 + } 16.48 + } 16.49 + 16.50 + interface IForm { 16.51 + void xyz(Object... args); 16.52 + } 16.53 + 16.54 + class F { 16.55 + private void doit(Object... args) { } 16.56 + } 16.57 +}