Sun, 04 Nov 2012 10:59:42 +0000
7192246: Add type-checking support for default methods
Summary: Add type-checking support for default methods as per Featherweight-Defender document
Reviewed-by: jjg, dlsmith
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Sat Nov 03 21:09:57 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Sun Nov 04 10:59:42 2012 +0000 1.3 @@ -67,7 +67,6 @@ 1.4 if ((mask&NATIVE) != 0) flags.add(Flag.NATIVE); 1.5 if ((mask&INTERFACE) != 0) flags.add(Flag.INTERFACE); 1.6 if ((mask&ABSTRACT) != 0) flags.add(Flag.ABSTRACT); 1.7 - if ((mask&DEFAULT) != 0) flags.add(Flag.DEFAULT); 1.8 if ((mask&STRICTFP) != 0) flags.add(Flag.STRICTFP); 1.9 if ((mask&BRIDGE) != 0) flags.add(Flag.BRIDGE); 1.10 if ((mask&SYNTHETIC) != 0) flags.add(Flag.SYNTHETIC);
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Sat Nov 03 21:09:57 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Sun Nov 04 10:59:42 2012 +0000 2.3 @@ -206,6 +206,9 @@ 2.4 public boolean allowDefaultMethods() { 2.5 return compareTo(JDK1_8) >= 0; 2.6 } 2.7 + public boolean allowStrictMethodClashCheck() { 2.8 + return compareTo(JDK1_8) >= 0; 2.9 + } 2.10 public boolean allowEffectivelyFinalInInnerClasses() { 2.11 return compareTo(JDK1_8) >= 0; 2.12 }
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Nov 03 21:09:57 2012 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Sun Nov 04 10:59:42 2012 +0000 3.3 @@ -1192,9 +1192,9 @@ 3.4 3.5 // check for an inherited implementation 3.6 if ((flags() & ABSTRACT) != 0 || 3.7 - (other.flags() & ABSTRACT) == 0 || 3.8 - !other.isOverridableIn(origin) || 3.9 - !this.isMemberOf(origin, types)) 3.10 + (other.flags() & ABSTRACT) == 0 || 3.11 + !other.isOverridableIn(origin) || 3.12 + !this.isMemberOf(origin, types)) 3.13 return false; 3.14 3.15 // assert types.asSuper(origin.type, other.owner) != null;
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Sat Nov 03 21:09:57 2012 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Sun Nov 04 10:59:42 2012 +0000 4.3 @@ -75,6 +75,7 @@ 4.4 final boolean allowBoxing; 4.5 final boolean allowCovariantReturns; 4.6 final boolean allowObjectToPrimitiveCast; 4.7 + final boolean allowDefaultMethods; 4.8 final ClassReader reader; 4.9 final Check chk; 4.10 JCDiagnostic.Factory diags; 4.11 @@ -98,6 +99,7 @@ 4.12 allowBoxing = source.allowBoxing(); 4.13 allowCovariantReturns = source.allowCovariantReturns(); 4.14 allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); 4.15 + allowDefaultMethods = source.allowDefaultMethods(); 4.16 reader = ClassReader.instance(context); 4.17 chk = Check.instance(context); 4.18 capturedName = names.fromString("<captured wildcard>"); 4.19 @@ -2146,6 +2148,13 @@ 4.20 return List.nil(); 4.21 } 4.22 }; 4.23 + 4.24 + public boolean isDirectSuperInterface(Type t, TypeSymbol tsym) { 4.25 + for (Type t2 : interfaces(tsym.type)) { 4.26 + if (isSameType(t, t2)) return true; 4.27 + } 4.28 + return false; 4.29 + } 4.30 // </editor-fold> 4.31 4.32 // <editor-fold defaultstate="collapsed" desc="isDerivedRaw"> 4.33 @@ -2310,6 +2319,10 @@ 4.34 return false; 4.35 } 4.36 4.37 + public boolean overridesObjectMethod(Symbol msym) { 4.38 + return ((MethodSymbol)msym).implementation(syms.objectType.tsym, this, true) != null; 4.39 + } 4.40 + 4.41 // <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site"> 4.42 class ImplementationCache { 4.43 4.44 @@ -2455,6 +2468,70 @@ 4.45 } 4.46 // </editor-fold> 4.47 4.48 + 4.49 + //where 4.50 + public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { 4.51 + return interfaceCandidates(site, ms, false); 4.52 + } 4.53 + 4.54 + public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms, boolean intfOnly) { 4.55 + Filter<Symbol> filter = new MethodFilter(ms, site, intfOnly); 4.56 + List<MethodSymbol> candidates = List.nil(); 4.57 + for (Symbol s : membersClosure(site, false).getElements(filter)) { 4.58 + if (!site.tsym.isInterface() && !s.owner.isInterface()) { 4.59 + return List.of((MethodSymbol)s); 4.60 + } else if (!candidates.contains(s)) { 4.61 + candidates = candidates.prepend((MethodSymbol)s); 4.62 + } 4.63 + } 4.64 + return prune(candidates, ownerComparator); 4.65 + } 4.66 + 4.67 + public List<MethodSymbol> prune(List<MethodSymbol> methods, Comparator<MethodSymbol> cmp) { 4.68 + ListBuffer<MethodSymbol> methodsMin = ListBuffer.lb(); 4.69 + for (MethodSymbol m1 : methods) { 4.70 + boolean isMin_m1 = true; 4.71 + for (MethodSymbol m2 : methods) { 4.72 + if (m1 == m2) continue; 4.73 + if (cmp.compare(m2, m1) < 0) { 4.74 + isMin_m1 = false; 4.75 + break; 4.76 + } 4.77 + } 4.78 + if (isMin_m1) 4.79 + methodsMin.append(m1); 4.80 + } 4.81 + return methodsMin.toList(); 4.82 + } 4.83 + 4.84 + Comparator<MethodSymbol> ownerComparator = new Comparator<MethodSymbol>() { 4.85 + public int compare(MethodSymbol s1, MethodSymbol s2) { 4.86 + return s1.owner.isSubClass(s2.owner, Types.this) ? -1 : 1; 4.87 + } 4.88 + }; 4.89 + // where 4.90 + private class MethodFilter implements Filter<Symbol> { 4.91 + 4.92 + Symbol msym; 4.93 + Type site; 4.94 + boolean intfOnly; 4.95 + 4.96 + MethodFilter(Symbol msym, Type site, boolean intfOnly) { 4.97 + this.msym = msym; 4.98 + this.site = site; 4.99 + this.intfOnly = intfOnly; 4.100 + } 4.101 + 4.102 + public boolean accepts(Symbol s) { 4.103 + return s.kind == Kinds.MTH && 4.104 + (!intfOnly || s.owner.isInterface()) && 4.105 + s.name == msym.name && 4.106 + s.isInheritedIn(site.tsym, Types.this) && 4.107 + overrideEquivalent(memberType(site, s), memberType(site, msym)); 4.108 + } 4.109 + }; 4.110 + // </editor-fold> 4.111 + 4.112 /** 4.113 * Does t have the same arguments as s? It is assumed that both 4.114 * types are (possibly polymorphic) method types. Monomorphic
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Nov 03 21:09:57 2012 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Sun Nov 04 10:59:42 2012 +0000 5.3 @@ -135,6 +135,7 @@ 5.4 allowStringsInSwitch = source.allowStringsInSwitch(); 5.5 allowPoly = source.allowPoly() && options.isSet("allowPoly"); 5.6 allowLambda = source.allowLambda(); 5.7 + allowDefaultMethods = source.allowDefaultMethods(); 5.8 sourceName = source.name; 5.9 relax = (options.isSet("-retrofit") || 5.10 options.isSet("-relax")); 5.11 @@ -178,6 +179,10 @@ 5.12 */ 5.13 boolean allowCovariantReturns; 5.14 5.15 + /** Switch: support default methods ? 5.16 + */ 5.17 + boolean allowDefaultMethods; 5.18 + 5.19 /** Switch: support lambda expressions ? 5.20 */ 5.21 boolean allowLambda; 5.22 @@ -898,6 +903,10 @@ 5.23 5.24 localEnv.info.lint = lint; 5.25 5.26 + if (isDefaultMethod && types.overridesObjectMethod(m)) { 5.27 + log.error(tree, "default.overrides.object.member", m.name, Kinds.kindName(m.location()), m.location()); 5.28 + } 5.29 + 5.30 // Enter all type parameters into the local method scope. 5.31 for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) 5.32 localEnv.info.scope.enterIfAbsent(l.head.type.tsym); 5.33 @@ -961,10 +970,12 @@ 5.34 log.error(tree.pos(), 5.35 "default.allowed.in.intf.annotation.member"); 5.36 } 5.37 - } else if ((owner.flags() & INTERFACE) != 0 && !isDefaultMethod) { 5.38 - log.error(tree.body.pos(), "intf.meth.cant.have.body"); 5.39 - } else if ((tree.mods.flags & ABSTRACT) != 0) { 5.40 - log.error(tree.pos(), "abstract.meth.cant.have.body"); 5.41 + } else if ((tree.sym.flags() & ABSTRACT) != 0 && !isDefaultMethod) { 5.42 + if ((owner.flags() & INTERFACE) != 0) { 5.43 + log.error(tree.body.pos(), "intf.meth.cant.have.body"); 5.44 + } else { 5.45 + log.error(tree.pos(), "abstract.meth.cant.have.body"); 5.46 + } 5.47 } else if ((tree.mods.flags & NATIVE) != 0) { 5.48 log.error(tree.pos(), "native.meth.cant.have.body"); 5.49 } else { 5.50 @@ -3281,6 +3292,23 @@ 5.51 } 5.52 } 5.53 5.54 + if (env.info.defaultSuperCallSite != null && 5.55 + !types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true).contains(sym)) { 5.56 + Symbol ovSym = null; 5.57 + for (MethodSymbol msym : types.interfaceCandidates(env.enclClass.type, (MethodSymbol)sym, true)) { 5.58 + if (msym.overrides(sym, msym.enclClass(), types, true)) { 5.59 + for (Type i : types.interfaces(env.enclClass.type)) { 5.60 + if (i.tsym.isSubClass(msym.owner, types)) { 5.61 + ovSym = i.tsym; 5.62 + break; 5.63 + } 5.64 + } 5.65 + } 5.66 + } 5.67 + log.error(env.tree.pos(), "illegal.default.super.call", env.info.defaultSuperCallSite, 5.68 + diags.fragment("overridden.default", sym, ovSym)); 5.69 + } 5.70 + 5.71 // Compute the identifier's instantiated type. 5.72 // For methods, we need to compute the instance type by 5.73 // Resolve.instantiate from the symbol's type as well as 5.74 @@ -3700,6 +3728,9 @@ 5.75 // are compatible (i.e. no two define methods with same arguments 5.76 // yet different return types). (JLS 8.4.6.3) 5.77 chk.checkCompatibleSupertypes(tree.pos(), c.type); 5.78 + if (allowDefaultMethods) { 5.79 + chk.checkDefaultMethodClashes(tree.pos(), c.type); 5.80 + } 5.81 } 5.82 5.83 // Check that class does not import the same parameterized interface
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Sat Nov 03 21:09:57 2012 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Sun Nov 04 10:59:42 2012 +0000 6.3 @@ -72,6 +72,10 @@ 6.4 */ 6.5 Attr.ResultInfo returnResult = null; 6.6 6.7 + /** Symbol corresponding to the site of a qualified default super call 6.8 + */ 6.9 + Type defaultSuperCallSite = null; 6.10 + 6.11 /** Duplicate this context, replacing scope field and copying all others. 6.12 */ 6.13 AttrContext dup(Scope scope) { 6.14 @@ -84,6 +88,7 @@ 6.15 info.lint = lint; 6.16 info.enclVar = enclVar; 6.17 info.returnResult = returnResult; 6.18 + info.defaultSuperCallSite = defaultSuperCallSite; 6.19 return info; 6.20 } 6.21
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Nov 03 21:09:57 2012 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Sun Nov 04 10:59:42 2012 +0000 7.3 @@ -119,6 +119,9 @@ 7.4 allowAnnotations = source.allowAnnotations(); 7.5 allowCovariantReturns = source.allowCovariantReturns(); 7.6 allowSimplifiedVarargs = source.allowSimplifiedVarargs(); 7.7 + allowDefaultMethods = source.allowDefaultMethods(); 7.8 + allowStrictMethodClashCheck = source.allowStrictMethodClashCheck() && 7.9 + options.isSet("strictMethodClashCheck"); //pre-lambda guard 7.10 complexInference = options.isSet("complexinference"); 7.11 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); 7.12 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); 7.13 @@ -162,6 +165,14 @@ 7.14 */ 7.15 boolean allowSimplifiedVarargs; 7.16 7.17 + /** Switch: default methods enabled? 7.18 + */ 7.19 + boolean allowDefaultMethods; 7.20 + 7.21 + /** Switch: should unrelated return types trigger a method clash? 7.22 + */ 7.23 + boolean allowStrictMethodClashCheck; 7.24 + 7.25 /** Switch: -complexinference option set? 7.26 */ 7.27 boolean complexInference; 7.28 @@ -1114,7 +1125,7 @@ 7.29 } else if ((sym.owner.flags_field & INTERFACE) != 0) { 7.30 if ((flags & DEFAULT) != 0) { 7.31 mask = InterfaceDefaultMethodMask; 7.32 - implicit = PUBLIC; 7.33 + implicit = PUBLIC | ABSTRACT; 7.34 } else { 7.35 mask = implicit = InterfaceMethodFlags; 7.36 } 7.37 @@ -2047,11 +2058,21 @@ 7.38 undef == null && e != null; 7.39 e = e.sibling) { 7.40 if (e.sym.kind == MTH && 7.41 - (e.sym.flags() & (ABSTRACT|IPROXY)) == ABSTRACT) { 7.42 + (e.sym.flags() & (ABSTRACT|IPROXY|DEFAULT)) == ABSTRACT) { 7.43 MethodSymbol absmeth = (MethodSymbol)e.sym; 7.44 MethodSymbol implmeth = absmeth.implementation(impl, types, true); 7.45 - if (implmeth == null || implmeth == absmeth) 7.46 + if (implmeth == null || implmeth == absmeth) { 7.47 + //look for default implementations 7.48 + if (allowDefaultMethods) { 7.49 + MethodSymbol prov = types.interfaceCandidates(impl.type, absmeth).head; 7.50 + if (prov != null && prov.overrides(absmeth, impl, types, true)) { 7.51 + implmeth = prov; 7.52 + } 7.53 + } 7.54 + } 7.55 + if (implmeth == null || implmeth == absmeth) { 7.56 undef = absmeth; 7.57 + } 7.58 } 7.59 } 7.60 if (undef == null) { 7.61 @@ -2354,7 +2375,7 @@ 7.62 if (m2 == m1) continue; 7.63 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as 7.64 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error 7.65 - if (!types.isSubSignature(sym.type, types.memberType(site, m2), false) && 7.66 + if (!types.isSubSignature(sym.type, types.memberType(site, m2), allowStrictMethodClashCheck) && 7.67 types.hasSameArgs(m2.erasure(types), m1.erasure(types))) { 7.68 sym.flags_field |= CLASH; 7.69 String key = m1 == sym ? 7.70 @@ -2386,7 +2407,7 @@ 7.71 for (Symbol s : types.membersClosure(site, true).getElementsByName(sym.name, cf)) { 7.72 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as 7.73 //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error 7.74 - if (!types.isSubSignature(sym.type, types.memberType(site, s), false) && 7.75 + if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck) && 7.76 types.hasSameArgs(s.erasure(types), sym.erasure(types))) { 7.77 log.error(pos, 7.78 "name.clash.same.erasure.no.hide", 7.79 @@ -2420,6 +2441,62 @@ 7.80 } 7.81 } 7.82 7.83 + void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) { 7.84 + DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site); 7.85 + for (Symbol m : types.membersClosure(site, false).getElements(dcf)) { 7.86 + Assert.check(m.kind == MTH); 7.87 + List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m); 7.88 + if (prov.size() > 1) { 7.89 + ListBuffer<Symbol> abstracts = ListBuffer.lb(); 7.90 + ListBuffer<Symbol> defaults = ListBuffer.lb(); 7.91 + for (MethodSymbol provSym : prov) { 7.92 + if ((provSym.flags() & DEFAULT) != 0) { 7.93 + defaults = defaults.append(provSym); 7.94 + } else if ((provSym.flags() & ABSTRACT) != 0) { 7.95 + abstracts = abstracts.append(provSym); 7.96 + } 7.97 + if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) { 7.98 + //strong semantics - issue an error if two sibling interfaces 7.99 + //have two override-equivalent defaults - or if one is abstract 7.100 + //and the other is default 7.101 + String errKey; 7.102 + Symbol s1 = defaults.first(); 7.103 + Symbol s2; 7.104 + if (defaults.size() > 1) { 7.105 + errKey = "types.incompatible.unrelated.defaults"; 7.106 + s2 = defaults.toList().tail.head; 7.107 + } else { 7.108 + errKey = "types.incompatible.abstract.default"; 7.109 + s2 = abstracts.first(); 7.110 + } 7.111 + log.error(pos, errKey, 7.112 + Kinds.kindName(site.tsym), site, 7.113 + m.name, types.memberType(site, m).getParameterTypes(), 7.114 + s1.location(), s2.location()); 7.115 + break; 7.116 + } 7.117 + } 7.118 + } 7.119 + } 7.120 + } 7.121 + 7.122 + //where 7.123 + private class DefaultMethodClashFilter implements Filter<Symbol> { 7.124 + 7.125 + Type site; 7.126 + 7.127 + DefaultMethodClashFilter(Type site) { 7.128 + this.site = site; 7.129 + } 7.130 + 7.131 + public boolean accepts(Symbol s) { 7.132 + return s.kind == MTH && 7.133 + (s.flags() & DEFAULT) != 0 && 7.134 + s.isInheritedIn(site.tsym, types) && 7.135 + !s.isConstructor(); 7.136 + } 7.137 + } 7.138 + 7.139 /** Report a conflict between a user symbol and a synthetic symbol. 7.140 */ 7.141 private void syntheticError(DiagnosticPosition pos, Symbol sym) {
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Sat Nov 03 21:09:57 2012 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Sun Nov 04 10:59:42 2012 +0000 8.3 @@ -3631,15 +3631,26 @@ 8.4 8.5 public void visitSelect(JCFieldAccess tree) { 8.6 // need to special case-access of the form C.super.x 8.7 - // these will always need an access method. 8.8 + // these will always need an access method, unless C 8.9 + // is a default interface subclassed by the current class. 8.10 boolean qualifiedSuperAccess = 8.11 tree.selected.hasTag(SELECT) && 8.12 - TreeInfo.name(tree.selected) == names._super; 8.13 + TreeInfo.name(tree.selected) == names._super && 8.14 + !types.isDirectSuperInterface(((JCFieldAccess)tree.selected).selected.type, currentClass); 8.15 tree.selected = translate(tree.selected); 8.16 - if (tree.name == names._class) 8.17 + if (tree.name == names._class) { 8.18 result = classOf(tree.selected); 8.19 - else if (tree.name == names._this || tree.name == names._super) 8.20 + } 8.21 + else if (tree.name == names._super && 8.22 + types.isDirectSuperInterface(tree.selected.type, currentClass)) { 8.23 + //default super call!! Not a classic qualified super call 8.24 + TypeSymbol supSym = tree.selected.type.tsym; 8.25 + Assert.checkNonNull(types.asSuper(currentClass.type, supSym)); 8.26 + result = tree; 8.27 + } 8.28 + else if (tree.name == names._this || tree.name == names._super) { 8.29 result = makeThis(tree.pos(), tree.selected.type.tsym); 8.30 + } 8.31 else 8.32 result = access(tree.sym, tree, enclOp, qualifiedSuperAccess); 8.33 }
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Nov 03 21:09:57 2012 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sun Nov 04 10:59:42 2012 +0000 9.3 @@ -560,6 +560,12 @@ 9.4 MethodSymbol m = new MethodSymbol(0, tree.name, null, enclScope.owner); 9.5 m.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, m, tree); 9.6 tree.sym = m; 9.7 + 9.8 + //if this is a default method, add the DEFAULT flag to the enclosing interface 9.9 + if ((tree.mods.flags & DEFAULT) != 0) { 9.10 + m.enclClass().flags_field |= DEFAULT; 9.11 + } 9.12 + 9.13 Env<AttrContext> localEnv = methodEnv(tree, env); 9.14 9.15 DeferredLintHandler prevLintHandler = 9.16 @@ -677,7 +683,7 @@ 9.17 localEnv.info.scope.owner = tree.sym; 9.18 } 9.19 if ((tree.mods.flags & STATIC) != 0 || 9.20 - (env.enclClass.sym.flags() & INTERFACE) != 0) 9.21 + ((env.enclClass.sym.flags() & INTERFACE) != 0 && env.enclMethod == null)) 9.22 localEnv.info.staticLevel++; 9.23 return localEnv; 9.24 } 9.25 @@ -1001,20 +1007,19 @@ 9.26 } 9.27 } 9.28 9.29 - // If this is a class, enter symbols for this and super into 9.30 - // current scope. 9.31 - if ((c.flags_field & INTERFACE) == 0) { 9.32 - VarSymbol thisSym = 9.33 - new VarSymbol(FINAL | HASINIT, names._this, c.type, c); 9.34 - thisSym.pos = Position.FIRSTPOS; 9.35 - env.info.scope.enter(thisSym); 9.36 - if (ct.supertype_field.hasTag(CLASS)) { 9.37 - VarSymbol superSym = 9.38 - new VarSymbol(FINAL | HASINIT, names._super, 9.39 - ct.supertype_field, c); 9.40 - superSym.pos = Position.FIRSTPOS; 9.41 - env.info.scope.enter(superSym); 9.42 - } 9.43 + // enter symbols for 'this' into current scope. 9.44 + VarSymbol thisSym = 9.45 + new VarSymbol(FINAL | HASINIT, names._this, c.type, c); 9.46 + thisSym.pos = Position.FIRSTPOS; 9.47 + env.info.scope.enter(thisSym); 9.48 + // if this is a class, enter symbol for 'super' into current scope. 9.49 + if ((c.flags_field & INTERFACE) == 0 && 9.50 + ct.supertype_field.hasTag(CLASS)) { 9.51 + VarSymbol superSym = 9.52 + new VarSymbol(FINAL | HASINIT, names._super, 9.53 + ct.supertype_field, c); 9.54 + superSym.pos = Position.FIRSTPOS; 9.55 + env.info.scope.enter(superSym); 9.56 } 9.57 9.58 // check that no package exists with same fully qualified name,
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sat Nov 03 21:09:57 2012 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sun Nov 04 10:59:42 2012 +0000 10.3 @@ -52,6 +52,7 @@ 10.4 import java.util.EnumSet; 10.5 import java.util.Iterator; 10.6 import java.util.Map; 10.7 +import java.util.Set; 10.8 10.9 import javax.lang.model.element.ElementVisitor; 10.10 10.11 @@ -88,6 +89,7 @@ 10.12 public final boolean boxingEnabled; // = source.allowBoxing(); 10.13 public final boolean varargsEnabled; // = source.allowVarargs(); 10.14 public final boolean allowMethodHandles; 10.15 + public final boolean allowDefaultMethods; 10.16 private final boolean debugResolve; 10.17 final EnumSet<VerboseResolutionMode> verboseResolutionMode; 10.18 10.19 @@ -122,6 +124,7 @@ 10.20 verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); 10.21 Target target = Target.instance(context); 10.22 allowMethodHandles = target.hasMethodHandles(); 10.23 + allowDefaultMethods = source.allowDefaultMethods(); 10.24 polymorphicSignatureScope = new Scope(syms.noSymbol); 10.25 10.26 inapplicableMethodException = new InapplicableMethodException(diags); 10.27 @@ -1327,6 +1330,42 @@ 10.28 } 10.29 } 10.30 10.31 + Symbol lookupMethod(Env<AttrContext> env, 10.32 + Type site, 10.33 + Name name, 10.34 + List<Type> argtypes, 10.35 + List<Type> typeargtypes, 10.36 + Scope sc, 10.37 + Symbol bestSoFar, 10.38 + boolean allowBoxing, 10.39 + boolean useVarargs, 10.40 + boolean operator, 10.41 + boolean abstractok) { 10.42 + for (Symbol s : sc.getElementsByName(name, new LookupFilter(abstractok))) { 10.43 + bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, 10.44 + bestSoFar, allowBoxing, useVarargs, operator); 10.45 + } 10.46 + return bestSoFar; 10.47 + } 10.48 + //where 10.49 + class LookupFilter implements Filter<Symbol> { 10.50 + 10.51 + boolean abstractOk; 10.52 + 10.53 + LookupFilter(boolean abstractOk) { 10.54 + this.abstractOk = abstractOk; 10.55 + } 10.56 + 10.57 + public boolean accepts(Symbol s) { 10.58 + long flags = s.flags(); 10.59 + return s.kind == MTH && 10.60 + (flags & SYNTHETIC) == 0 && 10.61 + (abstractOk || 10.62 + (flags & DEFAULT) != 0 || 10.63 + (flags & ABSTRACT) == 0); 10.64 + } 10.65 + }; 10.66 + 10.67 /** Find best qualified method matching given name, type and value 10.68 * arguments. 10.69 * @param env The current environment. 10.70 @@ -1371,49 +1410,76 @@ 10.71 boolean allowBoxing, 10.72 boolean useVarargs, 10.73 boolean operator) { 10.74 - boolean abstractOk = true; 10.75 - List<Type> itypes = List.nil(); 10.76 + @SuppressWarnings({"unchecked","rawtypes"}) 10.77 + List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() }; 10.78 + InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK; 10.79 for (TypeSymbol s : superclasses(intype)) { 10.80 bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, 10.81 s.members(), bestSoFar, allowBoxing, useVarargs, operator, true); 10.82 - //We should not look for abstract methods if receiver is a concrete class 10.83 - //(as concrete classes are expected to implement all abstracts coming 10.84 - //from superinterfaces) 10.85 - abstractOk &= (s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0; 10.86 - if (abstractOk) { 10.87 + if (name == names.init) return bestSoFar; 10.88 + iphase = (iphase == null) ? null : iphase.update(s, this); 10.89 + if (iphase != null) { 10.90 for (Type itype : types.interfaces(s.type)) { 10.91 - itypes = types.union(types.closure(itype), itypes); 10.92 + itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]); 10.93 } 10.94 } 10.95 - if (name == names.init) break; 10.96 } 10.97 10.98 Symbol concrete = bestSoFar.kind < ERR && 10.99 (bestSoFar.flags() & ABSTRACT) == 0 ? 10.100 bestSoFar : methodNotFound; 10.101 10.102 - if (name != names.init) { 10.103 + for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) { 10.104 + if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethods) break; 10.105 //keep searching for abstract methods 10.106 - for (Type itype : itypes) { 10.107 + for (Type itype : itypes[iphase2.ordinal()]) { 10.108 if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) 10.109 + if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && 10.110 + (itype.tsym.flags() & DEFAULT) == 0) continue; 10.111 bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, 10.112 - itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); 10.113 - if (concrete != bestSoFar && 10.114 - concrete.kind < ERR && bestSoFar.kind < ERR && 10.115 - types.isSubSignature(concrete.type, bestSoFar.type)) { 10.116 - //this is an hack - as javac does not do full membership checks 10.117 - //most specific ends up comparing abstract methods that might have 10.118 - //been implemented by some concrete method in a subclass and, 10.119 - //because of raw override, it is possible for an abstract method 10.120 - //to be more specific than the concrete method - so we need 10.121 - //to explicitly call that out (see CR 6178365) 10.122 - bestSoFar = concrete; 10.123 - } 10.124 + itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); 10.125 + if (concrete != bestSoFar && 10.126 + concrete.kind < ERR && bestSoFar.kind < ERR && 10.127 + types.isSubSignature(concrete.type, bestSoFar.type)) { 10.128 + //this is an hack - as javac does not do full membership checks 10.129 + //most specific ends up comparing abstract methods that might have 10.130 + //been implemented by some concrete method in a subclass and, 10.131 + //because of raw override, it is possible for an abstract method 10.132 + //to be more specific than the concrete method - so we need 10.133 + //to explicitly call that out (see CR 6178365) 10.134 + bestSoFar = concrete; 10.135 + } 10.136 } 10.137 } 10.138 return bestSoFar; 10.139 } 10.140 10.141 + enum InterfaceLookupPhase { 10.142 + ABSTRACT_OK() { 10.143 + @Override 10.144 + InterfaceLookupPhase update(Symbol s, Resolve rs) { 10.145 + //We should not look for abstract methods if receiver is a concrete class 10.146 + //(as concrete classes are expected to implement all abstracts coming 10.147 + //from superinterfaces) 10.148 + if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) { 10.149 + return this; 10.150 + } else if (rs.allowDefaultMethods) { 10.151 + return DEFAULT_OK; 10.152 + } else { 10.153 + return null; 10.154 + } 10.155 + } 10.156 + }, 10.157 + DEFAULT_OK() { 10.158 + @Override 10.159 + InterfaceLookupPhase update(Symbol s, Resolve rs) { 10.160 + return this; 10.161 + } 10.162 + }; 10.163 + 10.164 + abstract InterfaceLookupPhase update(Symbol s, Resolve rs); 10.165 + } 10.166 + 10.167 /** 10.168 * Return an Iterable object to scan the superclasses of a given type. 10.169 * It's crucial that the scan is done lazily, as we don't want to accidentally 10.170 @@ -1467,34 +1533,6 @@ 10.171 }; 10.172 } 10.173 10.174 - /** 10.175 - * Lookup a method with given name and argument types in a given scope 10.176 - */ 10.177 - Symbol lookupMethod(Env<AttrContext> env, 10.178 - Type site, 10.179 - Name name, 10.180 - List<Type> argtypes, 10.181 - List<Type> typeargtypes, 10.182 - Scope sc, 10.183 - Symbol bestSoFar, 10.184 - boolean allowBoxing, 10.185 - boolean useVarargs, 10.186 - boolean operator, 10.187 - boolean abstractok) { 10.188 - for (Symbol s : sc.getElementsByName(name, lookupFilter)) { 10.189 - bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, 10.190 - bestSoFar, allowBoxing, useVarargs, operator); 10.191 - } 10.192 - return bestSoFar; 10.193 - } 10.194 - //where 10.195 - Filter<Symbol> lookupFilter = new Filter<Symbol>() { 10.196 - public boolean accepts(Symbol s) { 10.197 - return s.kind == MTH && 10.198 - (s.flags() & SYNTHETIC) == 0; 10.199 - } 10.200 - }; 10.201 - 10.202 /** Find unqualified method matching given name, type and value arguments. 10.203 * @param env The current environment. 10.204 * @param name The method's name. 10.205 @@ -1920,7 +1958,7 @@ 10.206 /** Check that sym is not an abstract method. 10.207 */ 10.208 void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { 10.209 - if ((sym.flags() & ABSTRACT) != 0) 10.210 + if ((sym.flags() & ABSTRACT) != 0 && (sym.flags() & DEFAULT) == 0) 10.211 log.error(pos, "abstract.cant.be.accessed.directly", 10.212 kindName(sym), sym, sym.location()); 10.213 } 10.214 @@ -2744,9 +2782,47 @@ 10.215 if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; 10.216 env1 = env1.outer; 10.217 } 10.218 + if (allowDefaultMethods && c.isInterface() && 10.219 + name == names._super && !isStatic(env) && 10.220 + types.isDirectSuperInterface(c.type, env.enclClass.sym)) { 10.221 + //this might be a default super call if one of the superinterfaces is 'c' 10.222 + for (Type t : pruneInterfaces(env.enclClass.type)) { 10.223 + if (t.tsym == c) { 10.224 + env.info.defaultSuperCallSite = t; 10.225 + return new VarSymbol(0, names._super, 10.226 + types.asSuper(env.enclClass.type, c), env.enclClass.sym); 10.227 + } 10.228 + } 10.229 + //find a direct superinterface that is a subtype of 'c' 10.230 + for (Type i : types.interfaces(env.enclClass.type)) { 10.231 + if (i.tsym.isSubClass(c, types) && i.tsym != c) { 10.232 + log.error(pos, "illegal.default.super.call", c, 10.233 + diags.fragment("redundant.supertype", c, i)); 10.234 + return syms.errSymbol; 10.235 + } 10.236 + } 10.237 + Assert.error(); 10.238 + } 10.239 log.error(pos, "not.encl.class", c); 10.240 return syms.errSymbol; 10.241 } 10.242 + //where 10.243 + private List<Type> pruneInterfaces(Type t) { 10.244 + ListBuffer<Type> result = ListBuffer.lb(); 10.245 + for (Type t1 : types.interfaces(t)) { 10.246 + boolean shouldAdd = true; 10.247 + for (Type t2 : types.interfaces(t)) { 10.248 + if (t1 != t2 && types.isSubtypeNoCapture(t2, t1)) { 10.249 + shouldAdd = false; 10.250 + } 10.251 + } 10.252 + if (shouldAdd) { 10.253 + result.append(t1); 10.254 + } 10.255 + } 10.256 + return result.toList(); 10.257 + } 10.258 + 10.259 10.260 /** 10.261 * Resolve `c.this' for an enclosing class c that contains the
11.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sat Nov 03 21:09:57 2012 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sun Nov 04 10:59:42 2012 +0000 11.3 @@ -115,6 +115,9 @@ 11.4 */ 11.5 boolean lintClassfile; 11.6 11.7 + /** Switch: allow default methods 11.8 + */ 11.9 + boolean allowDefaultMethods; 11.10 11.11 /** Switch: preserve parameter names from the variable table. 11.12 */ 11.13 @@ -279,6 +282,7 @@ 11.14 allowVarargs = source.allowVarargs(); 11.15 allowAnnotations = source.allowAnnotations(); 11.16 allowSimplifiedVarargs = source.allowSimplifiedVarargs(); 11.17 + allowDefaultMethods = source.allowDefaultMethods(); 11.18 saveParameterNames = options.isSet("save-parameter-names"); 11.19 cacheCompletionFailure = options.isUnset("dev"); 11.20 preferSource = "source".equals(options.get("-Xprefer")); 11.21 @@ -937,6 +941,18 @@ 11.22 11.23 new AttributeReader(names.Code, V45_3, MEMBER_ATTRIBUTE) { 11.24 protected void read(Symbol sym, int attrLen) { 11.25 + if (currentOwner.isInterface() && 11.26 + (sym.flags_field & ABSTRACT) == 0 && !name.equals(names.clinit)) { 11.27 + if (majorVersion > Target.JDK1_8.majorVersion || 11.28 + //todo replace with Target.Version when available 11.29 + (majorVersion == Target.JDK1_8.majorVersion && minorVersion >= Target.JDK1_8.minorVersion)) { 11.30 + currentOwner.flags_field |= DEFAULT; 11.31 + sym.flags_field |= DEFAULT | ABSTRACT; 11.32 + } else { 11.33 + //protect against ill-formed classfiles 11.34 + throw new CompletionFailure(currentOwner, "default method found in pre JDK 8 classfile"); 11.35 + } 11.36 + } 11.37 if (readAllOfClassFile || saveParameterNames) 11.38 ((MethodSymbol)sym).code = readCode(sym); 11.39 else
12.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Sat Nov 03 21:09:57 2012 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Sun Nov 04 10:59:42 2012 +0000 12.3 @@ -1540,7 +1540,7 @@ 12.4 List<Type> interfaces = types.interfaces(c.type); 12.5 List<Type> typarams = c.type.getTypeArguments(); 12.6 12.7 - int flags = adjustFlags(c.flags()); 12.8 + int flags = adjustFlags(c.flags() & ~DEFAULT); 12.9 if ((flags & PROTECTED) != 0) flags |= PUBLIC; 12.10 flags = flags & ClassFlags & ~STRICTFP; 12.11 if ((flags & INTERFACE) == 0) flags |= ACC_SUPER; 12.12 @@ -1676,6 +1676,8 @@ 12.13 result |= ACC_BRIDGE; 12.14 if ((flags & VARARGS) != 0 && target.useVarargsFlag()) 12.15 result |= ACC_VARARGS; 12.16 + if ((flags & DEFAULT) != 0) 12.17 + result &= ~ABSTRACT; 12.18 return result; 12.19 } 12.20
13.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Items.java Sat Nov 03 21:09:57 2012 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Items.java Sun Nov 04 10:59:42 2012 +0000 13.3 @@ -523,7 +523,7 @@ 13.4 Item invoke() { 13.5 MethodType mtype = (MethodType)member.externalType(types); 13.6 int rescode = Code.typecode(mtype.restype); 13.7 - if ((member.owner.flags() & Flags.INTERFACE) != 0) { 13.8 + if ((member.owner.flags() & Flags.INTERFACE) != 0 && !nonvirtual) { 13.9 code.emitInvokeinterface(pool.put(member), mtype); 13.10 } else if (nonvirtual) { 13.11 code.emitInvokespecial(pool.put(member), mtype);
14.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sat Nov 03 21:09:57 2012 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sun Nov 04 10:59:42 2012 +0000 14.3 @@ -574,7 +574,7 @@ 14.4 interface expected here 14.5 14.6 compiler.err.intf.meth.cant.have.body=\ 14.7 - interface methods cannot have body 14.8 + interface abstract methods cannot have body 14.9 14.10 compiler.err.invalid.annotation.member.type=\ 14.11 invalid type for annotation member 14.12 @@ -941,6 +941,31 @@ 14.13 compiler.err.types.incompatible.diff.ret=\ 14.14 types {0} and {1} are incompatible; both define {2}, but with unrelated return types 14.15 14.16 +# 0: kind, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol 14.17 +compiler.err.types.incompatible.unrelated.defaults=\ 14.18 + {0} {1} inherits unrelated defaults for {2}({3}) from types {4} and {5} 14.19 + 14.20 +# 0: kind, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol 14.21 +compiler.err.types.incompatible.abstract.default=\ 14.22 + {0} {1} inherits abstract and default for {2}({3}) from types {4} and {5} 14.23 + 14.24 +# 0: name, 1: kind, 2: symbol 14.25 +compiler.err.default.overrides.object.member=\ 14.26 + default method {0} in {1} {2} overrides a member of java.lang.Object 14.27 + 14.28 +# 0: type, 1: message segment 14.29 +compiler.err.illegal.default.super.call=\ 14.30 + bad type qualifier {0} in default super call\n\ 14.31 + {1} 14.32 + 14.33 +# 0: symbol, 1: type 14.34 +compiler.misc.overridden.default=\ 14.35 + method {0} is overridden in {2} 14.36 + 14.37 +# 0: symbol, 1: symbol 14.38 +compiler.misc.redundant.supertype=\ 14.39 + redundant interface {0} is extended by {1} 14.40 + 14.41 compiler.err.unclosed.char.lit=\ 14.42 unclosed character literal 14.43
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/defaultMethods/ClassReaderTest/ClassReaderTest.java Sun Nov 04 10:59:42 2012 +0000 15.3 @@ -0,0 +1,32 @@ 15.4 +/* 15.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @summary check that default methods don't cause ClassReader to complete classes recursively 15.30 + * @author Maurizio Cimadamore 15.31 + * @compile -XDallowDefaultMethods pkg/Foo.java 15.32 + * @compile ClassReaderTest.java 15.33 + */ 15.34 + 15.35 +abstract class ClassReaderTest implements pkg.Foo {}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/defaultMethods/ClassReaderTest/pkg/Foo.java Sun Nov 04 10:59:42 2012 +0000 16.3 @@ -0,0 +1,34 @@ 16.4 +/* 16.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +package pkg; 16.28 + 16.29 +public interface Foo { 16.30 + default void m1() { Impl.m1(this); } 16.31 + default void m2() { Impl.m2(this); } 16.32 +} 16.33 + 16.34 +class Impl { 16.35 + static void m1(Foo f) { } 16.36 + static void m2(Foo f) { } 16.37 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/defaultMethods/Neg01.java Sun Nov 04 10:59:42 2012 +0000 17.3 @@ -0,0 +1,18 @@ 17.4 +/* 17.5 + * @test /nodynamiccopyright/ 17.6 + * @summary negative test for ambiguous defaults 17.7 + * @compile/fail/ref=Neg01.out -XDallowDefaultMethods -XDrawDiagnostics Neg01.java 17.8 + */ 17.9 + 17.10 +class Neg01 { 17.11 + interface IA { default int m() { return Neg01.m1(this); } } 17.12 + interface IB { default int m() { return Neg01.m2(this); } } 17.13 + 17.14 + static class A implements IA {} 17.15 + static class B implements IB {} 17.16 + 17.17 + static class AB implements IA, IB {} 17.18 + 17.19 + static int m1(IA a) { return 0; } 17.20 + static int m2(IB b) { return 0; } 17.21 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/defaultMethods/Neg01.out Sun Nov 04 10:59:42 2012 +0000 18.3 @@ -0,0 +1,2 @@ 18.4 +Neg01.java:14:12: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg01.AB, m, , Neg01.IA, Neg01.IB 18.5 +1 error
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/defaultMethods/Neg02.java Sun Nov 04 10:59:42 2012 +0000 19.3 @@ -0,0 +1,26 @@ 19.4 +/* 19.5 + * @test /nodynamiccopyright/ 19.6 + * @summary check that ill-formed MI hierarchies do not compile 19.7 + * @compile/fail/ref=Neg02.out -XDallowDefaultMethods -XDrawDiagnostics Neg02.java 19.8 + */ 19.9 + 19.10 +class Neg02 { 19.11 + interface A { 19.12 + default void m() { Neg02.impl(this); } 19.13 + } 19.14 + 19.15 + interface B { 19.16 + default void m() { Neg02.impl(this); } 19.17 + } 19.18 + 19.19 + static class X implements A, B { } //error 19.20 + 19.21 + void test(X x) { 19.22 + x.m(); 19.23 + ((A)x).m(); 19.24 + ((B)x).m(); 19.25 + } 19.26 + 19.27 + static void impl(A a) { } 19.28 + static void impl(B b) { } 19.29 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/defaultMethods/Neg02.out Sun Nov 04 10:59:42 2012 +0000 20.3 @@ -0,0 +1,2 @@ 20.4 +Neg02.java:16:13: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg02.X, m, , Neg02.A, Neg02.B 20.5 +1 error
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/defaultMethods/Neg03.java Sun Nov 04 10:59:42 2012 +0000 21.3 @@ -0,0 +1,38 @@ 21.4 +/* 21.5 + * @test /nodynamiccopyright/ 21.6 + * @summary check that re-abstraction works properly 21.7 + * @compile/fail/ref=Neg03.out -XDallowDefaultMethods -XDrawDiagnostics Neg03.java 21.8 + */ 21.9 + 21.10 +class Neg03 { 21.11 + interface A { 21.12 + default void m() { Neg03.one(this); } 21.13 + } 21.14 + 21.15 + interface B { 21.16 + default void m() { Neg03.two(this); } 21.17 + } 21.18 + 21.19 + interface C extends A, B { 21.20 + default void m() { Neg03.one(this); } 21.21 + } 21.22 + 21.23 + static class X implements C, A { } //ok - ignore extraneous remix of A 21.24 + 21.25 + interface D extends A, B { 21.26 + void m(); // ok - m() is not reabstracted! 21.27 + } 21.28 + 21.29 + static class Y implements D, A { } // invalid - abstract D.m() 21.30 + 21.31 + interface E extends A { 21.32 + void m(); // reabstraction of m() 21.33 + } 21.34 + 21.35 + static class W implements D, E { } // invalid - abstracts D.m()/E.m() 21.36 + 21.37 + static class Z implements D, A, B { } // invalid - abstract D.m() 21.38 + 21.39 + static void one(Object a) { } 21.40 + static void two(Object a) { } 21.41 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/defaultMethods/Neg03.out Sun Nov 04 10:59:42 2012 +0000 22.3 @@ -0,0 +1,4 @@ 22.4 +Neg03.java:26:12: compiler.err.does.not.override.abstract: Neg03.Y, m(), Neg03.D 22.5 +Neg03.java:32:12: compiler.err.does.not.override.abstract: Neg03.W, m(), Neg03.D 22.6 +Neg03.java:34:12: compiler.err.does.not.override.abstract: Neg03.Z, m(), Neg03.D 22.7 +3 errors
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/defaultMethods/Neg04.java Sun Nov 04 10:59:42 2012 +0000 23.3 @@ -0,0 +1,14 @@ 23.4 +/* 23.5 + * @test /nodynamiccopyright/ 23.6 + * @summary check that default method must have most specific return type 23.7 + * @compile/fail/ref=Neg04.out -XDallowDefaultMethods -XDrawDiagnostics Neg04.java 23.8 + */ 23.9 + 23.10 +class Neg04 { 23.11 + interface IA1 { Integer m(); } 23.12 + interface IA2 extends IA1 { default Number m() { return Neg04.m(this); } } //error 23.13 + 23.14 + abstract class C implements IA1, IA2 {} 23.15 + 23.16 + static int m(IA2 a) { return 0; } 23.17 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/defaultMethods/Neg04.out Sun Nov 04 10:59:42 2012 +0000 24.3 @@ -0,0 +1,2 @@ 24.4 +Neg04.java:9:48: compiler.err.override.incompatible.ret: (compiler.misc.clashes.with: m(), Neg04.IA2, m(), Neg04.IA1), java.lang.Number, java.lang.Integer 24.5 +1 error
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/tools/javac/defaultMethods/Neg05.java Sun Nov 04 10:59:42 2012 +0000 25.3 @@ -0,0 +1,16 @@ 25.4 +/* 25.5 + * @test /nodynamiccopyright/ 25.6 + * @summary check that abstract methods are compatible with inherited defaults 25.7 + * @compile/fail/ref=Neg05.out -XDallowDefaultMethods -XDrawDiagnostics Neg05.java 25.8 + */ 25.9 + 25.10 +class Neg05 { 25.11 + interface IA1 { default Number m() { return Neg05.m1(this); } } 25.12 + interface IA2 extends IA1 { default Integer m() { return Neg05.m2(this); } } 25.13 + interface IA3 extends IA2 { Number m(); } //error 25.14 + 25.15 + static class C implements IA3{} 25.16 + 25.17 + static int m1(IA1 a) { return 0; } 25.18 + static int m2(IA2 b) { return 0; } 25.19 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javac/defaultMethods/Neg05.out Sun Nov 04 10:59:42 2012 +0000 26.3 @@ -0,0 +1,3 @@ 26.4 +Neg05.java:10:40: compiler.err.override.incompatible.ret: (compiler.misc.clashes.with: m(), Neg05.IA3, m(), Neg05.IA2), java.lang.Number, java.lang.Integer 26.5 +Neg05.java:12:12: compiler.err.does.not.override.abstract: Neg05.C, m(), Neg05.IA3 26.6 +2 errors
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/defaultMethods/Neg06.java Sun Nov 04 10:59:42 2012 +0000 27.3 @@ -0,0 +1,16 @@ 27.4 +/* 27.5 + * @test /nodynamiccopyright/ 27.6 + * @summary flow analysis is not run on inlined default bodies 27.7 + * @compile/fail/ref=Neg06.out -XDallowDefaultMethods -XDrawDiagnostics Neg06.java 27.8 + */ 27.9 + 27.10 +class Neg06 { 27.11 + 27.12 + interface A { 27.13 + default String m() { C.m(); } 27.14 + } 27.15 + 27.16 + static class C { 27.17 + static String m() { return ""; } 27.18 + } 27.19 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/defaultMethods/Neg06.out Sun Nov 04 10:59:42 2012 +0000 28.3 @@ -0,0 +1,2 @@ 28.4 +Neg06.java:10:37: compiler.err.missing.ret.stmt 28.5 +1 error
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/tools/javac/defaultMethods/Neg07.java Sun Nov 04 10:59:42 2012 +0000 29.3 @@ -0,0 +1,21 @@ 29.4 +/* 29.5 + * @test /nodynamiccopyright/ 29.6 + * @summary check that default overrides are properly type-checked 29.7 + * @compile/fail/ref=Neg07.out -XDallowDefaultMethods -XDrawDiagnostics Neg07.java 29.8 + */ 29.9 + 29.10 +class Neg07 { 29.11 + interface I { 29.12 + default int m() { return 1; } 29.13 + } 29.14 + 29.15 + static class C1 { 29.16 + public void m() { } //incompatible return 29.17 + } 29.18 + 29.19 + static class C2 extends C1 implements I { } 29.20 + 29.21 + static class C3 implements I { 29.22 + public void m() { } //incompatible return 29.23 + } 29.24 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/tools/javac/defaultMethods/Neg07.out Sun Nov 04 10:59:42 2012 +0000 30.3 @@ -0,0 +1,3 @@ 30.4 +Neg07.java:16:12: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C1, m(), Neg07.I), void, int 30.5 +Neg07.java:19:21: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C3, m(), Neg07.I), void, int 30.6 +2 errors
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/tools/javac/defaultMethods/Neg08.java Sun Nov 04 10:59:42 2012 +0000 31.3 @@ -0,0 +1,20 @@ 31.4 +/* 31.5 + * @test /nodynamiccopyright/ 31.6 + * @summary check that default overrides are properly type-checked 31.7 + * @compile/fail/ref=Neg08.out -XDallowDefaultMethods -XDrawDiagnostics Neg08.java 31.8 + */ 31.9 +class Neg08 { 31.10 + interface I { 31.11 + default void m() { } 31.12 + } 31.13 + 31.14 + static class C1 { 31.15 + void m() { } //weaker modifier 31.16 + } 31.17 + 31.18 + static class C2 extends C1 implements I { } 31.19 + 31.20 + static class C3 implements I { 31.21 + void m() { } //weaker modifier 31.22 + } 31.23 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/defaultMethods/Neg08.out Sun Nov 04 10:59:42 2012 +0000 32.3 @@ -0,0 +1,3 @@ 32.4 +Neg08.java:15:12: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C1, m(), Neg08.I), public 32.5 +Neg08.java:18:14: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C3, m(), Neg08.I), public 32.6 +2 errors
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/defaultMethods/Neg09.java Sun Nov 04 10:59:42 2012 +0000 33.3 @@ -0,0 +1,22 @@ 33.4 +/* 33.5 + * @test /nodynamiccopyright/ 33.6 + * @summary check that default overrides are properly type-checked 33.7 + * @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg09.java 33.8 + */ 33.9 +import java.util.List; 33.10 + 33.11 +class Neg09 { 33.12 + interface I { 33.13 + default List<String> m() { return null; } 33.14 + } 33.15 + 33.16 + static class C1 { 33.17 + public List m() { return null; } //unchecked (return) override 33.18 + } 33.19 + 33.20 + static class C2 extends C1 implements I { } 33.21 + 33.22 + static class C3 implements I { 33.23 + public List m() { return null; } //unchecked (return) override 33.24 + } 33.25 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javac/defaultMethods/Neg09.out Sun Nov 04 10:59:42 2012 +0000 34.3 @@ -0,0 +1,5 @@ 34.4 +Neg09.java:17:12: compiler.warn.override.unchecked.ret: (compiler.misc.unchecked.implement: m(), Neg09.C1, m(), Neg09.I), java.util.List, java.util.List<java.lang.String> 34.5 +Neg09.java:20:21: compiler.warn.override.unchecked.ret: (compiler.misc.unchecked.implement: m(), Neg09.C3, m(), Neg09.I), java.util.List, java.util.List<java.lang.String> 34.6 +- compiler.err.warnings.and.werror 34.7 +1 error 34.8 +2 warnings
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/defaultMethods/Neg10.java Sun Nov 04 10:59:42 2012 +0000 35.3 @@ -0,0 +1,20 @@ 35.4 +/* 35.5 + * @test /nodynamiccopyright/ 35.6 + * @summary check that default overrides are properly type-checked 35.7 + * @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg10.java 35.8 + */ 35.9 +class Neg10 { 35.10 + interface I<X extends Exception> { 35.11 + default void m() throws X { } 35.12 + } 35.13 + 35.14 + static class C1 { 35.15 + public void m() throws Exception { } //unchecked (throws) override 35.16 + } 35.17 + 35.18 + static class C2<Z extends Exception> extends C1 implements I<Z> { } 35.19 + 35.20 + static class C3<Z extends Exception> implements I<Z> { 35.21 + public void m() throws Exception { } //unchecked (throws) override 35.22 + } 35.23 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/defaultMethods/Neg10.out Sun Nov 04 10:59:42 2012 +0000 36.3 @@ -0,0 +1,5 @@ 36.4 +Neg10.java:15:12: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C1, m(), Neg10.I), java.lang.Exception 36.5 +Neg10.java:18:21: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C3, m(), Neg10.I), java.lang.Exception 36.6 +- compiler.err.warnings.and.werror 36.7 +1 error 36.8 +2 warnings
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/tools/javac/defaultMethods/Neg11.java Sun Nov 04 10:59:42 2012 +0000 37.3 @@ -0,0 +1,20 @@ 37.4 +/* 37.5 + * @test /nodynamiccopyright/ 37.6 + * @summary check that default overrides are properly type-checked 37.7 + * @compile/fail/ref=Neg11.out -XDallowDefaultMethods -XDrawDiagnostics Neg11.java 37.8 + */ 37.9 +class Neg11 { 37.10 + interface I { 37.11 + default void m() { } 37.12 + } 37.13 + 37.14 + static class C1 { 37.15 + public void m() throws Exception { } //bad throws 37.16 + } 37.17 + 37.18 + static class C2 extends C1 implements I { } 37.19 + 37.20 + static class C3 implements I { 37.21 + public void m() throws Exception { } //bad throws 37.22 + } 37.23 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/defaultMethods/Neg11.out Sun Nov 04 10:59:42 2012 +0000 38.3 @@ -0,0 +1,3 @@ 38.4 +Neg11.java:15:12: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C1, m(), Neg11.I), java.lang.Exception 38.5 +Neg11.java:18:21: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C3, m(), Neg11.I), java.lang.Exception 38.6 +2 errors
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/defaultMethods/Neg12.java Sun Nov 04 10:59:42 2012 +0000 39.3 @@ -0,0 +1,27 @@ 39.4 +/* 39.5 + * @test /nodynamiccopyright/ 39.6 + * @summary check that abstract methods are discarded in overload resolution diags 39.7 + * @compile/fail/ref=Neg12.out -XDallowDefaultMethods -XDrawDiagnostics Neg12.java 39.8 + */ 39.9 +class Neg12 { 39.10 + 39.11 + interface I1 { 39.12 + default void m(String s) {}; 39.13 + } 39.14 + 39.15 + interface I2 { 39.16 + void m(String s); 39.17 + } 39.18 + 39.19 + static class B { 39.20 + void m(Integer i) { } 39.21 + } 39.22 + 39.23 + static class C extends B implements I1 { } 39.24 + static class D extends B implements I2 { } 39.25 + 39.26 + void test(C c, D d) { 39.27 + c.m(); 39.28 + d.m(); 39.29 + } 39.30 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/tools/javac/defaultMethods/Neg12.out Sun Nov 04 10:59:42 2012 +0000 40.3 @@ -0,0 +1,4 @@ 40.4 +Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2 40.5 +Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, ,{(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch))} 40.6 +Neg12.java:25:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Integer, compiler.misc.no.args, kindname.class, Neg12.B, (compiler.misc.arg.length.mismatch) 40.7 +3 errors
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/tools/javac/defaultMethods/Neg13.java Sun Nov 04 10:59:42 2012 +0000 41.3 @@ -0,0 +1,18 @@ 41.4 +/* 41.5 + * @test /nodynamiccopyright/ 41.6 + * @summary check that default method overriding object members are flagged as error 41.7 + * @compile/fail/ref=Neg13.out -XDallowDefaultMethods -XDrawDiagnostics Neg13.java 41.8 + */ 41.9 +interface Neg13 { 41.10 + default protected Object clone() { return null; } //protected not allowed here 41.11 + default boolean equals(Object obj) { return false; } 41.12 + default protected void finalize() { } //protected not allowed here 41.13 + default Class<?> getClass() { return null; } 41.14 + default int hashCode() { return 0; } 41.15 + default void notify() { } 41.16 + default void notifyAll() { } 41.17 + default String toString() { return null; } 41.18 + default void wait() { } 41.19 + default void wait(long timeout) { } 41.20 + default void wait(long timeout, int nanos) { } 41.21 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/defaultMethods/Neg13.out Sun Nov 04 10:59:42 2012 +0000 42.3 @@ -0,0 +1,12 @@ 42.4 +Neg13.java:7:30: compiler.err.mod.not.allowed.here: protected 42.5 +Neg13.java:9:28: compiler.err.mod.not.allowed.here: protected 42.6 +Neg13.java:8:21: compiler.err.default.overrides.object.member: equals, kindname.interface, Neg13 42.7 +Neg13.java:10:22: compiler.err.override.meth: (compiler.misc.cant.override: getClass(), Neg13, getClass(), java.lang.Object), final 42.8 +Neg13.java:11:17: compiler.err.default.overrides.object.member: hashCode, kindname.interface, Neg13 42.9 +Neg13.java:12:18: compiler.err.override.meth: (compiler.misc.cant.override: notify(), Neg13, notify(), java.lang.Object), final 42.10 +Neg13.java:13:18: compiler.err.override.meth: (compiler.misc.cant.override: notifyAll(), Neg13, notifyAll(), java.lang.Object), final 42.11 +Neg13.java:14:20: compiler.err.default.overrides.object.member: toString, kindname.interface, Neg13 42.12 +Neg13.java:15:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(), Neg13, wait(), java.lang.Object), final 42.13 +Neg13.java:16:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(long), Neg13, wait(long), java.lang.Object), final 42.14 +Neg13.java:17:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(long,int), Neg13, wait(long,int), java.lang.Object), final 42.15 +11 errors
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/defaultMethods/Neg14.java Sun Nov 04 10:59:42 2012 +0000 43.3 @@ -0,0 +1,11 @@ 43.4 +/* 43.5 + * @test /nodynamiccopyright/ 43.6 + * @summary check that a class cannot have two sibling interfaces with a default and abstract method 43.7 + * @compile/fail/ref=Neg14.out -XDallowDefaultMethods -XDrawDiagnostics Neg14.java 43.8 + */ 43.9 +class Neg14 { 43.10 + interface IA { int m(); } 43.11 + interface IB { default int m() { return 1; } } 43.12 + 43.13 + abstract class AB implements IA, IB {} 43.14 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/tools/javac/defaultMethods/Neg14.out Sun Nov 04 10:59:42 2012 +0000 44.3 @@ -0,0 +1,2 @@ 44.4 +Neg14.java:10:14: compiler.err.types.incompatible.abstract.default: kindname.class, Neg14.AB, m, , Neg14.IB, Neg14.IA 44.5 +1 error
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/tools/javac/defaultMethods/Neg15.java Sun Nov 04 10:59:42 2012 +0000 45.3 @@ -0,0 +1,14 @@ 45.4 +/* 45.5 + * @test /nodynamiccopyright/ 45.6 + * @summary check that level skipping in default super calls is correctly rejected 45.7 + * @compile/fail/ref=Neg15.out -XDallowDefaultMethods -XDrawDiagnostics Neg15.java 45.8 + */ 45.9 +class Neg15 { 45.10 + interface I { default void m() { } } 45.11 + interface J extends I { default void m() { } } 45.12 + interface K extends I {} 45.13 + 45.14 + static class C implements J, K { 45.15 + void foo() { K.super.m(); } 45.16 + } 45.17 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/tools/javac/defaultMethods/Neg15.out Sun Nov 04 10:59:42 2012 +0000 46.3 @@ -0,0 +1,2 @@ 46.4 +Neg15.java:12:31: compiler.err.illegal.default.super.call: Neg15.K, (compiler.misc.overridden.default: m(), Neg15.J) 46.5 +1 error
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/defaultMethods/Neg16.java Sun Nov 04 10:59:42 2012 +0000 47.3 @@ -0,0 +1,13 @@ 47.4 +/* 47.5 + * @test /nodynamiccopyright/ 47.6 + * @summary check that level skipping in default super calls is correctly rejected 47.7 + * @compile/fail/ref=Neg16.out -XDallowDefaultMethods -XDrawDiagnostics Neg16.java 47.8 + */ 47.9 +class Neg16 { 47.10 + interface I { default void m() { } } 47.11 + interface J extends I { default void m() { } } 47.12 + 47.13 + static class C implements I, J { 47.14 + void foo() { I.super.m(); } 47.15 + } 47.16 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/tools/javac/defaultMethods/Neg16.out Sun Nov 04 10:59:42 2012 +0000 48.3 @@ -0,0 +1,2 @@ 48.4 +Neg16.java:11:23: compiler.err.illegal.default.super.call: Neg16.I, (compiler.misc.redundant.supertype: Neg16.I, Neg16.J) 48.5 +1 error
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/defaultMethods/Pos01.java Sun Nov 04 10:59:42 2012 +0000 49.3 @@ -0,0 +1,61 @@ 49.4 +/* 49.5 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +/* 49.28 + * @test 49.29 + * @summary basic test for default methods 49.30 + * @ignore awaits lambda support 49.31 + * @author Maurizio Cimadamore 49.32 + * @compile -XDallowLambda -XDallowPoly -XDallowDefaultMethods Pos01.java 49.33 + */ 49.34 + 49.35 +import java.util.*; 49.36 + 49.37 +class Pos01 { 49.38 + 49.39 + interface Mapper<T> { 49.40 + T map(T in); 49.41 + } 49.42 + 49.43 + interface ExtendedList<T> extends List<T> { 49.44 + default List<T> testMap(Mapper<T> r) { 49.45 + return Pos01.<T>listMapper(this, r); 49.46 + } 49.47 + } 49.48 + 49.49 + static class MyList<E> extends ArrayList<E> implements ExtendedList<E> {} 49.50 + 49.51 + public static void main(String[] args) { 49.52 + MyList<Integer> l = new MyList<Integer>(); 49.53 + l.add(1); l.add(2); l.add(3); 49.54 + l.testMap((Integer x) -> x * x ); 49.55 + } 49.56 + 49.57 + static <T> List<T> listMapper(List<T> l, Mapper<T> mapper) { 49.58 + MyList<T> new_list = new MyList<T>(); 49.59 + for (T el : l) { 49.60 + new_list.add(mapper.map(el)); 49.61 + } 49.62 + return new_list; 49.63 + } 49.64 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/defaultMethods/Pos02.java Sun Nov 04 10:59:42 2012 +0000 50.3 @@ -0,0 +1,48 @@ 50.4 +/* 50.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +/* 50.28 + * @test 50.29 + * @summary test for explicit resolution of ambiguous default methods 50.30 + * @author Maurizio Cimadamore 50.31 + * @compile -XDallowDefaultMethods Pos02.java 50.32 + */ 50.33 + 50.34 +class Pos02 { 50.35 + interface IA { default int m() { return Pos02.m1(this); } } 50.36 + interface IB { default int m() { return Pos02.m2(this); } } 50.37 + 50.38 + static class A implements IA {} 50.39 + static class B implements IB {} 50.40 + 50.41 + static class AB implements IA, IB { 50.42 + public int m() { return 0; } 50.43 + void test() { 50.44 + AB.this.m(); 50.45 + IA.super.m(); 50.46 + } 50.47 + } 50.48 + 50.49 + static int m1(IA a) { return 0; } 50.50 + static int m2(IB b) { return 0; } 50.51 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/defaultMethods/Pos04.java Sun Nov 04 10:59:42 2012 +0000 51.3 @@ -0,0 +1,43 @@ 51.4 +/* 51.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +/* 51.28 + * @test 51.29 + * @summary test for overriding with default method 51.30 + * @author Maurizio Cimadamore 51.31 + * @compile -XDallowDefaultMethods Pos04.java 51.32 + */ 51.33 + 51.34 +class Pos04 { 51.35 + interface A { default int m() { return Pos04.m(this); } } 51.36 + static abstract class B { public int m() { return 0; } } 51.37 + 51.38 + static class C extends B implements A { 51.39 + void test() { 51.40 + C.this.m(); 51.41 + A.super.m(); 51.42 + } 51.43 + } 51.44 + 51.45 + static int m(A a) { return 0; } 51.46 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/tools/javac/defaultMethods/Pos05.java Sun Nov 04 10:59:42 2012 +0000 52.3 @@ -0,0 +1,45 @@ 52.4 +/* 52.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. 52.11 + * 52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.15 + * version 2 for more details (a copy is included in the LICENSE file that 52.16 + * accompanied this code). 52.17 + * 52.18 + * You should have received a copy of the GNU General Public License version 52.19 + * 2 along with this work; if not, write to the Free Software Foundation, 52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.21 + * 52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.23 + * or visit www.oracle.com if you need additional information or have any 52.24 + * questions. 52.25 + */ 52.26 + 52.27 +/* 52.28 + * @test 52.29 + * @summary check that indirectly inherited default methods are discovered during resolution 52.30 + * @author Maurizio Cimadamore 52.31 + * @compile -XDallowDefaultMethods Pos05.java 52.32 + */ 52.33 + 52.34 +class Pos05 { 52.35 + interface A { 52.36 + default void m() { Pos05.impl(this); } 52.37 + } 52.38 + 52.39 + interface B extends A { } 52.40 + 52.41 + static class E implements B { } 52.42 + 52.43 + void test(E e) { 52.44 + e.m(); 52.45 + } 52.46 + 52.47 + static void impl(A a) { } 52.48 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/tools/javac/defaultMethods/Pos06.java Sun Nov 04 10:59:42 2012 +0000 53.3 @@ -0,0 +1,49 @@ 53.4 +/* 53.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. 53.11 + * 53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.15 + * version 2 for more details (a copy is included in the LICENSE file that 53.16 + * accompanied this code). 53.17 + * 53.18 + * You should have received a copy of the GNU General Public License version 53.19 + * 2 along with this work; if not, write to the Free Software Foundation, 53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.21 + * 53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.23 + * or visit www.oracle.com if you need additional information or have any 53.24 + * questions. 53.25 + */ 53.26 + 53.27 +/* 53.28 + * @test 53.29 + * @summary check that well-formed MI hierarchies behaves well w.r.t. method resolution (i.e. no ambiguities) 53.30 + * @author Maurizio Cimadamore 53.31 + * @compile -XDallowDefaultMethods Pos06.java 53.32 + */ 53.33 + 53.34 +class Pos06 { 53.35 + interface A { 53.36 + default void m() { Pos06.impl(this); } 53.37 + } 53.38 + 53.39 + interface B extends A { 53.40 + default void m() { Pos06.impl(this); } 53.41 + } 53.42 + 53.43 + static class X implements A, B { } 53.44 + 53.45 + void test(X x) { 53.46 + x.m(); 53.47 + ((A)x).m(); 53.48 + ((B)x).m(); 53.49 + } 53.50 + 53.51 + static void impl(Object a) { } 53.52 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javac/defaultMethods/Pos07.java Sun Nov 04 10:59:42 2012 +0000 54.3 @@ -0,0 +1,44 @@ 54.4 +/* 54.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +/* 54.28 + * @test 54.29 + * @summary check that compilation order does not matter 54.30 + * @author Maurizio Cimadamore 54.31 + * @compile -XDallowDefaultMethods Pos07.java 54.32 + */ 54.33 + 54.34 +class Pos07 { 54.35 + interface A { 54.36 + default void foo() { Pos07.impl(this); } 54.37 + default void bar() { Pos07.impl(this); } 54.38 + } 54.39 + 54.40 + static class C implements B, A {} 54.41 + 54.42 + interface B extends A { 54.43 + default void foo() { Pos07.impl(this); } 54.44 + } 54.45 + 54.46 + static void impl(A a) {} 54.47 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javac/defaultMethods/Pos08.java Sun Nov 04 10:59:42 2012 +0000 55.3 @@ -0,0 +1,46 @@ 55.4 +/* 55.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +/* 55.28 + * @test 55.29 + * @summary check that common overrider solves default method conflicts 55.30 + * @author Maurizio Cimadamore 55.31 + * @compile -XDallowDefaultMethods Pos08.java 55.32 + */ 55.33 + 55.34 +class Pos08 { 55.35 + interface A { 55.36 + default void m() { Pos08.a(this); } 55.37 + } 55.38 + 55.39 + interface B { 55.40 + default void m() { Pos08.b(this); } 55.41 + } 55.42 + 55.43 + interface C extends A, B { 55.44 + default void m() { Pos08.b(this); } 55.45 + } 55.46 + 55.47 + static void a(A o) { } 55.48 + static void b(B o) { } 55.49 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/tools/javac/defaultMethods/Pos10.java Sun Nov 04 10:59:42 2012 +0000 56.3 @@ -0,0 +1,43 @@ 56.4 +/* 56.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. 56.11 + * 56.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.15 + * version 2 for more details (a copy is included in the LICENSE file that 56.16 + * accompanied this code). 56.17 + * 56.18 + * You should have received a copy of the GNU General Public License version 56.19 + * 2 along with this work; if not, write to the Free Software Foundation, 56.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.21 + * 56.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.23 + * or visit www.oracle.com if you need additional information or have any 56.24 + * questions. 56.25 + */ 56.26 + 56.27 +/* 56.28 + * @test 56.29 + * @summary check that type-variables in generic extension decl can be accessed from default impl 56.30 + * @author Maurizio Cimadamore 56.31 + * @compile -XDallowDefaultMethods Pos10.java 56.32 + */ 56.33 + 56.34 +class Pos10 { 56.35 + interface Function<X,Y> { 56.36 + Y apply(X x); 56.37 + } 56.38 + 56.39 + interface A<T> { 56.40 + default <R> void m(Function<T,R> f) { Impl.<T,R>m(this, f); } 56.41 + } 56.42 + 56.43 + static class Impl { 56.44 + static <T,R> void m(A<T> a, Function<T,R> f) { } 56.45 + } 56.46 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/test/tools/javac/defaultMethods/Pos11.java Sun Nov 04 10:59:42 2012 +0000 57.3 @@ -0,0 +1,56 @@ 57.4 +/* 57.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. 57.11 + * 57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.15 + * version 2 for more details (a copy is included in the LICENSE file that 57.16 + * accompanied this code). 57.17 + * 57.18 + * You should have received a copy of the GNU General Public License version 57.19 + * 2 along with this work; if not, write to the Free Software Foundation, 57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.21 + * 57.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 57.23 + * or visit www.oracle.com if you need additional information or have any 57.24 + * questions. 57.25 + */ 57.26 + 57.27 +/* 57.28 + * @test 57.29 + * @summary complex test with conflict resolution via overriding 57.30 + * @author Brian Goetz 57.31 + * @compile -XDallowDefaultMethods Pos11.java 57.32 + */ 57.33 + 57.34 +class Pos11 { 57.35 + interface A { 57.36 + default void get() { Pos11.one(this); } 57.37 + } 57.38 + 57.39 + interface B { 57.40 + default void get() { Pos11.two(this); } 57.41 + } 57.42 + 57.43 + interface C extends A { 57.44 + default void get() { Pos11.two(this); } 57.45 + } 57.46 + 57.47 + interface D extends A, B { 57.48 + default void get() { Pos11.two(this); } 57.49 + } 57.50 + 57.51 + static class X implements C { } 57.52 + 57.53 + static class Y implements C, A { } 57.54 + 57.55 + static class Z implements D, A, B { } 57.56 + 57.57 + static void one(Object a) { } 57.58 + static void two(Object a) { } 57.59 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/test/tools/javac/defaultMethods/Pos12.java Sun Nov 04 10:59:42 2012 +0000 58.3 @@ -0,0 +1,39 @@ 58.4 +/* 58.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 + * 58.8 + * This code is free software; you can redistribute it and/or modify it 58.9 + * under the terms of the GNU General Public License version 2 only, as 58.10 + * published by the Free Software Foundation. 58.11 + * 58.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 58.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.15 + * version 2 for more details (a copy is included in the LICENSE file that 58.16 + * accompanied this code). 58.17 + * 58.18 + * You should have received a copy of the GNU General Public License version 58.19 + * 2 along with this work; if not, write to the Free Software Foundation, 58.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.21 + * 58.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 58.23 + * or visit www.oracle.com if you need additional information or have any 58.24 + * questions. 58.25 + */ 58.26 + 58.27 +/* 58.28 + * @test 58.29 + * @summary check that 'this' can be used from within an extension method 58.30 + * @compile -XDallowDefaultMethods Pos12.java 58.31 + */ 58.32 + 58.33 +interface Pos12 { 58.34 + 58.35 + default Object m() { 58.36 + Object o = this; 58.37 + f(this); 58.38 + return this; 58.39 + } 58.40 + 58.41 + void f(Object o); 58.42 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/test/tools/javac/defaultMethods/Pos13.java Sun Nov 04 10:59:42 2012 +0000 59.3 @@ -0,0 +1,62 @@ 59.4 +/* 59.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. 59.11 + * 59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.15 + * version 2 for more details (a copy is included in the LICENSE file that 59.16 + * accompanied this code). 59.17 + * 59.18 + * You should have received a copy of the GNU General Public License version 59.19 + * 2 along with this work; if not, write to the Free Software Foundation, 59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.21 + * 59.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 59.23 + * or visit www.oracle.com if you need additional information or have any 59.24 + * questions. 59.25 + */ 59.26 + 59.27 +/* 59.28 + * @test 59.29 + * @summary qualified 'this' inside default method causes StackOverflowException 59.30 + * @compile -XDallowDefaultMethods Pos13.java 59.31 + */ 59.32 + 59.33 +public class Pos13 { 59.34 + 59.35 + static int assertionCount = 0; 59.36 + 59.37 + static void assertTrue(boolean cond) { 59.38 + assertionCount++; 59.39 + if (!cond) 59.40 + throw new AssertionError(); 59.41 + } 59.42 + 59.43 + interface Outer { 59.44 + abstract void doSomething(); 59.45 + 59.46 + default void m() { 59.47 + new SubOuter() { 59.48 + public void doSomething() { 59.49 + Outer.this.doSomething(); 59.50 + } 59.51 + }.doSomething(); 59.52 + } 59.53 + } 59.54 + 59.55 + interface SubOuter extends Outer { } 59.56 + 59.57 + static class E implements Outer { 59.58 + public void doSomething() { assertTrue(true); } 59.59 + } 59.60 + 59.61 + public static void main(String[] args) { 59.62 + new E().m(); 59.63 + assertTrue(assertionCount == 1); 59.64 + } 59.65 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 60.2 +++ b/test/tools/javac/defaultMethods/Pos14.java Sun Nov 04 10:59:42 2012 +0000 60.3 @@ -0,0 +1,39 @@ 60.4 +/* 60.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 60.7 + * 60.8 + * This code is free software; you can redistribute it and/or modify it 60.9 + * under the terms of the GNU General Public License version 2 only, as 60.10 + * published by the Free Software Foundation. 60.11 + * 60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 60.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 60.15 + * version 2 for more details (a copy is included in the LICENSE file that 60.16 + * accompanied this code). 60.17 + * 60.18 + * You should have received a copy of the GNU General Public License version 60.19 + * 2 along with this work; if not, write to the Free Software Foundation, 60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 60.21 + * 60.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 60.23 + * or visit www.oracle.com if you need additional information or have any 60.24 + * questions. 60.25 + */ 60.26 + 60.27 +/* 60.28 + * @test 60.29 + * @summary check that overload resolution selects most specific signature 60.30 + * @compile -XDallowDefaultMethods Pos14.java 60.31 + */ 60.32 + 60.33 +class Pos14 { 60.34 + interface A { default Object m() { return null; } } 60.35 + static abstract class B { abstract public String m(); } 60.36 + 60.37 + static abstract class C extends B implements A { 60.38 + void test() { 60.39 + m().length(); 60.40 + } 60.41 + } 60.42 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/test/tools/javac/defaultMethods/Pos15.java Sun Nov 04 10:59:42 2012 +0000 61.3 @@ -0,0 +1,39 @@ 61.4 +/* 61.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.7 + * 61.8 + * This code is free software; you can redistribute it and/or modify it 61.9 + * under the terms of the GNU General Public License version 2 only, as 61.10 + * published by the Free Software Foundation. 61.11 + * 61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.15 + * version 2 for more details (a copy is included in the LICENSE file that 61.16 + * accompanied this code). 61.17 + * 61.18 + * You should have received a copy of the GNU General Public License version 61.19 + * 2 along with this work; if not, write to the Free Software Foundation, 61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.21 + * 61.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 61.23 + * or visit www.oracle.com if you need additional information or have any 61.24 + * questions. 61.25 + */ 61.26 + 61.27 +/* 61.28 + * @test 61.29 + * @summary check that overload resolution selects most specific signature 61.30 + * @compile -XDallowDefaultMethods Pos15.java 61.31 + */ 61.32 + 61.33 +class Pos15 { 61.34 + interface A { default String m() { return null; } } 61.35 + static abstract class B { abstract public Object m(); } 61.36 + 61.37 + static abstract class C extends B implements A { 61.38 + void test() { 61.39 + m().length(); 61.40 + } 61.41 + } 61.42 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/test/tools/javac/defaultMethods/Pos16.java Sun Nov 04 10:59:42 2012 +0000 62.3 @@ -0,0 +1,42 @@ 62.4 +/* 62.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 62.7 + * 62.8 + * This code is free software; you can redistribute it and/or modify it 62.9 + * under the terms of the GNU General Public License version 2 only, as 62.10 + * published by the Free Software Foundation. 62.11 + * 62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 62.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 62.15 + * version 2 for more details (a copy is included in the LICENSE file that 62.16 + * accompanied this code). 62.17 + * 62.18 + * You should have received a copy of the GNU General Public License version 62.19 + * 2 along with this work; if not, write to the Free Software Foundation, 62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 62.21 + * 62.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 62.23 + * or visit www.oracle.com if you need additional information or have any 62.24 + * questions. 62.25 + */ 62.26 + 62.27 +/* 62.28 + * @test 62.29 + * @summary 'class wins' should not short-circuit overload resolution 62.30 + * @compile -XDallowDefaultMethods Pos16.java 62.31 + */ 62.32 + 62.33 +class Pos16 { 62.34 + interface I { 62.35 + default String m(Integer i) { return ""; } 62.36 + } 62.37 + 62.38 + class C implements I { 62.39 + Integer m(Object o) { return 1; } 62.40 + } 62.41 + 62.42 + void test(C c) { 62.43 + c.m(1).length(); 62.44 + } 62.45 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/test/tools/javac/defaultMethods/TestDefaultBody.java Sun Nov 04 10:59:42 2012 +0000 63.3 @@ -0,0 +1,125 @@ 63.4 +/* 63.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.7 + * 63.8 + * This code is free software; you can redistribute it and/or modify it 63.9 + * under the terms of the GNU General Public License version 2 only, as 63.10 + * published by the Free Software Foundation. 63.11 + * 63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.15 + * version 2 for more details (a copy is included in the LICENSE file that 63.16 + * accompanied this code). 63.17 + * 63.18 + * You should have received a copy of the GNU General Public License version 63.19 + * 2 along with this work; if not, write to the Free Software Foundation, 63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 63.21 + * 63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 63.23 + * or visit www.oracle.com if you need additional information or have any 63.24 + * questions. 63.25 + */ 63.26 + 63.27 +/* 63.28 + * @test 63.29 + * @ignore awaits for VM support 63.30 + * @summary check that code attributed for default methods is correctly generated 63.31 + * @compile -XDallowDefaultMethods TestDefaultBody.java 63.32 + * @run main TestDefaultBody 63.33 + */ 63.34 + 63.35 +import com.sun.tools.classfile.AccessFlags; 63.36 +import com.sun.tools.classfile.Attribute; 63.37 +import com.sun.tools.classfile.ClassFile; 63.38 +import com.sun.tools.classfile.ConstantPool.*; 63.39 +import com.sun.tools.classfile.Code_attribute; 63.40 +import com.sun.tools.classfile.Instruction; 63.41 +import com.sun.tools.classfile.Method; 63.42 + 63.43 +import com.sun.tools.classfile.Opcode; 63.44 +import java.io.*; 63.45 + 63.46 +public class TestDefaultBody { 63.47 + 63.48 + interface TestInterface { 63.49 + int no_default(int i); 63.50 + default int yes_default(int i) { return impl(this, i); } 63.51 + } 63.52 + 63.53 + static int impl(TestInterface ti, int i) { return 0; } 63.54 + 63.55 + static final String TARGET_CLASS_NAME = "TestDefaultBody"; 63.56 + static final String TARGET_NAME = "impl"; 63.57 + static final String TARGET_TYPE = "(LTestDefaultBody$TestInterface;I)I"; 63.58 + static final String SUBTEST_NAME = TestInterface.class.getName() + ".class"; 63.59 + static final String TEST_METHOD_NAME = "yes_default"; 63.60 + 63.61 + public static void main(String... args) throws Exception { 63.62 + new TestDefaultBody().run(); 63.63 + } 63.64 + 63.65 + public void run() throws Exception { 63.66 + String workDir = System.getProperty("test.classes"); 63.67 + File compiledTest = new File(workDir, SUBTEST_NAME); 63.68 + verifyDefaultBody(compiledTest); 63.69 + } 63.70 + 63.71 + void verifyDefaultBody(File f) { 63.72 + System.err.println("verify: " + f); 63.73 + try { 63.74 + ClassFile cf = ClassFile.read(f); 63.75 + Method testMethod = null; 63.76 + Code_attribute codeAttr = null; 63.77 + for (Method m : cf.methods) { 63.78 + codeAttr = (Code_attribute)m.attributes.get(Attribute.Code); 63.79 + String mname = m.getName(cf.constant_pool); 63.80 + if (mname.equals(TEST_METHOD_NAME)) { 63.81 + testMethod = m; 63.82 + break; 63.83 + } else { 63.84 + codeAttr = null; 63.85 + } 63.86 + } 63.87 + if (testMethod == null) { 63.88 + throw new Error("Test method not found"); 63.89 + } 63.90 + if (testMethod.access_flags.is(AccessFlags.ACC_ABSTRACT)) { 63.91 + throw new Error("Test method is abstract"); 63.92 + } 63.93 + if (codeAttr == null) { 63.94 + throw new Error("Code attribute in test method not found"); 63.95 + } 63.96 + 63.97 + boolean found = false; 63.98 + for (Instruction instr : codeAttr.getInstructions()) { 63.99 + if (instr.getOpcode() == Opcode.INVOKESTATIC) { 63.100 + found = true; 63.101 + int pc_index = instr.getShort(1); 63.102 + CONSTANT_Methodref_info mref = (CONSTANT_Methodref_info)cf.constant_pool.get(pc_index); 63.103 + String className = mref.getClassName(); 63.104 + String targetName = mref.getNameAndTypeInfo().getName(); 63.105 + String targetType = mref.getNameAndTypeInfo().getType(); 63.106 + 63.107 + if (!className.equals(TARGET_CLASS_NAME)) { 63.108 + throw new Error("unexpected class in default method body " + className); 63.109 + } 63.110 + if (!targetName.equals(TARGET_NAME)) { 63.111 + throw new Error("unexpected method name in default method body " + targetName); 63.112 + } 63.113 + if (!targetType.equals(TARGET_TYPE)) { 63.114 + throw new Error("unexpected method type in default method body " + targetType); 63.115 + } 63.116 + break; 63.117 + } 63.118 + } 63.119 + 63.120 + if (!found) { 63.121 + throw new Error("no invokestatic found in default method body"); 63.122 + } 63.123 + } catch (Exception e) { 63.124 + e.printStackTrace(); 63.125 + throw new Error("error reading " + f +": " + e); 63.126 + } 63.127 + } 63.128 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/test/tools/javac/defaultMethods/TestNoBridgeOnDefaults.java Sun Nov 04 10:59:42 2012 +0000 64.3 @@ -0,0 +1,87 @@ 64.4 +/* 64.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 64.7 + * 64.8 + * This code is free software; you can redistribute it and/or modify it 64.9 + * under the terms of the GNU General Public License version 2 only, as 64.10 + * published by the Free Software Foundation. 64.11 + * 64.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 64.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 64.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 64.15 + * version 2 for more details (a copy is included in the LICENSE file that 64.16 + * accompanied this code). 64.17 + * 64.18 + * You should have received a copy of the GNU General Public License version 64.19 + * 2 along with this work; if not, write to the Free Software Foundation, 64.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 64.21 + * 64.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 64.23 + * or visit www.oracle.com if you need additional information or have any 64.24 + * questions. 64.25 + */ 64.26 + 64.27 +/* 64.28 + * @test 64.29 + * @ignore awaits for VM support 64.30 + * @summary check that javac does not generate bridge methods for defaults 64.31 + * @compile -XDallowDefaultMethods TestNoBridgeOnDefaults.java 64.32 + * @run main TestNoBridgeOnDefaults 64.33 + */ 64.34 + 64.35 +import com.sun.tools.classfile.ClassFile; 64.36 +import com.sun.tools.classfile.ConstantPool.*; 64.37 +import com.sun.tools.classfile.Method; 64.38 + 64.39 +import java.io.*; 64.40 + 64.41 +public class TestNoBridgeOnDefaults { 64.42 + 64.43 + interface A<X> { 64.44 + default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); } 64.45 + } 64.46 + 64.47 + static abstract class B<X> implements A<X> { } 64.48 + 64.49 + interface C<X> extends A<X> { 64.50 + default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); } 64.51 + } 64.52 + 64.53 + static abstract class D<X> extends B<X> implements C<X> { } 64.54 + 64.55 + static class Impl { 64.56 + static <X, Y> A<X> m1(A<X> rec, X x, Y y) { return null; } 64.57 + static <X, Y> C<X> m2(C<X> rec, X x, Y y) { return null; } 64.58 + } 64.59 + 64.60 + static final String[] SUBTEST_NAMES = { B.class.getName() + ".class", D.class.getName() + ".class" }; 64.61 + static final String TEST_METHOD_NAME = "m"; 64.62 + 64.63 + public static void main(String... args) throws Exception { 64.64 + new TestNoBridgeOnDefaults().run(); 64.65 + } 64.66 + 64.67 + public void run() throws Exception { 64.68 + String workDir = System.getProperty("test.classes"); 64.69 + for (int i = 0 ; i < SUBTEST_NAMES.length ; i ++) { 64.70 + File compiledTest = new File(workDir, SUBTEST_NAMES[i]); 64.71 + checkNoBridgeOnDefaults(compiledTest); 64.72 + } 64.73 + } 64.74 + 64.75 + void checkNoBridgeOnDefaults(File f) { 64.76 + System.err.println("check: " + f); 64.77 + try { 64.78 + ClassFile cf = ClassFile.read(f); 64.79 + for (Method m : cf.methods) { 64.80 + String mname = m.getName(cf.constant_pool); 64.81 + if (mname.equals(TEST_METHOD_NAME)) { 64.82 + throw new Error("unexpected bridge method found " + m); 64.83 + } 64.84 + } 64.85 + } catch (Exception e) { 64.86 + e.printStackTrace(); 64.87 + throw new Error("error reading " + f +": " + e); 64.88 + } 64.89 + } 64.90 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/test/tools/javac/defaultMethods/crossCompile/Clinit.java Sun Nov 04 10:59:42 2012 +0000 65.3 @@ -0,0 +1,29 @@ 65.4 +/* 65.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 65.7 + * 65.8 + * This code is free software; you can redistribute it and/or modify it 65.9 + * under the terms of the GNU General Public License version 2 only, as 65.10 + * published by the Free Software Foundation. 65.11 + * 65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 65.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 65.15 + * version 2 for more details (a copy is included in the LICENSE file that 65.16 + * accompanied this code). 65.17 + * 65.18 + * You should have received a copy of the GNU General Public License version 65.19 + * 2 along with this work; if not, write to the Free Software Foundation, 65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 65.21 + * 65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 65.23 + * or visit www.oracle.com if you need additional information or have any 65.24 + * questions. 65.25 + */ 65.26 +interface Clinit { 65.27 + String s = Inner.m(); 65.28 + 65.29 + static class Inner { 65.30 + static String m() { return ""; } 65.31 + } 65.32 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 66.2 +++ b/test/tools/javac/defaultMethods/crossCompile/CrossCompile.java Sun Nov 04 10:59:42 2012 +0000 66.3 @@ -0,0 +1,34 @@ 66.4 +/* 66.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 66.7 + * 66.8 + * This code is free software; you can redistribute it and/or modify it 66.9 + * under the terms of the GNU General Public License version 2 only, as 66.10 + * published by the Free Software Foundation. 66.11 + * 66.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 66.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 66.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 66.15 + * version 2 for more details (a copy is included in the LICENSE file that 66.16 + * accompanied this code). 66.17 + * 66.18 + * You should have received a copy of the GNU General Public License version 66.19 + * 2 along with this work; if not, write to the Free Software Foundation, 66.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 66.21 + * 66.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 66.23 + * or visit www.oracle.com if you need additional information or have any 66.24 + * questions. 66.25 + */ 66.26 + 66.27 +/* 66.28 + * @test 66.29 + * @summary check that clinit in interface doesn't cause spurious default method diagnostics 66.30 + * @compile -source 1.4 -target 1.4 Clinit.java 66.31 + * @compile CrossCompile.java 66.32 + */ 66.33 +class CrossCompile { 66.34 + void test() { 66.35 + String s = Clinit.s; 66.36 + } 66.37 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/test/tools/javac/defaultMethods/fd/FDTest.java Sun Nov 04 10:59:42 2012 +0000 67.3 @@ -0,0 +1,147 @@ 67.4 +/* 67.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 67.7 + * 67.8 + * This code is free software; you can redistribute it and/or modify it 67.9 + * under the terms of the GNU General Public License version 2 only, as 67.10 + * published by the Free Software Foundation. 67.11 + * 67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 67.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 67.15 + * version 2 for more details (a copy is included in the LICENSE file that 67.16 + * accompanied this code). 67.17 + * 67.18 + * You should have received a copy of the GNU General Public License version 67.19 + * 2 along with this work; if not, write to the Free Software Foundation, 67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 67.21 + * 67.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 67.23 + * or visit www.oracle.com if you need additional information or have any 67.24 + * questions. 67.25 + */ 67.26 + 67.27 +/* 67.28 + * @test 67.29 + * @summary Automatic test for checking correctness of default resolution 67.30 + */ 67.31 + 67.32 +import shapegen.*; 67.33 + 67.34 +import com.sun.source.util.JavacTask; 67.35 + 67.36 +import java.net.URI; 67.37 +import java.util.Arrays; 67.38 +import java.util.ArrayList; 67.39 +import java.util.Collection; 67.40 +import java.util.List; 67.41 + 67.42 +import javax.tools.Diagnostic; 67.43 +import javax.tools.JavaCompiler; 67.44 +import javax.tools.JavaFileObject; 67.45 +import javax.tools.SimpleJavaFileObject; 67.46 +import javax.tools.StandardJavaFileManager; 67.47 +import javax.tools.ToolProvider; 67.48 + 67.49 +public class FDTest { 67.50 + 67.51 + enum TestKind { 67.52 + POSITIVE, 67.53 + NEGATIVE; 67.54 + 67.55 + Collection<Hierarchy> getHierarchy(HierarchyGenerator hg) { 67.56 + return this == POSITIVE ? 67.57 + hg.getOK() : hg.getErr(); 67.58 + } 67.59 + } 67.60 + 67.61 + public static void main(String[] args) throws Exception { 67.62 + //create default shared JavaCompiler - reused across multiple compilations 67.63 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 67.64 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 67.65 + 67.66 + HierarchyGenerator hg = new HierarchyGenerator(); 67.67 + for (TestKind tk : TestKind.values()) { 67.68 + for (Hierarchy hs : tk.getHierarchy(hg)) { 67.69 + new FDTest(tk, hs).run(comp, fm); 67.70 + } 67.71 + } 67.72 + } 67.73 + 67.74 + TestKind tk; 67.75 + Hierarchy hs; 67.76 + DefenderTestSource source; 67.77 + DiagnosticChecker diagChecker; 67.78 + 67.79 + FDTest(TestKind tk, Hierarchy hs) { 67.80 + this.tk = tk; 67.81 + this.hs = hs; 67.82 + this.source = new DefenderTestSource(); 67.83 + this.diagChecker = new DiagnosticChecker(); 67.84 + } 67.85 + 67.86 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 67.87 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 67.88 + Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source)); 67.89 + try { 67.90 + ct.analyze(); 67.91 + } catch (Throwable ex) { 67.92 + throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); 67.93 + } 67.94 + check(); 67.95 + } 67.96 + 67.97 + void check() { 67.98 + boolean errorExpected = tk == TestKind.NEGATIVE; 67.99 + if (errorExpected != diagChecker.errorFound) { 67.100 + throw new AssertionError("problem in source: \n" + 67.101 + "\nerror found = " + diagChecker.errorFound + 67.102 + "\nerror expected = " + errorExpected + 67.103 + "\n" + dumpHierarchy() + 67.104 + "\n" + source.getCharContent(true)); 67.105 + } 67.106 + } 67.107 + 67.108 + String dumpHierarchy() { 67.109 + StringBuilder buf = new StringBuilder(); 67.110 + buf.append("root = " + hs.root + "\n"); 67.111 + for (ClassCase cc : hs.all) { 67.112 + buf.append(" class name = " + cc.getName() + "\n"); 67.113 + buf.append(" class OK = " + cc.get_OK() + "\n"); 67.114 + buf.append(" prov = " + cc.get_mprov() + "\n"); 67.115 + 67.116 + } 67.117 + return buf.toString(); 67.118 + } 67.119 + 67.120 + class DefenderTestSource extends SimpleJavaFileObject { 67.121 + 67.122 + String source; 67.123 + 67.124 + public DefenderTestSource() { 67.125 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 67.126 + StringBuilder buf = new StringBuilder(); 67.127 + List<ClassCase> defaultRef = new ArrayList<>(); 67.128 + for (ClassCase cc : hs.all) { 67.129 + hs.genClassDef(buf, cc, null, defaultRef); 67.130 + } 67.131 + source = buf.toString(); 67.132 + } 67.133 + 67.134 + @Override 67.135 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 67.136 + return source; 67.137 + } 67.138 + } 67.139 + 67.140 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 67.141 + 67.142 + boolean errorFound; 67.143 + 67.144 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 67.145 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 67.146 + errorFound = true; 67.147 + } 67.148 + } 67.149 + } 67.150 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 68.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/ClassCase.java Sun Nov 04 10:59:42 2012 +0000 68.3 @@ -0,0 +1,310 @@ 68.4 +/* 68.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 68.7 + * 68.8 + * This code is free software; you can redistribute it and/or modify it 68.9 + * under the terms of the GNU General Public License version 2 only, as 68.10 + * published by the Free Software Foundation. Oracle designates this 68.11 + * particular file as subject to the "Classpath" exception as provided 68.12 + * by Oracle in the LICENSE file that accompanied this code. 68.13 + * 68.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 68.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 68.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 68.17 + * version 2 for more details (a copy is included in the LICENSE file that 68.18 + * accompanied this code). 68.19 + * 68.20 + * You should have received a copy of the GNU General Public License version 68.21 + * 2 along with this work; if not, write to the Free Software Foundation, 68.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 68.23 + * 68.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 68.25 + * or visit www.oracle.com if you need additional information or have any 68.26 + * questions. 68.27 + */ 68.28 + 68.29 +package shapegen; 68.30 + 68.31 +import java.util.ArrayList; 68.32 +import java.util.HashSet; 68.33 +import java.util.List; 68.34 +import java.util.Map; 68.35 +import java.util.Set; 68.36 + 68.37 +/** 68.38 + * 68.39 + * @author Robert Field 68.40 + */ 68.41 +public class ClassCase { 68.42 + 68.43 + public enum Kind { 68.44 + IVAC (true, "v"), 68.45 + IPRESENT (true, "p"), 68.46 + IDEFAULT (true, "d"), 68.47 + CNONE (false, "n"), 68.48 + CABSTRACT (false, "a"), 68.49 + CCONCRETE (false, "c"); 68.50 + 68.51 + private final String prefix; 68.52 + public final boolean isInterface; 68.53 + 68.54 + Kind(boolean isInterface, String prefix) { 68.55 + this.isInterface = isInterface; 68.56 + this.prefix = prefix; 68.57 + } 68.58 + } 68.59 + 68.60 + public final Kind kind; 68.61 + private final ClassCase superclass; 68.62 + private final List<ClassCase> supertypes; 68.63 + 68.64 + private String name; 68.65 + private boolean _OK; 68.66 + private boolean _HasClassMethod; 68.67 + private Set<ClassCase> _mprov; 68.68 + private boolean _IsConcrete; 68.69 + private boolean _HasDefault; 68.70 + private ClassCase _mres; 68.71 + private ClassCase _mdefend; 68.72 + 68.73 + private Set<RuleGroup> executed = new HashSet<RuleGroup>() {}; 68.74 + 68.75 + public ClassCase(Kind kind, ClassCase superclass, List<ClassCase> interfaces) { 68.76 + this.kind = kind; 68.77 + this.superclass = superclass; 68.78 + 68.79 + // Set supertypes from superclass (if any) and interfaces 68.80 + List<ClassCase> lc; 68.81 + if (superclass == null) { 68.82 + lc = interfaces; 68.83 + } else { 68.84 + lc = new ArrayList<>(); 68.85 + lc.add(superclass); 68.86 + lc.addAll(interfaces); 68.87 + } 68.88 + this.supertypes = lc; 68.89 + } 68.90 + 68.91 + public final boolean isInterface() { return kind.isInterface; } 68.92 + public final boolean isClass() { return !kind.isInterface; } 68.93 + 68.94 + public Set<ClassCase> get_mprov() { 68.95 + exec(RuleGroup.PROVENENCE); 68.96 + return _mprov; 68.97 + } 68.98 + 68.99 + public void set_mprov(ClassCase cc) { 68.100 + Set<ClassCase> s = new HashSet<>(); 68.101 + s.add(cc); 68.102 + _mprov = s; 68.103 + } 68.104 + 68.105 + public void set_mprov(Set<ClassCase> s) { 68.106 + _mprov = s; 68.107 + } 68.108 + 68.109 + public ClassCase get_mres() { 68.110 + exec(RuleGroup.RESOLUTION); 68.111 + return _mres; 68.112 + } 68.113 + 68.114 + public void set_mres(ClassCase cc) { 68.115 + _mres = cc; 68.116 + } 68.117 + 68.118 + public ClassCase get_mdefend() { 68.119 + exec(RuleGroup.DEFENDER); 68.120 + return _mdefend; 68.121 + } 68.122 + 68.123 + public void set_mdefend(ClassCase cc) { 68.124 + _mdefend = cc; 68.125 + } 68.126 + 68.127 + public boolean get_HasClassMethod() { 68.128 + exec(RuleGroup.PROVENENCE); 68.129 + return _HasClassMethod; 68.130 + } 68.131 + 68.132 + public void set_HasClassMethod(boolean bool) { 68.133 + _HasClassMethod = bool; 68.134 + } 68.135 + 68.136 + public boolean get_HasDefault() { 68.137 + exec(RuleGroup.MARKER); 68.138 + return _HasDefault; 68.139 + } 68.140 + 68.141 + public void set_HasDefault(boolean bool) { 68.142 + _HasDefault = bool; 68.143 + } 68.144 + 68.145 + public boolean get_IsConcrete() { 68.146 + exec(RuleGroup.MARKER); 68.147 + return _IsConcrete; 68.148 + } 68.149 + 68.150 + public void set_IsConcrete(boolean bool) { 68.151 + _IsConcrete = bool; 68.152 + } 68.153 + 68.154 + public boolean get_OK() { 68.155 + exec(RuleGroup.CHECKING); 68.156 + return _OK; 68.157 + } 68.158 + 68.159 + public void set_OK(boolean bool) { 68.160 + _OK = bool; 68.161 + } 68.162 + 68.163 + public boolean isMethodDefined() { 68.164 + for (ClassCase cc : supertypes) { 68.165 + if (cc.isMethodDefined()) { 68.166 + return true; 68.167 + } 68.168 + } 68.169 + switch (kind) { 68.170 + case CCONCRETE: 68.171 + case CABSTRACT: 68.172 + case IPRESENT: 68.173 + case IDEFAULT: 68.174 + return true; 68.175 + default: 68.176 + return false; 68.177 + } 68.178 + } 68.179 + 68.180 + public boolean isAbstract() { 68.181 + return isMethodDefined() && (get_mres()==null); 68.182 + } 68.183 + 68.184 + public boolean hasSuperclass() { 68.185 + return superclass != null; 68.186 + } 68.187 + 68.188 + public ClassCase getSuperclass() { 68.189 + return superclass; 68.190 + } 68.191 + 68.192 + public List<ClassCase> getSupertypes() { 68.193 + return supertypes; 68.194 + } 68.195 + 68.196 + public List<ClassCase> getInterfaces() { 68.197 + if (superclass != null) { 68.198 + if (supertypes.get(0) != superclass) { 68.199 + throw new AssertionError("superclass missing from supertypes"); 68.200 + } 68.201 + return supertypes.subList(1, supertypes.size()); 68.202 + } else { 68.203 + return supertypes; 68.204 + } 68.205 + } 68.206 + 68.207 + public boolean isSubtypeOf(ClassCase cc) { 68.208 + // S-Refl 68.209 + if (cc.equals(this)) { 68.210 + return true; 68.211 + } 68.212 + 68.213 + // S-Def 68.214 + for (ClassCase sp : getSupertypes()) { 68.215 + if (cc.equals(sp)) { 68.216 + return true; 68.217 + } 68.218 + } 68.219 + 68.220 + // _S-Trans 68.221 + for (ClassCase sp : getSupertypes()) { 68.222 + if (sp.isSubtypeOf(cc)) { 68.223 + return true; 68.224 + } 68.225 + } 68.226 + 68.227 + return false; 68.228 + } 68.229 + 68.230 + public void init(Map<String, Integer> namingContext) { 68.231 + if (name != null) { 68.232 + return; // Already inited 68.233 + } 68.234 + 68.235 + for (ClassCase sup : supertypes) { 68.236 + sup.init(namingContext); 68.237 + } 68.238 + 68.239 + // Build name 68.240 + StringBuilder sb = new StringBuilder(); 68.241 + if (!supertypes.isEmpty()) { 68.242 + sb.append(isInterface() ? "I" : "C"); 68.243 + for (ClassCase cc : supertypes) { 68.244 + sb.append(cc.getName()); 68.245 + } 68.246 + sb.append(kind.isInterface ? "i" : "c"); 68.247 + } 68.248 + sb.append(kind.prefix); 68.249 + String pname = sb.toString(); 68.250 + Integer icnt = namingContext.get(pname); 68.251 + int cnt = icnt == null ? 0 : icnt; 68.252 + ++cnt; 68.253 + namingContext.put(pname, cnt); 68.254 + if (cnt > 1) { 68.255 + sb.append(cnt); 68.256 + } 68.257 + this.name = sb.toString(); 68.258 + } 68.259 + 68.260 + public boolean isa(Kind... kinds) { 68.261 + for (Kind k : kinds) { 68.262 + if (kind == k) { 68.263 + return true; 68.264 + } 68.265 + } 68.266 + return false; 68.267 + } 68.268 + 68.269 + private void exec(RuleGroup rg ) { 68.270 + if (!executed.contains(rg)) { 68.271 + rg.exec(this); 68.272 + executed.add(rg); 68.273 + } 68.274 + } 68.275 + 68.276 + public void collectClasses(Set<ClassCase> seen) { 68.277 + seen.add(this); 68.278 + for (ClassCase cc : supertypes) { 68.279 + cc.collectClasses(seen); 68.280 + } 68.281 + } 68.282 + 68.283 + public String getID() { 68.284 + if (name == null) { 68.285 + throw new Error("Access to uninitialized ClassCase"); 68.286 + } else { 68.287 + return name; 68.288 + } 68.289 + } 68.290 + 68.291 + public final String getName() { 68.292 + if (name == null) { 68.293 + return "ClassCase uninited@" + hashCode(); 68.294 + } else { 68.295 + return name; 68.296 + } 68.297 + } 68.298 + 68.299 + @Override 68.300 + public boolean equals(Object obj) { 68.301 + return obj instanceof ClassCase && getID().equals(((ClassCase)obj).getID()); 68.302 + } 68.303 + 68.304 + @Override 68.305 + public int hashCode() { 68.306 + return getID().hashCode(); 68.307 + } 68.308 + 68.309 + @Override 68.310 + public String toString() { 68.311 + return getName(); 68.312 + } 68.313 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/Hierarchy.java Sun Nov 04 10:59:42 2012 +0000 69.3 @@ -0,0 +1,143 @@ 69.4 +/* 69.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 69.7 + * 69.8 + * This code is free software; you can redistribute it and/or modify it 69.9 + * under the terms of the GNU General Public License version 2 only, as 69.10 + * published by the Free Software Foundation. Oracle designates this 69.11 + * particular file as subject to the "Classpath" exception as provided 69.12 + * by Oracle in the LICENSE file that accompanied this code. 69.13 + * 69.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 69.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 69.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 69.17 + * version 2 for more details (a copy is included in the LICENSE file that 69.18 + * accompanied this code). 69.19 + * 69.20 + * You should have received a copy of the GNU General Public License version 69.21 + * 2 along with this work; if not, write to the Free Software Foundation, 69.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 69.23 + * 69.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 69.25 + * or visit www.oracle.com if you need additional information or have any 69.26 + * questions. 69.27 + */ 69.28 + 69.29 +package shapegen; 69.30 + 69.31 +import java.util.List; 69.32 +import java.util.HashMap; 69.33 +import java.util.HashSet; 69.34 +import java.util.Set; 69.35 + 69.36 +import static shapegen.ClassCase.Kind.*; 69.37 + 69.38 +/** 69.39 + * 69.40 + * @author Robert Field 69.41 + */ 69.42 +public class Hierarchy { 69.43 + 69.44 + public final ClassCase root; 69.45 + public final Set<ClassCase> all; 69.46 + 69.47 + public Hierarchy(ClassCase root) { 69.48 + this.root = root; 69.49 + root.init(new HashMap<String,Integer>()); 69.50 + Set<ClassCase> allClasses = new HashSet<>(); 69.51 + root.collectClasses(allClasses); 69.52 + this.all = allClasses; 69.53 + } 69.54 + 69.55 + public boolean anyDefaults() { 69.56 + for (ClassCase cc : all) { 69.57 + if (cc.kind == IDEFAULT) { 69.58 + return true; 69.59 + } 69.60 + } 69.61 + return false; 69.62 + } 69.63 + 69.64 + public boolean get_OK() { 69.65 + return root.get_OK(); 69.66 + } 69.67 + 69.68 + public String testName() { 69.69 + return root + "Test"; 69.70 + } 69.71 + 69.72 + private static void genInterfaceList(StringBuilder buf, String prefix, List<ClassCase> interfaces) { 69.73 + if (!interfaces.isEmpty()) { 69.74 + buf.append(" "); 69.75 + buf.append(prefix); 69.76 + buf.append(" "); 69.77 + buf.append(interfaces.get(0)); 69.78 + for (int i = 1; i < interfaces.size(); ++i) { 69.79 + buf.append(", " + interfaces.get(i)); 69.80 + } 69.81 + } 69.82 + } 69.83 + 69.84 + public static void genClassDef(StringBuilder buf, ClassCase cc, String implClass, List<ClassCase> defaultRef) { 69.85 + if (cc.isInterface()) { 69.86 + buf.append("interface "); 69.87 + buf.append(cc.getName() + " "); 69.88 + genInterfaceList(buf, "extends", cc.getInterfaces()); 69.89 + buf.append(" {\n"); 69.90 + 69.91 + switch (cc.kind) { 69.92 + case IDEFAULT: 69.93 + buf.append(" default String m() { return \"\"; }\n"); 69.94 + defaultRef.add(cc); 69.95 + break; 69.96 + case IPRESENT: 69.97 + buf.append(" String m();\n"); 69.98 + break; 69.99 + case IVAC: 69.100 + break; 69.101 + default: 69.102 + throw new AssertionError("Unexpected kind"); 69.103 + } 69.104 + buf.append("}\n\n"); 69.105 + } else { 69.106 + buf.append((cc.isAbstract()? "abstract " : "")); 69.107 + buf.append(" class " + cc.getName()); 69.108 + if (cc.getSuperclass() != null) { 69.109 + buf.append(" extends " + cc.getSuperclass()); 69.110 + } 69.111 + 69.112 + genInterfaceList(buf, "implements", cc.getInterfaces()); 69.113 + buf.append(" {\n"); 69.114 + 69.115 + switch (cc.kind) { 69.116 + case CCONCRETE: 69.117 + buf.append(" public String m() { return \"\"; }\n"); 69.118 + break; 69.119 + case CABSTRACT: 69.120 + buf.append(" public abstract String m();\n"); 69.121 + break; 69.122 + case CNONE: 69.123 + break; 69.124 + default: 69.125 + throw new AssertionError("Unexpected kind"); 69.126 + } 69.127 + buf.append("}\n\n"); 69.128 + } 69.129 + } 69.130 + 69.131 + @Override 69.132 + public boolean equals(Object obj) { 69.133 + return obj instanceof Hierarchy && root.getID().equals(((Hierarchy)obj).root.getID()); 69.134 + } 69.135 + 69.136 + @Override 69.137 + public int hashCode() { 69.138 + return root.getID().hashCode(); 69.139 + } 69.140 + 69.141 + @Override 69.142 + public String toString() { 69.143 + return root.getName(); 69.144 + } 69.145 + 69.146 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 70.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/HierarchyGenerator.java Sun Nov 04 10:59:42 2012 +0000 70.3 @@ -0,0 +1,190 @@ 70.4 +/* 70.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 70.7 + * 70.8 + * This code is free software; you can redistribute it and/or modify it 70.9 + * under the terms of the GNU General Public License version 2 only, as 70.10 + * published by the Free Software Foundation. Oracle designates this 70.11 + * particular file as subject to the "Classpath" exception as provided 70.12 + * by Oracle in the LICENSE file that accompanied this code. 70.13 + * 70.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 70.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 70.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 70.17 + * version 2 for more details (a copy is included in the LICENSE file that 70.18 + * accompanied this code). 70.19 + * 70.20 + * You should have received a copy of the GNU General Public License version 70.21 + * 2 along with this work; if not, write to the Free Software Foundation, 70.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 70.23 + * 70.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 70.25 + * or visit www.oracle.com if you need additional information or have any 70.26 + * questions. 70.27 + */ 70.28 + 70.29 +package shapegen; 70.30 + 70.31 +import shapegen.ClassCase.Kind; 70.32 + 70.33 +import java.util.Collection; 70.34 +import java.util.Set; 70.35 +import java.util.HashSet; 70.36 +import java.util.Collections; 70.37 +import java.util.ArrayList; 70.38 +import java.util.List; 70.39 + 70.40 +import static shapegen.ClassCase.Kind.*; 70.41 + 70.42 +import static java.lang.Math.pow; 70.43 + 70.44 +/** 70.45 + * 70.46 + * @author Robert Field 70.47 + */ 70.48 +public final class HierarchyGenerator { 70.49 + 70.50 + private static int okcnt = 0; 70.51 + private static int errcnt = 0; 70.52 + private static Set<Hierarchy> uniqueOK = new HashSet<>(); 70.53 + private static Set<Hierarchy> uniqueErr = new HashSet<>(); 70.54 + 70.55 + /** 70.56 + * @param args the command line arguments 70.57 + */ 70.58 + public HierarchyGenerator() { 70.59 + organize("exhaustive interface", iExhaustive(2)); 70.60 + organize("exhaustive class", cExhaustive()); 70.61 + organize("shapes interface", iShapes()); 70.62 + organize("shapes class/interface", ciShapes()); 70.63 + 70.64 + System.out.printf("\nExpect OK: %d -- unique %d", okcnt, uniqueOK.size()); 70.65 + System.out.printf("\nExpect Error: %d -- unique %d\n", errcnt, uniqueErr.size()); 70.66 + } 70.67 + 70.68 + public Collection<Hierarchy> getOK() { 70.69 + return uniqueOK; 70.70 + } 70.71 + 70.72 + public Collection<Hierarchy> getErr() { 70.73 + return uniqueErr; 70.74 + } 70.75 + 70.76 + private void organize(String tname, List<Hierarchy> totest) { 70.77 + System.out.printf("\nTesting %s....\n", tname); 70.78 + int nodefault = 0; 70.79 + List<Hierarchy> ok = new ArrayList<>(); 70.80 + List<Hierarchy> err = new ArrayList<>(); 70.81 + for (Hierarchy cc : totest) { 70.82 + if (cc.anyDefaults()) { 70.83 + //System.out.printf(" %s\n", cc); 70.84 + if (cc.get_OK()) { 70.85 + ok.add(cc); 70.86 + } else { 70.87 + err.add(cc); 70.88 + } 70.89 + } else { 70.90 + ++nodefault; 70.91 + } 70.92 + } 70.93 + 70.94 + errcnt += err.size(); 70.95 + okcnt += ok.size(); 70.96 + uniqueErr.addAll(err); 70.97 + uniqueOK.addAll(ok); 70.98 + 70.99 + System.out.printf(" %5d No default\n %5d Error\n %5d OK\n %5d Total\n", 70.100 + nodefault, err.size(), ok.size(), totest.size()); 70.101 + } 70.102 + 70.103 + public List<Hierarchy> iExhaustive(int idepth) { 70.104 + List<ClassCase> current = new ArrayList<>(); 70.105 + for (int i = 0; i < idepth; ++i) { 70.106 + current = ilayer(current); 70.107 + } 70.108 + return wrapInClassAndHierarchy(current); 70.109 + } 70.110 + 70.111 + private List<ClassCase> ilayer(List<ClassCase> srcLayer) { 70.112 + List<ClassCase> lay = new ArrayList<>(); 70.113 + for (int i = (int) pow(2, srcLayer.size()) - 1; i >= 0; --i) { 70.114 + List<ClassCase> itfs = new ArrayList<>(); 70.115 + for (int b = srcLayer.size() - 1; b >= 0; --b) { 70.116 + if ((i & (1<<b)) != 0) { 70.117 + itfs.add(srcLayer.get(b)); 70.118 + } 70.119 + } 70.120 + lay.add(new ClassCase(IVAC, null, itfs)); 70.121 + lay.add(new ClassCase(IPRESENT, null, itfs)); 70.122 + lay.add(new ClassCase(IDEFAULT, null, itfs)); 70.123 + lay.add(new ClassCase(IDEFAULT, null, itfs)); 70.124 + } 70.125 + return lay; 70.126 + } 70.127 + 70.128 + public List<Hierarchy> cExhaustive() { 70.129 + final Kind[] iKinds = new Kind[]{IDEFAULT, IVAC, IPRESENT, null}; 70.130 + final Kind[] cKinds = new Kind[]{CNONE, CABSTRACT, CCONCRETE}; 70.131 + List<Hierarchy> totest = new ArrayList<>(); 70.132 + for (int i1 = 0; i1 < iKinds.length; ++i1) { 70.133 + for (int i2 = 0; i2 < iKinds.length; ++i2) { 70.134 + for (int i3 = 0; i3 < iKinds.length; ++i3) { 70.135 + for (int c1 = 0; c1 < cKinds.length; ++c1) { 70.136 + for (int c2 = 0; c2 < cKinds.length; ++c2) { 70.137 + for (int c3 = 0; c3 < cKinds.length; ++c3) { 70.138 + totest.add( new Hierarchy( 70.139 + new ClassCase(cKinds[c1], 70.140 + new ClassCase(cKinds[c2], 70.141 + new ClassCase(cKinds[c3], 70.142 + null, 70.143 + iList(iKinds[i1]) 70.144 + ), 70.145 + iList(iKinds[i2]) 70.146 + ), 70.147 + iList(iKinds[i3]) 70.148 + ))); 70.149 + } 70.150 + } 70.151 + } 70.152 + } 70.153 + } 70.154 + } 70.155 + return totest; 70.156 + } 70.157 + 70.158 + private List<ClassCase> iList(Kind kind) { 70.159 + if (kind == null) { 70.160 + return Collections.EMPTY_LIST; 70.161 + } else { 70.162 + List<ClassCase> itfs = new ArrayList<>(); 70.163 + itfs.add(new ClassCase(kind, null, Collections.EMPTY_LIST)); 70.164 + return itfs; 70.165 + } 70.166 + } 70.167 + 70.168 + public List<Hierarchy> ciShapes() { 70.169 + return wrapInHierarchy(TTShape.allCases(true)); 70.170 + } 70.171 + 70.172 + public List<Hierarchy> iShapes() { 70.173 + return wrapInClassAndHierarchy(TTShape.allCases(false)); 70.174 + } 70.175 + 70.176 + public List<Hierarchy> wrapInClassAndHierarchy(List<ClassCase> ihs) { 70.177 + List<Hierarchy> totest = new ArrayList<>(); 70.178 + for (ClassCase cc : ihs) { 70.179 + List<ClassCase> interfaces = new ArrayList<>(); 70.180 + interfaces.add(cc); 70.181 + totest.add(new Hierarchy(new ClassCase(CNONE, null, interfaces))); 70.182 + } 70.183 + return totest; 70.184 + } 70.185 + 70.186 + public List<Hierarchy> wrapInHierarchy(List<ClassCase> ihs) { 70.187 + List<Hierarchy> totest = new ArrayList<>(); 70.188 + for (ClassCase cc : ihs) { 70.189 + totest.add(new Hierarchy(cc)); 70.190 + } 70.191 + return totest; 70.192 + } 70.193 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 71.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/Rule.java Sun Nov 04 10:59:42 2012 +0000 71.3 @@ -0,0 +1,48 @@ 71.4 +/* 71.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 71.7 + * 71.8 + * This code is free software; you can redistribute it and/or modify it 71.9 + * under the terms of the GNU General Public License version 2 only, as 71.10 + * published by the Free Software Foundation. Oracle designates this 71.11 + * particular file as subject to the "Classpath" exception as provided 71.12 + * by Oracle in the LICENSE file that accompanied this code. 71.13 + * 71.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 71.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 71.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 71.17 + * version 2 for more details (a copy is included in the LICENSE file that 71.18 + * accompanied this code). 71.19 + * 71.20 + * You should have received a copy of the GNU General Public License version 71.21 + * 2 along with this work; if not, write to the Free Software Foundation, 71.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 71.23 + * 71.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 71.25 + * or visit www.oracle.com if you need additional information or have any 71.26 + * questions. 71.27 + */ 71.28 + 71.29 +package shapegen; 71.30 + 71.31 +/** 71.32 + * 71.33 + * @author Robert Field 71.34 + */ 71.35 +public abstract class Rule { 71.36 + 71.37 + public final String name; 71.38 + 71.39 + public Rule(String name) { 71.40 + this.name = name; 71.41 + } 71.42 + 71.43 + abstract boolean guard(ClassCase cc); 71.44 + 71.45 + abstract void eval(ClassCase cc); 71.46 + 71.47 + @Override 71.48 + public String toString() { 71.49 + return name; 71.50 + } 71.51 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 72.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/RuleGroup.java Sun Nov 04 10:59:42 2012 +0000 72.3 @@ -0,0 +1,206 @@ 72.4 +/* 72.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 72.7 + * 72.8 + * This code is free software; you can redistribute it and/or modify it 72.9 + * under the terms of the GNU General Public License version 2 only, as 72.10 + * published by the Free Software Foundation. Oracle designates this 72.11 + * particular file as subject to the "Classpath" exception as provided 72.12 + * by Oracle in the LICENSE file that accompanied this code. 72.13 + * 72.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 72.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 72.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 72.17 + * version 2 for more details (a copy is included in the LICENSE file that 72.18 + * accompanied this code). 72.19 + * 72.20 + * You should have received a copy of the GNU General Public License version 72.21 + * 2 along with this work; if not, write to the Free Software Foundation, 72.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 72.23 + * 72.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 72.25 + * or visit www.oracle.com if you need additional information or have any 72.26 + * questions. 72.27 + */ 72.28 + 72.29 +package shapegen; 72.30 + 72.31 +import java.util.HashSet; 72.32 +import java.util.Set; 72.33 + 72.34 +import static shapegen.ClassCase.Kind.*; 72.35 + 72.36 +/** 72.37 + * 72.38 + * @author Robert Field 72.39 + */ 72.40 +public class RuleGroup { 72.41 + 72.42 + final String name; 72.43 + private final Rule[] rules; 72.44 + 72.45 + public RuleGroup(String name, Rule[] rules) { 72.46 + this.name = name; 72.47 + this.rules = rules; 72.48 + } 72.49 + 72.50 + public boolean exec(ClassCase cc) { 72.51 + boolean found = false; 72.52 + for (Rule rule : rules) { 72.53 + if (rule.guard(cc)) { 72.54 + if (found) { 72.55 + throw new RuntimeException("Bad rules -- multiple matches " + toString() + " for " + cc); 72.56 + } else { 72.57 + rule.eval(cc); 72.58 + found = true; 72.59 + } 72.60 + } 72.61 + } 72.62 + return found; 72.63 + } 72.64 + 72.65 + @Override 72.66 + public String toString() { 72.67 + return name; 72.68 + } 72.69 + 72.70 + public static RuleGroup PROVENENCE = new RuleGroup("Provenence", new Rule[] { 72.71 + new Rule("P-CDeclare") { 72.72 + boolean guard(ClassCase cc) { 72.73 + return cc.isa(CCONCRETE, CABSTRACT); 72.74 + } 72.75 + 72.76 + void eval(ClassCase cc) { 72.77 + cc.set_mprov(cc); 72.78 + cc.set_HasClassMethod(true); 72.79 + } 72.80 + }, 72.81 + 72.82 + new Rule("P-IDeclare") { 72.83 + boolean guard(ClassCase cc) { 72.84 + return cc.isa(IDEFAULT, IPRESENT); 72.85 + } 72.86 + 72.87 + void eval(ClassCase cc) { 72.88 + cc.set_mprov(cc); 72.89 + } 72.90 + }, 72.91 + 72.92 + new Rule("P-IntfInh") { 72.93 + boolean guard(ClassCase cc) { 72.94 + return cc.isa(IVAC, CNONE) && !(cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 72.95 + } 72.96 + 72.97 + void eval(ClassCase cc) { 72.98 + Set<ClassCase> _S = new HashSet<>(); 72.99 + for (ClassCase t : cc.getSupertypes()) { 72.100 + _S.addAll(t.get_mprov()); 72.101 + } 72.102 + Set<ClassCase> tops = new HashSet<>(); 72.103 + for (ClassCase _W : _S) { 72.104 + for (ClassCase _V : _S) { 72.105 + if (_V.equals(_W) || !(_V.isSubtypeOf(_W))) { 72.106 + tops.add(_W); 72.107 + } 72.108 + } 72.109 + } 72.110 + cc.set_mprov(tops); 72.111 + } 72.112 + }, 72.113 + 72.114 + new Rule("P-ClassInh") { 72.115 + boolean guard(ClassCase cc) { 72.116 + return cc.isa(CNONE) && (cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); 72.117 + } 72.118 + 72.119 + void eval(ClassCase cc) { 72.120 + cc.set_mprov(cc.getSuperclass()); 72.121 + cc.set_HasClassMethod(true); 72.122 + } 72.123 + }, 72.124 + 72.125 + }); 72.126 + 72.127 + public static RuleGroup MARKER = new RuleGroup("Marker", new Rule[] { 72.128 + new Rule("M-Default") { 72.129 + boolean guard(ClassCase cc) { 72.130 + return cc.isa(IDEFAULT); 72.131 + } 72.132 + 72.133 + void eval(ClassCase cc) { 72.134 + cc.set_HasDefault(true); 72.135 + } 72.136 + }, 72.137 + 72.138 + new Rule("M-Conc") { 72.139 + boolean guard(ClassCase cc) { 72.140 + return cc.isa(CCONCRETE); 72.141 + } 72.142 + 72.143 + void eval(ClassCase cc) { 72.144 + cc.set_IsConcrete(true); 72.145 + } 72.146 + }, 72.147 + 72.148 + }); 72.149 + 72.150 + public static RuleGroup RESOLUTION = new RuleGroup("Resolution", new Rule[] { 72.151 + new Rule("R-Resolve") { 72.152 + boolean guard(ClassCase cc) { 72.153 + if (!(cc.isClass() && cc.get_mprov().size() == 1)) { 72.154 + return false; 72.155 + } 72.156 + ClassCase _V = cc.get_mprov().iterator().next(); 72.157 + return _V.get_IsConcrete() || _V.get_HasDefault(); 72.158 + } 72.159 + 72.160 + void eval(ClassCase cc) { 72.161 + ClassCase _V = cc.get_mprov().iterator().next(); 72.162 + cc.set_mres(_V); 72.163 + } 72.164 + }, 72.165 + 72.166 + }); 72.167 + 72.168 + public static RuleGroup DEFENDER = new RuleGroup("Defender", new Rule[] { 72.169 + new Rule("D-Defend") { 72.170 + boolean guard(ClassCase cc) { 72.171 + ClassCase mresSuper = cc.hasSuperclass() ? cc.getSuperclass().get_mres() : null; 72.172 + boolean eq = cc.get_mres() == null ? mresSuper == null : cc.get_mres().equals(mresSuper); 72.173 + return cc.isa(CNONE) && !eq; 72.174 + } 72.175 + 72.176 + void eval(ClassCase cc) { 72.177 + cc.set_mdefend(cc.get_mres()); 72.178 + } 72.179 + }, 72.180 + 72.181 + }); 72.182 + 72.183 + public static RuleGroup CHECKING = new RuleGroup("Checking", new Rule[] { 72.184 + new Rule("C-Check") { 72.185 + boolean guard(ClassCase cc) { 72.186 + for (ClassCase t : cc.getSupertypes()) { 72.187 + if (! t.get_OK()) { 72.188 + return false; 72.189 + } 72.190 + } 72.191 + int defenderCount = 0; 72.192 + int provCount = 0; 72.193 + for (ClassCase prov : cc.get_mprov()) { 72.194 + if (prov.get_HasDefault()) { 72.195 + defenderCount++; 72.196 + } 72.197 + provCount++; 72.198 + } 72.199 + return provCount <= 1 || defenderCount == 0; 72.200 + } 72.201 + 72.202 + void eval(ClassCase cc) { 72.203 + cc.set_OK(true); 72.204 + } 72.205 + }, 72.206 + 72.207 + }); 72.208 + 72.209 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/TTNode.java Sun Nov 04 10:59:42 2012 +0000 73.3 @@ -0,0 +1,126 @@ 73.4 +/* 73.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 73.7 + * 73.8 + * This code is free software; you can redistribute it and/or modify it 73.9 + * under the terms of the GNU General Public License version 2 only, as 73.10 + * published by the Free Software Foundation. Oracle designates this 73.11 + * particular file as subject to the "Classpath" exception as provided 73.12 + * by Oracle in the LICENSE file that accompanied this code. 73.13 + * 73.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 73.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 73.17 + * version 2 for more details (a copy is included in the LICENSE file that 73.18 + * accompanied this code). 73.19 + * 73.20 + * You should have received a copy of the GNU General Public License version 73.21 + * 2 along with this work; if not, write to the Free Software Foundation, 73.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 73.23 + * 73.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 73.25 + * or visit www.oracle.com if you need additional information or have any 73.26 + * questions. 73.27 + */ 73.28 + 73.29 +package shapegen; 73.30 + 73.31 +import shapegen.ClassCase.Kind; 73.32 + 73.33 +import java.util.ArrayList; 73.34 +import java.util.List; 73.35 +import java.util.Set; 73.36 + 73.37 +import static shapegen.ClassCase.Kind.*; 73.38 + 73.39 +/** 73.40 + * Type Template Node 73.41 + * 73.42 + * @author Robert Field 73.43 + */ 73.44 +public class TTNode { 73.45 + 73.46 + final List<TTNode> supertypes; 73.47 + final boolean canBeClass; 73.48 + 73.49 + private int currentKindIndex; 73.50 + private Kind[] kinds; 73.51 + 73.52 + public TTNode(List<TTNode> subtypes, boolean canBeClass) { 73.53 + this.supertypes = subtypes; 73.54 + this.canBeClass = canBeClass; 73.55 + } 73.56 + 73.57 + public void start(boolean includeClasses) { 73.58 + kinds = 73.59 + supertypes.isEmpty()? 73.60 + (new Kind[]{IDEFAULT, IPRESENT}) 73.61 + : ((includeClasses && canBeClass)? 73.62 + new Kind[]{CNONE, IVAC, IDEFAULT, IPRESENT} 73.63 + : new Kind[]{IVAC, IDEFAULT, IPRESENT}); 73.64 + currentKindIndex = 0; 73.65 + 73.66 + for (TTNode sub : supertypes) { 73.67 + sub.start(includeClasses); 73.68 + } 73.69 + } 73.70 + 73.71 + public boolean next() { 73.72 + ++currentKindIndex; 73.73 + if (currentKindIndex >= kinds.length) { 73.74 + currentKindIndex = 0; 73.75 + return false; 73.76 + } else { 73.77 + return true; 73.78 + } 73.79 + } 73.80 + 73.81 + public void collectAllSubtypes(Set<TTNode> subs) { 73.82 + subs.add(this); 73.83 + for (TTNode n : supertypes) { 73.84 + n.collectAllSubtypes(subs); 73.85 + } 73.86 + } 73.87 + 73.88 + private Kind getKind() { 73.89 + return kinds[currentKindIndex]; 73.90 + } 73.91 + 73.92 + boolean isInterface() { 73.93 + return getKind().isInterface; 73.94 + } 73.95 + 73.96 + boolean isClass() { 73.97 + return !isInterface(); 73.98 + } 73.99 + 73.100 + boolean hasDefault() { 73.101 + return getKind() == IDEFAULT; 73.102 + } 73.103 + 73.104 + public boolean isValid() { 73.105 + for (TTNode n : supertypes) { 73.106 + if (!n.isValid() || (isInterface() && n.isClass())) { 73.107 + return false; 73.108 + } 73.109 + } 73.110 + return true; 73.111 + } 73.112 + 73.113 + public ClassCase genCase() { 73.114 + ClassCase subclass; 73.115 + List<TTNode> ttintfs; 73.116 + if (isClass() && !supertypes.isEmpty() && supertypes.get(0).isClass()) { 73.117 + subclass = supertypes.get(0).genCase(); 73.118 + ttintfs = supertypes.subList(1, supertypes.size()); 73.119 + } else { 73.120 + subclass = null; 73.121 + ttintfs = supertypes; 73.122 + } 73.123 + List<ClassCase> intfs = new ArrayList<>(); 73.124 + for (TTNode node : ttintfs) { 73.125 + intfs.add(node.genCase()); 73.126 + } 73.127 + return new ClassCase(getKind(), subclass, intfs); 73.128 + } 73.129 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 74.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/TTParser.java Sun Nov 04 10:59:42 2012 +0000 74.3 @@ -0,0 +1,100 @@ 74.4 +/* 74.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 74.7 + * 74.8 + * This code is free software; you can redistribute it and/or modify it 74.9 + * under the terms of the GNU General Public License version 2 only, as 74.10 + * published by the Free Software Foundation. Oracle designates this 74.11 + * particular file as subject to the "Classpath" exception as provided 74.12 + * by Oracle in the LICENSE file that accompanied this code. 74.13 + * 74.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 74.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 74.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 74.17 + * version 2 for more details (a copy is included in the LICENSE file that 74.18 + * accompanied this code). 74.19 + * 74.20 + * You should have received a copy of the GNU General Public License version 74.21 + * 2 along with this work; if not, write to the Free Software Foundation, 74.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 74.23 + * 74.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 74.25 + * or visit www.oracle.com if you need additional information or have any 74.26 + * questions. 74.27 + */ 74.28 + 74.29 +package shapegen; 74.30 + 74.31 +import java.util.ArrayList; 74.32 +import java.util.HashMap; 74.33 +import java.util.List; 74.34 +import java.util.Map; 74.35 +import java.io.IOException; 74.36 +import java.io.StringReader; 74.37 + 74.38 +import static java.lang.Character.isLetter; 74.39 +import static java.lang.Character.isUpperCase; 74.40 +import static java.lang.Character.isWhitespace; 74.41 + 74.42 +/** 74.43 + * Parse a type template definition string 74.44 + * 74.45 + * input :: classDef 74.46 + * classDef :: letter [ ( classDef* ) ] 74.47 + * 74.48 + * @author Robert Field 74.49 + */ 74.50 +public class TTParser extends StringReader { 74.51 + 74.52 + private Map<Character, TTNode> letterMap = new HashMap<>(); 74.53 + private char ch; 74.54 + 74.55 + private final String def; 74.56 + 74.57 + public TTParser(String s) { 74.58 + super(s); 74.59 + this.def = s; 74.60 + } 74.61 + 74.62 + private void advance() throws IOException { 74.63 + do { 74.64 + ch = (char)read(); 74.65 + } while (isWhitespace(ch)); 74.66 + } 74.67 + 74.68 + public TTNode parse() { 74.69 + try { 74.70 + advance(); 74.71 + return classDef(); 74.72 + } catch (IOException t) { 74.73 + throw new RuntimeException(t); 74.74 + } 74.75 + } 74.76 + 74.77 + private TTNode classDef() throws IOException { 74.78 + if (!isLetter(ch)) { 74.79 + if (ch == (char)-1) { 74.80 + throw new IOException("Unexpected end of type template in " + def); 74.81 + } else { 74.82 + throw new IOException("Unexpected character in type template: " + (Character)ch + " in " + def); 74.83 + } 74.84 + } 74.85 + char nodeCh = ch; 74.86 + TTNode node = letterMap.get(nodeCh); 74.87 + boolean canBeClass = isUpperCase(nodeCh); 74.88 + advance(); 74.89 + if (node == null) { 74.90 + List<TTNode> subtypes = new ArrayList<>(); 74.91 + if (ch == '(') { 74.92 + advance(); 74.93 + while (ch != ')') { 74.94 + subtypes.add(classDef()); 74.95 + } 74.96 + advance(); 74.97 + } 74.98 + node = new TTNode(subtypes, canBeClass); 74.99 + letterMap.put(nodeCh, node); 74.100 + } 74.101 + return node; 74.102 + } 74.103 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/tools/javac/defaultMethods/fd/shapegen/TTShape.java Sun Nov 04 10:59:42 2012 +0000 75.3 @@ -0,0 +1,104 @@ 75.4 +/* 75.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. Oracle designates this 75.11 + * particular file as subject to the "Classpath" exception as provided 75.12 + * by Oracle in the LICENSE file that accompanied this code. 75.13 + * 75.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.17 + * version 2 for more details (a copy is included in the LICENSE file that 75.18 + * accompanied this code). 75.19 + * 75.20 + * You should have received a copy of the GNU General Public License version 75.21 + * 2 along with this work; if not, write to the Free Software Foundation, 75.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.23 + * 75.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 75.25 + * or visit www.oracle.com if you need additional information or have any 75.26 + * questions. 75.27 + */ 75.28 + 75.29 +package shapegen; 75.30 + 75.31 +import java.util.ArrayList; 75.32 +import java.util.HashSet; 75.33 +import java.util.List; 75.34 +import java.util.Set; 75.35 + 75.36 +/** 75.37 + * 75.38 + * @author Robert Field 75.39 + */ 75.40 +public class TTShape { 75.41 + 75.42 + private final TTNode root; 75.43 + private final TTNode[] nodes; 75.44 + 75.45 + TTShape(TTNode root) { 75.46 + this.root = root; 75.47 + Set<TTNode> subs = new HashSet<>(); 75.48 + root.collectAllSubtypes(subs); 75.49 + nodes = subs.toArray(new TTNode[subs.size()]); 75.50 + } 75.51 + 75.52 + private List<ClassCase> toCases(boolean includeClasses) { 75.53 + List<ClassCase> ccs = new ArrayList<>(); 75.54 + root.start(includeClasses); 75.55 + int i; 75.56 + outer: 75.57 + while (true) { 75.58 + if (root.isValid()) { 75.59 + ClassCase cc = root.genCase(); 75.60 + //System.out.println(cc); 75.61 + ccs.add(cc); 75.62 + } 75.63 + 75.64 + i = 0; 75.65 + do { 75.66 + if (i >= nodes.length) { 75.67 + break outer; 75.68 + } 75.69 + } while(!nodes[i++].next()); 75.70 + } 75.71 + return ccs; 75.72 + } 75.73 + 75.74 + public static List<ClassCase> allCases(boolean includeClasses) { 75.75 + List<ClassCase> ccs = new ArrayList<>(); 75.76 + for (TTShape shape : SHAPES) { 75.77 + ccs.addAll(shape.toCases(includeClasses)); 75.78 + } 75.79 + return ccs; 75.80 + } 75.81 + 75.82 + public static TTShape parse(String s) { 75.83 + return new TTShape(new TTParser(s).parse()); 75.84 + } 75.85 + 75.86 + public static final TTShape[] SHAPES = new TTShape[] { 75.87 + parse("a"), 75.88 + parse("a(b)"), 75.89 + parse("A(bb)"), 75.90 + parse("A(B(d)c(d))"), 75.91 + parse("A(b(c))"), 75.92 + parse("A(B(cd)d)"), 75.93 + parse("A(B(c)c)"), 75.94 + parse("A(B(Ce)d(e))"), 75.95 + parse("A(B(C)d(e))"), 75.96 + parse("A(Bc(d))"), 75.97 + parse("A(B(d)dc)"), 75.98 + parse("A(B(dc)dc)"), 75.99 + parse("A(B(c(d))d)"), 75.100 + parse("A(B(C(d))d)"), 75.101 + parse("A(B(C(e)d(e))e)"), 75.102 + parse("A(B(c(d))c)"), 75.103 + parse("A(B(dc(d))c)"), 75.104 + parse("A(B(C(d))d)"), 75.105 + }; 75.106 + 75.107 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/tools/javac/defaultMethods/separate/Separate.java Sun Nov 04 10:59:42 2012 +0000 76.3 @@ -0,0 +1,40 @@ 76.4 +/* 76.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 76.7 + * 76.8 + * This code is free software; you can redistribute it and/or modify it 76.9 + * under the terms of the GNU General Public License version 2 only, as 76.10 + * published by the Free Software Foundation. 76.11 + * 76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76.15 + * version 2 for more details (a copy is included in the LICENSE file that 76.16 + * accompanied this code). 76.17 + * 76.18 + * You should have received a copy of the GNU General Public License version 76.19 + * 2 along with this work; if not, write to the Free Software Foundation, 76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 76.21 + * 76.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 76.23 + * or visit www.oracle.com if you need additional information or have any 76.24 + * questions. 76.25 + */ 76.26 + 76.27 +/* 76.28 + * @test 76.29 + * @summary smoke test for separate compilation of default methods 76.30 + * @author Maurizio Cimadamore 76.31 + * @compile -XDallowDefaultMethods pkg1/A.java 76.32 + * @compile -XDallowDefaultMethods Separate.java 76.33 + */ 76.34 + 76.35 +import pkg1.A; 76.36 + 76.37 +class Separate { 76.38 + interface B extends A.I { 76.39 + default void m() { A.m(this); } 76.40 + } 76.41 + 76.42 + interface C extends A.I, B { } 76.43 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/tools/javac/defaultMethods/separate/pkg1/A.java Sun Nov 04 10:59:42 2012 +0000 77.3 @@ -0,0 +1,32 @@ 77.4 +/* 77.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 + * 77.8 + * This code is free software; you can redistribute it and/or modify it 77.9 + * under the terms of the GNU General Public License version 2 only, as 77.10 + * published by the Free Software Foundation. 77.11 + * 77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.15 + * version 2 for more details (a copy is included in the LICENSE file that 77.16 + * accompanied this code). 77.17 + * 77.18 + * You should have received a copy of the GNU General Public License version 77.19 + * 2 along with this work; if not, write to the Free Software Foundation, 77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.21 + * 77.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 77.23 + * or visit www.oracle.com if you need additional information or have any 77.24 + * questions. 77.25 + */ 77.26 + 77.27 +package pkg1; 77.28 + 77.29 +public class A { 77.30 + public interface I { 77.31 + default void m() { A.m(this); } 77.32 + } 77.33 + 77.34 + public static void m(Object o) {} 77.35 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java Sun Nov 04 10:59:42 2012 +0000 78.3 @@ -0,0 +1,406 @@ 78.4 +/* 78.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 78.7 + * 78.8 + * This code is free software; you can redistribute it and/or modify it 78.9 + * under the terms of the GNU General Public License version 2 only, as 78.10 + * published by the Free Software Foundation. 78.11 + * 78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 78.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 78.15 + * version 2 for more details (a copy is included in the LICENSE file that 78.16 + * accompanied this code). 78.17 + * 78.18 + * You should have received a copy of the GNU General Public License version 78.19 + * 2 along with this work; if not, write to the Free Software Foundation, 78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 78.21 + * 78.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 78.23 + * or visit www.oracle.com if you need additional information or have any 78.24 + * questions. 78.25 + */ 78.26 + 78.27 +/* 78.28 + * @test 78.29 + * @summary Automatic test for checking correctness of default super/this resolution 78.30 + */ 78.31 + 78.32 +import com.sun.source.util.JavacTask; 78.33 +import java.net.URI; 78.34 +import java.util.Arrays; 78.35 +import java.util.ArrayList; 78.36 +import java.util.List; 78.37 +import java.util.Locale; 78.38 +import java.util.Map; 78.39 +import javax.tools.Diagnostic; 78.40 +import javax.tools.JavaCompiler; 78.41 +import javax.tools.JavaFileObject; 78.42 +import javax.tools.SimpleJavaFileObject; 78.43 +import javax.tools.StandardJavaFileManager; 78.44 +import javax.tools.ToolProvider; 78.45 + 78.46 +public class TestDefaultSuperCall { 78.47 + 78.48 + static int checkCount = 0; 78.49 + 78.50 + enum InterfaceKind { 78.51 + DEFAULT("interface A extends B { default void m() { } }"), 78.52 + ABSTRACT("interface A extends B { void m(); }"), 78.53 + NONE("interface A extends B { }"); 78.54 + 78.55 + String interfaceStr; 78.56 + 78.57 + InterfaceKind(String interfaceStr) { 78.58 + this.interfaceStr = interfaceStr; 78.59 + } 78.60 + 78.61 + boolean methodDefined() { 78.62 + return this == DEFAULT; 78.63 + } 78.64 + } 78.65 + 78.66 + enum PruneKind { 78.67 + NO_PRUNE("interface C { }"), 78.68 + PRUNE("interface C extends A { }"); 78.69 + 78.70 + boolean methodDefined(InterfaceKind ik) { 78.71 + return this == PRUNE && 78.72 + ik.methodDefined(); 78.73 + } 78.74 + 78.75 + String interfaceStr; 78.76 + 78.77 + PruneKind(String interfaceStr) { 78.78 + this.interfaceStr = interfaceStr; 78.79 + } 78.80 + } 78.81 + 78.82 + enum QualifierKind { 78.83 + DIRECT_1("C"), 78.84 + DIRECT_2("A"), 78.85 + INDIRECT("B"), 78.86 + UNRELATED("E"), 78.87 + ENCLOSING_1(null), 78.88 + ENCLOSING_2(null); 78.89 + 78.90 + String qualifierStr; 78.91 + 78.92 + QualifierKind(String qualifierStr) { 78.93 + this.qualifierStr = qualifierStr; 78.94 + } 78.95 + 78.96 + String getQualifier(Shape sh) { 78.97 + switch (this) { 78.98 + case ENCLOSING_1: return sh.enclosingAt(0); 78.99 + case ENCLOSING_2: return sh.enclosingAt(1); 78.100 + default: 78.101 + return qualifierStr; 78.102 + } 78.103 + } 78.104 + 78.105 + boolean isEnclosing() { 78.106 + return this == ENCLOSING_1 || 78.107 + this == ENCLOSING_2; 78.108 + } 78.109 + 78.110 + boolean allowSuperCall(InterfaceKind ik, PruneKind pk) { 78.111 + switch (this) { 78.112 + case DIRECT_1: 78.113 + return pk.methodDefined(ik); 78.114 + case DIRECT_2: 78.115 + return ik.methodDefined() && pk == PruneKind.NO_PRUNE; 78.116 + default: 78.117 + return false; 78.118 + } 78.119 + } 78.120 + } 78.121 + 78.122 + enum ExprKind { 78.123 + THIS("this"), 78.124 + SUPER("super"); 78.125 + 78.126 + String exprStr; 78.127 + 78.128 + ExprKind(String exprStr) { 78.129 + this.exprStr = exprStr; 78.130 + } 78.131 + } 78.132 + 78.133 + enum ElementKind { 78.134 + INTERFACE("interface #N { #B }", true), 78.135 + INTERFACE_EXTENDS("interface #N extends A, C { #B }", true), 78.136 + CLASS("class #N { #B }", false), 78.137 + CLASS_EXTENDS("abstract class #N implements A, C { #B }", false), 78.138 + STATIC_CLASS("static class #N { #B }", true), 78.139 + STATIC_CLASS_EXTENDS("abstract static class #N implements A, C { #B }", true), 78.140 + ANON_CLASS("new Object() { #B };", false), 78.141 + METHOD("void test() { #B }", false), 78.142 + STATIC_METHOD("static void test() { #B }", true), 78.143 + DEFAULT_METHOD("default void test() { #B }", false); 78.144 + 78.145 + String templateDecl; 78.146 + boolean isStatic; 78.147 + 78.148 + ElementKind(String templateDecl, boolean isStatic) { 78.149 + this.templateDecl = templateDecl; 78.150 + this.isStatic = isStatic; 78.151 + } 78.152 + 78.153 + boolean isClassDecl() { 78.154 + switch(this) { 78.155 + case METHOD: 78.156 + case STATIC_METHOD: 78.157 + case DEFAULT_METHOD: 78.158 + return false; 78.159 + default: 78.160 + return true; 78.161 + } 78.162 + } 78.163 + 78.164 + boolean isAllowedEnclosing(ElementKind ek, boolean isTop) { 78.165 + switch (this) { 78.166 + case CLASS: 78.167 + case CLASS_EXTENDS: 78.168 + //class is implicitly static inside interface, so skip this combo 78.169 + return ek.isClassDecl() && 78.170 + ek != INTERFACE && ek != INTERFACE_EXTENDS; 78.171 + case ANON_CLASS: 78.172 + return !ek.isClassDecl(); 78.173 + case METHOD: 78.174 + return ek == CLASS || ek == CLASS_EXTENDS || 78.175 + ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS || 78.176 + ek == ANON_CLASS; 78.177 + case INTERFACE: 78.178 + case INTERFACE_EXTENDS: 78.179 + case STATIC_CLASS: 78.180 + case STATIC_CLASS_EXTENDS: 78.181 + case STATIC_METHOD: 78.182 + return (isTop && (ek == CLASS || ek == CLASS_EXTENDS)) || 78.183 + ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS; 78.184 + case DEFAULT_METHOD: 78.185 + return ek == INTERFACE || ek == INTERFACE_EXTENDS; 78.186 + default: 78.187 + throw new AssertionError("Bad enclosing element kind" + this); 78.188 + } 78.189 + } 78.190 + 78.191 + boolean isAllowedTop() { 78.192 + switch (this) { 78.193 + case CLASS: 78.194 + case CLASS_EXTENDS: 78.195 + case INTERFACE: 78.196 + case INTERFACE_EXTENDS: 78.197 + return true; 78.198 + default: 78.199 + return false; 78.200 + } 78.201 + } 78.202 + 78.203 + boolean hasSuper() { 78.204 + return this == INTERFACE_EXTENDS || 78.205 + this == STATIC_CLASS_EXTENDS || 78.206 + this == CLASS_EXTENDS; 78.207 + } 78.208 + } 78.209 + 78.210 + static class Shape { 78.211 + 78.212 + String shapeStr; 78.213 + List<ElementKind> enclosingElements; 78.214 + List<String> enclosingNames; 78.215 + List<String> elementsWithMethod; 78.216 + 78.217 + Shape(ElementKind... elements) { 78.218 + System.err.println("elements = " + Arrays.toString(elements)); 78.219 + enclosingElements = new ArrayList<>(); 78.220 + enclosingNames = new ArrayList<>(); 78.221 + elementsWithMethod = new ArrayList<>(); 78.222 + int count = 0; 78.223 + String prevName = null; 78.224 + for (ElementKind ek : elements) { 78.225 + String name = "name"+count++; 78.226 + if (ek.isStatic) { 78.227 + enclosingElements = new ArrayList<>(); 78.228 + enclosingNames = new ArrayList<>(); 78.229 + } 78.230 + if (ek.isClassDecl()) { 78.231 + enclosingElements.add(ek); 78.232 + enclosingNames.add(name); 78.233 + } else { 78.234 + elementsWithMethod.add(prevName); 78.235 + } 78.236 + String element = ek.templateDecl.replaceAll("#N", name); 78.237 + shapeStr = shapeStr == null ? element : shapeStr.replaceAll("#B", element); 78.238 + prevName = name; 78.239 + } 78.240 + } 78.241 + 78.242 + String getShape(QualifierKind qk, ExprKind ek) { 78.243 + String methName = ek == ExprKind.THIS ? "test" : "m"; 78.244 + String call = qk.getQualifier(this) + "." + ek.exprStr + "." + methName + "();"; 78.245 + return shapeStr.replaceAll("#B", call); 78.246 + } 78.247 + 78.248 + String enclosingAt(int index) { 78.249 + return index < enclosingNames.size() ? enclosingNames.get(index) : "BAD"; 78.250 + } 78.251 + } 78.252 + 78.253 + public static void main(String... args) throws Exception { 78.254 + 78.255 + //create default shared JavaCompiler - reused across multiple compilations 78.256 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 78.257 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 78.258 + 78.259 + for (InterfaceKind ik : InterfaceKind.values()) { 78.260 + for (PruneKind pk : PruneKind.values()) { 78.261 + for (ElementKind ek1 : ElementKind.values()) { 78.262 + if (!ek1.isAllowedTop()) continue; 78.263 + for (ElementKind ek2 : ElementKind.values()) { 78.264 + if (!ek2.isAllowedEnclosing(ek1, true)) continue; 78.265 + for (ElementKind ek3 : ElementKind.values()) { 78.266 + if (!ek3.isAllowedEnclosing(ek2, false)) continue; 78.267 + for (ElementKind ek4 : ElementKind.values()) { 78.268 + if (!ek4.isAllowedEnclosing(ek3, false)) continue; 78.269 + for (ElementKind ek5 : ElementKind.values()) { 78.270 + if (!ek5.isAllowedEnclosing(ek4, false) || ek5.isClassDecl()) continue; 78.271 + for (QualifierKind qk : QualifierKind.values()) { 78.272 + for (ExprKind ek : ExprKind.values()) { 78.273 + new TestDefaultSuperCall(ik, pk, new Shape(ek1, ek2, ek3, ek4, ek5), qk, ek).run(comp, fm); 78.274 + } 78.275 + } 78.276 + } 78.277 + } 78.278 + } 78.279 + } 78.280 + } 78.281 + } 78.282 + } 78.283 + System.out.println("Total check executed: " + checkCount); 78.284 + } 78.285 + 78.286 + InterfaceKind ik; 78.287 + PruneKind pk; 78.288 + Shape sh; 78.289 + QualifierKind qk; 78.290 + ExprKind ek; 78.291 + JavaSource source; 78.292 + DiagnosticChecker diagChecker; 78.293 + 78.294 + TestDefaultSuperCall(InterfaceKind ik, PruneKind pk, Shape sh, QualifierKind qk, ExprKind ek) { 78.295 + this.ik = ik; 78.296 + this.pk = pk; 78.297 + this.sh = sh; 78.298 + this.qk = qk; 78.299 + this.ek = ek; 78.300 + this.source = new JavaSource(); 78.301 + this.diagChecker = new DiagnosticChecker(); 78.302 + } 78.303 + 78.304 + class JavaSource extends SimpleJavaFileObject { 78.305 + 78.306 + String template = "interface E {}\n" + 78.307 + "interface B { }\n" + 78.308 + "#I\n" + 78.309 + "#P\n" + 78.310 + "#C"; 78.311 + 78.312 + String source; 78.313 + 78.314 + public JavaSource() { 78.315 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 78.316 + source = template.replaceAll("#I", ik.interfaceStr) 78.317 + .replaceAll("#P", pk.interfaceStr) 78.318 + .replaceAll("#C", sh.getShape(qk, ek)); 78.319 + } 78.320 + 78.321 + @Override 78.322 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 78.323 + return source; 78.324 + } 78.325 + } 78.326 + 78.327 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 78.328 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 78.329 + Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source)); 78.330 + try { 78.331 + ct.analyze(); 78.332 + } catch (Throwable ex) { 78.333 + throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); 78.334 + } 78.335 + check(); 78.336 + } 78.337 + 78.338 + void check() { 78.339 + boolean errorExpected = false; 78.340 + 78.341 + boolean badEnclosing = false; 78.342 + boolean badThis = false; 78.343 + boolean badSuper = false; 78.344 + 78.345 + if (qk == QualifierKind.ENCLOSING_1 && 78.346 + sh.enclosingNames.size() < 1) { 78.347 + errorExpected |= true; 78.348 + badEnclosing = true; 78.349 + } 78.350 + 78.351 + if (qk == QualifierKind.ENCLOSING_2 && 78.352 + sh.enclosingNames.size() < 2) { 78.353 + errorExpected |= true; 78.354 + badEnclosing = true; 78.355 + } 78.356 + 78.357 + if (ek == ExprKind.THIS) { 78.358 + boolean found = false; 78.359 + for (int i = 0; i < sh.enclosingElements.size(); i++) { 78.360 + if (sh.enclosingElements.get(i) == ElementKind.ANON_CLASS) continue; 78.361 + if (sh.enclosingNames.get(i).equals(qk.getQualifier(sh))) { 78.362 + found = sh.elementsWithMethod.contains(sh.enclosingNames.get(i)); 78.363 + break; 78.364 + } 78.365 + } 78.366 + errorExpected |= !found; 78.367 + if (!found) { 78.368 + badThis = true; 78.369 + } 78.370 + } 78.371 + 78.372 + if (ek == ExprKind.SUPER) { 78.373 + 78.374 + int lastIdx = sh.enclosingElements.size() - 1; 78.375 + boolean found = lastIdx == -1 ? false : 78.376 + sh.enclosingElements.get(lastIdx).hasSuper() && qk.allowSuperCall(ik, pk); 78.377 + 78.378 + errorExpected |= !found; 78.379 + if (!found) { 78.380 + badSuper = true; 78.381 + } 78.382 + } 78.383 + 78.384 + checkCount++; 78.385 + if (diagChecker.errorFound != errorExpected) { 78.386 + throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) + 78.387 + "\nenclosingElems: " + sh.enclosingElements + 78.388 + "\nenclosingNames: " + sh.enclosingNames + 78.389 + "\nelementsWithMethod: " + sh.elementsWithMethod + 78.390 + "\nbad encl: " + badEnclosing + 78.391 + "\nbad this: " + badThis + 78.392 + "\nbad super: " + badSuper + 78.393 + "\nqual kind: " + qk + 78.394 + "\nfound error: " + diagChecker.errorFound); 78.395 + } 78.396 + } 78.397 + 78.398 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 78.399 + 78.400 + boolean errorFound; 78.401 + 78.402 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 78.403 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 78.404 + System.err.println(diagnostic.getMessage(Locale.getDefault())); 78.405 + errorFound = true; 78.406 + } 78.407 + } 78.408 + } 78.409 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/test/tools/javac/diags/examples/DefaultOverridesObjectMember.java Sun Nov 04 10:59:42 2012 +0000 79.3 @@ -0,0 +1,29 @@ 79.4 +/* 79.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 79.7 + * 79.8 + * This code is free software; you can redistribute it and/or modify it 79.9 + * under the terms of the GNU General Public License version 2 only, as 79.10 + * published by the Free Software Foundation. 79.11 + * 79.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 79.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 79.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 79.15 + * version 2 for more details (a copy is included in the LICENSE file that 79.16 + * accompanied this code). 79.17 + * 79.18 + * You should have received a copy of the GNU General Public License version 79.19 + * 2 along with this work; if not, write to the Free Software Foundation, 79.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 79.21 + * 79.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 79.23 + * or visit www.oracle.com if you need additional information or have any 79.24 + * questions. 79.25 + */ 79.26 + 79.27 +// key: compiler.err.default.overrides.object.member 79.28 +// options: -XDallowDefaultMethods 79.29 + 79.30 +interface DefaultOverridesObjectMember { 79.31 + default String toString() { return ""; } 79.32 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/test/tools/javac/diags/examples/OverriddenDefault.java Sun Nov 04 10:59:42 2012 +0000 80.3 @@ -0,0 +1,36 @@ 80.4 +/* 80.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 80.7 + * 80.8 + * This code is free software; you can redistribute it and/or modify it 80.9 + * under the terms of the GNU General Public License version 2 only, as 80.10 + * published by the Free Software Foundation. 80.11 + * 80.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 80.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 80.15 + * version 2 for more details (a copy is included in the LICENSE file that 80.16 + * accompanied this code). 80.17 + * 80.18 + * You should have received a copy of the GNU General Public License version 80.19 + * 2 along with this work; if not, write to the Free Software Foundation, 80.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 80.21 + * 80.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 80.23 + * or visit www.oracle.com if you need additional information or have any 80.24 + * questions. 80.25 + */ 80.26 + 80.27 +// key: compiler.err.illegal.default.super.call 80.28 +// key: compiler.misc.overridden.default 80.29 +// options: -XDallowDefaultMethods 80.30 + 80.31 +class OverriddenDefault { 80.32 + interface I { default void m() { } } 80.33 + interface J extends I { default void m() { } } 80.34 + interface K extends I {} 80.35 + 80.36 + static class C implements J, K { 80.37 + void foo() { K.super.m(); } 80.38 + } 80.39 +} 80.40 \ No newline at end of file
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 81.2 +++ b/test/tools/javac/diags/examples/RedundantSupertype.java Sun Nov 04 10:59:42 2012 +0000 81.3 @@ -0,0 +1,35 @@ 81.4 +/* 81.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 81.7 + * 81.8 + * This code is free software; you can redistribute it and/or modify it 81.9 + * under the terms of the GNU General Public License version 2 only, as 81.10 + * published by the Free Software Foundation. 81.11 + * 81.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 81.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 81.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 81.15 + * version 2 for more details (a copy is included in the LICENSE file that 81.16 + * accompanied this code). 81.17 + * 81.18 + * You should have received a copy of the GNU General Public License version 81.19 + * 2 along with this work; if not, write to the Free Software Foundation, 81.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 81.21 + * 81.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 81.23 + * or visit www.oracle.com if you need additional information or have any 81.24 + * questions. 81.25 + */ 81.26 + 81.27 +// key: compiler.err.illegal.default.super.call 81.28 +// key: compiler.misc.redundant.supertype 81.29 +// options: -XDallowDefaultMethods 81.30 + 81.31 +class RedundantSupertype { 81.32 + interface I { default void m() { } } 81.33 + interface J extends I { default void m() { } } 81.34 + 81.35 + static class C implements I, J { 81.36 + void foo() { I.super.m(); } 81.37 + } 81.38 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 82.2 +++ b/test/tools/javac/diags/examples/TypesIncompatibleAbstractDefault.java Sun Nov 04 10:59:42 2012 +0000 82.3 @@ -0,0 +1,37 @@ 82.4 +/* 82.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 82.7 + * 82.8 + * This code is free software; you can redistribute it and/or modify it 82.9 + * under the terms of the GNU General Public License version 2 only, as 82.10 + * published by the Free Software Foundation. 82.11 + * 82.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 82.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 82.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 82.15 + * version 2 for more details (a copy is included in the LICENSE file that 82.16 + * accompanied this code). 82.17 + * 82.18 + * You should have received a copy of the GNU General Public License version 82.19 + * 2 along with this work; if not, write to the Free Software Foundation, 82.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 82.21 + * 82.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 82.23 + * or visit www.oracle.com if you need additional information or have any 82.24 + * questions. 82.25 + */ 82.26 + 82.27 +// key: compiler.err.types.incompatible.abstract.default 82.28 +// options: -XDallowDefaultMethods 82.29 + 82.30 +class TypesIncompatibleAbstractDefault { 82.31 + interface A { 82.32 + default void m() { } 82.33 + } 82.34 + 82.35 + interface B { 82.36 + void m(); 82.37 + } 82.38 + 82.39 + interface AB extends A, B { } 82.40 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 83.2 +++ b/test/tools/javac/diags/examples/TypesIncompatibleUnrelatedDefaults.java Sun Nov 04 10:59:42 2012 +0000 83.3 @@ -0,0 +1,37 @@ 83.4 +/* 83.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 83.7 + * 83.8 + * This code is free software; you can redistribute it and/or modify it 83.9 + * under the terms of the GNU General Public License version 2 only, as 83.10 + * published by the Free Software Foundation. 83.11 + * 83.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 83.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 83.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 83.15 + * version 2 for more details (a copy is included in the LICENSE file that 83.16 + * accompanied this code). 83.17 + * 83.18 + * You should have received a copy of the GNU General Public License version 83.19 + * 2 along with this work; if not, write to the Free Software Foundation, 83.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 83.21 + * 83.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 83.23 + * or visit www.oracle.com if you need additional information or have any 83.24 + * questions. 83.25 + */ 83.26 + 83.27 +// key: compiler.err.types.incompatible.unrelated.defaults 83.28 +// options: -XDallowDefaultMethods 83.29 + 83.30 +class TypesIncompatibleUnrelatedDefaults { 83.31 + interface A { 83.32 + default void m() { } 83.33 + } 83.34 + 83.35 + interface B { 83.36 + default void m() { } 83.37 + } 83.38 + 83.39 + interface AB extends A, B { } 83.40 +}
84.1 --- a/test/tools/javac/generics/7022054/T7022054pos1.java Sat Nov 03 21:09:57 2012 -0700 84.2 +++ b/test/tools/javac/generics/7022054/T7022054pos1.java Sun Nov 04 10:59:42 2012 +0000 84.3 @@ -26,7 +26,8 @@ 84.4 * @bug 7022054 84.5 * 84.6 * @summary Invalid compiler error on covariant overriding methods with the same erasure 84.7 - * @compile T7022054pos1.java 84.8 + * @compile -source 7 T7022054pos1.java 84.9 + * @compile/fail -XDstrictMethodClashCheck T7022054pos1.java 84.10 * 84.11 */ 84.12
85.1 --- a/test/tools/javac/generics/7022054/T7022054pos2.java Sat Nov 03 21:09:57 2012 -0700 85.2 +++ b/test/tools/javac/generics/7022054/T7022054pos2.java Sun Nov 04 10:59:42 2012 +0000 85.3 @@ -26,8 +26,8 @@ 85.4 * @bug 7022054 85.5 * 85.6 * @summary Invalid compiler error on covariant overriding methods with the same erasure 85.7 - * @compile T7022054pos2.java 85.8 - * 85.9 + * @compile -source 7 T7022054pos2.java 85.10 + * @compile/fail -XDstrictMethodClashCheck T7022054pos2.java 85.11 */ 85.12 85.13 class T7022054pos2 {
86.1 --- a/test/tools/javac/scope/7046348/EagerInterfaceCompletionTest.java Sat Nov 03 21:09:57 2012 -0700 86.2 +++ b/test/tools/javac/scope/7046348/EagerInterfaceCompletionTest.java Sun Nov 04 10:59:42 2012 +0000 86.3 @@ -30,6 +30,7 @@ 86.4 import java.io.File; 86.5 import java.net.URI; 86.6 import java.util.Arrays; 86.7 +import java.util.List; 86.8 86.9 import javax.tools.Diagnostic; 86.10 import javax.tools.DiagnosticListener; 86.11 @@ -43,13 +44,15 @@ 86.12 86.13 JavaCompiler javacTool; 86.14 File testDir; 86.15 + VersionKind versionKind; 86.16 HierarchyKind hierarchyKind; 86.17 TestKind testKind; 86.18 ActionKind actionKind; 86.19 86.20 - EagerInterfaceCompletionTest(JavaCompiler javacTool, File testDir, 86.21 + EagerInterfaceCompletionTest(JavaCompiler javacTool, File testDir, VersionKind versionKind, 86.22 HierarchyKind hierarchyKind, TestKind testKind, ActionKind actionKind) { 86.23 this.javacTool = javacTool; 86.24 + this.versionKind = versionKind; 86.25 this.hierarchyKind = hierarchyKind; 86.26 this.testDir = testDir; 86.27 this.testKind = testKind; 86.28 @@ -62,7 +65,7 @@ 86.29 actionKind.doAction(this); 86.30 DiagnosticChecker dc = new DiagnosticChecker(); 86.31 compile(dc, testKind.source); 86.32 - if (testKind.completionFailure(actionKind, hierarchyKind) != dc.errorFound) { 86.33 + if (testKind.completionFailure(versionKind, actionKind, hierarchyKind) != dc.errorFound) { 86.34 if (dc.errorFound) { 86.35 error("Unexpected completion failure" + 86.36 "\nhierarhcyKind " + hierarchyKind + 86.37 @@ -80,7 +83,8 @@ 86.38 void compile(DiagnosticChecker dc, JavaSource... sources) { 86.39 try { 86.40 CompilationTask ct = javacTool.getTask(null, null, dc, 86.41 - Arrays.asList("-d", testDir.getAbsolutePath(), "-cp", testDir.getAbsolutePath()), 86.42 + Arrays.asList("-d", testDir.getAbsolutePath(), "-cp", 86.43 + testDir.getAbsolutePath(), versionKind.optsArr[0], versionKind.optsArr[1]), 86.44 null, Arrays.asList(sources)); 86.45 ct.call(); 86.46 } 86.47 @@ -108,12 +112,25 @@ 86.48 boolean errorFound = false; 86.49 86.50 public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 86.51 - errorFound = true; 86.52 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 86.53 + errorFound = true; 86.54 + } 86.55 } 86.56 } 86.57 86.58 //global declarations 86.59 86.60 + enum VersionKind { 86.61 + PRE_LAMBDA("-source", "7"), 86.62 + LAMBDA("-source", "8"); 86.63 + 86.64 + String[] optsArr; 86.65 + 86.66 + VersionKind(String... optsArr) { 86.67 + this.optsArr = optsArr; 86.68 + } 86.69 + } 86.70 + 86.71 enum HierarchyKind { 86.72 INTERFACE("interface A { boolean f = false; void m(); }\n" + 86.73 "class B implements A { public void m() {} }"), 86.74 @@ -157,13 +174,14 @@ 86.75 this.source = new JavaSource("Test2.java", code); 86.76 } 86.77 86.78 - boolean completionFailure(ActionKind ak, HierarchyKind hk) { 86.79 + boolean completionFailure(VersionKind vk, ActionKind ak, HierarchyKind hk) { 86.80 switch (this) { 86.81 case ACCESS_ONLY: 86.82 case CONSTR: return ak == ActionKind.REMOVE_B; 86.83 case FIELD: 86.84 case SUPER: return true; 86.85 - case METHOD: return hk != HierarchyKind.INTERFACE || ak == ActionKind.REMOVE_B; 86.86 + case METHOD: return hk != HierarchyKind.INTERFACE || ak == ActionKind.REMOVE_B || 86.87 + (hk == HierarchyKind.INTERFACE && ak == ActionKind.REMOVE_A && vk == VersionKind.LAMBDA); 86.88 default: throw new AssertionError("Unexpected test kind " + this); 86.89 } 86.90 } 86.91 @@ -173,12 +191,15 @@ 86.92 String SCRATCH_DIR = System.getProperty("user.dir"); 86.93 JavaCompiler javacTool = ToolProvider.getSystemJavaCompiler(); 86.94 int n = 0; 86.95 - for (HierarchyKind hierarchyKind : HierarchyKind.values()) { 86.96 - for (TestKind testKind : TestKind.values()) { 86.97 - for (ActionKind actionKind : ActionKind.values()) { 86.98 - File testDir = new File(SCRATCH_DIR, "test"+n); 86.99 - new EagerInterfaceCompletionTest(javacTool, testDir, hierarchyKind, testKind, actionKind).test(); 86.100 - n++; 86.101 + for (VersionKind versionKind : VersionKind.values()) { 86.102 + for (HierarchyKind hierarchyKind : HierarchyKind.values()) { 86.103 + for (TestKind testKind : TestKind.values()) { 86.104 + for (ActionKind actionKind : ActionKind.values()) { 86.105 + File testDir = new File(SCRATCH_DIR, "test"+n); 86.106 + new EagerInterfaceCompletionTest(javacTool, testDir, versionKind, 86.107 + hierarchyKind, testKind, actionKind).test(); 86.108 + n++; 86.109 + } 86.110 } 86.111 } 86.112 }