Tue, 16 Apr 2013 08:16:07 -0700
Merge
src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/diags/examples/SecondaryBoundMustBeMarkerIntf.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/Intersection01.out | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/TargetType01.out | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java Thu Apr 11 09:40:22 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Tue Apr 16 08:16:07 2013 -0700 1.3 @@ -122,12 +122,15 @@ 1.4 private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well 1.5 private HtmlTag currHeaderTag; 1.6 1.7 + private final int implicitHeaderLevel; 1.8 + 1.9 // <editor-fold defaultstate="collapsed" desc="Top level"> 1.10 1.11 Checker(Env env) { 1.12 env.getClass(); 1.13 this.env = env; 1.14 tagStack = new LinkedList<TagStackItem>(); 1.15 + implicitHeaderLevel = env.implicitHeaderLevel; 1.16 } 1.17 1.18 public Void scan(DocCommentTree tree, TreePath p) { 1.19 @@ -386,7 +389,7 @@ 1.20 1.21 private int getHeaderLevel(HtmlTag tag) { 1.22 if (tag == null) 1.23 - return 0; 1.24 + return implicitHeaderLevel; 1.25 switch (tag) { 1.26 case H1: return 1; 1.27 case H2: return 2;
2.1 --- a/src/share/classes/com/sun/tools/doclint/DocLint.java Thu Apr 11 09:40:22 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java Tue Apr 16 08:16:07 2013 -0700 2.3 @@ -30,6 +30,7 @@ 2.4 import java.io.PrintWriter; 2.5 import java.util.ArrayList; 2.6 import java.util.List; 2.7 +import java.util.regex.Pattern; 2.8 2.9 import javax.lang.model.element.Name; 2.10 import javax.tools.StandardLocation; 2.11 @@ -72,6 +73,7 @@ 2.12 public static final String XMSGS_OPTION = "-Xmsgs"; 2.13 public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:"; 2.14 private static final String STATS = "-stats"; 2.15 + public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; 2.16 2.17 // <editor-fold defaultstate="collapsed" desc="Command-line entry point"> 2.18 public static void main(String... args) { 2.19 @@ -289,6 +291,9 @@ 2.20 env.messages.setOptions(null); 2.21 } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { 2.22 env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); 2.23 + } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) { 2.24 + char ch = arg.charAt(arg.length() - 1); 2.25 + env.setImplicitHeaders(Character.digit(ch, 10)); 2.26 } else 2.27 throw new IllegalArgumentException(arg); 2.28 }
3.1 --- a/src/share/classes/com/sun/tools/doclint/Env.java Thu Apr 11 09:40:22 2013 -0700 3.2 +++ b/src/share/classes/com/sun/tools/doclint/Env.java Tue Apr 16 08:16:07 2013 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -83,6 +83,8 @@ 3.11 /** Message handler. */ 3.12 final Messages messages; 3.13 3.14 + int implicitHeaderLevel = 0; 3.15 + 3.16 // Utility classes 3.17 DocTrees trees; 3.18 Elements elements; 3.19 @@ -102,7 +104,7 @@ 3.20 DocCommentTree currDocComment; 3.21 /** 3.22 * The access kind of the declaration containing the comment currently being analyzed. 3.23 - * This is the minimum (most restrictive) access kind of the declaration iteself 3.24 + * This is the minimum (most restrictive) access kind of the declaration itself 3.25 * and that of its containers. For example, a public method in a private class is 3.26 * noted as private. 3.27 */ 3.28 @@ -128,6 +130,10 @@ 3.29 java_lang_Void = elements.getTypeElement("java.lang.Void").asType(); 3.30 } 3.31 3.32 + void setImplicitHeaders(int n) { 3.33 + implicitHeaderLevel = n; 3.34 + } 3.35 + 3.36 /** Set the current declaration and its doc comment. */ 3.37 void setCurrent(TreePath path, DocCommentTree comment) { 3.38 currPath = path;
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Thu Apr 11 09:40:22 2013 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Tue Apr 16 08:16:07 2013 -0700 4.3 @@ -314,6 +314,7 @@ 4.4 modifiers.add(Modifier.SYNCHRONIZED); 4.5 if (0 != (flags & NATIVE)) modifiers.add(Modifier.NATIVE); 4.6 if (0 != (flags & STRICTFP)) modifiers.add(Modifier.STRICTFP); 4.7 + if (0 != (flags & DEFAULT)) modifiers.add(Modifier.DEFAULT); 4.8 modifiers = Collections.unmodifiableSet(modifiers); 4.9 modifierSets.put(flags, modifiers); 4.10 }
5.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Thu Apr 11 09:40:22 2013 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Tue Apr 16 08:16:07 2013 -0700 5.3 @@ -908,6 +908,12 @@ 5.4 return interfaces_field.prepend(supertype_field); 5.5 } 5.6 5.7 + public List<Type> getExplicitComponents() { 5.8 + return allInterfaces ? 5.9 + interfaces_field : 5.10 + getComponents(); 5.11 + } 5.12 + 5.13 @Override 5.14 public TypeKind getKind() { 5.15 return TypeKind.INTERSECTION;
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Apr 11 09:40:22 2013 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Apr 16 08:16:07 2013 -0700 6.3 @@ -610,7 +610,7 @@ 6.4 6.5 /** 6.6 * Scope filter used to skip methods that should be ignored (such as methods 6.7 - * overridden by j.l.Object) during function interface conversion/marker interface checks 6.8 + * overridden by j.l.Object) during function interface conversion interface check 6.9 */ 6.10 class DescriptorFilter implements Filter<Symbol> { 6.11 6.12 @@ -629,64 +629,6 @@ 6.13 } 6.14 }; 6.15 6.16 - // <editor-fold defaultstate="collapsed" desc="isMarker"> 6.17 - 6.18 - /** 6.19 - * A cache that keeps track of marker interfaces 6.20 - */ 6.21 - class MarkerCache { 6.22 - 6.23 - private WeakHashMap<TypeSymbol, Entry> _map = new WeakHashMap<TypeSymbol, Entry>(); 6.24 - 6.25 - class Entry { 6.26 - final boolean isMarkerIntf; 6.27 - final int prevMark; 6.28 - 6.29 - public Entry(boolean isMarkerIntf, 6.30 - int prevMark) { 6.31 - this.isMarkerIntf = isMarkerIntf; 6.32 - this.prevMark = prevMark; 6.33 - } 6.34 - 6.35 - boolean matches(int mark) { 6.36 - return this.prevMark == mark; 6.37 - } 6.38 - } 6.39 - 6.40 - boolean get(TypeSymbol origin) throws FunctionDescriptorLookupError { 6.41 - Entry e = _map.get(origin); 6.42 - CompoundScope members = membersClosure(origin.type, false); 6.43 - if (e == null || 6.44 - !e.matches(members.getMark())) { 6.45 - boolean isMarkerIntf = isMarkerInterfaceInternal(origin, members); 6.46 - _map.put(origin, new Entry(isMarkerIntf, members.getMark())); 6.47 - return isMarkerIntf; 6.48 - } 6.49 - else { 6.50 - return e.isMarkerIntf; 6.51 - } 6.52 - } 6.53 - 6.54 - /** 6.55 - * Is given symbol a marker interface 6.56 - */ 6.57 - public boolean isMarkerInterfaceInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError { 6.58 - return !origin.isInterface() ? 6.59 - false : 6.60 - !membersCache.getElements(new DescriptorFilter(origin)).iterator().hasNext(); 6.61 - } 6.62 - } 6.63 - 6.64 - private MarkerCache markerCache = new MarkerCache(); 6.65 - 6.66 - /** 6.67 - * Is given type a marker interface? 6.68 - */ 6.69 - public boolean isMarkerInterface(Type site) { 6.70 - return markerCache.get(site.tsym); 6.71 - } 6.72 - // </editor-fold> 6.73 - 6.74 // <editor-fold defaultstate="collapsed" desc="isSubtype"> 6.75 /** 6.76 * Is t an unchecked subtype of s? 6.77 @@ -2625,15 +2567,15 @@ 6.78 public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { 6.79 Filter<Symbol> filter = new MethodFilter(ms, site); 6.80 List<MethodSymbol> candidates = List.nil(); 6.81 - for (Symbol s : membersClosure(site, false).getElements(filter)) { 6.82 - if (!site.tsym.isInterface() && !s.owner.isInterface()) { 6.83 - return List.of((MethodSymbol)s); 6.84 - } else if (!candidates.contains(s)) { 6.85 - candidates = candidates.prepend((MethodSymbol)s); 6.86 + for (Symbol s : membersClosure(site, false).getElements(filter)) { 6.87 + if (!site.tsym.isInterface() && !s.owner.isInterface()) { 6.88 + return List.of((MethodSymbol)s); 6.89 + } else if (!candidates.contains(s)) { 6.90 + candidates = candidates.prepend((MethodSymbol)s); 6.91 + } 6.92 } 6.93 + return prune(candidates); 6.94 } 6.95 - return prune(candidates); 6.96 - } 6.97 6.98 public List<MethodSymbol> prune(List<MethodSymbol> methods) { 6.99 ListBuffer<MethodSymbol> methodsMin = ListBuffer.lb();
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 11 09:40:22 2013 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Apr 16 08:16:07 2013 -0700 7.3 @@ -2273,7 +2273,7 @@ 7.4 7.5 Type lambdaType; 7.6 if (pt() != Type.recoveryType) { 7.7 - target = checkIntersectionTarget(that, target, resultInfo.checkContext); 7.8 + target = targetChecker.visit(target, that); 7.9 lambdaType = types.findDescriptorType(target); 7.10 chk.checkFunctionalInterface(that, target); 7.11 } else { 7.12 @@ -2281,7 +2281,7 @@ 7.13 lambdaType = fallbackDescriptorType(that); 7.14 } 7.15 7.16 - setFunctionalInfo(that, pt(), lambdaType, resultInfo.checkContext.inferenceContext()); 7.17 + setFunctionalInfo(that, pt(), lambdaType, target, resultInfo.checkContext.inferenceContext()); 7.18 7.19 if (lambdaType.hasTag(FORALL)) { 7.20 //lambda expression target desc cannot be a generic method 7.21 @@ -2340,11 +2340,34 @@ 7.22 new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); 7.23 localEnv.info.returnResult = bodyResultInfo; 7.24 7.25 - if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { 7.26 - attribTree(that.getBody(), localEnv, bodyResultInfo); 7.27 - } else { 7.28 - JCBlock body = (JCBlock)that.body; 7.29 - attribStats(body.stats, localEnv); 7.30 + Log.DeferredDiagnosticHandler lambdaDeferredHandler = new Log.DeferredDiagnosticHandler(log); 7.31 + try { 7.32 + if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { 7.33 + attribTree(that.getBody(), localEnv, bodyResultInfo); 7.34 + } else { 7.35 + JCBlock body = (JCBlock)that.body; 7.36 + attribStats(body.stats, localEnv); 7.37 + } 7.38 + 7.39 + if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) { 7.40 + //check for errors in lambda body 7.41 + for (JCDiagnostic deferredDiag : lambdaDeferredHandler.getDiagnostics()) { 7.42 + if (deferredDiag.getKind() == JCDiagnostic.Kind.ERROR) { 7.43 + resultInfo.checkContext 7.44 + .report(that, diags.fragment("bad.arg.types.in.lambda", TreeInfo.types(that.params))); 7.45 + //we mark the lambda as erroneous - this is crucial in the recovery step 7.46 + //as parameter-dependent type error won't be reported in that stage, 7.47 + //meaning that a lambda will be deemed erroeneous only if there is 7.48 + //a target-independent error (which will cause method diagnostic 7.49 + //to be skipped). 7.50 + result = that.type = types.createErrorType(target); 7.51 + return; 7.52 + } 7.53 + } 7.54 + } 7.55 + } finally { 7.56 + lambdaDeferredHandler.reportDeferredDiagnostics(); 7.57 + log.popDiagnosticHandler(lambdaDeferredHandler); 7.58 } 7.59 7.60 result = check(that, target, VAL, resultInfo); 7.61 @@ -2373,26 +2396,55 @@ 7.62 } 7.63 } 7.64 } 7.65 - 7.66 - private Type checkIntersectionTarget(DiagnosticPosition pos, Type pt, CheckContext checkContext) { 7.67 - if (pt != Type.recoveryType && pt.isCompound()) { 7.68 - IntersectionClassType ict = (IntersectionClassType)pt; 7.69 - List<Type> bounds = ict.allInterfaces ? 7.70 - ict.getComponents().tail : 7.71 - ict.getComponents(); 7.72 - types.findDescriptorType(bounds.head); //propagate exception outwards! 7.73 - for (Type bound : bounds.tail) { 7.74 - if (!types.isMarkerInterface(bound)) { 7.75 - checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); 7.76 + //where 7.77 + Types.MapVisitor<DiagnosticPosition> targetChecker = new Types.MapVisitor<DiagnosticPosition>() { 7.78 + 7.79 + @Override 7.80 + public Type visitClassType(ClassType t, DiagnosticPosition pos) { 7.81 + return t.isCompound() ? 7.82 + visitIntersectionClassType((IntersectionClassType)t, pos) : t; 7.83 + } 7.84 + 7.85 + public Type visitIntersectionClassType(IntersectionClassType ict, DiagnosticPosition pos) { 7.86 + Symbol desc = types.findDescriptorSymbol(makeNotionalInterface(ict)); 7.87 + Type target = null; 7.88 + for (Type bound : ict.getExplicitComponents()) { 7.89 + TypeSymbol boundSym = bound.tsym; 7.90 + if (types.isFunctionalInterface(boundSym) && 7.91 + types.findDescriptorSymbol(boundSym) == desc) { 7.92 + target = bound; 7.93 + } else if (!boundSym.isInterface() || (boundSym.flags() & ANNOTATION) != 0) { 7.94 + //bound must be an interface 7.95 + reportIntersectionError(pos, "not.an.intf.component", boundSym); 7.96 + } 7.97 } 7.98 + return target != null ? 7.99 + target : 7.100 + ict.getExplicitComponents().head; //error recovery 7.101 } 7.102 - //for now (translation doesn't support intersection types) 7.103 - return bounds.head; 7.104 - } else { 7.105 - return pt; 7.106 - } 7.107 - } 7.108 - //where 7.109 + 7.110 + private TypeSymbol makeNotionalInterface(IntersectionClassType ict) { 7.111 + ListBuffer<Type> targs = ListBuffer.lb(); 7.112 + ListBuffer<Type> supertypes = ListBuffer.lb(); 7.113 + for (Type i : ict.interfaces_field) { 7.114 + if (i.isParameterized()) { 7.115 + targs.appendList(i.tsym.type.allparams()); 7.116 + } 7.117 + supertypes.append(i.tsym.type); 7.118 + } 7.119 + IntersectionClassType notionalIntf = 7.120 + (IntersectionClassType)types.makeCompoundType(supertypes.toList()); 7.121 + notionalIntf.allparams_field = targs.toList(); 7.122 + notionalIntf.tsym.flags_field |= INTERFACE; 7.123 + return notionalIntf.tsym; 7.124 + } 7.125 + 7.126 + private void reportIntersectionError(DiagnosticPosition pos, String key, Object... args) { 7.127 + resultInfo.checkContext.report(pos, diags.fragment("bad.intersection.target.for.functional.expr", 7.128 + diags.fragment(key, args))); 7.129 + } 7.130 + }; 7.131 + 7.132 private Type fallbackDescriptorType(JCExpression tree) { 7.133 switch (tree.getTag()) { 7.134 case LAMBDA: 7.135 @@ -2563,7 +2615,7 @@ 7.136 Type target; 7.137 Type desc; 7.138 if (pt() != Type.recoveryType) { 7.139 - target = checkIntersectionTarget(that, pt(), resultInfo.checkContext); 7.140 + target = targetChecker.visit(pt(), that); 7.141 desc = types.findDescriptorType(target); 7.142 chk.checkFunctionalInterface(that, target); 7.143 } else { 7.144 @@ -2571,11 +2623,12 @@ 7.145 desc = fallbackDescriptorType(that); 7.146 } 7.147 7.148 - setFunctionalInfo(that, pt(), desc, resultInfo.checkContext.inferenceContext()); 7.149 + setFunctionalInfo(that, pt(), desc, target, resultInfo.checkContext.inferenceContext()); 7.150 List<Type> argtypes = desc.getParameterTypes(); 7.151 7.152 - Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, 7.153 - that.expr.type, that.name, argtypes, typeargtypes, true); 7.154 + Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = 7.155 + rs.resolveMemberReference(that.pos(), localEnv, that, 7.156 + that.expr.type, that.name, argtypes, typeargtypes, true, rs.resolveMethodCheck); 7.157 7.158 Symbol refSym = refResult.fst; 7.159 Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; 7.160 @@ -2765,19 +2818,24 @@ 7.161 * might contain inference variables, we might need to register an hook in the 7.162 * current inference context. 7.163 */ 7.164 - private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt, final Type descriptorType, InferenceContext inferenceContext) { 7.165 + private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt, 7.166 + final Type descriptorType, final Type primaryTarget, InferenceContext inferenceContext) { 7.167 if (inferenceContext.free(descriptorType)) { 7.168 inferenceContext.addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() { 7.169 public void typesInferred(InferenceContext inferenceContext) { 7.170 - setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType), inferenceContext); 7.171 + setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType), 7.172 + inferenceContext.asInstType(primaryTarget), inferenceContext); 7.173 } 7.174 }); 7.175 } else { 7.176 ListBuffer<TypeSymbol> targets = ListBuffer.lb(); 7.177 if (pt.hasTag(CLASS)) { 7.178 if (pt.isCompound()) { 7.179 + targets.append(primaryTarget.tsym); //this goes first 7.180 for (Type t : ((IntersectionClassType)pt()).interfaces_field) { 7.181 - targets.append(t.tsym); 7.182 + if (t != primaryTarget) { 7.183 + targets.append(t.tsym); 7.184 + } 7.185 } 7.186 } else { 7.187 targets.append(pt.tsym);
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Apr 11 09:40:22 2013 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Tue Apr 16 08:16:07 2013 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -28,6 +28,7 @@ 8.11 import com.sun.tools.javac.code.*; 8.12 import com.sun.tools.javac.tree.*; 8.13 import com.sun.tools.javac.util.*; 8.14 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 8.15 import com.sun.tools.javac.code.Symbol.*; 8.16 import com.sun.tools.javac.code.Type.*; 8.17 import com.sun.tools.javac.comp.Attr.ResultInfo; 8.18 @@ -531,12 +532,13 @@ 8.19 attr.memberReferenceQualifierResult(tree)); 8.20 ListBuffer<Type> argtypes = ListBuffer.lb(); 8.21 for (Type t : types.findDescriptorType(pt).getParameterTypes()) { 8.22 - argtypes.append(syms.errType); 8.23 + argtypes.append(Type.noType); 8.24 } 8.25 JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); 8.26 mref2.expr = exprTree; 8.27 Pair<Symbol, ?> lookupRes = 8.28 - rs.resolveMemberReference(tree, env, mref2, exprTree.type, tree.name, argtypes.toList(), null, true); 8.29 + rs.resolveMemberReference(tree, env, mref2, exprTree.type, 8.30 + tree.name, argtypes.toList(), null, true, rs.arityMethodCheck); 8.31 switch (lookupRes.fst.kind) { 8.32 //note: as argtypes are erroneous types, type-errors must 8.33 //have been caused by arity mismatch
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Apr 11 09:40:22 2013 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Apr 16 08:16:07 2013 -0700 9.3 @@ -143,7 +143,6 @@ 9.4 boolean allowBoxing, 9.5 boolean useVarargs, 9.6 Resolve.MethodResolutionContext resolveContext, 9.7 - Resolve.MethodCheck methodCheck, 9.8 Warner warn) throws InferenceException { 9.9 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG 9.10 final InferenceContext inferenceContext = new InferenceContext(tvars); 9.11 @@ -152,7 +151,7 @@ 9.12 DeferredAttr.DeferredAttrContext deferredAttrContext = 9.13 resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); 9.14 9.15 - methodCheck.argumentsAcceptable(env, deferredAttrContext, 9.16 + resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, 9.17 argtypes, mt.getParameterTypes(), warn); 9.18 9.19 if (allowGraphInference &&
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Thu Apr 11 09:40:22 2013 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Apr 16 08:16:07 2013 -0700 10.3 @@ -384,18 +384,6 @@ 10.4 Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym); 10.5 result = make.Ident(translatedSym).setType(tree.type); 10.6 } else { 10.7 - if (tree.sym.owner.kind == Kinds.TYP) { 10.8 - for (Map.Entry<Symbol, Symbol> encl_entry : lambdaContext.getSymbolMap(CAPTURED_THIS).entrySet()) { 10.9 - if (tree.sym.isMemberOf((ClassSymbol) encl_entry.getKey(), types)) { 10.10 - JCExpression enclRef = make.Ident(encl_entry.getValue()); 10.11 - result = tree.sym.name == names._this 10.12 - ? enclRef.setType(tree.type) 10.13 - : make.Select(enclRef, tree.sym).setType(tree.type); 10.14 - result = tree; 10.15 - return; 10.16 - } 10.17 - } 10.18 - } 10.19 //access to untranslated symbols (i.e. compile-time constants, 10.20 //members defined inside the lambda body, etc.) ) 10.21 super.visitIdent(tree); 10.22 @@ -1315,6 +1303,7 @@ 10.23 // the generated lambda method will not have type yet, but the 10.24 // enclosing method's name will have been generated with this same 10.25 // method, so it will be unique and never be overloaded. 10.26 + Assert.check(owner.type != null || directlyEnclosingLambda() != null); 10.27 if (owner.type != null) { 10.28 int methTypeHash = methodSig(owner.type).hashCode(); 10.29 buf.append(Integer.toHexString(methTypeHash));
11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Apr 11 09:40:22 2013 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Apr 16 08:16:07 2013 -0700 11.3 @@ -508,7 +508,6 @@ 11.4 List<Type> typeargtypes, 11.5 boolean allowBoxing, 11.6 boolean useVarargs, 11.7 - MethodCheck methodCheck, 11.8 Warner warn) throws Infer.InferenceException { 11.9 11.10 Type mt = types.memberType(site, m); 11.11 @@ -561,10 +560,9 @@ 11.12 allowBoxing, 11.13 useVarargs, 11.14 currentResolutionContext, 11.15 - methodCheck, 11.16 warn); 11.17 11.18 - methodCheck.argumentsAcceptable(env, currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn), 11.19 + currentResolutionContext.methodCheck.argumentsAcceptable(env, currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn), 11.20 argtypes, mt.getParameterTypes(), warn); 11.21 return mt; 11.22 } 11.23 @@ -582,7 +580,7 @@ 11.24 currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK; 11.25 MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase; 11.26 return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, 11.27 - step.isBoxingRequired(), step.isVarargsRequired(), resolveMethodCheck, warn); 11.28 + step.isBoxingRequired(), step.isVarargsRequired(), warn); 11.29 } 11.30 finally { 11.31 currentResolutionContext = prevContext; 11.32 @@ -599,11 +597,10 @@ 11.33 List<Type> typeargtypes, 11.34 boolean allowBoxing, 11.35 boolean useVarargs, 11.36 - MethodCheck methodCheck, 11.37 Warner warn) { 11.38 try { 11.39 return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, 11.40 - allowBoxing, useVarargs, methodCheck, warn); 11.41 + allowBoxing, useVarargs, warn); 11.42 } catch (InapplicableMethodException ex) { 11.43 return null; 11.44 } 11.45 @@ -628,6 +625,12 @@ 11.46 List<Type> argtypes, 11.47 List<Type> formals, 11.48 Warner warn); 11.49 + 11.50 + /** 11.51 + * Retrieve the method check object that will be used during a 11.52 + * most specific check. 11.53 + */ 11.54 + MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict); 11.55 } 11.56 11.57 /** 11.58 @@ -661,6 +664,100 @@ 11.59 } 11.60 11.61 /** 11.62 + * Dummy method check object. All methods are deemed applicable, regardless 11.63 + * of their formal parameter types. 11.64 + */ 11.65 + MethodCheck nilMethodCheck = new MethodCheck() { 11.66 + public void argumentsAcceptable(Env<AttrContext> env, DeferredAttrContext deferredAttrContext, List<Type> argtypes, List<Type> formals, Warner warn) { 11.67 + //do nothing - method always applicable regardless of actuals 11.68 + } 11.69 + 11.70 + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 11.71 + return this; 11.72 + } 11.73 + }; 11.74 + 11.75 + /** 11.76 + * Base class for 'real' method checks. The class defines the logic for 11.77 + * iterating through formals and actuals and provides and entry point 11.78 + * that can be used by subclasses in order to define the actual check logic. 11.79 + */ 11.80 + abstract class AbstractMethodCheck implements MethodCheck { 11.81 + @Override 11.82 + public void argumentsAcceptable(final Env<AttrContext> env, 11.83 + DeferredAttrContext deferredAttrContext, 11.84 + List<Type> argtypes, 11.85 + List<Type> formals, 11.86 + Warner warn) { 11.87 + //should we expand formals? 11.88 + boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); 11.89 + 11.90 + //inference context used during this method check 11.91 + InferenceContext inferenceContext = deferredAttrContext.inferenceContext; 11.92 + 11.93 + Type varargsFormal = useVarargs ? formals.last() : null; 11.94 + 11.95 + if (varargsFormal == null && 11.96 + argtypes.size() != formals.size()) { 11.97 + reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 11.98 + } 11.99 + 11.100 + while (argtypes.nonEmpty() && formals.head != varargsFormal) { 11.101 + checkArg(false, argtypes.head, formals.head, deferredAttrContext, warn); 11.102 + argtypes = argtypes.tail; 11.103 + formals = formals.tail; 11.104 + } 11.105 + 11.106 + if (formals.head != varargsFormal) { 11.107 + reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 11.108 + } 11.109 + 11.110 + if (useVarargs) { 11.111 + //note: if applicability check is triggered by most specific test, 11.112 + //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 11.113 + final Type elt = types.elemtype(varargsFormal); 11.114 + while (argtypes.nonEmpty()) { 11.115 + checkArg(true, argtypes.head, elt, deferredAttrContext, warn); 11.116 + argtypes = argtypes.tail; 11.117 + } 11.118 + } 11.119 + } 11.120 + 11.121 + /** 11.122 + * Does the actual argument conforms to the corresponding formal? 11.123 + */ 11.124 + abstract void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); 11.125 + 11.126 + protected void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { 11.127 + boolean inferDiag = inferenceContext != infer.emptyContext; 11.128 + InapplicableMethodException ex = inferDiag ? 11.129 + infer.inferenceException : inapplicableMethodException; 11.130 + if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { 11.131 + Object[] args2 = new Object[args.length + 1]; 11.132 + System.arraycopy(args, 0, args2, 1, args.length); 11.133 + args2[0] = inferenceContext.inferenceVars(); 11.134 + args = args2; 11.135 + } 11.136 + throw ex.setMessage(inferDiag ? diag.inferKey : diag.basicKey, args); 11.137 + } 11.138 + 11.139 + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 11.140 + return nilMethodCheck; 11.141 + } 11.142 + } 11.143 + 11.144 + /** 11.145 + * Arity-based method check. A method is applicable if the number of actuals 11.146 + * supplied conforms to the method signature. 11.147 + */ 11.148 + MethodCheck arityMethodCheck = new AbstractMethodCheck() { 11.149 + @Override 11.150 + void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 11.151 + //do nothing - actual always compatible to formals 11.152 + } 11.153 + }; 11.154 + 11.155 + /** 11.156 * Main method applicability routine. Given a list of actual types A, 11.157 * a list of formal types F, determines whether the types in A are 11.158 * compatible (by method invocation conversion) with the types in F. 11.159 @@ -678,62 +775,27 @@ 11.160 * 11.161 * A method check handler (see above) is used in order to report errors. 11.162 */ 11.163 - MethodCheck resolveMethodCheck = new MethodCheck() { 11.164 + MethodCheck resolveMethodCheck = new AbstractMethodCheck() { 11.165 + 11.166 + @Override 11.167 + void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { 11.168 + ResultInfo mresult = methodCheckResult(varargs, formal, deferredAttrContext, warn); 11.169 + mresult.check(null, actual); 11.170 + } 11.171 + 11.172 @Override 11.173 public void argumentsAcceptable(final Env<AttrContext> env, 11.174 DeferredAttrContext deferredAttrContext, 11.175 List<Type> argtypes, 11.176 List<Type> formals, 11.177 Warner warn) { 11.178 + super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); 11.179 //should we expand formals? 11.180 - boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); 11.181 - 11.182 - //inference context used during this method check 11.183 - InferenceContext inferenceContext = deferredAttrContext.inferenceContext; 11.184 - 11.185 - Type varargsFormal = useVarargs ? formals.last() : null; 11.186 - 11.187 - if (varargsFormal == null && 11.188 - argtypes.size() != formals.size()) { 11.189 - reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 11.190 + if (deferredAttrContext.phase.isVarargsRequired()) { 11.191 + //check varargs element type accessibility 11.192 + varargsAccessible(env, types.elemtype(formals.last()), 11.193 + deferredAttrContext.inferenceContext); 11.194 } 11.195 - 11.196 - while (argtypes.nonEmpty() && formals.head != varargsFormal) { 11.197 - ResultInfo mresult = methodCheckResult(false, formals.head, deferredAttrContext, warn); 11.198 - mresult.check(null, argtypes.head); 11.199 - argtypes = argtypes.tail; 11.200 - formals = formals.tail; 11.201 - } 11.202 - 11.203 - if (formals.head != varargsFormal) { 11.204 - reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 11.205 - } 11.206 - 11.207 - if (useVarargs) { 11.208 - //note: if applicability check is triggered by most specific test, 11.209 - //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 11.210 - final Type elt = types.elemtype(varargsFormal); 11.211 - ResultInfo mresult = methodCheckResult(true, elt, deferredAttrContext, warn); 11.212 - while (argtypes.nonEmpty()) { 11.213 - mresult.check(null, argtypes.head); 11.214 - argtypes = argtypes.tail; 11.215 - } 11.216 - //check varargs element type accessibility 11.217 - varargsAccessible(env, elt, inferenceContext); 11.218 - } 11.219 - } 11.220 - 11.221 - private void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { 11.222 - boolean inferDiag = inferenceContext != infer.emptyContext; 11.223 - InapplicableMethodException ex = inferDiag ? 11.224 - infer.inferenceException : inapplicableMethodException; 11.225 - if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { 11.226 - Object[] args2 = new Object[args.length + 1]; 11.227 - System.arraycopy(args, 0, args2, 1, args.length); 11.228 - args2[0] = inferenceContext.inferenceVars(); 11.229 - args = args2; 11.230 - } 11.231 - throw ex.setMessage(inferDiag ? diag.inferKey : diag.basicKey, args); 11.232 } 11.233 11.234 private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { 11.235 @@ -765,6 +827,11 @@ 11.236 }; 11.237 return new MethodResultInfo(to, checkContext); 11.238 } 11.239 + 11.240 + @Override 11.241 + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 11.242 + return new MostSpecificCheck(strict, actuals); 11.243 + } 11.244 }; 11.245 11.246 /** 11.247 @@ -1042,6 +1109,11 @@ 11.248 } 11.249 } 11.250 } 11.251 + 11.252 + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { 11.253 + Assert.error("Cannot get here!"); 11.254 + return null; 11.255 + } 11.256 } 11.257 11.258 public static class InapplicableMethodException extends RuntimeException { 11.259 @@ -1254,7 +1326,7 @@ 11.260 Assert.check(sym.kind < AMBIGUOUS); 11.261 try { 11.262 Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, 11.263 - allowBoxing, useVarargs, resolveMethodCheck, types.noWarnings); 11.264 + allowBoxing, useVarargs, types.noWarnings); 11.265 if (!operator) 11.266 currentResolutionContext.addApplicableCandidate(sym, mt); 11.267 } catch (InapplicableMethodException ex) { 11.268 @@ -1358,11 +1430,20 @@ 11.269 int maxLength = Math.max( 11.270 Math.max(m1.type.getParameterTypes().length(), actuals.length()), 11.271 m2.type.getParameterTypes().length()); 11.272 - Type mst = instantiate(env, site, m2, null, 11.273 - adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, 11.274 - allowBoxing, useVarargs, new MostSpecificCheck(!allowBoxing, actuals), noteWarner); 11.275 - return mst != null && 11.276 - !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); 11.277 + MethodResolutionContext prevResolutionContext = currentResolutionContext; 11.278 + try { 11.279 + currentResolutionContext = new MethodResolutionContext(); 11.280 + currentResolutionContext.step = prevResolutionContext.step; 11.281 + currentResolutionContext.methodCheck = 11.282 + prevResolutionContext.methodCheck.mostSpecificCheck(actuals, !allowBoxing); 11.283 + Type mst = instantiate(env, site, m2, null, 11.284 + adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, 11.285 + allowBoxing, useVarargs, noteWarner); 11.286 + return mst != null && 11.287 + !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); 11.288 + } finally { 11.289 + currentResolutionContext = prevResolutionContext; 11.290 + } 11.291 } 11.292 private List<Type> adjustArgs(List<Type> args, Symbol msym, int length, boolean allowVarargs) { 11.293 if ((msym.flags() & VARARGS) != 0 && allowVarargs) { 11.294 @@ -2124,14 +2205,14 @@ 11.295 Name name, 11.296 List<Type> argtypes, 11.297 List<Type> typeargtypes) { 11.298 - return lookupMethod(env, pos, env.enclClass.sym, new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) { 11.299 - @Override 11.300 - Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { 11.301 - return findFun(env, name, argtypes, typeargtypes, 11.302 - phase.isBoxingRequired(), 11.303 - phase.isVarargsRequired()); 11.304 - } 11.305 - }); 11.306 + return lookupMethod(env, pos, env.enclClass.sym, resolveMethodCheck, 11.307 + new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) { 11.308 + @Override 11.309 + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { 11.310 + return findFun(env, name, argtypes, typeargtypes, 11.311 + phase.isBoxingRequired(), 11.312 + phase.isVarargsRequired()); 11.313 + }}); 11.314 } 11.315 11.316 /** Resolve a qualified method identifier 11.317 @@ -2313,36 +2394,36 @@ 11.318 Type site, 11.319 List<Type> argtypes, 11.320 List<Type> typeargtypes) { 11.321 - return lookupMethod(env, pos, site.tsym, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { 11.322 - @Override 11.323 - Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { 11.324 - return findDiamond(env, site, argtypes, typeargtypes, 11.325 - phase.isBoxingRequired(), 11.326 - phase.isVarargsRequired()); 11.327 - } 11.328 - @Override 11.329 - Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { 11.330 - if (sym.kind >= AMBIGUOUS) { 11.331 - final JCDiagnostic details = sym.kind == WRONG_MTH ? 11.332 - ((InapplicableSymbolError)sym).errCandidate().details : 11.333 - null; 11.334 - sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { 11.335 - @Override 11.336 - JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, 11.337 - Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 11.338 - String key = details == null ? 11.339 - "cant.apply.diamond" : 11.340 - "cant.apply.diamond.1"; 11.341 - return diags.create(dkind, log.currentSource(), pos, key, 11.342 - diags.fragment("diamond", site.tsym), details); 11.343 + return lookupMethod(env, pos, site.tsym, resolveMethodCheck, 11.344 + new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { 11.345 + @Override 11.346 + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { 11.347 + return findDiamond(env, site, argtypes, typeargtypes, 11.348 + phase.isBoxingRequired(), 11.349 + phase.isVarargsRequired()); 11.350 + } 11.351 + @Override 11.352 + Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { 11.353 + if (sym.kind >= AMBIGUOUS) { 11.354 + final JCDiagnostic details = sym.kind == WRONG_MTH ? 11.355 + ((InapplicableSymbolError)sym).errCandidate().details : 11.356 + null; 11.357 + sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { 11.358 + @Override 11.359 + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, 11.360 + Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 11.361 + String key = details == null ? 11.362 + "cant.apply.diamond" : 11.363 + "cant.apply.diamond.1"; 11.364 + return diags.create(dkind, log.currentSource(), pos, key, 11.365 + diags.fragment("diamond", site.tsym), details); 11.366 + } 11.367 + }; 11.368 + sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); 11.369 + env.info.pendingResolutionPhase = currentResolutionContext.step; 11.370 } 11.371 - }; 11.372 - sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); 11.373 - env.info.pendingResolutionPhase = currentResolutionContext.step; 11.374 - } 11.375 - return sym; 11.376 - } 11.377 - }); 11.378 + return sym; 11.379 + }}); 11.380 } 11.381 11.382 /** This method scans all the constructor symbol in a given class scope - 11.383 @@ -2475,7 +2556,8 @@ 11.384 Type site, 11.385 Name name, List<Type> argtypes, 11.386 List<Type> typeargtypes, 11.387 - boolean boxingAllowed) { 11.388 + boolean boxingAllowed, 11.389 + MethodCheck methodCheck) { 11.390 MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC; 11.391 11.392 ReferenceLookupHelper boundLookupHelper; 11.393 @@ -2495,12 +2577,12 @@ 11.394 11.395 //step 1 - bound lookup 11.396 Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup()); 11.397 - Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundLookupHelper); 11.398 + Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, methodCheck, boundLookupHelper); 11.399 11.400 //step 2 - unbound lookup 11.401 ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup(); 11.402 Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup()); 11.403 - Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundLookupHelper); 11.404 + Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, methodCheck, unboundLookupHelper); 11.405 11.406 //merge results 11.407 Pair<Symbol, ReferenceLookupHelper> res; 11.408 @@ -2671,7 +2753,7 @@ 11.409 ReferenceLookupHelper unboundLookup() { 11.410 if (TreeInfo.isStaticSelector(referenceTree.expr, names) && 11.411 argtypes.nonEmpty() && 11.412 - types.isSubtypeUnchecked(argtypes.head, site)) { 11.413 + (argtypes.head.hasTag(NONE) || types.isSubtypeUnchecked(argtypes.head, site))) { 11.414 return new UnboundMethodReferenceLookupHelper(referenceTree, name, 11.415 site, argtypes, typeargtypes, maxPhase); 11.416 } else { 11.417 @@ -2704,8 +2786,8 @@ 11.418 UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, 11.419 List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { 11.420 super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase); 11.421 - Type asSuperSite = types.asSuper(argtypes.head, site.tsym); 11.422 - if (site.isRaw() && !asSuperSite.isErroneous()) { 11.423 + if (site.isRaw() && !argtypes.head.hasTag(NONE)) { 11.424 + Type asSuperSite = types.asSuper(argtypes.head, site.tsym); 11.425 this.site = asSuperSite; 11.426 } 11.427 } 11.428 @@ -2800,8 +2882,10 @@ 11.429 * at the end of the lookup, the helper is used to validate the results 11.430 * (this last step might trigger overload resolution diagnostics). 11.431 */ 11.432 - Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, LookupHelper lookupHelper) { 11.433 - return lookupMethod(env, pos, location, new MethodResolutionContext(), lookupHelper); 11.434 + Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, MethodCheck methodCheck, LookupHelper lookupHelper) { 11.435 + MethodResolutionContext resolveContext = new MethodResolutionContext(); 11.436 + resolveContext.methodCheck = methodCheck; 11.437 + return lookupMethod(env, pos, location, resolveContext, lookupHelper); 11.438 } 11.439 11.440 Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, 11.441 @@ -3595,6 +3679,8 @@ 11.442 11.443 MethodResolutionPhase step = null; 11.444 11.445 + MethodCheck methodCheck = resolveMethodCheck; 11.446 + 11.447 private boolean internalResolution = false; 11.448 private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE; 11.449
12.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu Apr 11 09:40:22 2013 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Tue Apr 16 08:16:07 2013 -0700 12.3 @@ -373,6 +373,17 @@ 12.4 Assert.check(alive || state.stacksize == 0); 12.5 } 12.6 12.7 + /** Emit a ldc (or ldc_w) instruction, taking into account operand size 12.8 + */ 12.9 + public void emitLdc(int od) { 12.10 + if (od <= 255) { 12.11 + emitop1(ldc1, od); 12.12 + } 12.13 + else { 12.14 + emitop2(ldc2, od); 12.15 + } 12.16 + } 12.17 + 12.18 /** Emit a multinewarray instruction. 12.19 */ 12.20 public void emitMultianewarray(int ndims, int type, Type arrayType) { 12.21 @@ -459,7 +470,15 @@ 12.22 public void emitInvokedynamic(int desc, Type mtype) { 12.23 // N.B. this format is under consideration by the JSR 292 EG 12.24 int argsize = width(mtype.getParameterTypes()); 12.25 - emitop(invokedynamic); 12.26 + int prevPos = pendingStatPos; 12.27 + try { 12.28 + //disable line number generation (we could have used 'emit1', that 12.29 + //bypasses stackmap generation - which is needed for indy calls) 12.30 + pendingStatPos = Position.NOPOS; 12.31 + emitop(invokedynamic); 12.32 + } finally { 12.33 + pendingStatPos = prevPos; 12.34 + } 12.35 if (!alive) return; 12.36 emit2(desc); 12.37 emit2(0);
13.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Apr 11 09:40:22 2013 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Apr 16 08:16:07 2013 -0700 13.3 @@ -1748,10 +1748,13 @@ 13.4 // Generate code for all arguments, where the expected types are 13.5 // the parameters of the method's external type (that is, any implicit 13.6 // outer instance of a super(...) call appears as first parameter). 13.7 + MethodSymbol msym = (MethodSymbol)TreeInfo.symbol(tree.meth); 13.8 genArgs(tree.args, 13.9 - TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes()); 13.10 - code.statBegin(tree.pos); 13.11 - code.markStatBegin(); 13.12 + msym.externalType(types).getParameterTypes()); 13.13 + if (!msym.isDynamic()) { 13.14 + code.statBegin(tree.pos); 13.15 + code.markStatBegin(); 13.16 + } 13.17 result = m.invoke(); 13.18 } 13.19 13.20 @@ -2227,7 +2230,7 @@ 13.21 13.22 if (tree.name == names._class) { 13.23 Assert.check(target.hasClassLiterals()); 13.24 - code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); 13.25 + code.emitLdc(makeRef(tree.pos(), tree.selected.type)); 13.26 result = items.makeStackItem(pt); 13.27 return; 13.28 }
14.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Items.java Thu Apr 11 09:40:22 2013 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Items.java Tue Apr 16 08:16:07 2013 -0700 14.3 @@ -1,5 +1,5 @@ 14.4 /* 14.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 14.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 14.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.8 * 14.9 * This code is free software; you can redistribute it and/or modify it 14.10 @@ -571,10 +571,8 @@ 14.11 int idx = pool.put(value); 14.12 if (typecode == LONGcode || typecode == DOUBLEcode) { 14.13 code.emitop2(ldc2w, idx); 14.14 - } else if (idx <= 255) { 14.15 - code.emitop1(ldc1, idx); 14.16 } else { 14.17 - code.emitop2(ldc2, idx); 14.18 + code.emitLdc(idx); 14.19 } 14.20 } 14.21
15.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Thu Apr 11 09:40:22 2013 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Tue Apr 16 08:16:07 2013 -0700 15.3 @@ -1,5 +1,5 @@ 15.4 /* 15.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 15.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 15.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.8 * 15.9 * This code is free software; you can redistribute it and/or modify it 15.10 @@ -497,6 +497,8 @@ 15.11 if (!(doclintOpts.size() == 1 15.12 && doclintOpts.iterator().next().equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) { 15.13 JavacTask t = BasicJavacTask.instance(context); 15.14 + // standard doclet normally generates H1, H2 15.15 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); 15.16 new DocLint().init(t, doclintOpts.toArray(new String[doclintOpts.size()])); 15.17 comp.keepComments = true; 15.18 }
16.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Thu Apr 11 09:40:22 2013 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Tue Apr 16 08:16:07 2013 -0700 16.3 @@ -1,5 +1,5 @@ 16.4 /* 16.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 16.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 16.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.8 * 16.9 * This code is free software; you can redistribute it and/or modify it 16.10 @@ -770,7 +770,7 @@ 16.11 * (which is treated as the beginning of the first line). 16.12 * Stops positioned at the closing '/'. 16.13 */ 16.14 - protected class BasicComment<U extends UnicodeReader> implements Comment { 16.15 + protected static class BasicComment<U extends UnicodeReader> implements Comment { 16.16 16.17 CommentStyle cs; 16.18 U comment_reader;
17.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Apr 11 09:40:22 2013 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Apr 16 08:16:07 2013 -0700 17.3 @@ -171,8 +171,8 @@ 17.4 17.5 protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) { 17.6 return keepEndPositions 17.7 - ? new SimpleEndPosTable() 17.8 - : new EmptyEndPosTable(); 17.9 + ? new SimpleEndPosTable(this) 17.10 + : new EmptyEndPosTable(this); 17.11 } 17.12 17.13 protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) { 17.14 @@ -3088,6 +3088,7 @@ 17.15 toplevel.docComments = docComments; 17.16 if (keepLineMap) 17.17 toplevel.lineMap = S.getLineMap(); 17.18 + this.endPosTable.setParser(null); // remove reference to parser 17.19 toplevel.endPositions = this.endPosTable; 17.20 return toplevel; 17.21 } 17.22 @@ -4003,11 +4004,12 @@ 17.23 /* 17.24 * a functional source tree and end position mappings 17.25 */ 17.26 - protected class SimpleEndPosTable extends AbstractEndPosTable { 17.27 + protected static class SimpleEndPosTable extends AbstractEndPosTable { 17.28 17.29 private final Map<JCTree, Integer> endPosMap; 17.30 17.31 - SimpleEndPosTable() { 17.32 + SimpleEndPosTable(JavacParser parser) { 17.33 + super(parser); 17.34 endPosMap = new HashMap<JCTree, Integer>(); 17.35 } 17.36 17.37 @@ -4016,12 +4018,12 @@ 17.38 } 17.39 17.40 protected <T extends JCTree> T to(T t) { 17.41 - storeEnd(t, token.endPos); 17.42 + storeEnd(t, parser.token.endPos); 17.43 return t; 17.44 } 17.45 17.46 protected <T extends JCTree> T toP(T t) { 17.47 - storeEnd(t, S.prevToken().endPos); 17.48 + storeEnd(t, parser.S.prevToken().endPos); 17.49 return t; 17.50 } 17.51 17.52 @@ -4043,7 +4045,11 @@ 17.53 /* 17.54 * a default skeletal implementation without any mapping overhead. 17.55 */ 17.56 - protected class EmptyEndPosTable extends AbstractEndPosTable { 17.57 + protected static class EmptyEndPosTable extends AbstractEndPosTable { 17.58 + 17.59 + EmptyEndPosTable(JavacParser parser) { 17.60 + super(parser); 17.61 + } 17.62 17.63 protected void storeEnd(JCTree tree, int endpos) { /* empty */ } 17.64 17.65 @@ -4065,13 +4071,21 @@ 17.66 17.67 } 17.68 17.69 - protected abstract class AbstractEndPosTable implements EndPosTable { 17.70 + protected static abstract class AbstractEndPosTable implements EndPosTable { 17.71 + /** 17.72 + * The current parser. 17.73 + */ 17.74 + protected JavacParser parser; 17.75 17.76 /** 17.77 * Store the last error position. 17.78 */ 17.79 protected int errorEndPos; 17.80 17.81 + public AbstractEndPosTable(JavacParser parser) { 17.82 + this.parser = parser; 17.83 + } 17.84 + 17.85 /** 17.86 * Store ending position for a tree, the value of which is the greater 17.87 * of last error position and the given ending position. 17.88 @@ -4106,5 +4120,9 @@ 17.89 errorEndPos = errPos; 17.90 } 17.91 } 17.92 + 17.93 + protected void setParser(JavacParser parser) { 17.94 + this.parser = parser; 17.95 + } 17.96 } 17.97 }
18.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Thu Apr 11 09:40:22 2013 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Tue Apr 16 08:16:07 2013 -0700 18.3 @@ -206,7 +206,7 @@ 18.4 } 18.5 } 18.6 18.7 - protected class JavadocComment extends JavaTokenizer.BasicComment<DocReader> { 18.8 + protected static class JavadocComment extends JavaTokenizer.BasicComment<DocReader> { 18.9 18.10 /** 18.11 * Translated and stripped contents of doc comment
19.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Apr 11 09:40:22 2013 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Apr 16 08:16:07 2013 -0700 19.3 @@ -216,9 +216,14 @@ 19.4 compiler.misc.no.suitable.functional.intf.inst=\ 19.5 cannot infer functional interface descriptor for {0} 19.6 19.7 +# 0: message segment 19.8 +compiler.misc.bad.intersection.target.for.functional.expr=\ 19.9 + bad intersection type target for lambda or method reference\n\ 19.10 + {0} 19.11 + 19.12 # 0: type 19.13 -compiler.misc.secondary.bound.must.be.marker.intf=\ 19.14 - secondary bound {0} must be a marker interface 19.15 +compiler.misc.not.an.intf.component=\ 19.16 + component type {0} is not an interface 19.17 19.18 # 0: symbol kind, 1: message segment 19.19 compiler.err.invalid.mref=\ 19.20 @@ -731,6 +736,11 @@ 19.21 compiler.misc.incompatible.arg.types.in.mref=\ 19.22 incompatible parameter types in method reference 19.23 19.24 +# 0: list of type 19.25 +compiler.misc.bad.arg.types.in.lambda=\ 19.26 + cannot type-check lambda expression with inferred parameter types\n\ 19.27 + inferred types: {0} 19.28 + 19.29 compiler.err.new.not.allowed.in.annotation=\ 19.30 ''new'' not allowed in an annotation 19.31
20.1 --- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Thu Apr 11 09:40:22 2013 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Apr 16 08:16:07 2013 -0700 20.3 @@ -1,5 +1,5 @@ 20.4 /* 20.5 - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 20.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 20.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.8 * 20.9 * This code is free software; you can redistribute it and/or modify it 20.10 @@ -112,9 +112,8 @@ 20.11 protected ClassLoader getClassLoader(URL[] urls) { 20.12 ClassLoader thisClassLoader = getClass().getClassLoader(); 20.13 20.14 - // Bug: 6558476 20.15 - // Ideally, ClassLoader should be Closeable, but before JDK7 it is not. 20.16 - // On older versions, try the following, to get a closeable classloader. 20.17 + // Allow the following to specify a closeable classloader 20.18 + // other than URLClassLoader. 20.19 20.20 // 1: Allow client to specify the class to use via hidden option 20.21 if (classLoaderClass != null) { 20.22 @@ -128,19 +127,6 @@ 20.23 // ignore errors loading user-provided class loader, fall through 20.24 } 20.25 } 20.26 - 20.27 - // 2: If URLClassLoader implements Closeable, use that. 20.28 - if (Closeable.class.isAssignableFrom(URLClassLoader.class)) 20.29 - return new URLClassLoader(urls, thisClassLoader); 20.30 - 20.31 - // 3: Try using private reflection-based CloseableURLClassLoader 20.32 - try { 20.33 - return new CloseableURLClassLoader(urls, thisClassLoader); 20.34 - } catch (Throwable t) { 20.35 - // ignore errors loading workaround class loader, fall through 20.36 - } 20.37 - 20.38 - // 4: If all else fails, use plain old standard URLClassLoader 20.39 return new URLClassLoader(urls, thisClassLoader); 20.40 } 20.41
21.1 --- a/src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java Thu Apr 11 09:40:22 2013 -0700 21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 21.3 @@ -1,108 +0,0 @@ 21.4 -/* 21.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. 21.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 - * 21.8 - * This code is free software; you can redistribute it and/or modify it 21.9 - * under the terms of the GNU General Public License version 2 only, as 21.10 - * published by the Free Software Foundation. Oracle designates this 21.11 - * particular file as subject to the "Classpath" exception as provided 21.12 - * by Oracle in the LICENSE file that accompanied this code. 21.13 - * 21.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 21.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.17 - * version 2 for more details (a copy is included in the LICENSE file that 21.18 - * accompanied this code). 21.19 - * 21.20 - * You should have received a copy of the GNU General Public License version 21.21 - * 2 along with this work; if not, write to the Free Software Foundation, 21.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.23 - * 21.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.25 - * or visit www.oracle.com if you need additional information or have any 21.26 - * questions. 21.27 - */ 21.28 - 21.29 -package com.sun.tools.javac.util; 21.30 - 21.31 -import java.io.Closeable; 21.32 -import java.io.IOException; 21.33 -import java.lang.reflect.Field; 21.34 -import java.net.URL; 21.35 -import java.net.URLClassLoader; 21.36 -import java.util.ArrayList; 21.37 -import java.util.jar.JarFile; 21.38 - 21.39 -/** 21.40 - * A URLClassLoader that also implements Closeable. 21.41 - * Reflection is used to access internal data structures in the URLClassLoader, 21.42 - * since no public API exists for this purpose. Therefore this code is somewhat 21.43 - * fragile. Caveat emptor. 21.44 - * @throws Error if the internal data structures are not as expected. 21.45 - * 21.46 - * <p><b>This is NOT part of any supported API. 21.47 - * If you write code that depends on this, you do so at your own risk. 21.48 - * This code and its internal interfaces are subject to change or 21.49 - * deletion without notice.</b> 21.50 - */ 21.51 -public class CloseableURLClassLoader 21.52 - extends URLClassLoader implements Closeable { 21.53 - public CloseableURLClassLoader(URL[] urls, ClassLoader parent) throws Error { 21.54 - super(urls, parent); 21.55 - try { 21.56 - getLoaders(); //proactive check that URLClassLoader is as expected 21.57 - } catch (Throwable t) { 21.58 - throw new Error("cannot create CloseableURLClassLoader", t); 21.59 - } 21.60 - } 21.61 - 21.62 - /** 21.63 - * Close any jar files that may have been opened by the class loader. 21.64 - * Reflection is used to access the jar files in the URLClassLoader's 21.65 - * internal data structures. 21.66 - * @throws java.io.IOException if the jar files cannot be found for any 21.67 - * reson, or if closing the jar file itself causes an IOException. 21.68 - */ 21.69 - @Override 21.70 - public void close() throws IOException { 21.71 - try { 21.72 - for (Object l: getLoaders()) { 21.73 - if (l.getClass().getName().equals("sun.misc.URLClassPath$JarLoader")) { 21.74 - Field jarField = l.getClass().getDeclaredField("jar"); 21.75 - JarFile jar = (JarFile) getField(l, jarField); 21.76 - if (jar != null) { 21.77 - //System.err.println("CloseableURLClassLoader: closing " + jar); 21.78 - jar.close(); 21.79 - } 21.80 - } 21.81 - } 21.82 - } catch (Throwable t) { 21.83 - IOException e = new IOException("cannot close class loader"); 21.84 - e.initCause(t); 21.85 - throw e; 21.86 - } 21.87 - } 21.88 - 21.89 - private ArrayList<?> getLoaders() 21.90 - throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException 21.91 - { 21.92 - Field ucpField = URLClassLoader.class.getDeclaredField("ucp"); 21.93 - Object urlClassPath = getField(this, ucpField); 21.94 - if (urlClassPath == null) 21.95 - throw new AssertionError("urlClassPath not set in URLClassLoader"); 21.96 - Field loadersField = urlClassPath.getClass().getDeclaredField("loaders"); 21.97 - return (ArrayList<?>) getField(urlClassPath, loadersField); 21.98 - } 21.99 - 21.100 - private Object getField(Object o, Field f) 21.101 - throws IllegalArgumentException, IllegalAccessException { 21.102 - boolean prev = f.isAccessible(); 21.103 - try { 21.104 - f.setAccessible(true); 21.105 - return f.get(o); 21.106 - } finally { 21.107 - f.setAccessible(prev); 21.108 - } 21.109 - } 21.110 - 21.111 -}
22.1 --- a/src/share/classes/com/sun/tools/javac/util/Pair.java Thu Apr 11 09:40:22 2013 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javac/util/Pair.java Tue Apr 16 08:16:07 2013 -0700 22.3 @@ -1,5 +1,5 @@ 22.4 /* 22.5 - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. 22.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 22.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.8 * 22.9 * This code is free software; you can redistribute it and/or modify it 22.10 @@ -25,6 +25,8 @@ 22.11 22.12 package com.sun.tools.javac.util; 22.13 22.14 +import java.util.Objects; 22.15 + 22.16 /** A generic class for pairs. 22.17 * 22.18 * <p><b>This is NOT part of any supported API. 22.19 @@ -46,15 +48,11 @@ 22.20 return "Pair[" + fst + "," + snd + "]"; 22.21 } 22.22 22.23 - private static boolean equals(Object x, Object y) { 22.24 - return (x == null && y == null) || (x != null && x.equals(y)); 22.25 - } 22.26 - 22.27 public boolean equals(Object other) { 22.28 return 22.29 other instanceof Pair<?,?> && 22.30 - equals(fst, ((Pair<?,?>)other).fst) && 22.31 - equals(snd, ((Pair<?,?>)other).snd); 22.32 + Objects.equals(fst, ((Pair<?,?>)other).fst) && 22.33 + Objects.equals(snd, ((Pair<?,?>)other).snd); 22.34 } 22.35 22.36 public int hashCode() {
23.1 --- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Apr 11 09:40:22 2013 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Apr 16 08:16:07 2013 -0700 23.3 @@ -395,6 +395,9 @@ 23.4 23.5 @Override 23.6 public String visitClassSymbol(ClassSymbol s, Locale locale) { 23.7 + if (s.type.isCompound()) { 23.8 + return visit(s.type, locale); 23.9 + } 23.10 String name = nameSimplifier.simplify(s); 23.11 if (name.length() == 0 || 23.12 !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) { 23.13 @@ -583,7 +586,11 @@ 23.14 23.15 @Override 23.16 public Void visitClassSymbol(ClassSymbol s, Void ignored) { 23.17 - nameSimplifier.addUsage(s); 23.18 + if (s.type.isCompound()) { 23.19 + typePreprocessor.visit(s.type); 23.20 + } else { 23.21 + nameSimplifier.addUsage(s); 23.22 + } 23.23 return null; 23.24 } 23.25
24.1 --- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java Thu Apr 11 09:40:22 2013 -0700 24.2 +++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java Tue Apr 16 08:16:07 2013 -0700 24.3 @@ -810,6 +810,8 @@ 24.4 24.5 JavacTask t = BasicJavacTask.instance(context); 24.6 doclint = new DocLint(); 24.7 + // standard doclet normally generates H1, H2 24.8 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); 24.9 doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); 24.10 } 24.11
25.1 --- a/src/share/classes/javax/annotation/processing/AbstractProcessor.java Thu Apr 11 09:40:22 2013 -0700 25.2 +++ b/src/share/classes/javax/annotation/processing/AbstractProcessor.java Tue Apr 16 08:16:07 2013 -0700 25.3 @@ -1,5 +1,5 @@ 25.4 /* 25.5 - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 25.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 25.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.8 * 25.9 * This code is free software; you can redistribute it and/or modify it 25.10 @@ -28,6 +28,7 @@ 25.11 import java.util.Set; 25.12 import java.util.HashSet; 25.13 import java.util.Collections; 25.14 +import java.util.Objects; 25.15 import javax.lang.model.element.*; 25.16 import javax.lang.model.SourceVersion; 25.17 import javax.tools.Diagnostic; 25.18 @@ -146,8 +147,7 @@ 25.19 public synchronized void init(ProcessingEnvironment processingEnv) { 25.20 if (initialized) 25.21 throw new IllegalStateException("Cannot call init more than once."); 25.22 - if (processingEnv == null) 25.23 - throw new NullPointerException("Tool provided null ProcessingEnvironment"); 25.24 + Objects.requireNonNull(processingEnv, "Tool provided null ProcessingEnvironment"); 25.25 25.26 this.processingEnv = processingEnv; 25.27 initialized = true;
26.1 --- a/src/share/classes/javax/lang/model/element/Modifier.java Thu Apr 11 09:40:22 2013 -0700 26.2 +++ b/src/share/classes/javax/lang/model/element/Modifier.java Tue Apr 16 08:16:07 2013 -0700 26.3 @@ -1,5 +1,5 @@ 26.4 /* 26.5 - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 26.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 26.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.8 * 26.9 * This code is free software; you can redistribute it and/or modify it 26.10 @@ -53,6 +53,11 @@ 26.11 /** The modifier {@code protected} */ PROTECTED, 26.12 /** The modifier {@code private} */ PRIVATE, 26.13 /** The modifier {@code abstract} */ ABSTRACT, 26.14 + /** 26.15 + * The modifier {@code default} 26.16 + * @since 1.8 26.17 + */ 26.18 + DEFAULT, 26.19 /** The modifier {@code static} */ STATIC, 26.20 /** The modifier {@code final} */ FINAL, 26.21 /** The modifier {@code transient} */ TRANSIENT,
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/T4965689/ClassLiteralWastesByteTest.java Tue Apr 16 08:16:07 2013 -0700 27.3 @@ -0,0 +1,66 @@ 27.4 +/* 27.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + */ 27.26 + 27.27 +/* 27.28 + * @test 27.29 + * @bug 4965689 27.30 + * @summary class literal code wastes a byte 27.31 + */ 27.32 + 27.33 +import java.io.PrintWriter; 27.34 +import java.io.StringWriter; 27.35 +import java.nio.file.Paths; 27.36 + 27.37 +public class ClassLiteralWastesByteTest { 27.38 + 27.39 + private static final String assertionErrorMsg = 27.40 + "Instead of ldc_w, ldc instruction should have been generated"; 27.41 + 27.42 + public static void main(String[] args) { 27.43 + new ClassLiteralWastesByteTest().run(); 27.44 + } 27.45 + 27.46 + void run() { 27.47 + check("-c", Paths.get(System.getProperty("test.classes"), 27.48 + "test.class").toString()); 27.49 + } 27.50 + 27.51 + void check(String... params) { 27.52 + StringWriter s; 27.53 + String out; 27.54 + try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { 27.55 + com.sun.tools.javap.Main.run(params, pw); 27.56 + out = s.toString(); 27.57 + } 27.58 + if (out.contains("ldc_w")) { 27.59 + throw new AssertionError(assertionErrorMsg); 27.60 + } 27.61 + } 27.62 + 27.63 +} 27.64 + 27.65 +class test { 27.66 + void m() { 27.67 + Class<?> aClass = test.class; 27.68 + } 27.69 +}
28.1 --- a/test/tools/javac/T6558476.java Thu Apr 11 09:40:22 2013 -0700 28.2 +++ b/test/tools/javac/T6558476.java Tue Apr 16 08:16:07 2013 -0700 28.3 @@ -1,5 +1,5 @@ 28.4 /* 28.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 28.6 + * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.8 * 28.9 * This code is free software; you can redistribute it and/or modify it 28.10 @@ -23,6 +23,8 @@ 28.11 28.12 /* 28.13 * @test 28.14 + * @bug 6558476 28.15 + * @summary com/sun/tools/javac/Main.compile don't release file handles on return 28.16 * @run main/othervm -Xmx512m -Xms512m T6558476 28.17 */ 28.18 28.19 @@ -70,8 +72,7 @@ 28.20 28.21 public static void main(String[] args) throws IOException { 28.22 File javaHomeDir = new File(System.getProperty("java.home")); 28.23 - File tmpDir = new File(System.getProperty("java.io.tmpdir")); 28.24 - File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536)); 28.25 + File outputDir = new File("outputDir" + new Random().nextInt(65536)); 28.26 outputDir.mkdir(); 28.27 outputDir.deleteOnExit(); 28.28
29.1 --- a/test/tools/javac/T6900149.java Thu Apr 11 09:40:22 2013 -0700 29.2 +++ b/test/tools/javac/T6900149.java Tue Apr 16 08:16:07 2013 -0700 29.3 @@ -1,5 +1,5 @@ 29.4 /* 29.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 29.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 29.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.8 * 29.9 * This code is free software; you can redistribute it and/or modify it 29.10 @@ -39,7 +39,7 @@ 29.11 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 29.12 StandardJavaFileManager fm = 29.13 compiler.getStandardFileManager(null, null, null); 29.14 - File emptyFile = File.createTempFile("Empty", ".java"); 29.15 + File emptyFile = createTempFile("Empty.java"); 29.16 File[] files = new File[] { emptyFile, emptyFile }; 29.17 CompilationTask task = compiler.getTask(null, fm, diag, 29.18 null, null, fm.getJavaFileObjects(files)); 29.19 @@ -47,4 +47,10 @@ 29.20 throw new AssertionError("compilation failed"); 29.21 } 29.22 } 29.23 + 29.24 + private static File createTempFile(String path) throws IOException { 29.25 + File f = new File(path); 29.26 + try (FileWriter out = new FileWriter(f)) { } 29.27 + return f; 29.28 + } 29.29 }
30.1 --- a/test/tools/javac/diags/CheckExamples.java Thu Apr 11 09:40:22 2013 -0700 30.2 +++ b/test/tools/javac/diags/CheckExamples.java Tue Apr 16 08:16:07 2013 -0700 30.3 @@ -1,5 +1,5 @@ 30.4 /* 30.5 - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 30.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 30.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.8 * 30.9 * This code is free software; you can redistribute it and/or modify it 30.10 @@ -34,6 +34,8 @@ 30.11 */ 30.12 30.13 import java.io.*; 30.14 +import java.nio.file.*; 30.15 +import java.nio.file.attribute.BasicFileAttributes; 30.16 import java.util.*; 30.17 30.18 /** 30.19 @@ -53,7 +55,27 @@ 30.20 * Standard entry point. 30.21 */ 30.22 public static void main(String... args) throws Exception { 30.23 - new CheckExamples().run(); 30.24 + boolean jtreg = (System.getProperty("test.src") != null); 30.25 + Path tmpDir; 30.26 + boolean deleteOnExit; 30.27 + if (jtreg) { 30.28 + // use standard jtreg scratch directory: the current directory 30.29 + tmpDir = Paths.get(System.getProperty("user.dir")); 30.30 + deleteOnExit = false; 30.31 + } else { 30.32 + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), 30.33 + CheckExamples.class.getName()); 30.34 + deleteOnExit = true; 30.35 + } 30.36 + Example.setTempDir(tmpDir.toFile()); 30.37 + 30.38 + try { 30.39 + new CheckExamples().run(); 30.40 + } finally { 30.41 + if (deleteOnExit) { 30.42 + clean(tmpDir); 30.43 + } 30.44 + } 30.45 } 30.46 30.47 /** 30.48 @@ -190,6 +212,25 @@ 30.49 30.50 int errors; 30.51 30.52 + /** 30.53 + * Clean the contents of a directory. 30.54 + */ 30.55 + static void clean(Path dir) throws IOException { 30.56 + Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { 30.57 + @Override 30.58 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 30.59 + Files.delete(file); 30.60 + return super.visitFile(file, attrs); 30.61 + } 30.62 + 30.63 + @Override 30.64 + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { 30.65 + if (exc == null) Files.delete(dir); 30.66 + return super.postVisitDirectory(dir, exc); 30.67 + } 30.68 + }); 30.69 + } 30.70 + 30.71 static class Counts { 30.72 static String[] prefixes = { 30.73 "compiler.err.",
31.1 --- a/test/tools/javac/diags/RunExamples.java Thu Apr 11 09:40:22 2013 -0700 31.2 +++ b/test/tools/javac/diags/RunExamples.java Tue Apr 16 08:16:07 2013 -0700 31.3 @@ -1,5 +1,5 @@ 31.4 /* 31.5 - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 31.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 31.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.8 * 31.9 * This code is free software; you can redistribute it and/or modify it 31.10 @@ -33,7 +33,8 @@ 31.11 */ 31.12 31.13 import java.io.*; 31.14 -import java.text.SimpleDateFormat; 31.15 +import java.nio.file.*; 31.16 +import java.nio.file.attribute.BasicFileAttributes; 31.17 import java.util.*; 31.18 import java.util.regex.Matcher; 31.19 import java.util.regex.Pattern; 31.20 @@ -56,16 +57,18 @@ 31.21 public class RunExamples { 31.22 public static void main(String... args) throws Exception { 31.23 jtreg = (System.getProperty("test.src") != null); 31.24 - File tmpDir; 31.25 + Path tmpDir; 31.26 + boolean deleteOnExit; 31.27 if (jtreg) { 31.28 // use standard jtreg scratch directory: the current directory 31.29 - tmpDir = new File(System.getProperty("user.dir")); 31.30 + tmpDir = Paths.get(System.getProperty("user.dir")); 31.31 + deleteOnExit = false; 31.32 } else { 31.33 - tmpDir = new File(System.getProperty("java.io.tmpdir"), 31.34 - RunExamples.class.getName() 31.35 - + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date())); 31.36 + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), 31.37 + RunExamples.class.getName()); 31.38 + deleteOnExit = true; 31.39 } 31.40 - Example.setTempDir(tmpDir); 31.41 + Example.setTempDir(tmpDir.toFile()); 31.42 31.43 RunExamples r = new RunExamples(); 31.44 31.45 @@ -73,15 +76,8 @@ 31.46 if (r.run(args)) 31.47 return; 31.48 } finally { 31.49 - /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the 31.50 - * jtreg scratch directory, which is the current directory. 31.51 - * In case someone is faking jtreg mode, make sure to only 31.52 - * clean tmpDir when it is reasonable to do so. 31.53 - */ 31.54 - if (tmpDir.isDirectory() && 31.55 - tmpDir.getName().startsWith(RunExamples.class.getName())) { 31.56 - if (clean(tmpDir)) 31.57 - tmpDir.delete(); 31.58 + if (deleteOnExit) { 31.59 + clean(tmpDir); 31.60 } 31.61 } 31.62 31.63 @@ -203,14 +199,20 @@ 31.64 /** 31.65 * Clean the contents of a directory. 31.66 */ 31.67 - static boolean clean(File dir) { 31.68 - boolean ok = true; 31.69 - for (File f: dir.listFiles()) { 31.70 - if (f.isDirectory()) 31.71 - ok &= clean(f); 31.72 - ok &= f.delete(); 31.73 - } 31.74 - return ok; 31.75 + static void clean(Path dir) throws IOException { 31.76 + Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { 31.77 + @Override 31.78 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 31.79 + Files.delete(file); 31.80 + return super.visitFile(file, attrs); 31.81 + } 31.82 + 31.83 + @Override 31.84 + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { 31.85 + if (exc == null) Files.delete(dir); 31.86 + return super.postVisitDirectory(dir, exc); 31.87 + } 31.88 + }); 31.89 } 31.90 31.91 static abstract class Runner {
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/diags/examples/BadArgTypesInLambda.java Tue Apr 16 08:16:07 2013 -0700 32.3 @@ -0,0 +1,38 @@ 32.4 +/* 32.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. 32.11 + * 32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 + * version 2 for more details (a copy is included in the LICENSE file that 32.16 + * accompanied this code). 32.17 + * 32.18 + * You should have received a copy of the GNU General Public License version 32.19 + * 2 along with this work; if not, write to the Free Software Foundation, 32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 + * 32.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.23 + * or visit www.oracle.com if you need additional information or have any 32.24 + * questions. 32.25 + */ 32.26 + 32.27 +// key: compiler.err.cant.apply.symbol 32.28 +// key: compiler.misc.no.conforming.assignment.exists 32.29 +// key: compiler.misc.bad.arg.types.in.lambda 32.30 + 32.31 +class BadArgTypesInLambda { 32.32 + interface SAM { 32.33 + void m(Integer i); 32.34 + } 32.35 + 32.36 + void g(SAM s) { } 32.37 + 32.38 + void test() { 32.39 + g(x->{ String s = x; }); 32.40 + } 32.41 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/diags/examples/NotAnInterfaceComponent.java Tue Apr 16 08:16:07 2013 -0700 33.3 @@ -0,0 +1,30 @@ 33.4 +/* 33.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.23 + * or visit www.oracle.com if you need additional information or have any 33.24 + * questions. 33.25 + */ 33.26 + 33.27 +// key: compiler.err.prob.found.req 33.28 +// key: compiler.misc.bad.intersection.target.for.functional.expr 33.29 +// key: compiler.misc.not.an.intf.component 33.30 + 33.31 +class NotAnInterfaceComponent { 33.32 + Object o = (Object & Runnable) ()-> { }; 33.33 +}
34.1 --- a/test/tools/javac/diags/examples/SecondaryBoundMustBeMarkerIntf.java Thu Apr 11 09:40:22 2013 -0700 34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 34.3 @@ -1,29 +0,0 @@ 34.4 -/* 34.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 34.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 - * 34.8 - * This code is free software; you can redistribute it and/or modify it 34.9 - * under the terms of the GNU General Public License version 2 only, as 34.10 - * published by the Free Software Foundation. 34.11 - * 34.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 - * version 2 for more details (a copy is included in the LICENSE file that 34.16 - * accompanied this code). 34.17 - * 34.18 - * You should have received a copy of the GNU General Public License version 34.19 - * 2 along with this work; if not, write to the Free Software Foundation, 34.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 - * 34.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.23 - * or visit www.oracle.com if you need additional information or have any 34.24 - * questions. 34.25 - */ 34.26 - 34.27 -// key: compiler.err.prob.found.req 34.28 -// key: compiler.misc.secondary.bound.must.be.marker.intf 34.29 - 34.30 -class SecondaryBoundMustBeMarkerInterface { 34.31 - Runnable r = (Runnable & Comparable<?>)()->{}; 34.32 -}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/doclint/ImplicitHeadersTest.java Tue Apr 16 08:16:07 2013 -0700 35.3 @@ -0,0 +1,35 @@ 35.4 +/* 35.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +/* 35.28 + * @test 35.29 + * @bug 8006346 35.30 + * @summary doclint should make allowance for headers generated by standard doclet 35.31 + * @compile -Xdoclint:all/public ImplicitHeadersTest.java 35.32 + */ 35.33 + 35.34 +/** 35.35 + * <h3> Header </h3> 35.36 + */ 35.37 +public class ImplicitHeadersTest { } 35.38 +
36.1 --- a/test/tools/javac/lambda/BadRecovery.out Thu Apr 11 09:40:22 2013 -0700 36.2 +++ b/test/tools/javac/lambda/BadRecovery.out Tue Apr 16 08:16:07 2013 -0700 36.3 @@ -1,3 +1,2 @@ 36.4 -BadRecovery.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, BadRecovery.SAM1, @369, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda)) 36.5 BadRecovery.java:17:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null) 36.6 -2 errors 36.7 +1 error
37.1 --- a/test/tools/javac/lambda/Intersection01.java Thu Apr 11 09:40:22 2013 -0700 37.2 +++ b/test/tools/javac/lambda/Intersection01.java Tue Apr 16 08:16:07 2013 -0700 37.3 @@ -25,7 +25,7 @@ 37.4 * @test 37.5 * @bug 8002099 37.6 * @summary Add support for intersection types in cast expression 37.7 - * @compile/fail/ref=Intersection01.out -XDrawDiagnostics Intersection01.java 37.8 + * @compile Intersection01.java 37.9 */ 37.10 class Intersection01 { 37.11
38.1 --- a/test/tools/javac/lambda/Intersection01.out Thu Apr 11 09:40:22 2013 -0700 38.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 38.3 @@ -1,3 +0,0 @@ 38.4 -Intersection01.java:36:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: java.io.Serializable, (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) 38.5 -Intersection01.java:38:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: java.io.Serializable, (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) 38.6 -2 errors
39.1 --- a/test/tools/javac/lambda/TargetType01.java Thu Apr 11 09:40:22 2013 -0700 39.2 +++ b/test/tools/javac/lambda/TargetType01.java Tue Apr 16 08:16:07 2013 -0700 39.3 @@ -1,5 +1,5 @@ 39.4 /* 39.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 39.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 39.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.8 * 39.9 * This code is free software; you can redistribute it and/or modify it 39.10 @@ -23,11 +23,10 @@ 39.11 39.12 /* 39.13 * @test 39.14 - * @bug 8003280 39.15 + * @bug 8003280 8009131 39.16 * @summary Add lambda tests 39.17 * check nested case of overload resolution and lambda parameter inference 39.18 - * @author Maurizio Cimadamore 39.19 - * @compile/fail/ref=TargetType01.out -XDrawDiagnostics TargetType01.java 39.20 + * @compile TargetType01.java 39.21 */ 39.22 39.23 class TargetType01 {
40.1 --- a/test/tools/javac/lambda/TargetType01.out Thu Apr 11 09:40:22 2013 -0700 40.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 40.3 @@ -1,3 +0,0 @@ 40.4 -TargetType01.java:46:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 40.5 -TargetType01.java:46:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 40.6 -2 errors
41.1 --- a/test/tools/javac/lambda/TargetType43.out Thu Apr 11 09:40:22 2013 -0700 41.2 +++ b/test/tools/javac/lambda/TargetType43.out Tue Apr 16 08:16:07 2013 -0700 41.3 @@ -1,5 +1,4 @@ 41.4 TargetType43.java:13:20: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf: java.lang.Object) 41.5 TargetType43.java:13:30: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) 41.6 -TargetType43.java:14:9: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Object, @359, kindname.class, TargetType43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: java.lang.Object)) 41.7 TargetType43.java:14:21: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) 41.8 -4 errors 41.9 +3 errors
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/lambda/TargetType66.java Tue Apr 16 08:16:07 2013 -0700 42.3 @@ -0,0 +1,26 @@ 42.4 +/* 42.5 + * @test /nodynamiccopyright/ 42.6 + * @bug 8009131 42.7 + * @summary Overload: javac should discard methods that lead to errors in lambdas with implicit parameter types 42.8 + * @compile/fail/ref=TargetType66.out -XDrawDiagnostics TargetType66.java 42.9 + */ 42.10 +class TargetType66 { 42.11 + interface SAM1 { 42.12 + void m(String s); 42.13 + } 42.14 + 42.15 + interface SAM2 { 42.16 + void m(Integer s); 42.17 + } 42.18 + 42.19 + void g(SAM1 s1) { } 42.20 + void g(SAM2 s2) { } 42.21 + 42.22 + void test() { 42.23 + g(x->{ String s = x; }); //g(SAM1) 42.24 + g(x->{ Integer i = x; }); //g(SAM2) 42.25 + g(x->{ Object o = x; }); //ambiguous 42.26 + g(x->{ Character c = x; }); //error: inapplicable methods 42.27 + g(x->{ Character c = ""; }); //error: incompatible types 42.28 + } 42.29 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/lambda/TargetType66.out Tue Apr 16 08:16:07 2013 -0700 43.3 @@ -0,0 +1,4 @@ 43.4 +TargetType66.java:22:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 43.5 +TargetType66.java:23:9: compiler.err.cant.apply.symbols: kindname.method, g, @578,{(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.String))),(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.Integer)))} 43.6 +TargetType66.java:24:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character) 43.7 +3 errors
44.1 --- a/test/tools/javac/lambda/TestInvokeDynamic.java Thu Apr 11 09:40:22 2013 -0700 44.2 +++ b/test/tools/javac/lambda/TestInvokeDynamic.java Tue Apr 16 08:16:07 2013 -0700 44.3 @@ -24,7 +24,7 @@ 44.4 /* 44.5 * @test 44.6 * @bug 7194586 44.7 - * @bug 8003280 8006694 44.8 + * @bug 8003280 8006694 8010404 44.9 * @summary Add lambda tests 44.10 * Add back-end support for invokedynamic 44.11 * temporarily workaround combo tests are causing time out in several platforms 44.12 @@ -48,6 +48,7 @@ 44.13 import com.sun.tools.classfile.Code_attribute; 44.14 import com.sun.tools.classfile.ConstantPool.*; 44.15 import com.sun.tools.classfile.Instruction; 44.16 +import com.sun.tools.classfile.LineNumberTable_attribute; 44.17 import com.sun.tools.classfile.Method; 44.18 44.19 import com.sun.tools.javac.api.JavacTaskImpl; 44.20 @@ -239,7 +240,7 @@ 44.21 int id = checkCount.incrementAndGet(); 44.22 JavaSource source = new JavaSource(id); 44.23 JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc, 44.24 - null, null, Arrays.asList(source)); 44.25 + Arrays.asList("-g"), null, Arrays.asList(source)); 44.26 Context context = ct.getContext(); 44.27 Symtab syms = Symtab.instance(context); 44.28 Names names = Names.instance(context); 44.29 @@ -349,6 +350,16 @@ 44.30 bsm_ref.getNameAndTypeInfo().getType() + " " + 44.31 asBSMSignatureString()); 44.32 } 44.33 + 44.34 + LineNumberTable_attribute lnt = 44.35 + (LineNumberTable_attribute)ea.attributes.get(Attribute.LineNumberTable); 44.36 + 44.37 + if (lnt == null) { 44.38 + throw new Error("No LineNumberTable attribute"); 44.39 + } 44.40 + if (lnt.line_number_table_length != 2) { 44.41 + throw new Error("Wrong number of entries in LineNumberTable"); 44.42 + } 44.43 } catch (Exception e) { 44.44 e.printStackTrace(); 44.45 throw new Error("error reading " + compiledTest +": " + e); 44.46 @@ -376,7 +387,10 @@ 44.47 "}\n" + 44.48 "class Test#ID {\n" + 44.49 " void m() { }\n" + 44.50 - " void test() { m(); }\n" + 44.51 + " void test() {\n" + 44.52 + " Object o = this; // marker statement \n" + 44.53 + " m();\n" + 44.54 + " }\n" + 44.55 "}"; 44.56 44.57 String source;
45.1 --- a/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Thu Apr 11 09:40:22 2013 -0700 45.2 +++ b/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Tue Apr 16 08:16:07 2013 -0700 45.3 @@ -28,10 +28,11 @@ 45.4 */ 45.5 45.6 import com.sun.source.util.JavacTask; 45.7 -import com.sun.tools.javac.util.List; 45.8 import com.sun.tools.javac.util.ListBuffer; 45.9 import java.net.URI; 45.10 +import java.util.ArrayList; 45.11 import java.util.Arrays; 45.12 +import java.util.List; 45.13 import javax.tools.Diagnostic; 45.14 import javax.tools.JavaCompiler; 45.15 import javax.tools.JavaFileObject; 45.16 @@ -45,37 +46,45 @@ 45.17 45.18 enum BoundKind { 45.19 INTF, 45.20 - CLASS, 45.21 - SAM, 45.22 - ZAM; 45.23 + CLASS; 45.24 } 45.25 45.26 enum MethodKind { 45.27 - NONE, 45.28 - ABSTRACT, 45.29 - DEFAULT; 45.30 + NONE(false), 45.31 + ABSTRACT_M(true), 45.32 + DEFAULT_M(false), 45.33 + ABSTRACT_G(true), 45.34 + DEFAULT_G(false); 45.35 + 45.36 + boolean isAbstract; 45.37 + 45.38 + MethodKind(boolean isAbstract) { 45.39 + this.isAbstract = isAbstract; 45.40 + } 45.41 } 45.42 45.43 enum TypeKind { 45.44 - A("interface A { }\n", "A", BoundKind.ZAM), 45.45 - B("interface B { default void m() { } }\n", "B", BoundKind.ZAM), 45.46 - C("interface C { void m(); }\n", "C", BoundKind.SAM), 45.47 - D("interface D extends B { }\n", "D", BoundKind.ZAM), 45.48 - E("interface E extends C { }\n", "E", BoundKind.SAM), 45.49 - F("interface F extends C { void g(); }\n", "F", BoundKind.INTF), 45.50 - G("interface G extends B { void g(); }\n", "G", BoundKind.SAM), 45.51 - H("interface H extends A { void g(); }\n", "H", BoundKind.SAM), 45.52 + A("interface A { }\n", "A", BoundKind.INTF, MethodKind.NONE), 45.53 + B("interface B { default void m() { } }\n", "B", BoundKind.INTF, MethodKind.DEFAULT_M), 45.54 + C("interface C { void m(); }\n", "C", BoundKind.INTF, MethodKind.ABSTRACT_M), 45.55 + D("interface D extends B { }\n", "D", BoundKind.INTF, MethodKind.DEFAULT_M), 45.56 + E("interface E extends C { }\n", "E", BoundKind.INTF, MethodKind.ABSTRACT_M), 45.57 + F("interface F extends C { void g(); }\n", "F", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.ABSTRACT_M), 45.58 + G("interface G extends B { void g(); }\n", "G", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.DEFAULT_M), 45.59 + H("interface H extends A { void g(); }\n", "H", BoundKind.INTF, MethodKind.ABSTRACT_G), 45.60 OBJECT("", "Object", BoundKind.CLASS), 45.61 STRING("", "String", BoundKind.CLASS); 45.62 45.63 String declStr; 45.64 String typeStr; 45.65 BoundKind boundKind; 45.66 + MethodKind[] methodKinds; 45.67 45.68 - private TypeKind(String declStr, String typeStr, BoundKind boundKind) { 45.69 + private TypeKind(String declStr, String typeStr, BoundKind boundKind, MethodKind... methodKinds) { 45.70 this.declStr = declStr; 45.71 this.typeStr = typeStr; 45.72 this.boundKind = boundKind; 45.73 + this.methodKinds = methodKinds; 45.74 } 45.75 45.76 boolean compatibleSupertype(TypeKind tk) { 45.77 @@ -263,14 +272,22 @@ 45.78 boolean errorExpected = !cInfo.wellFormed(); 45.79 45.80 if (ek.isFunctional) { 45.81 - //first bound must be a SAM 45.82 - errorExpected |= cInfo.types[0].boundKind != BoundKind.SAM; 45.83 - if (cInfo.types.length > 1) { 45.84 - //additional bounds must be ZAMs 45.85 - for (int i = 1; i < cInfo.types.length; i++) { 45.86 - errorExpected |= cInfo.types[i].boundKind != BoundKind.ZAM; 45.87 + List<MethodKind> mks = new ArrayList<>(); 45.88 + for (TypeKind tk : cInfo.types) { 45.89 + if (tk.boundKind == BoundKind.CLASS) { 45.90 + errorExpected = true; 45.91 + break; 45.92 + } else { 45.93 + mks = mergeMethods(mks, Arrays.asList(tk.methodKinds)); 45.94 } 45.95 } 45.96 + int abstractCount = 0; 45.97 + for (MethodKind mk : mks) { 45.98 + if (mk.isAbstract) { 45.99 + abstractCount++; 45.100 + } 45.101 + } 45.102 + errorExpected |= abstractCount != 1; 45.103 } 45.104 45.105 if (errorExpected != diagChecker.errorFound) { 45.106 @@ -281,6 +298,32 @@ 45.107 } 45.108 } 45.109 45.110 + List<MethodKind> mergeMethods(List<MethodKind> l1, List<MethodKind> l2) { 45.111 + List<MethodKind> mergedMethods = new ArrayList<>(l1); 45.112 + for (MethodKind mk2 : l2) { 45.113 + boolean add = !mergedMethods.contains(mk2); 45.114 + switch (mk2) { 45.115 + case ABSTRACT_G: 45.116 + add = add && !mergedMethods.contains(MethodKind.DEFAULT_G); 45.117 + break; 45.118 + case ABSTRACT_M: 45.119 + add = add && !mergedMethods.contains(MethodKind.DEFAULT_M); 45.120 + break; 45.121 + case DEFAULT_G: 45.122 + mergedMethods.remove(MethodKind.ABSTRACT_G); 45.123 + case DEFAULT_M: 45.124 + mergedMethods.remove(MethodKind.ABSTRACT_M); 45.125 + case NONE: 45.126 + add = false; 45.127 + break; 45.128 + } 45.129 + if (add) { 45.130 + mergedMethods.add(mk2); 45.131 + } 45.132 + } 45.133 + return mergedMethods; 45.134 + } 45.135 + 45.136 static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 45.137 45.138 boolean errorFound;
46.1 --- a/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java Thu Apr 11 09:40:22 2013 -0700 46.2 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java Tue Apr 16 08:16:07 2013 -0700 46.3 @@ -427,6 +427,8 @@ 46.4 */ 46.5 public void testReflectCall() { 46.6 Interface I = new Interface("I", DefaultMethod.std("99")); 46.7 + //workaround accessibility issue when loading C with DirectedClassLoader 46.8 + I.addAccessFlag(AccessFlag.PUBLIC); 46.9 Class C = new Class("C", I); 46.10 46.11 Compiler.Flags[] flags = this.verbose ?
47.1 --- a/test/tools/javac/processing/model/element/TestExecutableElement.java Thu Apr 11 09:40:22 2013 -0700 47.2 +++ b/test/tools/javac/processing/model/element/TestExecutableElement.java Tue Apr 16 08:16:07 2013 -0700 47.3 @@ -1,5 +1,5 @@ 47.4 /* 47.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 47.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 47.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.8 * 47.9 * This code is free software; you can redistribute it and/or modify it 47.10 @@ -23,7 +23,7 @@ 47.11 47.12 /* 47.13 * @test 47.14 - * @bug 8005046 47.15 + * @bug 8005046 8011052 47.16 * @summary Test basic properties of javax.lang.element.Element 47.17 * @author Joseph D. Darcy 47.18 * @library /tools/javac/lib 47.19 @@ -35,6 +35,7 @@ 47.20 import java.util.Formatter; 47.21 import java.util.Set; 47.22 import java.util.Objects; 47.23 +import java.util.regex.*; 47.24 import javax.annotation.processing.*; 47.25 import javax.lang.model.SourceVersion; 47.26 import static javax.lang.model.SourceVersion.*; 47.27 @@ -79,9 +80,39 @@ 47.28 47.29 boolean methodIsDefault = method.isDefault(); 47.30 47.31 + if (expectedDefault) { 47.32 + if (!method.getModifiers().contains(Modifier.DEFAULT)) { 47.33 + messager.printMessage(ERROR, 47.34 + "Modifier \"default\" not present as expected.", 47.35 + method); 47.36 + } 47.37 + 47.38 + // Check printing output 47.39 + java.io.Writer stringWriter = new java.io.StringWriter(); 47.40 + eltUtils.printElements(stringWriter, method); 47.41 + Pattern p = Pattern.compile(expectedIsDefault.expectedTextRegex(), Pattern.DOTALL); 47.42 + 47.43 + if (! p.matcher(stringWriter.toString()).matches()) { 47.44 + messager.printMessage(ERROR, 47.45 + new Formatter().format("Unexpected printing ouptput:%n\tgot %s,%n\texpected pattern %s.", 47.46 + stringWriter.toString(), 47.47 + expectedIsDefault.expectedTextRegex()).toString(), 47.48 + method); 47.49 + } 47.50 + 47.51 + System.out.println("\t" + stringWriter.toString()); 47.52 + 47.53 + } else { 47.54 + if (method.getModifiers().contains(Modifier.DEFAULT)) { 47.55 + messager.printMessage(ERROR, 47.56 + "Modifier \"default\" present when not expected.", 47.57 + method); 47.58 + } 47.59 + } 47.60 + 47.61 if (methodIsDefault != expectedDefault) { 47.62 messager.printMessage(ERROR, 47.63 - new Formatter().format("Unexpected Executable.isDefault result: got %s, expected %s", 47.64 + new Formatter().format("Unexpected Executable.isDefault result: got ``%s'', expected ``%s''.", 47.65 expectedDefault, 47.66 methodIsDefault).toString(), 47.67 method); 47.68 @@ -98,6 +129,7 @@ 47.69 @Target(ElementType.METHOD) 47.70 @interface IsDefault { 47.71 boolean value(); 47.72 + String expectedTextRegex() default ""; 47.73 } 47.74 47.75 /** 47.76 @@ -108,6 +140,6 @@ 47.77 boolean process(Set<? extends TypeElement> annotations, 47.78 RoundEnvironment roundEnv); 47.79 47.80 - @IsDefault(true) 47.81 - default void quux() {}; 47.82 + @IsDefault(value=true, expectedTextRegex="\\s*@IsDefault\\(.*\\)\\s*default strictfp void quux\\(\\);\\s*$") 47.83 + default strictfp void quux() {}; 47.84 }
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/tools/javadoc/doclint/ImplicitHeadersTest.java Tue Apr 16 08:16:07 2013 -0700 48.3 @@ -0,0 +1,45 @@ 48.4 +/* 48.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. 48.11 + * 48.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 + * version 2 for more details (a copy is included in the LICENSE file that 48.16 + * accompanied this code). 48.17 + * 48.18 + * You should have received a copy of the GNU General Public License version 48.19 + * 2 along with this work; if not, write to the Free Software Foundation, 48.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 + * 48.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 + * or visit www.oracle.com if you need additional information or have any 48.24 + * questions. 48.25 + */ 48.26 + 48.27 +/* 48.28 + * @test 48.29 + * @bug 8006346 48.30 + * @summary doclint should make allowance for headers generated by standard doclet 48.31 + */ 48.32 + 48.33 +import java.io.File; 48.34 + 48.35 +/** 48.36 + * <h3> Header </h3> 48.37 + */ 48.38 +public class ImplicitHeadersTest { 48.39 + public static void main(String... args) { 48.40 + File testSrc = new File(System.getProperty("test.src")); 48.41 + File testFile = new File(testSrc, ImplicitHeadersTest.class.getSimpleName() + ".java"); 48.42 + String[] javadocArgs = { "-d", "out", testFile.getPath() }; 48.43 + int rc = com.sun.tools.javadoc.Main.execute(javadocArgs); 48.44 + if (rc != 0) 48.45 + throw new Error("unexpected exit: rc=" + rc); 48.46 + } 48.47 +} 48.48 +