Mon, 23 Jun 2014 00:01:40 +0100
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Thu Jun 19 17:59:42 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Mon Jun 23 00:01:40 2014 +0100 1.3 @@ -276,6 +276,11 @@ 1.4 */ 1.5 public static final long LAMBDA_METHOD = 1L<<49; 1.6 1.7 + /** 1.8 + * Flag to control recursion in TransTypes 1.9 + */ 1.10 + public static final long TYPE_TRANSLATED = 1L<<50; 1.11 + 1.12 /** Modifier masks. 1.13 */ 1.14 public static final int 1.15 @@ -295,7 +300,8 @@ 1.16 ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT, 1.17 InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, 1.18 AnnotationTypeElementMask = ABSTRACT | PUBLIC, 1.19 - LocalVarFlags = FINAL | PARAMETER; 1.20 + LocalVarFlags = FINAL | PARAMETER, 1.21 + ReceiverParamFlags = PARAMETER; 1.22 1.23 1.24 public static Set<Modifier> asModifierSet(long flags) { 1.25 @@ -385,7 +391,8 @@ 1.26 BAD_OVERRIDE(Flags.BAD_OVERRIDE), 1.27 SIGNATURE_POLYMORPHIC(Flags.SIGNATURE_POLYMORPHIC), 1.28 THROWS(Flags.THROWS), 1.29 - LAMBDA_METHOD(Flags.LAMBDA_METHOD); 1.30 + LAMBDA_METHOD(Flags.LAMBDA_METHOD), 1.31 + TYPE_TRANSLATED(Flags.TYPE_TRANSLATED); 1.32 1.33 Flag(long flag) { 1.34 this.value = flag;
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Jun 19 17:59:42 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon Jun 23 00:01:40 2014 +0100 2.3 @@ -779,42 +779,41 @@ 2.4 2.5 @Override 2.6 public List<Attribute.Compound> getAnnotationMirrors() { 2.7 - return onlyTypeVariableAnnotations(owner.getRawTypeAttributes()); 2.8 - } 2.9 - 2.10 - private List<Attribute.Compound> onlyTypeVariableAnnotations( 2.11 - List<Attribute.TypeCompound> candidates) { 2.12 - // Declaration annotations on TypeParameters are stored in type attributes 2.13 + // Declaration annotations on type variables are stored in type attributes 2.14 + // on the owner of the TypeVariableSymbol 2.15 + List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); 2.16 + int index = owner.getTypeParameters().indexOf(this); 2.17 List<Attribute.Compound> res = List.nil(); 2.18 for (Attribute.TypeCompound a : candidates) { 2.19 - if (a.position.type == TargetType.CLASS_TYPE_PARAMETER || 2.20 - a.position.type == TargetType.METHOD_TYPE_PARAMETER) 2.21 + if (isCurrentSymbolsAnnotation(a, index)) 2.22 res = res.prepend(a); 2.23 } 2.24 2.25 - return res = res.reverse(); 2.26 + return res.reverse(); 2.27 } 2.28 2.29 - 2.30 - 2.31 // Helper to getAnnotation[s] 2.32 @Override 2.33 public <A extends Annotation> Attribute.Compound getAttribute(Class<A> annoType) { 2.34 - 2.35 String name = annoType.getName(); 2.36 2.37 // Declaration annotations on type variables are stored in type attributes 2.38 // on the owner of the TypeVariableSymbol 2.39 List<Attribute.TypeCompound> candidates = owner.getRawTypeAttributes(); 2.40 + int index = owner.getTypeParameters().indexOf(this); 2.41 for (Attribute.TypeCompound anno : candidates) 2.42 - if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || 2.43 - anno.position.type == TargetType.METHOD_TYPE_PARAMETER) 2.44 - if (name.contentEquals(anno.type.tsym.flatName())) 2.45 - return anno; 2.46 + if (isCurrentSymbolsAnnotation(anno, index) && 2.47 + name.contentEquals(anno.type.tsym.flatName())) 2.48 + return anno; 2.49 2.50 return null; 2.51 } 2.52 - 2.53 + //where: 2.54 + boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) { 2.55 + return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || 2.56 + anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && 2.57 + anno.position.parameter_index == index; 2.58 + } 2.59 2.60 2.61 @Override
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Jun 19 17:59:42 2014 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Jun 23 00:01:40 2014 +0100 3.3 @@ -629,7 +629,7 @@ 3.4 * (ii) perform functional interface bridge calculation. 3.5 */ 3.6 public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) { 3.7 - if (targets.isEmpty() || !isFunctionalInterface(targets.head)) { 3.8 + if (targets.isEmpty()) { 3.9 return null; 3.10 } 3.11 Symbol descSym = findDescriptorSymbol(targets.head.tsym); 3.12 @@ -2300,7 +2300,7 @@ 3.13 public Type visitType(Type t, Void ignored) { 3.14 // A note on wildcards: there is no good way to 3.15 // determine a supertype for a super bounded wildcard. 3.16 - return null; 3.17 + return Type.noType; 3.18 } 3.19 3.20 @Override 3.21 @@ -2467,7 +2467,7 @@ 3.22 return false; 3.23 return 3.24 t.isRaw() || 3.25 - supertype(t) != null && isDerivedRaw(supertype(t)) || 3.26 + supertype(t) != Type.noType && isDerivedRaw(supertype(t)) || 3.27 isDerivedRaw(interfaces(t)); 3.28 } 3.29
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 19 17:59:42 2014 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Jun 23 00:01:40 2014 +0100 4.3 @@ -94,6 +94,7 @@ 4.4 final Annotate annotate; 4.5 final TypeAnnotations typeAnnotations; 4.6 final DeferredLintHandler deferredLintHandler; 4.7 + final TypeEnvs typeEnvs; 4.8 4.9 public static Attr instance(Context context) { 4.10 Attr instance = context.get(attrKey); 4.11 @@ -123,6 +124,7 @@ 4.12 annotate = Annotate.instance(context); 4.13 typeAnnotations = TypeAnnotations.instance(context); 4.14 deferredLintHandler = DeferredLintHandler.instance(context); 4.15 + typeEnvs = TypeEnvs.instance(context); 4.16 4.17 Options options = Options.instance(context); 4.18 4.19 @@ -432,7 +434,7 @@ 4.20 } 4.21 4.22 public Type attribType(JCTree node, TypeSymbol sym) { 4.23 - Env<AttrContext> env = enter.typeEnvs.get(sym); 4.24 + Env<AttrContext> env = typeEnvs.get(sym); 4.25 Env<AttrContext> localEnv = env.dup(node, env.info.dup()); 4.26 return attribTree(node, localEnv, unknownTypeInfo); 4.27 } 4.28 @@ -2966,10 +2968,19 @@ 4.29 if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && 4.30 pt != Type.recoveryType) { 4.31 //check that functional interface class is well-formed 4.32 - ClassSymbol csym = types.makeFunctionalInterfaceClass(env, 4.33 - names.empty, List.of(fExpr.targets.head), ABSTRACT); 4.34 - if (csym != null) { 4.35 - chk.checkImplementations(env.tree, csym, csym); 4.36 + try { 4.37 + /* Types.makeFunctionalInterfaceClass() may throw an exception 4.38 + * when it's executed post-inference. See the listener code 4.39 + * above. 4.40 + */ 4.41 + ClassSymbol csym = types.makeFunctionalInterfaceClass(env, 4.42 + names.empty, List.of(fExpr.targets.head), ABSTRACT); 4.43 + if (csym != null) { 4.44 + chk.checkImplementations(env.tree, csym, csym); 4.45 + } 4.46 + } catch (Types.FunctionDescriptorLookupError ex) { 4.47 + JCDiagnostic cause = ex.getDiagnostic(); 4.48 + resultInfo.checkContext.report(env.tree, cause); 4.49 } 4.50 } 4.51 } 4.52 @@ -4051,7 +4062,7 @@ 4.53 // ... and attribute the bound class 4.54 c.flags_field |= UNATTRIBUTED; 4.55 Env<AttrContext> cenv = enter.classEnv(cd, env); 4.56 - enter.typeEnvs.put(c, cenv); 4.57 + typeEnvs.put(c, cenv); 4.58 attribClass(c); 4.59 return owntype; 4.60 } 4.61 @@ -4201,9 +4212,9 @@ 4.62 c.flags_field &= ~UNATTRIBUTED; 4.63 4.64 // Get environment current at the point of class definition. 4.65 - Env<AttrContext> env = enter.typeEnvs.get(c); 4.66 - 4.67 - // The info.lint field in the envs stored in enter.typeEnvs is deliberately uninitialized, 4.68 + Env<AttrContext> env = typeEnvs.get(c); 4.69 + 4.70 + // The info.lint field in the envs stored in typeEnvs is deliberately uninitialized, 4.71 // because the annotations were not available at the time the env was created. Therefore, 4.72 // we look up the environment chain for the first enclosing environment for which the 4.73 // lint value is set. Typically, this is the parent env, but might be further if there
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jun 19 17:59:42 2014 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Jun 23 00:01:40 2014 +0100 5.3 @@ -1038,7 +1038,9 @@ 5.4 5.5 switch (sym.kind) { 5.6 case VAR: 5.7 - if (sym.owner.kind != TYP) 5.8 + if (TreeInfo.isReceiverParam(tree)) 5.9 + mask = ReceiverParamFlags; 5.10 + else if (sym.owner.kind != TYP) 5.11 mask = LocalVarFlags; 5.12 else if ((sym.owner.flags_field & INTERFACE) != 0) 5.13 mask = implicit = InterfaceVarFlags; 5.14 @@ -2677,7 +2679,7 @@ 5.15 checkClassBounds(pos, seensofar, it); 5.16 } 5.17 Type st = types.supertype(type); 5.18 - if (st != null) checkClassBounds(pos, seensofar, st); 5.19 + if (st != Type.noType) checkClassBounds(pos, seensofar, st); 5.20 } 5.21 5.22 /** Enter interface into into set.
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Jun 19 17:59:42 2014 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon Jun 23 00:01:40 2014 +0100 6.3 @@ -77,6 +77,7 @@ 6.4 final Types types; 6.5 final Flow flow; 6.6 final Names names; 6.7 + final TypeEnvs typeEnvs; 6.8 6.9 public static DeferredAttr instance(Context context) { 6.10 DeferredAttr instance = context.get(deferredAttrKey); 6.11 @@ -100,6 +101,7 @@ 6.12 flow = Flow.instance(context); 6.13 names = Names.instance(context); 6.14 stuckTree = make.Ident(names.empty).setType(Type.stuckType); 6.15 + typeEnvs = TypeEnvs.instance(context); 6.16 emptyDeferredAttrContext = 6.17 new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { 6.18 @Override 6.19 @@ -400,7 +402,7 @@ 6.20 //it is possible that nested expressions inside argument expression 6.21 //are left unchecked - in such cases there's nothing to clean up. 6.22 if (csym == null) return; 6.23 - enter.typeEnvs.remove(csym); 6.24 + typeEnvs.remove(csym); 6.25 chk.compiled.remove(csym.flatname); 6.26 syms.classes.remove(csym.flatname); 6.27 super.visitClassDef(tree); 6.28 @@ -928,7 +930,7 @@ 6.29 6.30 LambdaReturnScanner() { 6.31 super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP, 6.32 - FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); 6.33 + FORLOOP, IF, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); 6.34 } 6.35 } 6.36
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Thu Jun 19 17:59:42 2014 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Mon Jun 23 00:01:40 2014 +0100 7.3 @@ -105,6 +105,7 @@ 7.4 Names names; 7.5 JavaFileManager fileManager; 7.6 PkgInfo pkginfoOpt; 7.7 + TypeEnvs typeEnvs; 7.8 7.9 private final Todo todo; 7.10 7.11 @@ -142,14 +143,9 @@ 7.12 7.13 Options options = Options.instance(context); 7.14 pkginfoOpt = PkgInfo.get(options); 7.15 + typeEnvs = TypeEnvs.instance(context); 7.16 } 7.17 7.18 - /** A hashtable mapping classes and packages to the environments current 7.19 - * at the points of their definitions. 7.20 - */ 7.21 - Map<TypeSymbol,Env<AttrContext>> typeEnvs = 7.22 - new HashMap<TypeSymbol,Env<AttrContext>>(); 7.23 - 7.24 /** Accessor for typeEnvs 7.25 */ 7.26 public Env<AttrContext> getEnv(TypeSymbol sym) {
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Jun 19 17:59:42 2014 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Jun 23 00:01:40 2014 +0100 8.3 @@ -82,6 +82,7 @@ 8.4 private ConstFold cfolder; 8.5 private Target target; 8.6 private Source source; 8.7 + private final TypeEnvs typeEnvs; 8.8 private boolean allowEnums; 8.9 private final Name dollarAssertionsDisabled; 8.10 private final Name classDollar; 8.11 @@ -103,6 +104,7 @@ 8.12 cfolder = ConstFold.instance(context); 8.13 target = Target.instance(context); 8.14 source = Source.instance(context); 8.15 + typeEnvs = TypeEnvs.instance(context); 8.16 allowEnums = source.allowEnums(); 8.17 dollarAssertionsDisabled = names. 8.18 fromString(target.syntheticNameChar() + "assertionsDisabled"); 8.19 @@ -2452,10 +2454,16 @@ 8.20 } 8.21 8.22 public void visitClassDef(JCClassDecl tree) { 8.23 + Env<AttrContext> prevEnv = attrEnv; 8.24 ClassSymbol currentClassPrev = currentClass; 8.25 MethodSymbol currentMethodSymPrev = currentMethodSym; 8.26 + 8.27 currentClass = tree.sym; 8.28 currentMethodSym = null; 8.29 + attrEnv = typeEnvs.remove(currentClass); 8.30 + if (attrEnv == null) 8.31 + attrEnv = prevEnv; 8.32 + 8.33 classdefs.put(currentClass, tree); 8.34 8.35 proxies = proxies.dup(currentClass); 8.36 @@ -2527,6 +2535,7 @@ 8.37 // Append translated tree to `translated' queue. 8.38 translated.append(tree); 8.39 8.40 + attrEnv = prevEnv; 8.41 currentClass = currentClassPrev; 8.42 currentMethodSym = currentMethodSymPrev; 8.43
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Jun 19 17:59:42 2014 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Mon Jun 23 00:01:40 2014 +0100 9.3 @@ -86,6 +86,7 @@ 9.4 private final Target target; 9.5 private final DeferredLintHandler deferredLintHandler; 9.6 private final Lint lint; 9.7 + private final TypeEnvs typeEnvs; 9.8 9.9 public static MemberEnter instance(Context context) { 9.10 MemberEnter instance = context.get(memberEnterKey); 9.11 @@ -113,6 +114,7 @@ 9.12 target = Target.instance(context); 9.13 deferredLintHandler = DeferredLintHandler.instance(context); 9.14 lint = Lint.instance(context); 9.15 + typeEnvs = TypeEnvs.instance(context); 9.16 allowTypeAnnos = source.allowTypeAnnotations(); 9.17 allowRepeatedAnnos = source.allowRepeatedAnnotations(); 9.18 } 9.19 @@ -652,22 +654,8 @@ 9.20 attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); 9.21 } else { 9.22 attr.attribType(tree.vartype, localEnv); 9.23 - if (tree.nameexpr != null) { 9.24 - attr.attribExpr(tree.nameexpr, localEnv); 9.25 - MethodSymbol m = localEnv.enclMethod.sym; 9.26 - if (m.isConstructor()) { 9.27 - Type outertype = m.owner.owner.type; 9.28 - if (outertype.hasTag(TypeTag.CLASS)) { 9.29 - checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); 9.30 - checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); 9.31 - } else { 9.32 - log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); 9.33 - } 9.34 - } else { 9.35 - checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); 9.36 - checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); 9.37 - } 9.38 - } 9.39 + if (TreeInfo.isReceiverParam(tree)) 9.40 + checkReceiver(tree, localEnv); 9.41 } 9.42 } finally { 9.43 deferredLintHandler.setPos(prevLintPos); 9.44 @@ -714,6 +702,26 @@ 9.45 log.error(tree, diag, type, tree.type); 9.46 } 9.47 } 9.48 + void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) { 9.49 + attr.attribExpr(tree.nameexpr, localEnv); 9.50 + MethodSymbol m = localEnv.enclMethod.sym; 9.51 + if (m.isConstructor()) { 9.52 + Type outertype = m.owner.owner.type; 9.53 + if (outertype.hasTag(TypeTag.METHOD)) { 9.54 + // we have a local inner class 9.55 + outertype = m.owner.owner.owner.type; 9.56 + } 9.57 + if (outertype.hasTag(TypeTag.CLASS)) { 9.58 + checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); 9.59 + checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); 9.60 + } else { 9.61 + log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); 9.62 + } 9.63 + } else { 9.64 + checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); 9.65 + checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); 9.66 + } 9.67 + } 9.68 9.69 public boolean needsLazyConstValue(JCTree tree) { 9.70 InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); 9.71 @@ -1018,7 +1026,7 @@ 9.72 9.73 ClassSymbol c = (ClassSymbol)sym; 9.74 ClassType ct = (ClassType)c.type; 9.75 - Env<AttrContext> env = enter.typeEnvs.get(c); 9.76 + Env<AttrContext> env = typeEnvs.get(c); 9.77 JCClassDecl tree = (JCClassDecl)env.tree; 9.78 boolean wasFirst = isFirst; 9.79 isFirst = false;
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Jun 19 17:59:42 2014 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon Jun 23 00:01:40 2014 +0100 10.3 @@ -967,10 +967,11 @@ 10.4 translateClass((ClassSymbol)st.tsym); 10.5 } 10.6 10.7 - Env<AttrContext> myEnv = enter.typeEnvs.remove(c); 10.8 - if (myEnv == null) { 10.9 + Env<AttrContext> myEnv = enter.getEnv(c); 10.10 + if (myEnv == null || (c.flags_field & TYPE_TRANSLATED) != 0) { 10.11 return; 10.12 } 10.13 + c.flags_field |= TYPE_TRANSLATED; 10.14 10.15 /* The two assertions below are set for early detection of any attempt 10.16 * to translate a class that:
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TypeEnvs.java Mon Jun 23 00:01:40 2014 +0100 11.3 @@ -0,0 +1,63 @@ 11.4 +/* 11.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. Oracle designates this 11.11 + * particular file as subject to the "Classpath" exception as provided 11.12 + * by Oracle in the LICENSE file that accompanied this code. 11.13 + * 11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 + * version 2 for more details (a copy is included in the LICENSE file that 11.18 + * accompanied this code). 11.19 + * 11.20 + * You should have received a copy of the GNU General Public License version 11.21 + * 2 along with this work; if not, write to the Free Software Foundation, 11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 + * 11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.25 + * or visit www.oracle.com if you need additional information or have any 11.26 + * questions. 11.27 + */ 11.28 + 11.29 +package com.sun.tools.javac.comp; 11.30 + 11.31 +import java.util.Collection; 11.32 +import java.util.HashMap; 11.33 +import com.sun.tools.javac.code.Symbol.TypeSymbol; 11.34 +import com.sun.tools.javac.util.Context; 11.35 + 11.36 +/** This class contains the type environments used by Enter, MemberEnter, 11.37 + * Attr, DeferredAttr, and Lower. 11.38 + * 11.39 + * <p><b>This is NOT part of any supported API. 11.40 + * If you write code that depends on this, you do so at your own risk. 11.41 + * This code and its internal interfaces are subject to change or 11.42 + * deletion without notice.</b> 11.43 + */ 11.44 +class TypeEnvs { 11.45 + private static final long serialVersionUID = 571524752489954631L; 11.46 + 11.47 + protected static final Context.Key<TypeEnvs> typeEnvsKey = new Context.Key<>(); 11.48 + public static TypeEnvs instance(Context context) { 11.49 + TypeEnvs instance = context.get(typeEnvsKey); 11.50 + if (instance == null) 11.51 + instance = new TypeEnvs(context); 11.52 + return instance; 11.53 + } 11.54 + 11.55 + private HashMap<TypeSymbol,Env<AttrContext>> map; 11.56 + protected TypeEnvs(Context context) { 11.57 + map = new HashMap<>(); 11.58 + context.put(typeEnvsKey, this); 11.59 + } 11.60 + 11.61 + Env<AttrContext> get(TypeSymbol sym) { return map.get(sym); } 11.62 + Env<AttrContext> put(TypeSymbol sym, Env<AttrContext> env) { return map.put(sym, env); } 11.63 + Env<AttrContext> remove(TypeSymbol sym) { return map.remove(sym); } 11.64 + Collection<Env<AttrContext>> values() { return map.values(); } 11.65 + void clear() { map.clear(); } 11.66 +}
12.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jun 19 17:59:42 2014 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Jun 23 00:01:40 2014 +0100 12.3 @@ -135,6 +135,14 @@ 12.4 } 12.5 } 12.6 12.7 + public static boolean isReceiverParam(JCTree tree) { 12.8 + if (tree.hasTag(VARDEF)) { 12.9 + return ((JCVariableDecl)tree).nameexpr != null; 12.10 + } else { 12.11 + return false; 12.12 + } 12.13 + } 12.14 + 12.15 /** Is there a constructor declaration in the given list of trees? 12.16 */ 12.17 public static boolean hasConstructors(List<JCTree> trees) {
13.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Jun 19 17:59:42 2014 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Mon Jun 23 00:01:40 2014 +0100 13.3 @@ -355,13 +355,41 @@ 13.4 private final DiagnosticType type; 13.5 private final DiagnosticSource source; 13.6 private final DiagnosticPosition position; 13.7 - private final int line; 13.8 - private final int column; 13.9 private final String key; 13.10 protected final Object[] args; 13.11 private final Set<DiagnosticFlag> flags; 13.12 private final LintCategory lintCategory; 13.13 13.14 + /** source line position (set lazily) */ 13.15 + private SourcePosition sourcePosition; 13.16 + 13.17 + /** 13.18 + * This class is used to defer the line/column position fetch logic after diagnostic construction. 13.19 + */ 13.20 + class SourcePosition { 13.21 + 13.22 + private final int line; 13.23 + private final int column; 13.24 + 13.25 + SourcePosition() { 13.26 + int n = (position == null ? Position.NOPOS : position.getPreferredPosition()); 13.27 + if (n == Position.NOPOS || source == null) 13.28 + line = column = -1; 13.29 + else { 13.30 + line = source.getLineNumber(n); 13.31 + column = source.getColumnNumber(n, true); 13.32 + } 13.33 + } 13.34 + 13.35 + public int getLineNumber() { 13.36 + return line; 13.37 + } 13.38 + 13.39 + public int getColumnNumber() { 13.40 + return column; 13.41 + } 13.42 + } 13.43 + 13.44 /** 13.45 * Create a diagnostic object. 13.46 * @param formatter the formatter to use for the diagnostic 13.47 @@ -391,14 +419,6 @@ 13.48 this.position = pos; 13.49 this.key = key; 13.50 this.args = args; 13.51 - 13.52 - int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); 13.53 - if (n == Position.NOPOS || source == null) 13.54 - line = column = -1; 13.55 - else { 13.56 - line = source.getLineNumber(n); 13.57 - column = source.getColumnNumber(n, true); 13.58 - } 13.59 } 13.60 13.61 /** 13.62 @@ -495,7 +515,10 @@ 13.63 * @return the line number within the source referred to by this diagnostic 13.64 */ 13.65 public long getLineNumber() { 13.66 - return line; 13.67 + if (sourcePosition == null) { 13.68 + sourcePosition = new SourcePosition(); 13.69 + } 13.70 + return sourcePosition.getLineNumber(); 13.71 } 13.72 13.73 /** 13.74 @@ -503,7 +526,10 @@ 13.75 * @return the column number within the line of source referred to by this diagnostic 13.76 */ 13.77 public long getColumnNumber() { 13.78 - return column; 13.79 + if (sourcePosition == null) { 13.80 + sourcePosition = new SourcePosition(); 13.81 + } 13.82 + return sourcePosition.getColumnNumber(); 13.83 } 13.84 13.85 /**
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/T8038975/AccessTest.java Mon Jun 23 00:01:40 2014 +0100 14.3 @@ -0,0 +1,39 @@ 14.4 +/* 14.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 8038975 14.30 + * @summary Access control in enhanced for 14.31 + * @compile AccessTest.java 14.32 + */ 14.33 + 14.34 +import a.*; 14.35 +public class AccessTest { 14.36 + private static class Impl extends B { 14.37 + public void method(Inner inner) { 14.38 + for (A a : inner) 14.39 + System.out.println(a); 14.40 + } 14.41 + } 14.42 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/T8038975/a/A.java Mon Jun 23 00:01:40 2014 +0100 15.3 @@ -0,0 +1,25 @@ 15.4 +/* 15.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +package a; 15.28 +public class A { }
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/T8038975/a/B.java Mon Jun 23 00:01:40 2014 +0100 16.3 @@ -0,0 +1,27 @@ 16.4 +/* 16.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +package a; 16.28 +public class B { 16.29 + protected abstract class Inner implements Iterable<A> { } 16.30 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/annotations/FinalReceiverTest.java Mon Jun 23 00:01:40 2014 +0100 17.3 @@ -0,0 +1,14 @@ 17.4 +/* 17.5 + * @test /nodynamiccopyright/ 17.6 + * @bug 8027886 17.7 + * @summary Receiver parameters must not be final 17.8 + * @compile/fail/ref=FinalReceiverTest.out -XDrawDiagnostics FinalReceiverTest.java 17.9 + */ 17.10 + 17.11 +class FinalReceiverTest { 17.12 + void m() { 17.13 + class Inner { 17.14 + Inner(final FinalReceiverTest FinalReceiverTest.this) {} 17.15 + } 17.16 + } 17.17 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/annotations/FinalReceiverTest.out Mon Jun 23 00:01:40 2014 +0100 18.3 @@ -0,0 +1,2 @@ 18.4 +FinalReceiverTest.java:11:43: compiler.err.mod.not.allowed.here: final 18.5 +1 error
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/annotations/LocalInnerReceiverTest.java Mon Jun 23 00:01:40 2014 +0100 19.3 @@ -0,0 +1,37 @@ 19.4 +/* 19.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/* 19.28 + * @test 19.29 + * @bug 8029042 19.30 + * @summary Receiver parameter not supported on local class constructor 19.31 + * @compile LocalInnerReceiverTest.java 19.32 + */ 19.33 + 19.34 +class LocalInnerReceiverTest { 19.35 + void m() { 19.36 + class Inner { 19.37 + Inner(LocalInnerReceiverTest LocalInnerReceiverTest.this) {} 19.38 + } 19.39 + } 19.40 +}
20.1 --- a/test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java Thu Jun 19 17:59:42 2014 -0700 20.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java Mon Jun 23 00:01:40 2014 +0100 20.3 @@ -54,14 +54,6 @@ 20.4 <T extends Runnable> void accept(@B("m") WithValue this, T r) throws Exception { } 20.5 } 20.6 20.7 -class WithFinal { 20.8 - void plain(final @B("m") WithFinal this) { } 20.9 - <T> void generic(final @B("m") WithFinal this) { } 20.10 - void withException(final @B("m") WithFinal this) throws Exception { } 20.11 - String nonVoid(final @B("m") WithFinal this) { return null; } 20.12 - <T extends Runnable> void accept(final @B("m") WithFinal this, T r) throws Exception { } 20.13 -} 20.14 - 20.15 class WithBody { 20.16 Object f; 20.17
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke.java Mon Jun 23 00:01:40 2014 +0100 21.3 @@ -0,0 +1,15 @@ 21.4 +/* @test /nodynamiccopyright/ 21.5 + * @bug 8037385 21.6 + * @summary Must not allow static interface method invocation in legacy code 21.7 + * @compile -source 8 -Xlint:-options StaticInvoke.java 21.8 + * @compile/fail/ref=StaticInvoke7.out -source 7 -Xlint:-options -XDrawDiagnostics StaticInvoke.java 21.9 + * @compile/fail/ref=StaticInvoke6.out -source 6 -Xlint:-options -XDrawDiagnostics StaticInvoke.java 21.10 + */ 21.11 +import java.util.stream.Stream; 21.12 + 21.13 +class StaticInvoke { 21.14 + void test() { 21.15 + Stream.empty(); 21.16 + java.util.stream.Stream.empty(); 21.17 + } 21.18 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke6.out Mon Jun 23 00:01:40 2014 +0100 22.3 @@ -0,0 +1,3 @@ 22.4 +StaticInvoke.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6 22.5 +StaticInvoke.java:13:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6 22.6 +2 errors
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke7.out Mon Jun 23 00:01:40 2014 +0100 23.3 @@ -0,0 +1,3 @@ 23.4 +StaticInvoke.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7 23.5 +StaticInvoke.java:13:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7 23.6 +2 errors
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/generics/wildcards/T8034147.java Mon Jun 23 00:01:40 2014 +0100 24.3 @@ -0,0 +1,35 @@ 24.4 +/* 24.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. 24.11 + * 24.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.15 + * version 2 for more details (a copy is included in the LICENSE file that 24.16 + * accompanied this code). 24.17 + * 24.18 + * You should have received a copy of the GNU General Public License version 24.19 + * 2 along with this work; if not, write to the Free Software Foundation, 24.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.21 + * 24.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.23 + * or visit www.oracle.com if you need additional information or have any 24.24 + * questions. 24.25 + */ 24.26 + 24.27 +/* 24.28 + * @test 24.29 + * @bug 8034147 24.30 + * @summary javac crashes with a NullPointerException during bounds checking 24.31 + * @compile T8034147.java 24.32 + */ 24.33 + 24.34 +class T8034147 { 24.35 + static class One<X extends Two<? super X>> {} 24.36 + static class Two<Y extends Three<? extends Y>> implements Three<Y> {} 24.37 + interface Three<Z> {} 24.38 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.java Mon Jun 23 00:01:40 2014 +0100 25.3 @@ -0,0 +1,24 @@ 25.4 +/* 25.5 + * @test /nodynamiccopyright/ 25.6 + * @bug 8038182 25.7 + * @summary javac crash with FunctionDescriptorLookupError for invalid functional interface 25.8 + * @compile/fail/ref=CrashFunctionDescriptorExceptionTest.out -XDrawDiagnostics CrashFunctionDescriptorExceptionTest.java 25.9 + */ 25.10 + 25.11 +class CrashFunctionDescriptorExceptionTest { 25.12 + 25.13 + @SuppressWarnings("unchecked") 25.14 + void m () { 25.15 + bar((B b) -> {}); 25.16 + } 25.17 + 25.18 + <E extends A<E>> void bar(I<E> i) {} 25.19 + 25.20 + class A<E> {} 25.21 + 25.22 + class B<E> extends A<E> {} 25.23 + 25.24 + interface I<E extends A<E>> { 25.25 + void foo(E e); 25.26 + } 25.27 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.out Mon Jun 23 00:01:40 2014 +0100 26.3 @@ -0,0 +1,2 @@ 26.4 +CrashFunctionDescriptorExceptionTest.java:12:13: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: CrashFunctionDescriptorExceptionTest.I<CrashFunctionDescriptorExceptionTest.B>) 26.5 +1 error
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.java Mon Jun 23 00:01:40 2014 +0100 27.3 @@ -0,0 +1,33 @@ 27.4 +/* 27.5 + * @test /nodynamiccopyright/ 27.6 + * @bug 8042759 27.7 + * @summary Lambda returning implicitly-typed lambdas considered pertinent to applicability 27.8 + * @compile/fail/ref=ImplicitLambdaConsideredForApplicabilityTest.out -XDrawDiagnostics ImplicitLambdaConsideredForApplicabilityTest.java 27.9 + */ 27.10 + 27.11 +abstract class ImplicitLambdaConsideredForApplicabilityTest { 27.12 + interface A { 27.13 + B m(int a, int b); 27.14 + } 27.15 + 27.16 + interface C { 27.17 + String m(int a, int b); 27.18 + } 27.19 + 27.20 + interface B { 27.21 + int m(int c); 27.22 + } 27.23 + 27.24 + abstract void foo(A a); 27.25 + 27.26 + abstract void foo(C c); 27.27 + 27.28 + void bar() { 27.29 + foo((int a, int b) -> { 27.30 + if(a < b) 27.31 + return c -> 0; 27.32 + else 27.33 + return c -> 0; 27.34 + }); 27.35 + } 27.36 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.out Mon Jun 23 00:01:40 2014 +0100 28.3 @@ -0,0 +1,2 @@ 28.4 +ImplicitLambdaConsideredForApplicabilityTest.java:26:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.A), ImplicitLambdaConsideredForApplicabilityTest, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.C), ImplicitLambdaConsideredForApplicabilityTest 28.5 +1 error
29.1 --- a/test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java Thu Jun 19 17:59:42 2014 -0700 29.2 +++ b/test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java Mon Jun 23 00:01:40 2014 +0100 29.3 @@ -1,5 +1,5 @@ 29.4 /* 29.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 29.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 29.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.8 * 29.9 * This code is free software; you can redistribute it and/or modify it 29.10 @@ -23,7 +23,7 @@ 29.11 29.12 /* 29.13 * @test 29.14 - * @bug 8011027 29.15 + * @bug 8011027 8046916 29.16 * @library /tools/javac/lib 29.17 * @build JavacTestingAbstractProcessor TestTypeParameterAnnotations 29.18 * @compile -processor TestTypeParameterAnnotations -proc:only TestTypeParameterAnnotations.java 29.19 @@ -33,10 +33,16 @@ 29.20 import java.lang.annotation.*; 29.21 import javax.annotation.processing.*; 29.22 import javax.lang.model.element.*; 29.23 -import javax.lang.model.util.*; 29.24 import javax.tools.*; 29.25 29.26 -public class TestTypeParameterAnnotations<@Foo @Bar @Baz T> extends JavacTestingAbstractProcessor { 29.27 +@ExpectedTypeParameterAnnotations(typeParameterName="T1", 29.28 + annotations={"Foo1", "Bar1", "Baz1"}) 29.29 +@ExpectedTypeParameterAnnotations(typeParameterName="T2", annotations={}) 29.30 +@ExpectedTypeParameterAnnotations(typeParameterName="T3", 29.31 + annotations={"Foo2", "Bar2", "Baz2"}) 29.32 +@ExpectedTypeParameterAnnotations(typeParameterName="T4", annotations={}) 29.33 +public class TestTypeParameterAnnotations<@Foo1 @Bar1 @Baz1 T1, T2, @Foo2 @Bar2 @Baz2 T3, T4> extends 29.34 + JavacTestingAbstractProcessor { 29.35 int round = 0; 29.36 29.37 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 29.38 @@ -74,82 +80,69 @@ 29.39 int check(Element e, List<? extends TypeParameterElement> typarams) { 29.40 if (typarams.isEmpty()) 29.41 return 0; 29.42 - if (typarams.size() != 1) 29.43 - return 0; 29.44 29.45 - for (TypeParameterElement tpe: typarams) { 29.46 - boolean b1 = checkAnnotationMirrors(tpe, tpe.getAnnotationMirrors()); 29.47 - boolean b2 = checkAnnotationMirrors(tpe, elements.getAllAnnotationMirrors(tpe)); 29.48 - boolean b3 = checkGetAnnotation(tpe); 29.49 - boolean b4 = checkGetAnnotations(tpe); 29.50 - return b1 && b2 && b3 && b4 ? 1 : 0; 29.51 + for (TypeParameterElement tpe : typarams) { 29.52 + ExpectedTypeParameterAnnotations expected = null; 29.53 + for (ExpectedTypeParameterAnnotations a : e.getAnnotationsByType(ExpectedTypeParameterAnnotations.class)) { 29.54 + if (tpe.getSimpleName().contentEquals(a.typeParameterName())) { 29.55 + expected = a; 29.56 + break; 29.57 + } 29.58 + } 29.59 + if (expected == null) { 29.60 + throw new IllegalStateException("Does not have expected values annotation."); 29.61 + } 29.62 + checkAnnotationMirrors(tpe, tpe.getAnnotationMirrors(), expected); 29.63 + checkAnnotationMirrors(tpe, elements.getAllAnnotationMirrors(tpe), expected); 29.64 + checkGetAnnotation(tpe, expected); 29.65 + checkGetAnnotations(tpe, expected); 29.66 } 29.67 - return 0; 29.68 + 29.69 + return typarams.size(); 29.70 } 29.71 29.72 - boolean checkAnnotationMirrors(TypeParameterElement tpe, List<? extends AnnotationMirror> l) { 29.73 - if (l.size() != 3) { 29.74 - error("To few annotations, got " + l.size() + 29.75 - ", should be 3", tpe); 29.76 - return false; 29.77 + void checkAnnotationMirrors(TypeParameterElement tpe, List<? extends AnnotationMirror> l, ExpectedTypeParameterAnnotations expected) { 29.78 + String[] expectedAnnotations = expected.annotations(); 29.79 + 29.80 + if (l.size() != expectedAnnotations.length) { 29.81 + error("Incorrect number of annotations, got " + l.size() + 29.82 + ", should be " + expectedAnnotations.length, tpe); 29.83 + return ; 29.84 } 29.85 29.86 - AnnotationMirror m = l.get(0); 29.87 - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Foo"))) { 29.88 - error("Wrong type of annotation, was expecting @Foo", m.getAnnotationType().asElement()); 29.89 - return false; 29.90 + for (int i = 0; i < expectedAnnotations.length; i++) { 29.91 + AnnotationMirror m = l.get(i); 29.92 + if (!m.getAnnotationType().asElement().equals(elements.getTypeElement(expectedAnnotations[i]))) { 29.93 + error("Wrong type of annotation, was expecting @Foo", m.getAnnotationType().asElement()); 29.94 + return ; 29.95 + } 29.96 } 29.97 - m = l.get(1); 29.98 - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Bar"))) { 29.99 - error("Wrong type of annotation, was expecting @Bar", m.getAnnotationType().asElement()); 29.100 - return false; 29.101 - } 29.102 - m = l.get(2); 29.103 - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Baz"))) { 29.104 - error("Wrong type of annotation, was expecting @Baz", m.getAnnotationType().asElement()); 29.105 - return false; 29.106 - } 29.107 - return true; 29.108 } 29.109 29.110 - boolean checkGetAnnotation(TypeParameterElement tpe) { 29.111 - Foo f = tpe.getAnnotation(Foo.class); 29.112 - if (f == null) 29.113 - error("Expecting @Foo to be present in getAnnotation()", tpe); 29.114 + void checkGetAnnotation(TypeParameterElement tpe, ExpectedTypeParameterAnnotations expected) { 29.115 + List<String> expectedAnnotations = Arrays.asList(expected.annotations()); 29.116 29.117 - Bar b = tpe.getAnnotation(Bar.class); 29.118 - if (b == null) 29.119 - error("Expecting @Bar to be present in getAnnotation()", tpe); 29.120 + for (Class<? extends Annotation> c : ALL_ANNOTATIONS) { 29.121 + Object a = tpe.getAnnotation(c); 29.122 29.123 - Baz z = tpe.getAnnotation(Baz.class); 29.124 - if (z == null) 29.125 - error("Expecting @Baz to be present in getAnnotation()", tpe); 29.126 - 29.127 - return f != null && 29.128 - b != null && 29.129 - z != null; 29.130 + if (a != null ^ expectedAnnotations.indexOf(c.getName()) != (-1)) { 29.131 + error("Unexpected behavior for " + c.getName(), tpe); 29.132 + return ; 29.133 + } 29.134 + } 29.135 } 29.136 29.137 - boolean checkGetAnnotations(TypeParameterElement tpe) { 29.138 - Foo[] f = tpe.getAnnotationsByType(Foo.class); 29.139 - if (f.length != 1) { 29.140 - error("Expecting 1 @Foo to be present in getAnnotationsByType()", tpe); 29.141 - return false; 29.142 + void checkGetAnnotations(TypeParameterElement tpe, ExpectedTypeParameterAnnotations expected) { 29.143 + List<String> expectedAnnotations = Arrays.asList(expected.annotations()); 29.144 + 29.145 + for (Class<? extends Annotation> c : ALL_ANNOTATIONS) { 29.146 + Object[] a = tpe.getAnnotationsByType(c); 29.147 + 29.148 + if (a.length > 0 ^ expectedAnnotations.indexOf(c.getName()) != (-1)) { 29.149 + error("Unexpected behavior for " + c.getName(), tpe); 29.150 + return ; 29.151 + } 29.152 } 29.153 - 29.154 - Bar[] b = tpe.getAnnotationsByType(Bar.class); 29.155 - if (b.length != 1) { 29.156 - error("Expecting 1 @Bar to be present in getAnnotationsByType()", tpe); 29.157 - return false; 29.158 - } 29.159 - 29.160 - Baz[] z = tpe.getAnnotationsByType(Baz.class); 29.161 - if (z.length != 1) { 29.162 - error("Expecting 1 @Baz to be present in getAnnotationsByType()", tpe); 29.163 - return false; 29.164 - } 29.165 - 29.166 - return true; 29.167 } 29.168 29.169 void note(String msg) { 29.170 @@ -168,23 +161,71 @@ 29.171 messager.printMessage(Diagnostic.Kind.ERROR, msg); 29.172 } 29.173 29.174 + Class<? extends Annotation>[] ALL_ANNOTATIONS = new Class[] { 29.175 + Foo1.class, Bar1.class, Baz1.class, 29.176 + Foo2.class, Bar2.class, Baz2.class, 29.177 + }; 29.178 + 29.179 // additional generic elements to test 29.180 - <@Foo @Bar @Baz X> X m(X x) { return x; } 29.181 + @ExpectedTypeParameterAnnotations(typeParameterName="W", 29.182 + annotations={"Foo1", "Bar1", "Baz1"}) 29.183 + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) 29.184 + @ExpectedTypeParameterAnnotations(typeParameterName="Y", 29.185 + annotations={"Foo2", "Bar2", "Baz2"}) 29.186 + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) 29.187 + <@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> X m(X x) { return x; } 29.188 29.189 - interface Intf<@Foo @Bar @Baz X> { X m() ; } 29.190 + @ExpectedTypeParameterAnnotations(typeParameterName="W", 29.191 + annotations={"Foo1", "Bar1", "Baz1"}) 29.192 + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) 29.193 + @ExpectedTypeParameterAnnotations(typeParameterName="Y", 29.194 + annotations={"Foo2", "Bar2", "Baz2"}) 29.195 + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) 29.196 + interface Intf<@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> { X m() ; } 29.197 29.198 - class Class<@Foo @Bar @Baz X> { 29.199 - <@Foo @Bar @Baz Y> Class() { } 29.200 + @ExpectedTypeParameterAnnotations(typeParameterName="W", 29.201 + annotations={"Foo1", "Bar1", "Baz1"}) 29.202 + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) 29.203 + @ExpectedTypeParameterAnnotations(typeParameterName="Y", 29.204 + annotations={"Foo2", "Bar2", "Baz2"}) 29.205 + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) 29.206 + class Clazz<@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> { 29.207 + @ExpectedTypeParameterAnnotations(typeParameterName="W", 29.208 + annotations={"Foo1", "Bar1", "Baz1"}) 29.209 + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) 29.210 + @ExpectedTypeParameterAnnotations(typeParameterName="Y", 29.211 + annotations={"Foo2", "Bar2", "Baz2"}) 29.212 + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) 29.213 + <@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> Clazz() { } 29.214 } 29.215 29.216 - final int expect = 5; // top level class, plus preceding examples 29.217 + final int expect = 5 * 4; // top level class, plus preceding examples, 4 type variables each 29.218 } 29.219 29.220 @Target(ElementType.TYPE_PARAMETER) 29.221 -@interface Foo {} 29.222 +@interface Foo1 {} 29.223 29.224 @Target(ElementType.TYPE_PARAMETER) 29.225 -@interface Bar {} 29.226 +@interface Bar1 {} 29.227 29.228 @Target(ElementType.TYPE_PARAMETER) 29.229 -@interface Baz {} 29.230 +@interface Baz1 {} 29.231 + 29.232 +@Target(ElementType.TYPE_PARAMETER) 29.233 +@interface Foo2 {} 29.234 + 29.235 +@Target(ElementType.TYPE_PARAMETER) 29.236 +@interface Bar2 {} 29.237 + 29.238 +@Target(ElementType.TYPE_PARAMETER) 29.239 +@interface Baz2 {} 29.240 + 29.241 +@Repeatable(ExpectedTypeParameterAnnotationsCollection.class) 29.242 +@interface ExpectedTypeParameterAnnotations { 29.243 + public String typeParameterName(); 29.244 + public String[] annotations(); 29.245 +} 29.246 + 29.247 +@interface ExpectedTypeParameterAnnotationsCollection { 29.248 + public ExpectedTypeParameterAnnotations[] value(); 29.249 +}