Mercurial > hg > openjdk > lambda > langtools
changeset 1590:b38937b3090e
Switch default method syntax to EDR syntax (default as attribute)
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Flags.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Tue Nov 06 15:39:30 2012 -0800 @@ -252,9 +252,9 @@ public static final long CLASH = 1L<<42; /** - * Flag that marks a defender method/interface + * Internal flag that marks a default method/interface */ - public static final long DEFENDER = 1L<<44; + public static final long DEFAULT = 1L<<43; /** Modifier masks. */ @@ -268,11 +268,13 @@ VOLATILE | TRANSIENT | ENUM, ConstructorFlags = AccessFlags, InterfaceMethodFlags = ABSTRACT | PUBLIC, - InterfaceDefenderMethodMask = PUBLIC | STRICTFP | SYNCHRONIZED, MethodFlags = AccessFlags | ABSTRACT | STATIC | NATIVE | SYNCHRONIZED | FINAL | STRICTFP; public static final long - LocalVarFlags = FINAL | PARAMETER; + ExtendedStandardFlags = (long)StandardFlags | DEFAULT, + InterfaceDefaultMethodMask = ABSTRACT | PUBLIC | STRICTFP | SYNCHRONIZED | DEFAULT, + LocalVarFlags = FINAL | PARAMETER; + public static Set<Modifier> asModifierSet(long flags) { Set<Modifier> modifiers = modifierSets.get(flags);
--- a/src/share/classes/com/sun/tools/javac/code/Source.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Tue Nov 06 15:39:30 2012 -0800 @@ -203,7 +203,7 @@ public boolean allowMethodReferences() { return compareTo(JDK1_8) >= 0; } - public boolean allowDefenderMethods() { + public boolean allowDefaultMethods() { return compareTo(JDK1_8) >= 0; } public boolean allowPreciseCheckConflict() {
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Tue Nov 06 15:39:30 2012 -0800 @@ -436,7 +436,8 @@ } public Set<Modifier> getModifiers() { - return Flags.asModifierSet(flags()); + long flags = flags(); + return Flags.asModifierSet((flags() & DEFAULT) != 0 ? flags & ~ABSTRACT : flags); } public Name getSimpleName() { @@ -1191,7 +1192,7 @@ // check for an inherited implementation if ((flags() & ABSTRACT) != 0 || - ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFENDER) == 0) || + ((other.flags() & ABSTRACT) == 0 && (other.flags() & DEFAULT) == 0) || !other.isOverridableIn(origin) || !this.isMemberOf(origin, types)) return false;
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Nov 06 15:39:30 2012 -0800 @@ -103,7 +103,7 @@ allowBoxing = source.allowBoxing(); allowCovariantReturns = source.allowCovariantReturns(); allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); - allowDefenderMethods = source.allowDefenderMethods(); + allowDefenderMethods = source.allowDefaultMethods(); reader = ClassReader.instance(context); chk = Check.instance(context); capturedName = names.fromString("<captured wildcard>"); @@ -401,6 +401,7 @@ public boolean accepts(Symbol sym) { return sym.kind == Kinds.MTH && (sym.flags() & ABSTRACT) != 0 && + (sym.flags() & DEFAULT) == 0 && !overridesObjectMethod(origin, sym) && notOverridden(sym); }
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 06 15:39:30 2012 -0800 @@ -137,7 +137,7 @@ allowStringsInSwitch = source.allowStringsInSwitch(); allowPoly = source.allowPoly(); allowLambda = source.allowLambda(); - allowDefenderMethods = source.allowDefenderMethods(); + allowDefaultMethods = source.allowDefaultMethods(); allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses(); sourceName = source.name; relax = (options.isSet("-retrofit") || @@ -188,7 +188,7 @@ /** Switch: support defender methods ? */ - boolean allowDefenderMethods; + boolean allowDefaultMethods; /** Switch: allow references to surrounding object from anonymous * objects during constructor call? @@ -879,7 +879,7 @@ public void visitMethodDef(JCMethodDecl tree) { MethodSymbol m = tree.sym; - boolean isDefender = (m.flags() & DEFENDER) != 0; + boolean isDefaultMethod = (m.flags() & DEFAULT) != 0; Lint lint = env.info.lint.augment(m.annotations, m.flags()); Lint prevLint = chk.setLint(lint); @@ -904,7 +904,7 @@ } chk.checkOverride(tree, m); - if (isDefender) { + if (isDefaultMethod) { //when attributing defender method body we need a synthetic 'this' variable //whose type is the type of the enclosing interface VarSymbol _this = new VarSymbol(0, names._this, m.owner.type, m.owner); @@ -968,8 +968,8 @@ // Empty bodies are only allowed for // abstract, native, or interface methods, or for methods // in a retrofit signature class. - if ((owner.flags() & INTERFACE) == 0 && - (tree.mods.flags & (ABSTRACT | NATIVE)) == 0 && + if (isDefaultMethod || ((owner.flags() & INTERFACE) == 0 && + (tree.mods.flags & (ABSTRACT | NATIVE)) == 0) && !relax) log.error(tree.pos(), "missing.meth.body.or.decl.abstract"); if (tree.defaultValue != null) { @@ -977,10 +977,12 @@ log.error(tree.pos(), "default.allowed.in.intf.annotation.member"); } - } else if ((owner.flags() & INTERFACE) != 0 && !isDefender) { - log.error(tree.body.pos(), "intf.meth.cant.have.body"); - } else if ((tree.mods.flags & ABSTRACT) != 0) { - log.error(tree.pos(), "abstract.meth.cant.have.body"); + } else if ((tree.sym.flags() & ABSTRACT) != 0 && !isDefaultMethod) { + if ((owner.flags() & INTERFACE) != 0) { + log.error(tree.body.pos(), "intf.meth.cant.have.body"); + } else { + log.error(tree.pos(), "abstract.meth.cant.have.body"); + } } else if ((tree.mods.flags & NATIVE) != 0) { log.error(tree.pos(), "native.meth.cant.have.body"); } else { @@ -2287,30 +2289,30 @@ return t; } } - - Type fallbackDescriptorType(JCExpression tree) { - switch (tree.getTag()) { - case LAMBDA: - JCLambda lambda = (JCLambda)tree; - List<Type> argtypes = List.nil(); - for (JCVariableDecl param : lambda.params) { - argtypes = param.vartype != null ? - argtypes.append(param.vartype.type) : - argtypes.append(syms.errType); - } - return new MethodType(argtypes, Type.recoveryType, List.<Type>nil(), syms.methodClass); - case REFERENCE: - return new MethodType(List.<Type>nil(), Type.recoveryType, List.<Type>nil(), syms.methodClass); - default: - Assert.error("Cannot get here!"); + //where + private Type fallbackDescriptorType(JCExpression tree) { + switch (tree.getTag()) { + case LAMBDA: + JCLambda lambda = (JCLambda)tree; + List<Type> argtypes = List.nil(); + for (JCVariableDecl param : lambda.params) { + argtypes = param.vartype != null ? + argtypes.append(param.vartype.type) : + argtypes.append(syms.errType); + } + return new MethodType(argtypes, Type.recoveryType, List.<Type>nil(), syms.methodClass); + case REFERENCE: + return new MethodType(List.<Type>nil(), Type.recoveryType, List.<Type>nil(), syms.methodClass); + default: + Assert.error("Cannot get here!"); + } + return null; } - return null; - } - - //where + private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts) { checkAccessibleTypes(pos, env, inferenceContext, List.from(ts)); } + private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts) { if (inferenceContext.free(ts)) { inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() { @@ -3765,7 +3767,7 @@ // are compatible (i.e. no two define methods with same arguments // yet different return types). (JLS 8.4.6.3) chk.checkCompatibleSupertypes(tree.pos(), c.type); - if (allowDefenderMethods) { + if (allowDefaultMethods) { chk.checkDefenderClashes(tree.pos(), c.type); } }
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Nov 06 15:39:30 2012 -0800 @@ -116,7 +116,7 @@ allowAnnotations = source.allowAnnotations(); allowCovariantReturns = source.allowCovariantReturns(); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); - allowDefenderMethods = source.allowDefenderMethods(); + allowDefenderMethods = source.allowDefaultMethods(); allowPreciseCheckConflict = source.allowPreciseCheckConflict(); complexInference = options.isSet("complexinference"); warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); @@ -1084,9 +1084,9 @@ } else mask = ConstructorFlags; } else if ((sym.owner.flags_field & INTERFACE) != 0) { - if ((flags & DEFENDER) != 0) { - mask = InterfaceDefenderMethodMask; - implicit = PUBLIC; + if ((flags & DEFAULT) != 0) { + mask = InterfaceDefaultMethodMask; + implicit = PUBLIC | ABSTRACT; } else { mask = implicit = InterfaceMethodFlags; } @@ -1137,7 +1137,7 @@ default: throw new AssertionError(); } - long illegal = flags & StandardFlags & ~mask; + long illegal = flags & ExtendedStandardFlags & ~mask; if (illegal != 0) { if ((illegal & INTERFACE) != 0) { log.error(pos, "intf.not.allowed.here"); @@ -1153,7 +1153,7 @@ // in the presence of inner classes. Should it be deleted here? checkDisjoint(pos, flags, ABSTRACT, - PRIVATE | STATIC)) + PRIVATE | STATIC | DEFAULT)) && checkDisjoint(pos, flags, ABSTRACT | INTERFACE, @@ -1177,7 +1177,7 @@ STRICTFP))) { // skip } - return flags & (mask | ~StandardFlags) | implicit; + return flags & (mask | ~ExtendedStandardFlags) | implicit; } @@ -1862,7 +1862,7 @@ Type st1 = null; if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types)) continue; Symbol impl = ((MethodSymbol)s1).implementation(site.tsym, types, false); - if (impl != null && (impl.flags() & (ABSTRACT|DEFENDER)) == 0) continue; + if (impl != null && (impl.flags() & ABSTRACT) == 0) continue; for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) { Symbol s2 = e2.sym; if (s1 == s2) continue; @@ -1960,8 +1960,7 @@ Scope.Entry e = c.members().lookup(m.name); while (e.scope != null) { if (m.overrides(e.sym, origin, types, false)) { - if ((e.sym.flags() & (ABSTRACT)) == 0 && - (m.owner.isInterface() || (e.sym.flags() & (DEFENDER)) == 0)) { + if ((e.sym.flags() & ABSTRACT) == 0) { checkOverride(tree, m, (MethodSymbol)e.sym, origin); } } @@ -2016,7 +2015,7 @@ undef == null && e != null; e = e.sibling) { if (e.sym.kind == MTH && - (e.sym.flags() & (ABSTRACT|IPROXY)) == ABSTRACT) { + (e.sym.flags() & (ABSTRACT|IPROXY|DEFAULT)) == ABSTRACT) { MethodSymbol absmeth = (MethodSymbol)e.sym; MethodSymbol implmeth = absmeth.implementation(impl, types, true); if (implmeth == null || implmeth == absmeth) { @@ -2256,7 +2255,7 @@ if ((allowGenerics || origin != lc) && (lc.flags() & ABSTRACT) != 0) { for (Scope.Entry e=lc.members().elems; e != null; e=e.sibling) { if (e.sym.kind == MTH && - !e.sym.isStatic() && (e.sym.flags() & (ABSTRACT|DEFENDER)) != 0) { + (e.sym.flags() & (STATIC|ABSTRACT)) == ABSTRACT) { MethodSymbol absmeth = (MethodSymbol)e.sym; MethodSymbol implmeth = absmeth.implementation(origin, types, false); if (implmeth != null && implmeth != absmeth && @@ -2407,21 +2406,35 @@ } List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m); if (prov.size() > 1) { - boolean hasDefender = false; - for (MethodSymbol provSym : prov) { - if ((provSym.flags() & DEFENDER) != 0) { - hasDefender = true; + List<Symbol> abstracts = List.nil(); + List<Symbol> defaults = List.nil(); + for (MethodSymbol provSym : prov) { + if ((provSym.flags() & DEFAULT) != 0) { + defaults = defaults.append(provSym); + } else if ((provSym.flags() & ABSTRACT) != 0) { + abstracts = abstracts.append(provSym); + } + if (defaults.nonEmpty() && defaults.size() + abstracts.size() >= 2) { + //strong semantics - issue an error if two sibling interfaces + //have two overide-equivalent defaults - or if one is abstract + //and the other is default + String errKey; + Symbol s1 = defaults.head; + Symbol s2; + if (defaults.size() > 1) { + errKey = "types.incompatible.unrelated.defaults"; + s2 = defaults.tail.head; + } else { + errKey = "types.incompatible.abstract.default"; + s2 = abstracts.head; + } + log.error(pos, errKey, + Kinds.kindName(site.tsym), site, + m.name, types.memberType(site, m).getParameterTypes(), + s1.location(), s2.location()); break; } } - if (hasDefender) { - Symbol tsym1 = prov.head.owner; - Symbol tsym2 = prov.tail.head.owner; - log.error(pos, "types.incompatible.unrelated.defaults", - Kinds.kindName(site.tsym), site, - m.name, types.memberType(site, m).getParameterTypes(), - tsym1, tsym2); - } } } } @@ -2437,7 +2450,7 @@ public boolean accepts(Symbol s) { return s.kind == MTH && - (s.flags() & DEFENDER) != 0 && + (s.flags() & DEFAULT) != 0 && s.isInheritedIn(site.tsym, types) && !s.isConstructor(); }
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Nov 06 15:39:30 2012 -0800 @@ -714,7 +714,7 @@ // If instance access isn't needed, make it static // Interface methods much be public default methods, otherwise make it private - translatedSym.flags_field = SYNTHETIC | (needInstance? 0 : STATIC) | (inInterface? PUBLIC | DEFENDER : PRIVATE); + translatedSym.flags_field = SYNTHETIC | (needInstance? 0 : STATIC) | (inInterface? PUBLIC | DEFAULT : PRIVATE); //compute synthetic params ListBuffer<JCVariableDecl> params = ListBuffer.lb();
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Nov 06 15:39:30 2012 -0800 @@ -3636,13 +3636,13 @@ boolean qualifiedSuperAccess = tree.selected.hasTag(SELECT) && TreeInfo.name(tree.selected) == names._super && - (((JCFieldAccess)tree.selected).selected.type.tsym.flags() & DEFENDER) == 0; + (((JCFieldAccess)tree.selected).selected.type.tsym.flags() & DEFAULT) == 0; tree.selected = translate(tree.selected); if (tree.name == names._class) { result = classOf(tree.selected); } else if (tree.name == names._super && - (tree.selected.type.tsym.flags() & DEFENDER) != 0) { + (tree.selected.type.tsym.flags() & DEFAULT) != 0) { //default super call!! Not a classic qualified super call TypeSymbol supSym = tree.selected.type.tsym; Type ctype = currentClass.type;
--- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Tue Nov 06 15:39:30 2012 -0800 @@ -562,8 +562,8 @@ tree.sym = m; //if this is a defender method, add the DEFENDER flag to the enclosing interface - if ((tree.mods.flags & DEFENDER) != 0) { - m.owner.flags_field |= DEFENDER; + if ((tree.mods.flags & DEFAULT) != 0) { + m.owner.flags_field |= DEFAULT; } Env<AttrContext> localEnv = methodEnv(tree, env);
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Nov 06 15:39:30 2012 -0800 @@ -88,7 +88,7 @@ public final boolean boxingEnabled; // = source.allowBoxing(); public final boolean varargsEnabled; // = source.allowVarargs(); public final boolean allowMethodHandles; - public final boolean allowDefenderMethods; + public final boolean allowDefaultMethods; private final boolean debugResolve; final EnumSet<VerboseResolutionMode> verboseResolutionMode; @@ -123,7 +123,7 @@ verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); Target target = Target.instance(context); allowMethodHandles = target.hasMethodHandles(); - allowDefenderMethods = source.allowDefenderMethods(); + allowDefaultMethods = source.allowDefaultMethods(); polymorphicSignatureScope = new Scope(syms.noSymbol); inapplicableMethodException = new InapplicableMethodException(diags); @@ -1378,6 +1378,42 @@ return new AmbiguityError(m1, m2); } } + + Symbol lookupMethod(Env<AttrContext> env, + Type site, + Name name, + List<Type> argtypes, + List<Type> typeargtypes, + Scope sc, + Symbol bestSoFar, + boolean allowBoxing, + boolean useVarargs, + boolean operator, + boolean abstractok) { + for (Symbol s : sc.getElementsByName(name, new LookupFilter(abstractok))) { + bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, + bestSoFar, allowBoxing, useVarargs, operator); + } + return bestSoFar; + } + //where + class LookupFilter implements Filter<Symbol> { + + boolean abstractOk; + + LookupFilter(boolean abstractOk) { + this.abstractOk = abstractOk; + } + + public boolean accepts(Symbol s) { + long flags = s.flags(); + return s.kind == MTH && + (flags & SYNTHETIC) == 0 && + (abstractOk || + (flags & DEFAULT) != 0 || + (flags & ABSTRACT) == 0); + } + }; /** Find best qualified method matching given name, type and value * arguments. @@ -1441,17 +1477,18 @@ } } } - Symbol concrete = bestSoFar.kind < ERR && + + Symbol concrete = bestSoFar.kind < ERR && (bestSoFar.flags() & ABSTRACT) == 0 ? bestSoFar : methodNotFound; for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) { - if (iphase2 == InterfaceLookupPhase.DEFENDER_OK && !allowDefenderMethods) break; + if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethods) break; //keep searching for abstract methods for (Type itype : itypesMap.get(iphase2)) { if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) - if (iphase2 == InterfaceLookupPhase.DEFENDER_OK && - (itype.tsym.flags() & DEFENDER) == 0) continue; + if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && + (itype.tsym.flags() & DEFAULT) == 0) continue; bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); if (concrete != bestSoFar && @@ -1469,7 +1506,7 @@ } return bestSoFar; } - + enum InterfaceLookupPhase { ABSTRACT_OK() { @Override @@ -1479,20 +1516,20 @@ //from superinterfaces) if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) { return this; - } else if (rs.allowDefenderMethods) { - return DEFENDER_OK; + } else if (rs.allowDefaultMethods) { + return DEFAULT_OK; } else { return null; } } }, - DEFENDER_OK() { + DEFAULT_OK() { @Override InterfaceLookupPhase update(Symbol s, Resolve rs) { return this; } }; - + abstract InterfaceLookupPhase update(Symbol s, Resolve rs); } @@ -1549,34 +1586,6 @@ }; } - /** - * Lookup a method with given name and argument types in a given scope - */ - Symbol lookupMethod(Env<AttrContext> env, - Type site, - Name name, - List<Type> argtypes, - List<Type> typeargtypes, - Scope sc, - Symbol bestSoFar, - boolean allowBoxing, - boolean useVarargs, - boolean operator, - boolean abstractok) { - for (Symbol s : sc.getElementsByName(name, lookupFilter)) { - bestSoFar = selectBest(env, site, argtypes, typeargtypes, s, - bestSoFar, allowBoxing, useVarargs, operator); - } - return bestSoFar; - } - //where - Filter<Symbol> lookupFilter = new Filter<Symbol>() { - public boolean accepts(Symbol s) { - return s.kind == MTH && - (s.flags() & SYNTHETIC) == 0; - } - }; - /** Find unqualified method matching given name, type and value arguments. * @param env The current environment. * @param name The method's name. @@ -1965,7 +1974,7 @@ return argtypes; } }; - + LogResolveHelper methodLogResolveHelper = new LogResolveHelper() { public boolean resolveDiagnosticNeeded(Type site, List<Type> argtypes, List<Type> typeargtypes) { return !site.isErroneous() && @@ -2005,7 +2014,7 @@ /** Check that sym is not an abstract method. */ void checkNonAbstract(DiagnosticPosition pos, Symbol sym) { - if ((sym.flags() & ABSTRACT) != 0) + if ((sym.flags() & ABSTRACT) != 0 && (sym.flags() & DEFAULT) == 0) log.error(pos, "abstract.cant.be.accessed.directly", kindName(sym), sym, sym.location()); } @@ -2436,6 +2445,8 @@ /** name of the symbol to lookup */ Name name; + + /** location in which the lookup takes place */ Type site; /** actual types used during the lookup */ @@ -2827,7 +2838,7 @@ if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; } - if (allowDefenderMethods && c.isInterface() && name == names._super && !isStatic(env)) { + if (allowDefaultMethods && c.isInterface() && name == names._super && !isStatic(env)) { //this might be a defender super call if one of the superinterfaces is 'c' for (Type t : pruneInterfaces(env.enclClass.type)) { if (t.tsym == c) {
--- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Tue Nov 06 15:39:30 2012 -0800 @@ -352,7 +352,7 @@ // where MethodSymbol implementation(MethodSymbol msym, TypeSymbol origin, Filter<Symbol> implFilter, boolean checkResult) { MethodSymbol impl = msym.implementation(origin, types, checkResult, implFilter); - return (impl != null && (impl.flags() & DEFENDER) != 0) ? + return (impl != null && (impl.flags() & DEFAULT) != 0) ? null : impl; }
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Tue Nov 06 15:39:30 2012 -0800 @@ -117,7 +117,7 @@ /** Switch: allow defender methods */ - boolean allowDefenderMethods; + boolean allowDefaultMethods; /** Switch: preserve parameter names from the variable table. */ @@ -282,7 +282,7 @@ allowVarargs = source.allowVarargs(); allowAnnotations = source.allowAnnotations(); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); - allowDefenderMethods = source.allowDefenderMethods(); + allowDefaultMethods = source.allowDefaultMethods(); saveParameterNames = options.isSet("save-parameter-names"); cacheCompletionFailure = options.isUnset("dev"); preferSource = "source".equals(options.get("-Xprefer")); @@ -1736,8 +1736,8 @@ (flags & ABSTRACT) == 0 && !name.equals(names.clinit)) { if (majorVersion > Target.JDK1_8.majorVersion || (majorVersion == Target.JDK1_8.majorVersion && minorVersion >= Target.JDK1_8.minorVersion)) { - currentOwner.flags_field |= DEFENDER; - flags |= DEFENDER; + currentOwner.flags_field |= DEFAULT; + flags |= DEFAULT | ABSTRACT; } else { //protect against ill-formed classfiles throw new CompletionFailure(currentOwner, "extension method found in pre JDK 8 classfile");
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Nov 06 15:39:30 2012 -0800 @@ -1540,7 +1540,7 @@ List<Type> interfaces = types.interfaces(c.type); List<Type> typarams = c.type.getTypeArguments(); - int flags = adjustFlags(c.flags() & ~DEFENDER); + int flags = adjustFlags(c.flags() & ~DEFAULT); if ((flags & PROTECTED) != 0) flags |= PUBLIC; flags = flags & ClassFlags & ~STRICTFP; if ((flags & INTERFACE) == 0) flags |= ACC_SUPER; @@ -1676,6 +1676,8 @@ result |= ACC_BRIDGE; if ((flags & VARARGS) != 0 && target.useVarargsFlag()) result |= ACC_VARARGS; + if ((flags & DEFAULT) != 0) + result &= ~ABSTRACT; return result; }
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Nov 06 15:39:30 2012 -0800 @@ -1580,10 +1580,6 @@ public void visitSelect(JCFieldAccess tree) { super.visitSelect(tree); if (tree.sym.kind == VAR) complexity+=1; } - public void visitReference(JCMemberReference tree) - { scan(TreeInfo.getSelector(tree.expr)); - complexity+=1; } - public void visitIdent(JCIdent tree) { if (tree.sym.kind == VAR) { complexity+=1;
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Nov 06 15:39:30 2012 -0800 @@ -112,9 +112,9 @@ this.allowDiamond = source.allowDiamond(); this.allowMulticatch = source.allowMulticatch(); this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true); - this.allowDefenderMethods = source.allowDefenderMethods(); this.allowLambda = source.allowLambda(); this.allowMethodReferences = source.allowMethodReferences(); + this.allowDefaultMethods = source.allowDefaultMethods(); this.keepDocComments = keepDocComments; docComments = newDocCommentTable(keepDocComments); this.keepLineMap = keepLineMap; @@ -144,10 +144,6 @@ */ boolean allowMulticatch; - /** Switch: Should defender methods declaration be accepted? - */ - boolean allowDefenderMethods; - /** Switch: Should varargs be recognized? */ boolean allowVarargs; @@ -187,6 +183,10 @@ /** Switch: should we allow method/constructor references? */ boolean allowMethodReferences; + + /** Switch: Should default methods declaration be accepted? + */ + boolean allowDefaultMethods; /** Switch: should we keep docComments? */ @@ -1837,7 +1837,7 @@ JCClassDecl body = null; if (token.kind == LBRACE) { int pos = token.pos; - List<JCTree> defs = classOrInterfaceBody(names.empty, false, false); + List<JCTree> defs = classOrInterfaceBody(names.empty, false); JCModifiers mods = F.at(Position.NOPOS).Modifiers(0); body = toP(F.at(pos).AnonymousClassDef(mods, defs)); } @@ -2399,6 +2399,7 @@ case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break; case STRICTFP : flag = Flags.STRICTFP; break; case MONKEYS_AT : flag = Flags.ANNOTATION; break; + case DEFAULT : checkDefaultMethods(); flag = Flags.DEFAULT; break; case ERROR : flag = 0; nextToken(); break; default: break loop; } @@ -2793,7 +2794,7 @@ nextToken(); implementing = typeList(); } - List<JCTree> defs = classOrInterfaceBody(name, false, false); + List<JCTree> defs = classOrInterfaceBody(name, false); JCClassDecl result = toP(F.at(pos).ClassDef( mods, name, typarams, extending, implementing, defs)); attach(result, dc); @@ -2817,7 +2818,7 @@ nextToken(); extending = typeList(); } - List<JCTree> defs = classOrInterfaceBody(name, true, (mods.flags & Flags.ANNOTATION) != 0); + List<JCTree> defs = classOrInterfaceBody(name, true); JCClassDecl result = toP(F.at(pos).ClassDef( mods, name, typarams, null, extending, defs)); attach(result, dc); @@ -2872,7 +2873,7 @@ if (token.kind == SEMI) { nextToken(); while (token.kind != RBRACE && token.kind != EOF) { - defs.appendList(classOrInterfaceBodyDeclaration(enumName, false, + defs.appendList(classOrInterfaceBodyDeclaration(enumName, false)); if (token.pos <= endPosTable.errorEndPos) { // error recovery @@ -2904,7 +2905,7 @@ JCClassDecl body = null; if (token.kind == LBRACE) { JCModifiers mods1 = F.at(Position.NOPOS).Modifiers(Flags.ENUM | Flags.STATIC); - List<JCTree> defs = classOrInterfaceBody(names.empty, false, false); + List<JCTree> defs = classOrInterfaceBody(names.empty, false); body = toP(F.at(identPos).AnonymousClassDef(mods1, defs)); } if (args.isEmpty() && body == null) @@ -2934,7 +2935,7 @@ /** ClassBody = "{" {ClassBodyDeclaration} "}" * InterfaceBody = "{" {InterfaceBodyDeclaration} "}" */ - List<JCTree> classOrInterfaceBody(Name className, boolean isInterface, boolean isAnno) { + List<JCTree> classOrInterfaceBody(Name className, boolean isInterface) { accept(LBRACE); if (token.pos <= endPosTable.errorEndPos) { // error recovery @@ -2944,7 +2945,7 @@ } ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); while (token.kind != RBRACE && token.kind != EOF) { - defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface, isAnno)); + defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface)); if (token.pos <= endPosTable.errorEndPos) { // error recovery skip(false, true, true, false); @@ -2969,9 +2970,9 @@ * InterfaceBodyDeclaration = * ";" * | ModifiersOpt Type Ident - * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest | DefenderMethodDeclaratorRest ";" ) + * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) */ - protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface, boolean isAnno) { + protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { if (token.kind == SEMI) { nextToken(); return List.<JCTree>nil(); @@ -3010,13 +3011,15 @@ if (isInterface || tk.name() != className) error(pos, "invalid.meth.decl.ret.type.req"); return List.of(methodDeclaratorRest( - pos, mods, null, names.init, typarams, isInterface, isAnno, true, dc)); + pos, mods, null, names.init, typarams, + isInterface, true, dc)); } else { pos = token.pos; Name name = ident(); if (token.kind == LPAREN) { return List.of(methodDeclaratorRest( - pos, mods, type, name, typarams, isInterface, isAnno, isVoid, dc)); + pos, mods, type, name, typarams, + isInterface, isVoid, dc)); } else if (!isVoid && typarams.isEmpty()) { List<JCTree> defs = variableDeclaratorsRest(pos, mods, type, name, isInterface, dc, @@ -3047,15 +3050,13 @@ * FormalParameters [THROWS TypeList] ";" * ConstructorDeclaratorRest = * "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody - * DefenderMethodDeclaratorRest = - * "(" FormalParameterListOpt ")" [Annotations] [THROWS TypeList] DEFAULT IDENT { '.' [TYPEARGS] IDENT } */ protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List<JCTypeParameter> typarams, - boolean isInterface, boolean isAnno, boolean isVoid, + boolean isInterface, boolean isVoid, Comment dc) { List<JCVariableDecl> params = formalParameters(); if (!isVoid) type = bracketsOpt(type); @@ -3072,29 +3073,11 @@ } else { if (token.kind == DEFAULT) { accept(DEFAULT); - if (isAnno) { - defaultValue = annotationValue(); - accept(SEMI); - } else { - defaultValue = null; - if (!isInterface) { - syntaxError("defender.in.class"); - } - if (token.kind == LBRACE) { - checkDefenderMethods(); - mods.flags |= Flags.DEFENDER; - //an explicit defender declaration is just a method block - body = block(); - } else { - //recovery - defaultValue = annotationValue(); - accept(SEMI); - } - } + defaultValue = annotationValue(); } else { defaultValue = null; - accept(SEMI); } + accept(SEMI); if (token.pos <= endPosTable.errorEndPos) { // error recovery skip(false, true, false, false); @@ -3467,10 +3450,10 @@ allowMethodReferences = true; } } - void checkDefenderMethods() { - if (!allowDefenderMethods) { - log.error(token.pos, "defender.methods.not.supported.in.source", source.name); - allowDefenderMethods = true; + void checkDefaultMethods() { + if (!allowDefaultMethods) { + log.error(token.pos, "default.methods.not.supported.in.source", source.name); + allowDefaultMethods = true; } }
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Nov 06 15:39:30 2012 -0800 @@ -558,7 +558,7 @@ interface expected here compiler.err.intf.meth.cant.have.body=\ - interface methods cannot have body + interface abstract methods cannot have body compiler.err.invalid.annotation.member.type=\ invalid type for annotation member @@ -931,6 +931,11 @@ compiler.err.types.incompatible.unrelated.defaults=\ {0} {1} inherits unrelated defaults for {2}({3}) from types {4} and {5} +# 0: kind, 1: type, 2: name, 3: list of type, 4: symbol, 5: symbol +compiler.err.types.incompatible.abstract.default=\ + {0} {1} inherits abstract and default for {2}({3}) from types {4} and {5} + +# 0: name, 1: kind, 2: symbol compiler.err.default.overrides.object.member=\ extension method {0} in {1} {2} overrides a member of java.lang.Object @@ -1867,9 +1872,6 @@ compiler.err.unexpected.mref=\ method reference not expected here -compiler.err.defender.in.class=\ - Extension methods can only be used within an interface - ## The first argument {0} is a "kindname" (e.g. 'constructor', 'field', etc.) ## The second argument {1} is the non-resolved symbol ## The third argument {2} is a list of type parameters (non-empty if {1} is a method) @@ -2170,8 +2172,9 @@ method references are not supported in -source {0}\n\ (use -source 8 or higher to enable method references) -compiler.err.defender.methods.not.supported.in.source=\ - defender methods are not supported in -source {0}\n\ +# 0: string +compiler.err.default.methods.not.supported.in.source=\ + default methods are not supported in -source {0}\n\ (use -source 8 or higher to enable defender methods) ########################################
--- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Sat Nov 03 15:00:22 2012 +0000 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Nov 06 15:39:30 2012 -0800 @@ -226,16 +226,6 @@ if (!exec.expr.hasTag(APPLY)) return null; return (JCMethodInvocation)exec.expr; } - - /** get the first statement (apply) of the synthetic defender method body */ - public static JCMethodInvocation defenderMethodCall(JCTree tree) { - switch (tree.getTag()) { - case EXEC: return defenderMethodCall(((JCExpressionStatement)tree).expr); - case RETURN : return defenderMethodCall(((JCReturn)tree).expr); - case APPLY : return (JCMethodInvocation)tree; - default: return null; - } - } /** Return true if a tree represents a diamond new expr. */ public static boolean isDiamond(JCTree tree) { @@ -756,25 +746,6 @@ } } - /** Utility method: Get the base expression of this reference. - * For example, {@code String.valueOf} has a type name base, - * while {@code "foo".valueOf} has a expression base {@code "foo"}. - * Note that the base can be an expression independently - * of whether the member (method or field) is static or not. - * If the member is static, an expression base is evaluated and ignored. - * If the member is non-static, and if an expression base is present, - * the method handle must be partially applied to the base, - * using {@linkplain MethodHandle#bind}. - */ - public static JCExpression getSelector(JCTree tree) { - switch (tree.getTag()) { - case SELECT: return ((JCFieldAccess)tree).selected; - case APPLY: return getSelector(((JCMethodInvocation)tree).meth); - case NEWCLASS: return getSelector(((JCNewClass)tree).clazz); - default: return null; - } - } - /** Return true if this is a nonstatic selection. */ public static boolean nonstaticSelect(JCTree tree) { tree = skipParens(tree); @@ -819,8 +790,8 @@ * pre: flags != 0 */ public static long firstFlag(long flags) { - int flag = 1; - while ((flag & StandardFlags) != 0 && (flag & flags) == 0) + long flag = 1; + while ((flag & flags & ExtendedStandardFlags) == 0) flag = flag << 1; return flag; } @@ -828,7 +799,7 @@ /** Return flags as a string, separated by " ". */ public static String flagNames(long flags) { - return Flags.toString(flags & StandardFlags).trim(); + return Flags.toString(flags & ExtendedStandardFlags).trim(); } /** Operator precedences values.
--- a/test/tools/javac/defender/ClassReaderTest/ClassReaderTest.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/ClassReaderTest/ClassReaderTest.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,7 +25,7 @@ * @test * @summary check that defender methods don't cause ClassReader to complete classes recursively * @author Maurizio Cimadamore - * @compile pkg/Foo.java + * @compile -XDallowDefaultMethods pkg/Foo.java * @compile ClassReaderTest.java */
--- a/test/tools/javac/defender/ClassReaderTest/pkg/Foo.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/ClassReaderTest/pkg/Foo.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,8 +24,8 @@ package pkg; public interface Foo { - void m1() default { Impl.m1(this); } - void m2() default { Impl.m2(this); } + default void m1() { Impl.m1(this); } + default void m2() { Impl.m2(this); } } class Impl {
--- a/test/tools/javac/defender/Neg01.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg01.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,36 +1,12 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary negative test for ambiguous defender methods - * @author Maurizio Cimadamore - * @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java + * @compile/fail/ref=Neg01.out -XDallowDefaultMethods -XDrawDiagnostics Neg01.java */ class Neg01 { - interface IA { int m() default { return Neg01.m1(this); } } - interface IB { int m() default { return Neg01.m2(this); } } + interface IA { default int m() { return Neg01.m1(this); } } + interface IB { default int m() { return Neg01.m2(this); } } static class A implements IA {} static class B implements IB {}
--- a/test/tools/javac/defender/Neg01.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg01.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,2 +1,2 @@ -Neg01.java:38:12: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg01.AB, m, , Neg01.IA, Neg01.IB +Neg01.java:14:12: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg01.AB, m, , Neg01.IA, Neg01.IB 1 error
--- a/test/tools/javac/defender/Neg02.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg02.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,40 +1,16 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that ill-formed MI hierarchies do not compile - * @author Maurizio Cimadamore - * @compile/fail/ref=Neg02.out -XDrawDiagnostics Neg02.java + * @compile/fail/ref=Neg02.out -XDallowDefaultMethods -XDrawDiagnostics Neg02.java */ class Neg02 { interface A { - void m() default { Neg02.impl(this); } + default void m() { Neg02.impl(this); } } interface B { - void m() default { Neg02.impl(this); } + default void m() { Neg02.impl(this); } } static class X implements A, B { } //error
--- a/test/tools/javac/defender/Neg02.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg02.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,3 +1,2 @@ -Neg02.java:40:13: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg02.X, m, , Neg02.A, Neg02.B -Neg02.java:43:11: compiler.err.ref.ambiguous: m, kindname.method, m(), Neg02.B, kindname.method, m(), Neg02.A -2 errors +Neg02.java:16:13: compiler.err.types.incompatible.unrelated.defaults: kindname.class, Neg02.X, m, , Neg02.A, Neg02.B +1 error
--- a/test/tools/javac/defender/Neg03.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg03.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,45 +1,20 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that re-abstracted defender methods are skipped accordingly - * @author Brian Goetz - * @author Maurizio Cimadamore - * @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java + * @compile/fail/ref=Neg03.out -XDallowDefaultMethods -XDrawDiagnostics Neg03.java */ class Neg03 { interface A { - void m() default { Neg03.one(this); } + default void m() { Neg03.one(this); } } interface B { - void m() default { Neg03.two(this); } + default void m() { Neg03.two(this); } } interface C extends A, B { - void m() default { Neg03.one(this); } + default void m() { Neg03.one(this); } } static class X implements C, A { } //ok - ignore extraneous remix of A
--- a/test/tools/javac/defender/Neg03.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg03.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,4 +1,4 @@ -Neg03.java:51:12: compiler.err.does.not.override.abstract: Neg03.Y, m(), Neg03.D -Neg03.java:57:12: compiler.err.does.not.override.abstract: Neg03.W, m(), Neg03.D -Neg03.java:59:12: compiler.err.does.not.override.abstract: Neg03.Z, m(), Neg03.D +Neg03.java:26:12: compiler.err.does.not.override.abstract: Neg03.Y, m(), Neg03.D +Neg03.java:32:12: compiler.err.does.not.override.abstract: Neg03.W, m(), Neg03.D +Neg03.java:34:12: compiler.err.does.not.override.abstract: Neg03.Z, m(), Neg03.D 3 errors
--- a/test/tools/javac/defender/Neg04.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg04.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,36 +1,12 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @summary check that defender method must have most specific return type - * @author Maurizio Cimadamore - * @compile/fail/ref=Neg04.out -XDrawDiagnostics Neg04.java + * @test /nodynamiccopyright/ + * @summary check that defender method must have most specific return type + * @compile/fail/ref=Neg04.out -XDallowDefaultMethods -XDrawDiagnostics Neg04.java */ class Neg04 { interface IA1 { Integer m(); } - interface IA2 extends IA1 { Number m() default { return Neg04.m(this); } } //error + interface IA2 extends IA1 { default Number m() { return Neg04.m(this); } } //error abstract class C implements IA1, IA2 {}
--- a/test/tools/javac/defender/Neg04.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg04.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,2 +1,2 @@ -Neg04.java:33:40: compiler.err.override.incompatible.ret: (compiler.misc.clashes.with: m(), Neg04.IA2, m(), Neg04.IA1), java.lang.Number, java.lang.Integer +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 1 error
--- a/test/tools/javac/defender/Neg05.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg05.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,36 +1,12 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that abstract method are compatible with inherithed defenders - * @author Maurizio Cimadamore - * @compile/fail/ref=Neg05.out -XDrawDiagnostics Neg05.java + * @compile/fail/ref=Neg05.out -XDallowDefaultMethods -XDrawDiagnostics Neg05.java */ class Neg05 { - interface IA1 { Number m() default { return Neg05.m1(this); } } - interface IA2 extends IA1 { Integer m() default { return Neg05.m2(this); } } + interface IA1 { default Number m() { return Neg05.m1(this); } } + interface IA2 extends IA1 { default Integer m() { return Neg05.m2(this); } } interface IA3 extends IA2 { Number m(); } //error static class C implements IA3{}
--- a/test/tools/javac/defender/Neg05.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg05.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,3 +1,3 @@ -Neg05.java:34:40: compiler.err.override.incompatible.ret: (compiler.misc.clashes.with: m(), Neg05.IA3, m(), Neg05.IA2), java.lang.Number, java.lang.Integer -Neg05.java:36:12: compiler.err.does.not.override.abstract: Neg05.C, m(), Neg05.IA3 +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 +Neg05.java:12:12: compiler.err.does.not.override.abstract: Neg05.C, m(), Neg05.IA3 2 errors
--- a/test/tools/javac/defender/Neg06.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg06.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,36 +1,13 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary flow analysis is not run on inlined defender bodies - * @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java + * @compile/fail/ref=Neg06.out -XDallowDefaultMethods -XDrawDiagnostics Neg06.java */ class Neg06 { interface A { - String m() default { C.m(); } + default String m() { C.m(); } } static class C {
--- a/test/tools/javac/defender/Neg06.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg06.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,2 +1,2 @@ -Neg06.java:33:37: compiler.err.missing.ret.stmt +Neg06.java:10:37: compiler.err.missing.ret.stmt 1 error
--- a/test/tools/javac/defender/Neg07.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg07.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,35 +1,12 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default overrides are properly type-checked - * @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java + * @compile/fail/ref=Neg07.out -XDallowDefaultMethods -XDrawDiagnostics Neg07.java */ class Neg07 { interface I { - int m() default { return 1; } + default int m() { return 1; } } static class C1 {
--- a/test/tools/javac/defender/Neg07.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg07.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,3 +1,3 @@ -Neg07.java:39:12: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C1, m(), Neg07.I), void, int -Neg07.java:42:21: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C3, m(), Neg07.I), void, int +Neg07.java:16:12: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C1, m(), Neg07.I), void, int +Neg07.java:19:21: compiler.err.override.incompatible.ret: (compiler.misc.cant.implement: m(), Neg07.C3, m(), Neg07.I), void, int 2 errors
--- a/test/tools/javac/defender/Neg08.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg08.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,34 +1,11 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default overrides are properly type-checked - * @compile/fail/ref=Neg08.out -XDrawDiagnostics Neg08.java + * @compile/fail/ref=Neg08.out -XDallowDefaultMethods -XDrawDiagnostics Neg08.java */ class Neg08 { interface I { - void m() default { } + default void m() { } } static class C1 {
--- a/test/tools/javac/defender/Neg08.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg08.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,3 +1,3 @@ -Neg08.java:38:12: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C1, m(), Neg08.I), public -Neg08.java:41:14: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C3, m(), Neg08.I), public +Neg08.java:15:12: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C1, m(), Neg08.I), public +Neg08.java:18:14: compiler.err.override.weaker.access: (compiler.misc.cant.implement: m(), Neg08.C3, m(), Neg08.I), public 2 errors
--- a/test/tools/javac/defender/Neg09.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg09.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,36 +1,13 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default overrides are properly type-checked - * @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg09.java + * @compile/fail/ref=Neg09.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg09.java */ import java.util.List; class Neg09 { interface I { - List<String> m() default { return null; } + default List<String> m() { return null; } } static class C1 {
--- a/test/tools/javac/defender/Neg09.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg09.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,5 +1,5 @@ -Neg09.java:40: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> -Neg09.java:43: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> +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> +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> - compiler.err.warnings.and.werror 1 error 2 warnings
--- a/test/tools/javac/defender/Neg10.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg10.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,34 +1,11 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default overrides are properly type-checked - * @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDrawDiagnostics Neg10.java + * @compile/fail/ref=Neg10.out -Werror -Xlint:unchecked -XDallowDefaultMethods -XDrawDiagnostics Neg10.java */ class Neg10 { interface I<X extends Exception> { - void m() throws X default { } + default void m() throws X { } } static class C1 {
--- a/test/tools/javac/defender/Neg10.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg10.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,5 +1,5 @@ -Neg10.java:38:12: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C1, m(), Neg10.I), java.lang.Exception -Neg10.java:41:21: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C3, m(), Neg10.I), java.lang.Exception +Neg10.java:15:12: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C1, m(), Neg10.I), java.lang.Exception +Neg10.java:18:21: compiler.warn.override.unchecked.thrown: (compiler.misc.cant.implement: m(), Neg10.C3, m(), Neg10.I), java.lang.Exception - compiler.err.warnings.and.werror 1 error 2 warnings
--- a/test/tools/javac/defender/Neg11.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg11.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,34 +1,11 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default overrides are properly type-checked - * @compile/fail/ref=Neg11.out -XDrawDiagnostics Neg11.java + * @compile/fail/ref=Neg11.out -XDallowDefaultMethods -XDrawDiagnostics Neg11.java */ class Neg11 { interface I { - void m() default { } + default void m() { } } static class C1 {
--- a/test/tools/javac/defender/Neg11.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg11.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,3 +1,3 @@ -Neg11.java:38:12: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C1, m(), Neg11.I), java.lang.Exception -Neg11.java:41:21: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C3, m(), Neg11.I), java.lang.Exception +Neg11.java:15:12: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C1, m(), Neg11.I), java.lang.Exception +Neg11.java:18:21: compiler.err.override.meth.doesnt.throw: (compiler.misc.cant.implement: m(), Neg11.C3, m(), Neg11.I), java.lang.Exception 2 errors
--- a/test/tools/javac/defender/Neg12.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg12.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,35 +1,12 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that abstract methods are discarded in overload resolution diags - * @compile/fail/ref=Neg12.out -XDrawDiagnostics Neg12.java + * @compile/fail/ref=Neg12.out -XDallowDefaultMethods -XDrawDiagnostics Neg12.java */ class Neg12 { interface I1 { - void m(String s) default {}; + default void m(String s) {}; } interface I2 {
--- a/test/tools/javac/defender/Neg12.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg12.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,4 +1,4 @@ -Neg12.java:44:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2 -Neg12.java:47:10: compiler.err.cant.apply.symbols: kindname.method, m, compiler.misc.no.args,{(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))} -Neg12.java:48: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) +Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2 +Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, compiler.misc.no.args,{(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))} +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) 3 errors
--- a/test/tools/javac/defender/Neg13.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg13.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,41 +1,18 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test + * @test /nodynamiccopyright/ * @summary check that default method overriding object members are flagged as error - * @compile/fail/ref=Neg13.out -XDrawDiagnostics Neg13.java + * @compile/fail/ref=Neg13.out -XDallowDefaultMethods -XDrawDiagnostics Neg13.java */ interface Neg13 { - protected Object clone() default { return null; } //protected not allowed here - boolean equals(Object obj) default { return false; } - protected void finalize() default { } //protected not allowed here - Class<?> getClass() default { return null; } - int hashCode() default { return 0; } - void notify() default { } - void notifyAll() default { } - String toString() default { return null; } - void wait() default { } - void wait(long timeout) default { } - void wait(long timeout, int nanos) default { } + default protected Object clone() { return null; } //protected not allowed here + default boolean equals(Object obj) { return false; } + default protected void finalize() { } //protected not allowed here + default Class<?> getClass() { return null; } + default int hashCode() { return 0; } + default void notify() { } + default void notifyAll() { } + default String toString() { return null; } + default void wait() { } + default void wait(long timeout) { } + default void wait(long timeout, int nanos) { } }
--- a/test/tools/javac/defender/Neg13.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Neg13.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,12 +1,12 @@ -Neg13.java:30:22: compiler.err.mod.not.allowed.here: protected -Neg13.java:32:20: compiler.err.mod.not.allowed.here: protected -Neg13.java:31:13: compiler.err.default.overrides.object.member: equals, kindname.interface, Neg13 -Neg13.java:33:14: compiler.err.override.meth: (compiler.misc.cant.override: getClass(), Neg13, getClass(), java.lang.Object), final -Neg13.java:34:9: compiler.err.default.overrides.object.member: hashCode, kindname.interface, Neg13 -Neg13.java:35:10: compiler.err.override.meth: (compiler.misc.cant.override: notify(), Neg13, notify(), java.lang.Object), final -Neg13.java:36:10: compiler.err.override.meth: (compiler.misc.cant.override: notifyAll(), Neg13, notifyAll(), java.lang.Object), final -Neg13.java:37:12: compiler.err.default.overrides.object.member: toString, kindname.interface, Neg13 -Neg13.java:38:10: compiler.err.override.meth: (compiler.misc.cant.override: wait(), Neg13, wait(), java.lang.Object), final -Neg13.java:39:10: compiler.err.override.meth: (compiler.misc.cant.override: wait(long), Neg13, wait(long), java.lang.Object), final -Neg13.java:40:10: compiler.err.override.meth: (compiler.misc.cant.override: wait(long,int), Neg13, wait(long,int), java.lang.Object), final +Neg13.java:7:30: compiler.err.mod.not.allowed.here: protected +Neg13.java:9:28: compiler.err.mod.not.allowed.here: protected +Neg13.java:8:21: compiler.err.default.overrides.object.member: equals, kindname.interface, Neg13 +Neg13.java:10:22: compiler.err.override.meth: (compiler.misc.cant.override: getClass(), Neg13, getClass(), java.lang.Object), final +Neg13.java:11:17: compiler.err.default.overrides.object.member: hashCode, kindname.interface, Neg13 +Neg13.java:12:18: compiler.err.override.meth: (compiler.misc.cant.override: notify(), Neg13, notify(), java.lang.Object), final +Neg13.java:13:18: compiler.err.override.meth: (compiler.misc.cant.override: notifyAll(), Neg13, notifyAll(), java.lang.Object), final +Neg13.java:14:20: compiler.err.default.overrides.object.member: toString, kindname.interface, Neg13 +Neg13.java:15:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(), Neg13, wait(), java.lang.Object), final +Neg13.java:16:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(long), Neg13, wait(long), java.lang.Object), final +Neg13.java:17:18: compiler.err.override.meth: (compiler.misc.cant.override: wait(long,int), Neg13, wait(long,int), java.lang.Object), final 11 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/Neg14.java Tue Nov 06 15:39:30 2012 -0800 @@ -0,0 +1,11 @@ +/* + * @test /nodynamiccopyright/ + * @summary check that a class cannot have two sibling interfaces with a default and abstract method + * @compile/fail/ref=Neg14.out -XDallowDefaultMethods -XDrawDiagnostics Neg14.java + */ +class Neg14 { + interface IA { int m(); } + interface IB { default int m() { return 1; } } + + abstract class AB implements IA, IB {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/Neg14.out Tue Nov 06 15:39:30 2012 -0800 @@ -0,0 +1,2 @@ +Neg14.java:10:14: compiler.err.types.incompatible.abstract.default: kindname.class, Neg14.AB, m, , Neg14.IB, Neg14.IA +1 error
--- a/test/tools/javac/defender/Pos01.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos01.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,8 +24,9 @@ /* * @test * @summary basic test for defender methods + * @ignore awaits lambda support * @author Maurizio Cimadamore - * @compile Pos01.java + * @compile -XDallowLambda -XDallowPoly -XDallowDefaultMethods Pos01.java */ import java.util.*; @@ -37,7 +38,7 @@ } interface ExtendedList<T> extends List<T> { - List<T> testMap(Mapper<T> r) default { + default List<T> testMap(Mapper<T> r) { return Pos01.<T>listMapper(this, r); } }
--- a/test/tools/javac/defender/Pos02.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos02.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,12 +25,12 @@ * @test * @summary test for explicit resolution of ambiguous defender methods * @author Maurizio Cimadamore - * @compile Pos02.java + * @compile -XDallowDefaultMethods Pos02.java */ class Pos02 { - interface IA { int m() default { return Pos02.m1(this); } } - interface IB { int m() default { return Pos02.m2(this); } } + interface IA { default int m() { return Pos02.m1(this); } } + interface IB { default int m() { return Pos02.m2(this); } } static class A implements IA {} static class B implements IB {}
--- a/test/tools/javac/defender/Pos04.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos04.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,11 +25,11 @@ * @test * @summary test for overriding with defender method * @author Maurizio Cimadamore - * @compile Pos04.java + * @compile -XDallowDefaultMethods Pos04.java */ class Pos04 { - interface A { int m() default { return Pos04.m(this); } } + interface A { default int m() { return Pos04.m(this); } } static abstract class B { public int m() { return 0; } } static class C extends B implements A {
--- a/test/tools/javac/defender/Pos05.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos05.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,12 +25,12 @@ * @test * @summary check that indirectly inherithed extension methods are discovered during resolution * @author Maurizio Cimadamore - * @compile Pos05.java + * @compile -XDallowDefaultMethods Pos05.java */ class Pos05 { interface A { - void m() default { Pos05.impl(this); } + default void m() { Pos05.impl(this); } } interface B extends A { }
--- a/test/tools/javac/defender/Pos06.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos06.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,16 +25,16 @@ * @test * @summary check that well-formed MI hierarchies behaves well w.r.t. method resolution (i.e. no ambiguities) * @author Maurizio Cimadamore - * @compile Pos06.java + * @compile -XDallowDefaultMethods Pos06.java */ class Pos06 { interface A { - void m() default { Pos06.impl(this); } + default void m() { Pos06.impl(this); } } interface B extends A { - void m() default { Pos06.impl(this); } + default void m() { Pos06.impl(this); } } static class X implements A, B { }
--- a/test/tools/javac/defender/Pos07.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos07.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,19 +25,19 @@ * @test * @summary check that compilation order does not matter * @author Maurizio Cimadamore - * @compile Pos07.java + * @compile -XDallowDefaultMethods Pos07.java */ class Pos07 { interface A { - void foo() default { Pos07.impl(this); } - void bar() default { Pos07.impl(this); } + default void foo() { Pos07.impl(this); } + default void bar() { Pos07.impl(this); } } static class C implements B, A {} interface B extends A { - void foo() default { Pos07.impl(this); } + default void foo() { Pos07.impl(this); } } static void impl(A a) {}
--- a/test/tools/javac/defender/Pos08.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos08.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,20 +25,20 @@ * @test * @summary check that common overrider solves default method conflicts * @author Maurizio Cimadamore - * @compile Pos08.java + * @compile -XDallowDefaultMethods Pos08.java */ class Pos08 { interface A { - void m() default { Pos08.a(this); } + default void m() { Pos08.a(this); } } interface B { - void m() default { Pos08.b(this); } + default void m() { Pos08.b(this); } } interface C extends A, B { - void m() default { Pos08.b(this); } + default void m() { Pos08.b(this); } } static void a(A o) { }
--- a/test/tools/javac/defender/Pos09.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos09.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,15 +25,15 @@ * @test * @summary check that Defender bytecode attribute is used to restore default method as expected * @author Maurizio Cimadamore - * @compile pkg1/A.java - * @compile Pos09.java + * @compile -XDallowDefaultMethods pkg1/A.java + * @compile -XDallowDefaultMethods Pos09.java */ import pkg1.A; class Pos09 { interface B extends A.I { - void m() default { A.m(this); } + default void m() { A.m(this); } } interface C extends A.I, B { }
--- a/test/tools/javac/defender/Pos10.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos10.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,7 +25,7 @@ * @test * @summary check that type-variables in generic extension decl can be accessed from default impl * @author Maurizio Cimadamore - * @compile Pos10.java + * @compile -XDallowDefaultMethods Pos10.java */ class Pos10 { @@ -34,7 +34,7 @@ } interface A<T> { - <R> void m(Function<T,R> f) default { Impl.<T,R>m(this, f); } + default <R> void m(Function<T,R> f) { Impl.<T,R>m(this, f); } } static class Impl {
--- a/test/tools/javac/defender/Pos11.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos11.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,24 +25,24 @@ * @test * @summary complex test with conflict resolution via overriding * @author Brian Goetz - * @compile Pos11.java + * @compile -XDallowDefaultMethods Pos11.java */ class Pos11 { interface A { - void get() default { Pos11.one(this); } + default void get() { Pos11.one(this); } } interface B { - void get() default { Pos11.two(this); } + default void get() { Pos11.two(this); } } interface C extends A { - void get() default { Pos11.two(this); } + default void get() { Pos11.two(this); } } interface D extends A, B { - void get() default { Pos11.two(this); } + default void get() { Pos11.two(this); } } static class X implements C { }
--- a/test/tools/javac/defender/Pos12.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos12.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,12 +24,12 @@ /* * @test * @summary check that 'this' can be used from within an extension method - * @compile Pos12.java + * @compile -XDallowDefaultMethods Pos12.java */ interface Pos12 { - Object m() default { + default Object m() { Object o = this; f(this); return this;
--- a/test/tools/javac/defender/Pos13.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos13.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,6 +24,7 @@ /* * @test * @summary qualified 'this' inside default method causes StackOverflowException + * @compile -XDallowDefaultMethods Pos13.java */ public class Pos13 { @@ -39,7 +40,7 @@ interface Outer { abstract void doSomething(); - void m() default { + default void m() { new SubOuter() { public void doSomething() { Outer.this.doSomething();
--- a/test/tools/javac/defender/Pos14.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/Pos14.java Tue Nov 06 15:39:30 2012 -0800 @@ -23,32 +23,17 @@ /* * @test - * @summary qualified 'super' call inside default method causes StackOverflowException + * @summary check that overload resolution selects most specific signature + * @compile -XDallowDefaultMethods Pos14.java */ -public class Pos14 { - - static int assertionCount = 0; +class Pos14 { + interface A { default Object m() { return null; } } + static abstract class B { abstract public String m(); } - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - - interface I { - int m() default { return 88; } - } - - interface J extends I { - int m() default { return I.super.m(); } - } - - static class C implements J { } - - public static void main(String[] args) { - C c = new C(); - J j = c; - assertTrue(c.m() == j.m()); + static abstract class C extends B implements A { + void test() { + m().length(); + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/Pos15.java Tue Nov 06 15:39:30 2012 -0800 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary check that overload resolution selects most specific signature + * @compile -XDallowDefaultMethods Pos15.java + */ + +class Pos15 { + interface A { default String m() { return null; } } + static abstract class B { abstract public Object m(); } + + static abstract class C extends B implements A { + void test() { + m().length(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/Pos16.java Tue Nov 06 15:39:30 2012 -0800 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary 'class wins' should not short-circuit overload resolution + * @compile -XDallowDefaultMethods Pos16.java + */ + +class Pos16 { + interface I { + default String m(Integer i) { return ""; } + } + + class C implements I { + Integer m(Object o) { return 1; } + } + + void test(C c) { + c.m(1).length(); + } +}
--- a/test/tools/javac/defender/TestInlinedDefenderBody.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/TestInlinedDefenderBody.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,7 +24,7 @@ /* * @test * @summary check that code attributed for defender methods is correctly generated - * @compile TestInlinedDefenderBody.java + * @compile -XDallowDefaultMethods TestInlinedDefenderBody.java * @run main/othervm -Xverify:none TestInlinedDefenderBody */ @@ -43,7 +43,7 @@ interface TestInterface { int no_defender(int i); - int defender(int i) default { return impl(this, i); } + default int defender(int i) { return impl(this, i); } } static int impl(TestInterface ti, int i) { return 0; }
--- a/test/tools/javac/defender/TestNoBridgeOnDefenders.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/TestNoBridgeOnDefenders.java Tue Nov 06 15:39:30 2012 -0800 @@ -24,6 +24,7 @@ /* * @test * @summary check that javac does not generate bridge methods for defenders + * @compile -XDallowDefaultMethods TestNoBridgeOnDefenders.java * @run main/othervm -Xverify:none TestNoBridgeOnDefenders */ @@ -36,13 +37,13 @@ public class TestNoBridgeOnDefenders { interface A<X> { - <Y> A<X> m(X x, Y y) default { return Impl.<X,Y>m1(this, x, y); } + default <Y> A<X> m(X x, Y y) { return Impl.<X,Y>m1(this, x, y); } } static abstract class B<X> implements A<X> { } interface C<X> extends A<X> { - <Y> C<X> m(X x, Y y) default { return Impl.<X,Y>m2(this, x, y); } + default <Y> C<X> m(X x, Y y) { return Impl.<X,Y>m2(this, x, y); } } static abstract class D<X> extends B<X> implements C<X> { }
--- a/test/tools/javac/defender/fd/FDTest.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/fd/FDTest.java Tue Nov 06 15:39:30 2012 -0800 @@ -82,7 +82,7 @@ void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, - null, null, Arrays.asList(source)); + Arrays.asList("-XDallowDefaultMethods"), null, Arrays.asList(source)); try { ct.analyze(); } catch (Throwable ex) {
--- a/test/tools/javac/defender/fd/shapegen/Hierarchy.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/fd/shapegen/Hierarchy.java Tue Nov 06 15:39:30 2012 -0800 @@ -87,7 +87,7 @@ switch (cc.kind) { case IDEFAULT: - buf.append(" String m() default { return \"\"; }\n"); + buf.append(" default String m() { return \"\"; }\n"); defaultRef.add(cc); break; case IPRESENT:
--- a/test/tools/javac/defender/pkg1/A.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/pkg1/A.java Tue Nov 06 15:39:30 2012 -0800 @@ -25,7 +25,7 @@ public class A { public interface I { - void m() default { A.m(this); } + default void m() { A.m(this); } } public static void m(Object o) {}
--- a/test/tools/javac/defender/super/TestDefenderSuperCall.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/defender/super/TestDefenderSuperCall.java Tue Nov 06 15:39:30 2012 -0800 @@ -44,7 +44,7 @@ static int checkCount = 0; enum InterfaceKind { - DEFENDER("interface A extends B { void m() default { } }"), + DEFAULT("interface A extends B { default void m() { } }"), ABSTRACT("interface A extends B { void m(); }"), NONE("interface A extends B { }"); @@ -55,7 +55,7 @@ } boolean methodDefined() { - return this == DEFENDER; + return this == DEFAULT; } } @@ -136,7 +136,7 @@ ANON_CLASS("new Object() { #B };", false), METHOD("void test() { #B }", false), STATIC_METHOD("static void test() { #B }", true), - DEFENDER_METHOD("void test() default { #B }", false); + DEFAULT_METHOD("default void test() { #B }", false); String templateDecl; boolean isStatic; @@ -150,7 +150,7 @@ switch(this) { case METHOD: case STATIC_METHOD: - case DEFENDER_METHOD: + case DEFAULT_METHOD: return false; default: return true; @@ -177,7 +177,7 @@ case STATIC_METHOD: return (isTop && (ek == CLASS || ek == CLASS_EXTENDS)) || ek == STATIC_CLASS || ek == STATIC_CLASS_EXTENDS; - case DEFENDER_METHOD: + case DEFAULT_METHOD: return ek == INTERFACE || ek == INTERFACE_EXTENDS; default: throw new AssertionError("Bad enclosing element kind" + this);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defender/syntax/TestDefaultMethodsSyntax.java Tue Nov 06 15:39:30 2012 -0800 @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary Automatic test for checking set of allowed modifiers on interface methods + */ + +import com.sun.source.util.JavacTask; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import javax.tools.Diagnostic; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + + +public class TestDefaultMethodsSyntax { + + static int checkCount = 0; + + enum VersionKind { + PRE_LAMBDA("7"), + LAMBDA("8"); + + String versionString; + + VersionKind(String versionString) { + this.versionString = versionString; + } + + List<String> getOptions() { + return Arrays.asList("-XDallowDefaultMethods", "-source", versionString); + } + } + + enum ModifierKind { + NONE(""), + PUBLIC("public"), + PROTECTED("protected"), + PRIVATE("private"), + ABSTRACT("abstract"), + STATIC("static"), + NATIVE("native"), + SYNCHRONIZED("synchronized"), + FINAL("final"), + STRICTFP("strictfp"), + DEFAULT("default"); + + String modStr; + + private ModifierKind(String modStr) { + this.modStr = modStr; + } + + boolean isAllowed(EnclosingKind ek, ModifierKind otherMod) { + if (this == otherMod) return false; + switch (this) { + case NONE: + return true; + case ABSTRACT: + return otherMod != PRIVATE; + case NATIVE: + return otherMod != ABSTRACT && + otherMod != STRICTFP; + case FINAL: + case STATIC: + case SYNCHRONIZED: + case STRICTFP: + return otherMod != ABSTRACT; + case PUBLIC: + return true; + case PROTECTED: + return ek == EnclosingKind.ABSTRACT_CLASS; + case DEFAULT: + return otherMod != ABSTRACT; + default: + return true; + } + } + + static boolean intersect(ModifierKind mk, ModifierKind... mks) { + for (ModifierKind mk2 : mks) { + if (mk == mk2) return true; + } + return false; + } + + static boolean compatible(MethodKind mk, ModifierKind mod1, ModifierKind mod2, EnclosingKind ek) { + if (intersect(ABSTRACT, mod1, mod2) || intersect(NATIVE, mod1, mod2)) { + return mk == MethodKind.NO_BODY; + } else if (intersect(DEFAULT, mod1, mod2)) { + return mk == MethodKind.BODY; + } else { + return ek == EnclosingKind.INTERFACE ? + mk == MethodKind.NO_BODY : mk == MethodKind.BODY; + } + } + + boolean compatible(EnclosingKind ek) { + switch (this) { + case STATIC: + case PRIVATE: + case PROTECTED: + return ek != EnclosingKind.INTERFACE; + default: + return true; + } + } + + static boolean compatible(ModifierKind m1, ModifierKind m2, EnclosingKind ek) { + Result res1 = allowedModifierPairs[m1.ordinal()][m2.ordinal()]; + Result res2 = allowedModifierPairs[m2.ordinal()][m1.ordinal()]; + if (res1 != res2) { + throw new AssertionError(String.format("Ill-formed table: [%s,%s] != [%s,%s]", m1, m2, m2, m1)); + } else { + return res1.compatible(ek, m1, m2); + } + } + + interface Result { + boolean compatible(EnclosingKind ek, ModifierKind m1, ModifierKind m2); + } + + static final Result T = new Result() { + @Override + public boolean compatible(EnclosingKind ek, ModifierKind m1, ModifierKind m2) { + return true; + } + }; + + static final Result F = new Result() { + @Override + public boolean compatible(EnclosingKind ek, ModifierKind m1, ModifierKind m2) { + return false; + } + }; + + static final Result C = new Result() { + @Override + public boolean compatible(EnclosingKind ek, ModifierKind m1, ModifierKind m2) { + return ek != EnclosingKind.INTERFACE; + } + }; + + static final Result I = new Result() { + @Override + public boolean compatible(EnclosingKind ek, ModifierKind m1, ModifierKind m2) { + return ek == EnclosingKind.INTERFACE; + } + }; + + static Result[][] allowedModifierPairs = { + /* NONE PUBLIC PROTECTED PRIVATE ABSTRACT STATIC NATIVE SYNCHRONIZED FINAL STRICTFP DEFAULT */ + /* NONE */ { T , T , C , C , T , C , C , C , C , C , I }, + /* PUBLIC */ { T , F , F , F , T , C , C , C , C , C , I }, + /* PROTECTED */ { C , F , F , F , C , C , C , C , C , C , F }, + /* PRIVATE */ { C , F , F , F , F , C , C , C , C , C , F }, + /* ABSTRACT */ { T , T , C , F , F , F , F , F , F , F , F }, + /* STATIC */ { C , C , C , C , F , F , C , C , C , C , F }, + /* NATIVE */ { C , C , C , C , F , C , F , C , C , F , F }, + /* SYNCHRONIZED */ { C , C , C , C , F , C , C , F , C , C , I }, + /* FINAL */ { C , C , C , C , F , C , C , C , F , C , F }, + /* STRICTFP */ { C , C , C , C , F , C , F , C , C , F , I }, + /* DEFAULT */ { I , I , F , F , F , F , F , I , F , I , F }}; + } + + enum MethodKind { + NO_BODY("void m();"), + BODY("void m() { }"); + + String methStr; + + private MethodKind(String methStr) { + this.methStr = methStr; + } + } + + enum EnclosingKind { + ABSTRACT_CLASS("abstract class Test "), + INTERFACE("interface Test "); + + String enclStr; + + EnclosingKind(String enclStr) { + this.enclStr = enclStr; + } + } + + public static void main(String... args) throws Exception { + + //create default shared JavaCompiler - reused across multiple compilations + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + + for (VersionKind vk : VersionKind.values()) { + for (EnclosingKind ek : EnclosingKind.values()) { + for (MethodKind mk : MethodKind.values()) { + for (ModifierKind modk1 : ModifierKind.values()) { + for (ModifierKind modk2 : ModifierKind.values()) { + new TestDefaultMethodsSyntax(vk, ek, mk, modk1, modk2).run(comp, fm); + } + } + } + } + } + System.out.println("Total check executed: " + checkCount); + } + + VersionKind vk; + EnclosingKind ek; + MethodKind mk; + ModifierKind modk1, modk2; + JavaSource source; + DiagnosticChecker diagChecker; + + TestDefaultMethodsSyntax(VersionKind vk, EnclosingKind ek, MethodKind mk, ModifierKind modk1, ModifierKind modk2) { + this.vk = vk; + this.ek = ek; + this.mk = mk; + this.modk1 = modk1; + this.modk2 = modk2; + this.source = new JavaSource(); + this.diagChecker = new DiagnosticChecker(); + } + + class JavaSource extends SimpleJavaFileObject { + + String template = "#EK {\n" + + " #MOD1 #MOD2 #METH\n" + + "}\n"; + + String source; + + public JavaSource() { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + source = template.replaceAll("#EK", ek.enclStr) + .replaceAll("#MOD1", modk1.modStr) + .replaceAll("#MOD2", modk2.modStr) + .replaceAll("#METH", mk.methStr); + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, + vk.getOptions(), null, Arrays.asList(source)); + try { + ct.analyze(); + } catch (Throwable ex) { + throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); + } + check(); + } + + void check() { + boolean errorExpected = !ModifierKind.compatible(modk1, modk2, ek); + + errorExpected |= !ModifierKind.compatible(mk, modk1, modk2, ek); + + errorExpected |= !modk1.compatible(ek) || !modk2.compatible(ek); + + errorExpected |= ModifierKind.intersect(ModifierKind.DEFAULT, modk1, modk2) && + vk == VersionKind.PRE_LAMBDA; + + checkCount++; + if (diagChecker.errorFound != errorExpected) { + throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) + + "\nfound error: " + diagChecker.errorFound); + } + } + + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { + + boolean errorFound; + + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { + errorFound = true; + } + } + } +}
--- a/test/tools/javac/defender/syntax/TestDefenderModifiers.java Sat Nov 03 15:00:22 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @summary Automatic test for checking set of allowed modifiers on interface methods - */ - -import com.sun.source.util.JavacTask; -import java.net.URI; -import java.util.Arrays; -import java.util.EnumSet; -import javax.tools.Diagnostic; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileObject; -import javax.tools.SimpleJavaFileObject; -import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; - - -public class TestDefenderModifiers { - - static int checkCount = 0; - - enum ModifierKind { - PUBLIC("public", InterfaceMethodKind.ABSTRACT, InterfaceMethodKind.DEFENDER), - PROTECTED("protected"), - PRIVATE("private"), - ABSTRACT("abstract", InterfaceMethodKind.ABSTRACT), - STATIC("static"), - NATIVE("native"), - SYNCHRONIZED("synchronized", InterfaceMethodKind.DEFENDER), - FINAL("final"), - STRICTFP("strictfp", InterfaceMethodKind.DEFENDER); - - String modStr; - EnumSet<InterfaceMethodKind> allowedMethodKinds; - - private ModifierKind(String modStr, InterfaceMethodKind... allowedMethodKinds) { - this.modStr = modStr; - this.allowedMethodKinds = allowedMethodKinds.length == 0 ? - EnumSet.noneOf(InterfaceMethodKind.class) : - EnumSet.copyOf(Arrays.asList(allowedMethodKinds)); - } - } - - enum InterfaceMethodKind { - ABSTRACT("void m();"), - DEFENDER("void m() default { }"); - - String methStr; - - private InterfaceMethodKind(String methStr) { - this.methStr = methStr; - } - } - - public static void main(String... args) throws Exception { - - //create default shared JavaCompiler - reused across multiple compilations - JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); - StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); - - for (InterfaceMethodKind imk : InterfaceMethodKind.values()) { - for (ModifierKind mk : ModifierKind.values()) { - new TestDefenderModifiers(imk, mk).run(comp, fm); - } - } - System.out.println("Total check executed: " + checkCount); - } - - InterfaceMethodKind imk; - ModifierKind mk; - JavaSource source; - DiagnosticChecker diagChecker; - - TestDefenderModifiers(InterfaceMethodKind imk, ModifierKind mk) { - this.imk = imk; - this.mk = mk; - this.source = new JavaSource(); - this.diagChecker = new DiagnosticChecker(); - } - - class JavaSource extends SimpleJavaFileObject { - - String template = "interface I {\n" + - " #MOD #METH\n" + - "}\n"; - - String source; - - public JavaSource() { - super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); - source = template.replaceAll("#MOD", mk.modStr) - .replaceAll("#METH", imk.methStr); - } - - @Override - public CharSequence getCharContent(boolean ignoreEncodingErrors) { - return source; - } - } - - void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { - JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, - null, null, Arrays.asList(source)); - try { - ct.analyze(); - } catch (Throwable ex) { - throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true)); - } - check(); - } - - void check() { - boolean errorExpected = !mk.allowedMethodKinds.contains(imk); - - checkCount++; - if (diagChecker.errorFound != errorExpected) { - throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) + - "\nfound error: " + diagChecker.errorFound); - } - } - - static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { - - boolean errorFound; - - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { - if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { - errorFound = true; - } - } - } -}
--- a/test/tools/javac/diags/examples.not-yet.txt Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/diags/examples.not-yet.txt Tue Nov 06 15:39:30 2012 -0800 @@ -106,7 +106,7 @@ compiler.warn.unknown.enum.constant # in bad class file compiler.warn.unknown.enum.constant.reason # in bad class file compiler.err.default.overrides.object.member #LAMBDA -compiler.err.defender.in.class #LAMBDA -compiler.err.defender.methods.not.supported.in.source #LAMBDA +compiler.err.default.methods.not.supported.in.source #LAMBDA compiler.err.types.incompatible.unrelated.defaults #LAMBDA +compiler.err.types.incompatible.abstract.default #LAMBDA compiler.misc.conditional.target.cant.be.void #LAMBDA
--- a/test/tools/javac/lambda/Defender01.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/lambda/Defender01.java Tue Nov 06 15:39:30 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,7 @@ interface A{ Object m(); - void n() default { E.n(this); } + default void n() { E.n(this); } } static class E{
--- a/test/tools/javac/lambda/LambdaExpr20.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/lambda/LambdaExpr20.java Tue Nov 06 15:39:30 2012 -0800 @@ -30,7 +30,7 @@ class LambdaExpr20 { interface K { - void m() default { } + default void m() { } } static class Test implements K {
--- a/test/tools/javac/lambda/SourceLevelTest.java Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/lambda/SourceLevelTest.java Tue Nov 06 15:39:30 2012 -0800 @@ -29,7 +29,7 @@ class SourceLevelTest { interface I { - void m() default { SourceLevelTest.impl(this); } + default void m() { SourceLevelTest.impl(this); } } interface SAM {
--- a/test/tools/javac/lambda/SourceLevelTest.out Sat Nov 03 15:00:22 2012 +0000 +++ b/test/tools/javac/lambda/SourceLevelTest.out Tue Nov 06 15:39:30 2012 -0800 @@ -1,5 +1,5 @@ - compiler.warn.source.no.bootclasspath: 1.7 -SourceLevelTest.java:32:26: compiler.err.defender.methods.not.supported.in.source: 1.7 +SourceLevelTest.java:32:9: compiler.err.default.methods.not.supported.in.source: 1.7 SourceLevelTest.java:39:17: compiler.err.lambda.not.supported.in.source: 1.7 SourceLevelTest.java:40:20: compiler.err.method.references.not.supported.in.source: 1.7 3 errors