Sat, 08 Sep 2012 22:54:21 -0700
Merge
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Annotations.java Sat Sep 08 22:54:21 2012 -0700 1.3 @@ -0,0 +1,294 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javac.code; 1.30 + 1.31 +import java.util.Map; 1.32 +import javax.tools.JavaFileObject; 1.33 + 1.34 +import com.sun.tools.javac.comp.Annotate; 1.35 +import com.sun.tools.javac.comp.AttrContext; 1.36 +import com.sun.tools.javac.comp.Env; 1.37 +import com.sun.tools.javac.util.Assert; 1.38 +import com.sun.tools.javac.util.List; 1.39 +import com.sun.tools.javac.util.Log; 1.40 +import com.sun.tools.javac.util.Pair; 1.41 + 1.42 +import static com.sun.tools.javac.code.Kinds.PCK; 1.43 +import com.sun.tools.javac.util.*; 1.44 + 1.45 +/** 1.46 + * Container for all annotations (attributes in javac) on a Symbol. 1.47 + * 1.48 + * This class is explicitly mutable. Its contents will change when attributes 1.49 + * are annotated onto the Symbol. However this class depends on the facts that 1.50 + * List (in javac) is immutable. 1.51 + * 1.52 + * An instance of this class can be in one of three states: 1.53 + * 1.54 + * NOT_STARTED indicates that the Symbol this instance belongs to have not been 1.55 + * annotated (yet). Specifically if the declaration is not annotated this 1.56 + * instance will never move past NOT_STARTED. You can never go back to 1.57 + * NOT_STARTED. 1.58 + * 1.59 + * IN_PROGRESS annotations have been found on the declaration. Will be processed 1.60 + * later. You can reset to IN_PROGRESS. While IN_PROGRESS you can set the list 1.61 + * of attributes (and this moves out of the IN_PROGRESS state). 1.62 + * 1.63 + * "unnamed" this Annotations contains some attributes, possibly the final set. 1.64 + * While in this state you can only prepend or append to the attributes not set 1.65 + * it directly. You can also move back to the IN_PROGRESS sate using reset(). 1.66 + * 1.67 + * <p><b>This is NOT part of any supported API. If you write code that depends 1.68 + * on this, you do so at your own risk. This code and its internal interfaces 1.69 + * are subject to change or deletion without notice.</b> 1.70 + */ 1.71 +public class Annotations { 1.72 + 1.73 + private static final List<Attribute.Compound> NOT_STARTED = List.of(null); 1.74 + private static final List<Attribute.Compound> IN_PROGRESS = List.of(null); 1.75 + /* 1.76 + * This field should never be null 1.77 + */ 1.78 + private List<Attribute.Compound> attributes = NOT_STARTED; 1.79 + /* 1.80 + * The Symbol this Annotatios belong to 1.81 + */ 1.82 + private final Symbol s; 1.83 + 1.84 + public Annotations(Symbol s) { 1.85 + this.s = s; 1.86 + } 1.87 + 1.88 + public List<Attribute.Compound> getAttributes() { 1.89 + return filterSentinels(attributes); 1.90 + } 1.91 + 1.92 + public void setAttributes(List<Attribute.Compound> a) { 1.93 + Assert.check(pendingCompletion() || !isStarted()); 1.94 + if (a == null) { 1.95 + throw new NullPointerException(); 1.96 + } 1.97 + attributes = a; 1.98 + } 1.99 + 1.100 + public void setAttributes(Annotations other) { 1.101 + if (other == null) { 1.102 + throw new NullPointerException(); 1.103 + } 1.104 + setAttributes(other.getAttributes()); 1.105 + } 1.106 + 1.107 + public void setAttributesWithCompletion(final Annotate.AnnotateRepeatedContext ctx) { 1.108 + Assert.check(pendingCompletion() || (!isStarted() && s.kind == PCK)); 1.109 + 1.110 + Map<Symbol.TypeSymbol, ListBuffer<Attribute.Compound>> annotated = ctx.annotated; 1.111 + boolean atLeastOneRepeated = false; 1.112 + List<Attribute.Compound> buf = List.<Attribute.Compound>nil(); 1.113 + for (ListBuffer<Attribute.Compound> lb : annotated.values()) { 1.114 + if (lb.size() == 1) { 1.115 + buf = buf.prepend(lb.first()); 1.116 + } else { // repeated 1.117 + buf = buf.prepend(new Placeholder(lb.toList(), s)); 1.118 + atLeastOneRepeated = true; 1.119 + } 1.120 + } 1.121 + 1.122 + // Add non-repeating attributes 1.123 + setAttributes(buf.reverse()); 1.124 + 1.125 + if (atLeastOneRepeated) { 1.126 + // The Symbol s is now annotated with a combination of 1.127 + // finished non-repeating annotations and placeholders for 1.128 + // repeating annotations. 1.129 + // 1.130 + // We need to do this in two passes because when creating 1.131 + // a container for a repeating annotation we must 1.132 + // guarantee that the @ContainedBy on the 1.133 + // contained annotation is fully annotated 1.134 + // 1.135 + // The way we force this order is to do all repeating 1.136 + // annotations in a pass after all non-repeating are 1.137 + // finished. This will work because @ContainedBy 1.138 + // is non-repeating and therefore will be annotated in the 1.139 + // fist pass. 1.140 + 1.141 + // Queue a pass that will replace Attribute.Placeholders 1.142 + // with Attribute.Compound (made from synthesized containers). 1.143 + ctx.annotateRepeated(new Annotate.Annotator() { 1.144 + 1.145 + @Override 1.146 + public String toString() { 1.147 + return "repeated annotation pass of: " + s + " in: " + s.owner; 1.148 + } 1.149 + 1.150 + @Override 1.151 + public void enterAnnotation() { 1.152 + complete(ctx); 1.153 + } 1.154 + }); 1.155 + } 1.156 + } 1.157 + 1.158 + public Annotations reset() { 1.159 + attributes = IN_PROGRESS; 1.160 + return this; 1.161 + } 1.162 + 1.163 + public boolean isEmpty() { 1.164 + return !isStarted() 1.165 + || pendingCompletion() 1.166 + || attributes.isEmpty(); 1.167 + } 1.168 + 1.169 + public boolean pendingCompletion() { 1.170 + return attributes == IN_PROGRESS; 1.171 + } 1.172 + 1.173 + public Annotations append(List<Attribute.Compound> l) { 1.174 + attributes = filterSentinels(attributes); 1.175 + 1.176 + if (l.isEmpty()) { 1.177 + ; // no-op 1.178 + } else if (attributes.isEmpty()) { 1.179 + attributes = l; 1.180 + } else { 1.181 + attributes = attributes.appendList(l); 1.182 + } 1.183 + return this; 1.184 + } 1.185 + 1.186 + public Annotations prepend(List<Attribute.Compound> l) { 1.187 + attributes = filterSentinels(attributes); 1.188 + 1.189 + if (l.isEmpty()) { 1.190 + ; // no-op 1.191 + } else if (attributes.isEmpty()) { 1.192 + attributes = l; 1.193 + } else { 1.194 + attributes = attributes.prependList(l); 1.195 + } 1.196 + return this; 1.197 + } 1.198 + 1.199 + private List<Attribute.Compound> filterSentinels(List<Attribute.Compound> a) { 1.200 + return (a == IN_PROGRESS || a == NOT_STARTED) 1.201 + ? List.<Attribute.Compound>nil() 1.202 + : a; 1.203 + } 1.204 + 1.205 + private boolean isStarted() { 1.206 + return attributes != NOT_STARTED; 1.207 + } 1.208 + 1.209 + private List<Attribute.Compound> getPlaceholders() { 1.210 + List<Attribute.Compound> res = List.<Attribute.Compound>nil(); 1.211 + for (Attribute.Compound a : filterSentinels(attributes)) { 1.212 + if (a instanceof Placeholder) { 1.213 + res = res.prepend(a); 1.214 + } 1.215 + } 1.216 + return res.reverse(); 1.217 + } 1.218 + 1.219 + /* 1.220 + * Replace Placeholders for repeating annotations with their containers 1.221 + */ 1.222 + private void complete(Annotate.AnnotateRepeatedContext ctx) { 1.223 + Assert.check(!pendingCompletion()); 1.224 + Log log = ctx.log; 1.225 + Env<AttrContext> env = ctx.env; 1.226 + JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); 1.227 + try { 1.228 + 1.229 + if (isEmpty()) { 1.230 + return; 1.231 + } 1.232 + 1.233 + List<Attribute.Compound> result = List.nil(); 1.234 + for (Attribute.Compound a : getAttributes()) { 1.235 + if (a instanceof Placeholder) { 1.236 + Attribute.Compound replacement = replaceOne((Placeholder) a, ctx); 1.237 + 1.238 + if (null != replacement) { 1.239 + result = result.prepend(replacement); 1.240 + } 1.241 + } else { 1.242 + result = result.prepend(a); 1.243 + } 1.244 + } 1.245 + 1.246 + attributes = result.reverse(); 1.247 + 1.248 + Assert.check(Annotations.this.getPlaceholders().isEmpty()); 1.249 + } finally { 1.250 + log.useSource(oldSource); 1.251 + } 1.252 + } 1.253 + 1.254 + private Attribute.Compound replaceOne(Placeholder placeholder, Annotate.AnnotateRepeatedContext ctx) { 1.255 + Log log = ctx.log; 1.256 + 1.257 + // Process repeated annotations 1.258 + Attribute.Compound validRepeated = 1.259 + ctx.processRepeatedAnnotations(placeholder.getPlaceholderFor()); 1.260 + 1.261 + if (validRepeated != null) { 1.262 + // Check that the container isn't manually 1.263 + // present along with repeated instances of 1.264 + // its contained annotation. 1.265 + ListBuffer<Attribute.Compound> manualContainer = ctx.annotated.get(validRepeated.type.tsym); 1.266 + if (manualContainer != null) { 1.267 + log.error(ctx.pos.get(manualContainer.first()), "invalid.containedby.annotation.repeated.and.container.present", 1.268 + manualContainer.first().type.tsym); 1.269 + } 1.270 + } 1.271 + 1.272 + // A null return will delete the Placeholder 1.273 + return validRepeated; 1.274 + 1.275 + } 1.276 + 1.277 + private static class Placeholder extends Attribute.Compound { 1.278 + 1.279 + private List<Attribute.Compound> placeholderFor; 1.280 + private Symbol on; 1.281 + 1.282 + public Placeholder(List<Attribute.Compound> placeholderFor, Symbol on) { 1.283 + super(Type.noType, List.<Pair<Symbol.MethodSymbol, Attribute>>nil()); 1.284 + this.placeholderFor = placeholderFor; 1.285 + this.on = on; 1.286 + } 1.287 + 1.288 + @Override 1.289 + public String toString() { 1.290 + return "<placeholder: " + placeholderFor + " on: " + on + ">"; 1.291 + } 1.292 + 1.293 + public List<Attribute.Compound> getPlaceholderFor() { 1.294 + return placeholderFor; 1.295 + } 1.296 + } 1.297 +}
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java Sat Sep 08 22:43:38 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java Sat Sep 08 22:54:21 2012 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -103,11 +103,11 @@ 2.11 * represented as a ClassSymbol. 2.12 */ 2.13 public static class Class extends Attribute { 2.14 - public final Type type; 2.15 + public final Type classType; 2.16 public void accept(Visitor v) { v.visitClass(this); } 2.17 public Class(Types types, Type type) { 2.18 super(makeClassType(types, type)); 2.19 - this.type = type; 2.20 + this.classType = type; 2.21 } 2.22 static Type makeClassType(Types types, Type type) { 2.23 Type arg = type.isPrimitive() 2.24 @@ -118,13 +118,13 @@ 2.25 types.syms.classType.tsym); 2.26 } 2.27 public String toString() { 2.28 - return type + ".class"; 2.29 + return classType + ".class"; 2.30 } 2.31 public Type getValue() { 2.32 - return type; 2.33 + return classType; 2.34 } 2.35 public <R, P> R accept(AnnotationValueVisitor<R, P> v, P p) { 2.36 - return v.visitType(type, p); 2.37 + return v.visitType(classType, p); 2.38 } 2.39 } 2.40 2.41 @@ -212,6 +212,12 @@ 2.42 super(type); 2.43 this.values = values; 2.44 } 2.45 + 2.46 + public Array(Type type, List<Attribute> values) { 2.47 + super(type); 2.48 + this.values = values.toArray(new Attribute[values.size()]); 2.49 + } 2.50 + 2.51 public void accept(Visitor v) { v.visitArray(this); } 2.52 public String toString() { 2.53 StringBuilder buf = new StringBuilder();
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Lint.java Sat Sep 08 22:43:38 2012 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Lint.java Sat Sep 08 22:54:21 2012 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -70,16 +70,16 @@ 3.11 * Returns the result of combining the values in this object with 3.12 * the given annotations. 3.13 */ 3.14 - public Lint augment(List<Attribute.Compound> attrs) { 3.15 - return augmentor.augment(this, attrs); 3.16 + public Lint augment(Annotations annots) { 3.17 + return augmentor.augment(this, annots.getAttributes()); 3.18 } 3.19 3.20 /** 3.21 * Returns the result of combining the values in this object with 3.22 * the given annotations and flags. 3.23 */ 3.24 - public Lint augment(List<Attribute.Compound> attrs, long flags) { 3.25 - Lint l = augmentor.augment(this, attrs); 3.26 + public Lint augment(Annotations annots, long flags) { 3.27 + Lint l = augmentor.augment(this, annots.getAttributes()); 3.28 if ((flags & DEPRECATED) != 0) { 3.29 if (l == this) 3.30 l = new Lint(this);
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Sat Sep 08 22:43:38 2012 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Sat Sep 08 22:54:21 2012 -0700 4.3 @@ -203,6 +203,9 @@ 4.4 public boolean allowEffectivelyFinalInInnerClasses() { 4.5 return compareTo(JDK1_8) >= 0; 4.6 } 4.7 + public boolean allowRepeatedAnnotations() { 4.8 + return compareTo(JDK1_8) >= 0; 4.9 + } 4.10 public static SourceVersion toSourceVersion(Source source) { 4.11 switch(source) { 4.12 case JDK1_2:
5.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Sep 08 22:43:38 2012 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Sat Sep 08 22:54:21 2012 -0700 5.3 @@ -72,22 +72,24 @@ 5.4 */ 5.5 public long flags() { return flags_field; } 5.6 5.7 - /** The attributes of this symbol. 5.8 + /** The attributes of this symbol are contained in this 5.9 + * Annotations. The Annotations instance is NOT immutable. 5.10 */ 5.11 - public List<Attribute.Compound> attributes_field; 5.12 + public final Annotations annotations = new Annotations(this); 5.13 5.14 /** An accessor method for the attributes of this symbol. 5.15 * Attributes of class symbols should be accessed through the accessor 5.16 * method to make sure that the class symbol is loaded. 5.17 */ 5.18 public List<Attribute.Compound> getAnnotationMirrors() { 5.19 - return Assert.checkNonNull(attributes_field); 5.20 + return Assert.checkNonNull(annotations.getAttributes()); 5.21 } 5.22 5.23 /** Fetch a particular annotation from a symbol. */ 5.24 public Attribute.Compound attribute(Symbol anno) { 5.25 - for (Attribute.Compound a : getAnnotationMirrors()) 5.26 + for (Attribute.Compound a : getAnnotationMirrors()) { 5.27 if (a.type.tsym == anno) return a; 5.28 + } 5.29 return null; 5.30 } 5.31 5.32 @@ -120,7 +122,6 @@ 5.33 this.owner = owner; 5.34 this.completer = null; 5.35 this.erasure_field = null; 5.36 - this.attributes_field = List.nil(); 5.37 this.name = name; 5.38 } 5.39 5.40 @@ -657,10 +658,11 @@ 5.41 if (completer != null) complete(); 5.42 if (package_info != null && package_info.completer != null) { 5.43 package_info.complete(); 5.44 - if (attributes_field.isEmpty()) 5.45 - attributes_field = package_info.attributes_field; 5.46 + if (annotations.isEmpty()) { 5.47 + annotations.setAttributes(package_info.annotations); 5.48 } 5.49 - return Assert.checkNonNull(attributes_field); 5.50 + } 5.51 + return Assert.checkNonNull(annotations.getAttributes()); 5.52 } 5.53 5.54 /** A package "exists" if a type or package that exists has 5.55 @@ -762,7 +764,7 @@ 5.56 5.57 public List<Attribute.Compound> getAnnotationMirrors() { 5.58 if (completer != null) complete(); 5.59 - return Assert.checkNonNull(attributes_field); 5.60 + return Assert.checkNonNull(annotations.getAttributes()); 5.61 } 5.62 5.63 public Type erasure(Types types) {
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java Sat Sep 08 22:43:38 2012 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java Sat Sep 08 22:54:21 2012 -0700 6.3 @@ -156,6 +156,10 @@ 6.4 public final Type systemType; 6.5 public final Type autoCloseableType; 6.6 public final Type trustMeType; 6.7 + public final Type containedByType; 6.8 + public final Type containerForType; 6.9 + public final Type documentedType; 6.10 + public final Type elementTypeType; 6.11 6.12 /** The symbol representing the length field of an array. 6.13 */ 6.14 @@ -468,6 +472,10 @@ 6.15 deprecatedType = enterClass("java.lang.Deprecated"); 6.16 suppressWarningsType = enterClass("java.lang.SuppressWarnings"); 6.17 inheritedType = enterClass("java.lang.annotation.Inherited"); 6.18 + containedByType = enterClass("java.lang.annotation.ContainedBy"); 6.19 + containerForType = enterClass("java.lang.annotation.ContainerFor"); 6.20 + documentedType = enterClass("java.lang.annotation.Documented"); 6.21 + elementTypeType = enterClass("java.lang.annotation.ElementType"); 6.22 systemType = enterClass("java.lang.System"); 6.23 autoCloseableType = enterClass("java.lang.AutoCloseable"); 6.24 autoCloseableClose = new MethodSymbol(PUBLIC,
7.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Sat Sep 08 22:43:38 2012 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Sat Sep 08 22:54:21 2012 -0700 7.3 @@ -1358,6 +1358,20 @@ 7.4 } 7.5 return result; 7.6 } 7.7 + 7.8 + /** 7.9 + * Returns an ArrayType with the component type t 7.10 + * 7.11 + * @param t The component type of the ArrayType 7.12 + * @return the ArrayType for the given component 7.13 + */ 7.14 + public ArrayType makeArrayType(Type t) { 7.15 + if (t.tag == VOID || 7.16 + t.tag >= PACKAGE) { 7.17 + Assert.error("Type t must not be a a VOID or PACKAGE type, " + t.toString()); 7.18 + } 7.19 + return new ArrayType(t, syms.arrayClass); 7.20 + } 7.21 // </editor-fold> 7.22 7.23 // <editor-fold defaultstate="collapsed" desc="asSuper"> 7.24 @@ -3811,8 +3825,12 @@ 7.25 // <editor-fold defaultstate="collapsed" desc="Annotation support"> 7.26 7.27 public RetentionPolicy getRetention(Attribute.Compound a) { 7.28 + return getRetention(a.type.tsym); 7.29 + } 7.30 + 7.31 + public RetentionPolicy getRetention(Symbol sym) { 7.32 RetentionPolicy vis = RetentionPolicy.CLASS; // the default 7.33 - Attribute.Compound c = a.type.tsym.attribute(syms.retentionType.tsym); 7.34 + Attribute.Compound c = sym.attribute(syms.retentionType.tsym); 7.35 if (c != null) { 7.36 Attribute value = c.member(names.value); 7.37 if (value != null && value instanceof Attribute.Enum) {
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java Sat Sep 08 22:43:38 2012 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java Sat Sep 08 22:54:21 2012 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -25,7 +25,10 @@ 8.11 8.12 package com.sun.tools.javac.comp; 8.13 8.14 +import java.util.Map; 8.15 + 8.16 import com.sun.tools.javac.util.*; 8.17 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 8.18 import com.sun.tools.javac.code.*; 8.19 import com.sun.tools.javac.code.Symbol.*; 8.20 import com.sun.tools.javac.tree.*; 8.21 @@ -83,8 +86,9 @@ 8.22 private int enterCount = 0; 8.23 8.24 ListBuffer<Annotator> q = new ListBuffer<Annotator>(); 8.25 + ListBuffer<Annotator> repeatedQ = new ListBuffer<Annotator>(); 8.26 8.27 - public void later(Annotator a) { 8.28 + public void normal(Annotator a) { 8.29 q.append(a); 8.30 } 8.31 8.32 @@ -92,6 +96,10 @@ 8.33 q.prepend(a); 8.34 } 8.35 8.36 + public void repeated(Annotator a) { 8.37 + repeatedQ.append(a); 8.38 + } 8.39 + 8.40 /** Called when the Enter phase starts. */ 8.41 public void enterStart() { 8.42 enterCount++; 8.43 @@ -109,6 +117,10 @@ 8.44 try { 8.45 while (q.nonEmpty()) 8.46 q.next().enterAnnotation(); 8.47 + 8.48 + while (repeatedQ.nonEmpty()) { 8.49 + repeatedQ.next().enterAnnotation(); 8.50 + } 8.51 } finally { 8.52 enterCount--; 8.53 } 8.54 @@ -124,6 +136,53 @@ 8.55 String toString(); 8.56 } 8.57 8.58 + /** 8.59 + * This context contains all the information needed to synthesize new 8.60 + * annotations trees by the completer for repeating annotations. 8.61 + */ 8.62 + public class AnnotateRepeatedContext { 8.63 + public final Env<AttrContext> env; 8.64 + public final Map<Symbol.TypeSymbol, ListBuffer<Attribute.Compound>> annotated; 8.65 + public final Map<Attribute.Compound, JCDiagnostic.DiagnosticPosition> pos; 8.66 + public final Log log; 8.67 + 8.68 + public AnnotateRepeatedContext(Env<AttrContext> env, 8.69 + Map<Symbol.TypeSymbol, ListBuffer<Attribute.Compound>> annotated, 8.70 + Map<Attribute.Compound, JCDiagnostic.DiagnosticPosition> pos, 8.71 + Log log) { 8.72 + Assert.checkNonNull(env); 8.73 + Assert.checkNonNull(annotated); 8.74 + Assert.checkNonNull(pos); 8.75 + Assert.checkNonNull(log); 8.76 + 8.77 + this.env = env; 8.78 + this.annotated = annotated; 8.79 + this.pos = pos; 8.80 + this.log = log; 8.81 + } 8.82 + 8.83 + /** 8.84 + * Process a list of repeating annotations returning a new 8.85 + * Attribute.Compound that is the attribute for the synthesized tree 8.86 + * for the container. 8.87 + * 8.88 + * @param repeatingAnnotations a List of repeating annotations 8.89 + * @return a new Attribute.Compound that is the container for the repeatingAnnotations 8.90 + */ 8.91 + public Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> repeatingAnnotations) { 8.92 + return Annotate.this.processRepeatedAnnotations(repeatingAnnotations, this); 8.93 + } 8.94 + 8.95 + /** 8.96 + * Queue the Annotator a on the repeating annotations queue of the 8.97 + * Annotate instance this context belongs to. 8.98 + * 8.99 + * @param a the Annotator to enqueue for repeating annotation annotating 8.100 + */ 8.101 + public void annotateRepeated(Annotator a) { 8.102 + Annotate.this.repeated(a); 8.103 + } 8.104 + } 8.105 8.106 /* ******************************************************************** 8.107 * Compute an attribute from its annotation. 8.108 @@ -268,4 +327,219 @@ 8.109 log.error(tree.pos(), "annotation.value.not.allowable.type"); 8.110 return new Attribute.Error(attr.attribExpr(tree, env, expected)); 8.111 } 8.112 + 8.113 + /* ********************************* 8.114 + * Support for repeating annotations 8.115 + ***********************************/ 8.116 + 8.117 + /* Process repeated annotations. This method returns the 8.118 + * synthesized container annotation or null IFF all repeating 8.119 + * annotation are invalid. This method reports errors/warnings. 8.120 + */ 8.121 + private Attribute.Compound processRepeatedAnnotations(List<Attribute.Compound> annotations, 8.122 + AnnotateRepeatedContext ctx) { 8.123 + Attribute.Compound firstOccurrence = annotations.head; 8.124 + List<Attribute> repeated = List.nil(); 8.125 + Type origAnnoType; 8.126 + Type arrayOfOrigAnnoType = null; 8.127 + Type targetContainerType = null; 8.128 + MethodSymbol containerValueSymbol = null; 8.129 + 8.130 + Assert.check(!annotations.isEmpty() && 8.131 + !annotations.tail.isEmpty()); // i.e. size() > 1 8.132 + 8.133 + for (List<Attribute.Compound> al = annotations; 8.134 + !al.isEmpty(); 8.135 + al = al.tail) 8.136 + { 8.137 + Attribute.Compound currentAnno = al.head; 8.138 + 8.139 + origAnnoType = currentAnno.type; 8.140 + if (arrayOfOrigAnnoType == null) { 8.141 + arrayOfOrigAnnoType = types.makeArrayType(origAnnoType); 8.142 } 8.143 + 8.144 + Type currentContainerType = getContainingType(currentAnno, ctx.pos.get(currentAnno)); 8.145 + if (currentContainerType == null) { 8.146 + continue; 8.147 + } 8.148 + // Assert that the target Container is == for all repeated 8.149 + // annos of the same annotation type, the types should 8.150 + // come from the same Symbol, i.e. be '==' 8.151 + Assert.check(targetContainerType == null || currentContainerType == targetContainerType); 8.152 + targetContainerType = currentContainerType; 8.153 + 8.154 + containerValueSymbol = validateContainer(targetContainerType, origAnnoType, ctx.pos.get(currentAnno)); 8.155 + 8.156 + if (containerValueSymbol == null) { // Check of CA type failed 8.157 + // errors are already reported 8.158 + continue; 8.159 + } 8.160 + 8.161 + repeated = repeated.prepend(currentAnno); 8.162 + } 8.163 + 8.164 + if (!repeated.isEmpty()) { 8.165 + repeated = repeated.reverse(); 8.166 + JCAnnotation annoTree; 8.167 + TreeMaker m = make.at(ctx.pos.get(firstOccurrence)); 8.168 + Pair<MethodSymbol, Attribute> p = 8.169 + new Pair<MethodSymbol, Attribute>(containerValueSymbol, 8.170 + new Attribute.Array(arrayOfOrigAnnoType, repeated)); 8.171 + annoTree = m.Annotation(new Attribute.Compound(targetContainerType, 8.172 + List.of(p))); 8.173 + Attribute.Compound c = enterAnnotation(annoTree, 8.174 + targetContainerType, 8.175 + ctx.env); 8.176 + return c; 8.177 + } else { 8.178 + return null; // errors should have been reported elsewhere 8.179 + } 8.180 + } 8.181 + 8.182 + /** Fetches the actual Type that should be the containing annotation. */ 8.183 + private Type getContainingType(Attribute.Compound currentAnno, 8.184 + DiagnosticPosition pos) 8.185 + { 8.186 + Type origAnnoType = currentAnno.type; 8.187 + TypeSymbol origAnnoDecl = origAnnoType.tsym; 8.188 + 8.189 + // Fetch the ContainedBy annotation from the current 8.190 + // annotation's declaration, or null if it has none 8.191 + Attribute.Compound ca = origAnnoDecl.attribute(syms.containedByType.tsym); 8.192 + if (ca == null) { // has no ContainedBy annotation 8.193 + log.error(pos, "duplicate.annotation.missing.container", origAnnoType); 8.194 + return null; 8.195 + } 8.196 + 8.197 + return filterSame(extractContainingType(ca, pos, origAnnoDecl), 8.198 + origAnnoType); 8.199 + } 8.200 + 8.201 + // returns null if t is same as 's', returns 't' otherwise 8.202 + private Type filterSame(Type t, Type s) { 8.203 + if (t == null || s == null) { 8.204 + return t; 8.205 + } 8.206 + 8.207 + return types.isSameType(t, s) ? null : t; 8.208 + } 8.209 + 8.210 + /** Extract the actual Type to be used for a containing annotation. */ 8.211 + private Type extractContainingType(Attribute.Compound ca, 8.212 + DiagnosticPosition pos, 8.213 + TypeSymbol annoDecl) 8.214 + { 8.215 + // The next three checks check that the ContainedBy annotation 8.216 + // on the declaration of the annotation type that is repeating is 8.217 + // valid. 8.218 + 8.219 + // ContainedBy must have at least one element 8.220 + if (ca.values.isEmpty()) { 8.221 + log.error(pos, "invalid.containedby.annotation", annoDecl); 8.222 + return null; 8.223 + } 8.224 + Pair<MethodSymbol,Attribute> p = ca.values.head; 8.225 + Name name = p.fst.name; 8.226 + if (name != names.value) { // should contain only one element, named "value" 8.227 + log.error(pos, "invalid.containedby.annotation", annoDecl); 8.228 + return null; 8.229 + } 8.230 + if (!(p.snd instanceof Attribute.Class)) { // check that the value of "value" is an Attribute.Class 8.231 + log.error(pos, "invalid.containedby.annotation", annoDecl); 8.232 + return null; 8.233 + } 8.234 + 8.235 + return ((Attribute.Class)p.snd).getValue(); 8.236 + } 8.237 + 8.238 + /* Validate that the suggested targetContainerType Type is a valid 8.239 + * container type for repeated instances of originalAnnoType 8.240 + * annotations. Return null and report errors if this is not the 8.241 + * case, return the MethodSymbol of the value element in 8.242 + * targetContainerType if it is suitable (this is needed to 8.243 + * synthesize the container). */ 8.244 + private MethodSymbol validateContainer(Type targetContainerType, 8.245 + Type originalAnnoType, 8.246 + DiagnosticPosition pos) { 8.247 + MethodSymbol containerValueSymbol = null; 8.248 + boolean fatalError = false; 8.249 + 8.250 + // Validate that there is a (and only 1) value method 8.251 + Scope scope = targetContainerType.tsym.members(); 8.252 + int nr_value_elems = 0; 8.253 + boolean error = false; 8.254 + for(Symbol elm : scope.getElementsByName(names.value)) { 8.255 + nr_value_elems++; 8.256 + 8.257 + if (nr_value_elems == 1 && 8.258 + elm.kind == Kinds.MTH) { 8.259 + containerValueSymbol = (MethodSymbol)elm; 8.260 + } else { 8.261 + error = true; 8.262 + } 8.263 + } 8.264 + if (error) { 8.265 + log.error(pos, 8.266 + "invalid.containedby.annotation.multiple.values", 8.267 + targetContainerType, 8.268 + nr_value_elems); 8.269 + return null; 8.270 + } else if (nr_value_elems == 0) { 8.271 + log.error(pos, 8.272 + "invalid.containedby.annotation.no.value", 8.273 + targetContainerType); 8.274 + return null; 8.275 + } 8.276 + 8.277 + // validate that the 'value' element is a method 8.278 + // probably "impossible" to fail this 8.279 + if (containerValueSymbol.kind != Kinds.MTH) { 8.280 + log.error(pos, 8.281 + "invalid.containedby.annotation.invalid.value", 8.282 + targetContainerType); 8.283 + fatalError = true; 8.284 + } 8.285 + 8.286 + // validate that the 'value' element has the correct return type 8.287 + // i.e. array of original anno 8.288 + Type valueRetType = containerValueSymbol.type.getReturnType(); 8.289 + Type expectedType = types.makeArrayType(originalAnnoType); 8.290 + if (!(types.isArray(valueRetType) && 8.291 + types.isSameType(expectedType, valueRetType))) { 8.292 + log.error(pos, 8.293 + "invalid.containedby.annotation.value.return", 8.294 + targetContainerType, 8.295 + valueRetType, 8.296 + expectedType); 8.297 + fatalError = true; 8.298 + } 8.299 + 8.300 + // validate that all other elements of containing type has defaults 8.301 + scope = targetContainerType.tsym.members(); 8.302 + error = false; 8.303 + for(Symbol elm : scope.getElements()) { 8.304 + if (elm.name != names.value && 8.305 + elm.kind == Kinds.MTH && 8.306 + ((MethodSymbol)elm).defaultValue == null) { 8.307 + log.error(pos, 8.308 + "invalid.containedby.annotation.elem.nondefault", 8.309 + targetContainerType, 8.310 + elm); 8.311 + containerValueSymbol = null; 8.312 + error = true; 8.313 + } 8.314 + } 8.315 + if (error) { 8.316 + fatalError = true; 8.317 + } 8.318 + 8.319 + // Explicitly no check for/validity of @ContainerFor. That is 8.320 + // done on declaration of the container, and at reflect time. 8.321 + 8.322 + // The rest of the conditions for a valid containing annotation are made 8.323 + // in Check.validateRepeatedAnnotaton(); 8.324 + 8.325 + return fatalError ? null : containerValueSymbol; 8.326 + } 8.327 +}
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Sep 08 22:43:38 2012 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Sep 08 22:54:21 2012 -0700 9.3 @@ -662,10 +662,12 @@ 9.4 // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be 9.5 // null. In that case, calling augment will throw an NPE. To avoid this, for now we 9.6 // revert to the jdk 6 behavior and ignore the (unevaluated) attributes. 9.7 - if (env.info.enclVar.attributes_field == null) 9.8 + if (env.info.enclVar.annotations.pendingCompletion()) { 9.9 env.info.lint = lintEnv.info.lint; 9.10 - else 9.11 - env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); 9.12 + } else { 9.13 + env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.annotations, 9.14 + env.info.enclVar.flags()); 9.15 + } 9.16 9.17 Lint prevLint = chk.setLint(env.info.lint); 9.18 JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); 9.19 @@ -776,7 +778,7 @@ 9.20 public void visitMethodDef(JCMethodDecl tree) { 9.21 MethodSymbol m = tree.sym; 9.22 9.23 - Lint lint = env.info.lint.augment(m.attributes_field, m.flags()); 9.24 + Lint lint = env.info.lint.augment(m.annotations, m.flags()); 9.25 Lint prevLint = chk.setLint(lint); 9.26 MethodSymbol prevMethod = chk.setMethod(m); 9.27 try { 9.28 @@ -921,7 +923,7 @@ 9.29 } 9.30 9.31 VarSymbol v = tree.sym; 9.32 - Lint lint = env.info.lint.augment(v.attributes_field, v.flags()); 9.33 + Lint lint = env.info.lint.augment(v.annotations, v.flags()); 9.34 Lint prevLint = chk.setLint(lint); 9.35 9.36 // Check that the variable's declared type is well-formed. 9.37 @@ -3069,7 +3071,7 @@ 9.38 lintEnv = lintEnv.next; 9.39 9.40 // Having found the enclosing lint value, we can initialize the lint value for this class 9.41 - env.info.lint = lintEnv.info.lint.augment(c.attributes_field, c.flags()); 9.42 + env.info.lint = lintEnv.info.lint.augment(c.annotations, c.flags()); 9.43 9.44 Lint prevLint = chk.setLint(env.info.lint); 9.45 JavaFileObject prev = log.useSource(c.sourcefile); 9.46 @@ -3133,6 +3135,26 @@ 9.47 if (tree.typarams.nonEmpty()) 9.48 log.error(tree.typarams.head.pos(), 9.49 "intf.annotation.cant.have.type.params"); 9.50 + 9.51 + // If this annotation has a @ContainedBy, validate 9.52 + Attribute.Compound containedBy = c.attribute(syms.containedByType.tsym); 9.53 + if (containedBy != null) { 9.54 + // get diagnositc position for error reporting 9.55 + DiagnosticPosition cbPos = getDiagnosticPosition(tree, containedBy.type); 9.56 + Assert.checkNonNull(cbPos); 9.57 + 9.58 + chk.validateContainedBy(c, containedBy, cbPos); 9.59 + } 9.60 + 9.61 + // If this annotation has a @ContainerFor, validate 9.62 + Attribute.Compound containerFor = c.attribute(syms.containerForType.tsym); 9.63 + if (containerFor != null) { 9.64 + // get diagnositc position for error reporting 9.65 + DiagnosticPosition cfPos = getDiagnosticPosition(tree, containerFor.type); 9.66 + Assert.checkNonNull(cfPos); 9.67 + 9.68 + chk.validateContainerFor(c, containerFor, cfPos); 9.69 + } 9.70 } else { 9.71 // Check that all extended classes and interfaces 9.72 // are compatible (i.e. no two define methods with same arguments 9.73 @@ -3194,6 +3216,16 @@ 9.74 } 9.75 } 9.76 // where 9.77 + /** get a diagnostic position for an attribute of Type t, or null if attribute missing */ 9.78 + private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) { 9.79 + for(List<JCAnnotation> al = tree.mods.annotations; !al.isEmpty(); al = al.tail) { 9.80 + if (types.isSameType(al.head.annotationType.type, t)) 9.81 + return al.head.pos(); 9.82 + } 9.83 + 9.84 + return null; 9.85 + } 9.86 + 9.87 /** check if a class is a subtype of Serializable, if that is available. */ 9.88 private boolean isSerializable(ClassSymbol c) { 9.89 try {
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Sep 08 22:43:38 2012 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Sep 08 22:54:21 2012 -0700 10.3 @@ -69,7 +69,6 @@ 10.4 private final Infer infer; 10.5 private final Types types; 10.6 private final JCDiagnostic.Factory diags; 10.7 - private final boolean skipAnnotations; 10.8 private boolean warnOnSyntheticConflicts; 10.9 private boolean suppressAbortOnBadClassFile; 10.10 private boolean enableSunApiLintControl; 10.11 @@ -113,7 +112,6 @@ 10.12 allowCovariantReturns = source.allowCovariantReturns(); 10.13 allowSimplifiedVarargs = source.allowSimplifiedVarargs(); 10.14 complexInference = options.isSet("complexinference"); 10.15 - skipAnnotations = options.isSet("skipAnnotations"); 10.16 warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); 10.17 suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); 10.18 enableSunApiLintControl = options.isSet("enableSunApiLintControl"); 10.19 @@ -2422,14 +2420,13 @@ 10.20 /** Check the annotations of a symbol. 10.21 */ 10.22 public void validateAnnotations(List<JCAnnotation> annotations, Symbol s) { 10.23 - if (skipAnnotations) return; 10.24 for (JCAnnotation a : annotations) 10.25 validateAnnotation(a, s); 10.26 } 10.27 10.28 /** Check an annotation of a symbol. 10.29 */ 10.30 - public void validateAnnotation(JCAnnotation a, Symbol s) { 10.31 + private void validateAnnotation(JCAnnotation a, Symbol s) { 10.32 validateAnnotationTree(a); 10.33 10.34 if (!annotationApplicable(a, s)) 10.35 @@ -2441,6 +2438,215 @@ 10.36 } 10.37 } 10.38 10.39 + /** 10.40 + * Validate the proposed container 'containedBy' on the 10.41 + * annotation type symbol 's'. Report errors at position 10.42 + * 'pos'. 10.43 + * 10.44 + * @param s The (annotation)type declaration annotated with a @ContainedBy 10.45 + * @param containerAnno the @ContainedBy on 's' 10.46 + * @param pos where to report errors 10.47 + */ 10.48 + public void validateContainedBy(TypeSymbol s, Attribute.Compound containedBy, DiagnosticPosition pos) { 10.49 + Assert.check(types.isSameType(containedBy.type, syms.containedByType)); 10.50 + 10.51 + Type t = null; 10.52 + List<Pair<MethodSymbol,Attribute>> l = containedBy.values; 10.53 + if (!l.isEmpty()) { 10.54 + Assert.check(l.head.fst.name == names.value); 10.55 + t = ((Attribute.Class)l.head.snd).getValue(); 10.56 + } 10.57 + 10.58 + if (t == null) { 10.59 + log.error(pos, "invalid.container.wrong.containedby", s, containedBy); 10.60 + return; 10.61 + } 10.62 + 10.63 + validateHasContainerFor(t.tsym, s, pos); 10.64 + validateRetention(t.tsym, s, pos); 10.65 + validateDocumented(t.tsym, s, pos); 10.66 + validateInherited(t.tsym, s, pos); 10.67 + validateTarget(t.tsym, s, pos); 10.68 + } 10.69 + 10.70 + /** 10.71 + * Validate the proposed container 'containerFor' on the 10.72 + * annotation type symbol 's'. Report errors at position 10.73 + * 'pos'. 10.74 + * 10.75 + * @param s The (annotation)type declaration annotated with a @ContainerFor 10.76 + * @param containerFor the @ContainedFor on 's' 10.77 + * @param pos where to report errors 10.78 + */ 10.79 + public void validateContainerFor(TypeSymbol s, Attribute.Compound containerFor, DiagnosticPosition pos) { 10.80 + Assert.check(types.isSameType(containerFor.type, syms.containerForType)); 10.81 + 10.82 + Type t = null; 10.83 + List<Pair<MethodSymbol,Attribute>> l = containerFor.values; 10.84 + if (!l.isEmpty()) { 10.85 + Assert.check(l.head.fst.name == names.value); 10.86 + t = ((Attribute.Class)l.head.snd).getValue(); 10.87 + } 10.88 + 10.89 + if (t == null) { 10.90 + log.error(pos, "invalid.container.wrong.containerfor", s, containerFor); 10.91 + return; 10.92 + } 10.93 + 10.94 + validateHasContainedBy(t.tsym, s, pos); 10.95 + } 10.96 + 10.97 + private void validateHasContainedBy(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { 10.98 + Attribute.Compound containedBy = container.attribute(syms.containedByType.tsym); 10.99 + 10.100 + if (containedBy == null) { 10.101 + log.error(pos, "invalid.container.no.containedby", container, syms.containedByType.tsym); 10.102 + return; 10.103 + } 10.104 + 10.105 + Type t = null; 10.106 + List<Pair<MethodSymbol,Attribute>> l = containedBy.values; 10.107 + if (!l.isEmpty()) { 10.108 + Assert.check(l.head.fst.name == names.value); 10.109 + t = ((Attribute.Class)l.head.snd).getValue(); 10.110 + } 10.111 + 10.112 + if (t == null) { 10.113 + log.error(pos, "invalid.container.wrong.containedby", container, contained); 10.114 + return; 10.115 + } 10.116 + 10.117 + if (!types.isSameType(t, contained.type)) 10.118 + log.error(pos, "invalid.container.wrong.containedby", t.tsym, contained); 10.119 + } 10.120 + 10.121 + private void validateHasContainerFor(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { 10.122 + Attribute.Compound containerFor = container.attribute(syms.containerForType.tsym); 10.123 + 10.124 + if (containerFor == null) { 10.125 + log.error(pos, "invalid.container.no.containerfor", container, syms.containerForType.tsym); 10.126 + return; 10.127 + } 10.128 + 10.129 + Type t = null; 10.130 + List<Pair<MethodSymbol,Attribute>> l = containerFor.values; 10.131 + if (!l.isEmpty()) { 10.132 + Assert.check(l.head.fst.name == names.value); 10.133 + t = ((Attribute.Class)l.head.snd).getValue(); 10.134 + } 10.135 + 10.136 + if (t == null) { 10.137 + log.error(pos, "invalid.container.wrong.containerfor", container, contained); 10.138 + return; 10.139 + } 10.140 + 10.141 + if (!types.isSameType(t, contained.type)) 10.142 + log.error(pos, "invalid.container.wrong.containerfor", t.tsym, contained); 10.143 + } 10.144 + 10.145 + private void validateRetention(Symbol container, Symbol contained, DiagnosticPosition pos) { 10.146 + Attribute.RetentionPolicy containerRetention = types.getRetention(container); 10.147 + Attribute.RetentionPolicy containedRetention = types.getRetention(contained); 10.148 + 10.149 + boolean error = false; 10.150 + switch (containedRetention) { 10.151 + case RUNTIME: 10.152 + if (containerRetention != Attribute.RetentionPolicy.RUNTIME) { 10.153 + error = true; 10.154 + } 10.155 + break; 10.156 + case CLASS: 10.157 + if (containerRetention == Attribute.RetentionPolicy.SOURCE) { 10.158 + error = true; 10.159 + } 10.160 + } 10.161 + if (error ) { 10.162 + log.error(pos, "invalid.containedby.annotation.retention", 10.163 + container, containerRetention, 10.164 + contained, containedRetention); 10.165 + } 10.166 + } 10.167 + 10.168 + private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) { 10.169 + if (contained.attribute(syms.documentedType.tsym) != null) { 10.170 + if (container.attribute(syms.documentedType.tsym) == null) { 10.171 + log.error(pos, "invalid.containedby.annotation.not.documented", container, contained); 10.172 + } 10.173 + } 10.174 + } 10.175 + 10.176 + private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) { 10.177 + if (contained.attribute(syms.inheritedType.tsym) != null) { 10.178 + if (container.attribute(syms.inheritedType.tsym) == null) { 10.179 + log.error(pos, "invalid.containedby.annotation.not.inherited", container, contained); 10.180 + } 10.181 + } 10.182 + } 10.183 + 10.184 + private void validateTarget(Symbol container, Symbol contained, DiagnosticPosition pos) { 10.185 + Attribute.Array containedTarget = getAttributeTargetAttribute(contained); 10.186 + 10.187 + // If contained has no Target, we are done 10.188 + if (containedTarget == null) { 10.189 + return; 10.190 + } 10.191 + 10.192 + // If contained has Target m1, container must have a Target 10.193 + // annotation, m2, and m2 must be a subset of m1. (This is 10.194 + // trivially true if contained has no target as per above). 10.195 + 10.196 + // contained has target, but container has not, error 10.197 + Attribute.Array containerTarget = getAttributeTargetAttribute(container); 10.198 + if (containerTarget == null) { 10.199 + log.error(pos, "invalid.containedby.annotation.incompatible.target", container, contained); 10.200 + return; 10.201 + } 10.202 + 10.203 + Set<Name> containerTargets = new HashSet<Name>(); 10.204 + for (Attribute app : containerTarget.values) { 10.205 + if (!(app instanceof Attribute.Enum)) { 10.206 + continue; // recovery 10.207 + } 10.208 + Attribute.Enum e = (Attribute.Enum)app; 10.209 + containerTargets.add(e.value.name); 10.210 + } 10.211 + 10.212 + Set<Name> containedTargets = new HashSet<Name>(); 10.213 + for (Attribute app : containedTarget.values) { 10.214 + if (!(app instanceof Attribute.Enum)) { 10.215 + continue; // recovery 10.216 + } 10.217 + Attribute.Enum e = (Attribute.Enum)app; 10.218 + containedTargets.add(e.value.name); 10.219 + } 10.220 + 10.221 + if (!isTargetSubset(containedTargets, containerTargets)) { 10.222 + log.error(pos, "invalid.containedby.annotation.incompatible.target", container, contained); 10.223 + } 10.224 + } 10.225 + 10.226 + /** Checks that t is a subset of s, with respect to ElementType 10.227 + * semantics, specifically {ANNOTATION_TYPE} is a subset of {TYPE} 10.228 + */ 10.229 + private boolean isTargetSubset(Set<Name> s, Set<Name> t) { 10.230 + // Check that all elements in t are present in s 10.231 + for (Name n2 : t) { 10.232 + boolean currentElementOk = false; 10.233 + for (Name n1 : s) { 10.234 + if (n1 == n2) { 10.235 + currentElementOk = true; 10.236 + break; 10.237 + } else if (n1 == names.TYPE && n2 == names.ANNOTATION_TYPE) { 10.238 + currentElementOk = true; 10.239 + break; 10.240 + } 10.241 + } 10.242 + if (!currentElementOk) 10.243 + return false; 10.244 + } 10.245 + return true; 10.246 + } 10.247 + 10.248 /** Is s a method symbol that overrides a method in a superclass? */ 10.249 boolean isOverrider(Symbol s) { 10.250 if (s.kind != MTH || s.isStatic()) 10.251 @@ -2461,12 +2667,10 @@ 10.252 10.253 /** Is the annotation applicable to the symbol? */ 10.254 boolean annotationApplicable(JCAnnotation a, Symbol s) { 10.255 - Attribute.Compound atTarget = 10.256 - a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym); 10.257 - if (atTarget == null) return true; 10.258 - Attribute atValue = atTarget.member(names.value); 10.259 - if (!(atValue instanceof Attribute.Array)) return true; // error recovery 10.260 - Attribute.Array arr = (Attribute.Array) atValue; 10.261 + Attribute.Array arr = getAttributeTargetAttribute(a.annotationType.type.tsym); 10.262 + if (arr == null) { 10.263 + return true; 10.264 + } 10.265 for (Attribute app : arr.values) { 10.266 if (!(app instanceof Attribute.Enum)) return true; // recovery 10.267 Attribute.Enum e = (Attribute.Enum) app; 10.268 @@ -2508,6 +2712,16 @@ 10.269 return false; 10.270 } 10.271 10.272 + 10.273 + Attribute.Array getAttributeTargetAttribute(Symbol s) { 10.274 + Attribute.Compound atTarget = 10.275 + s.attribute(syms.annotationTargetType.tsym); 10.276 + if (atTarget == null) return null; // ok, is applicable 10.277 + Attribute atValue = atTarget.member(names.value); 10.278 + if (!(atValue instanceof Attribute.Array)) return null; // error recovery 10.279 + return (Attribute.Array) atValue; 10.280 + } 10.281 + 10.282 /** Check an annotation value. 10.283 */ 10.284 public void validateAnnotation(JCAnnotation a) {
11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Sat Sep 08 22:43:38 2012 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Sat Sep 08 22:54:21 2012 -0700 11.3 @@ -157,7 +157,7 @@ 11.4 Env<AttrContext> lintEnv = localEnv; 11.5 while (lintEnv.info.lint == null) 11.6 lintEnv = lintEnv.next; 11.7 - localEnv.info.lint = lintEnv.info.lint.augment(sym.attributes_field, sym.flags()); 11.8 + localEnv.info.lint = lintEnv.info.lint.augment(sym.annotations, sym.flags()); 11.9 return localEnv; 11.10 } 11.11
12.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Sat Sep 08 22:43:38 2012 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Sat Sep 08 22:54:21 2012 -0700 12.3 @@ -406,7 +406,7 @@ 12.4 Lint lintPrev = lint; 12.5 12.6 pendingExits = new ListBuffer<PendingExit>(); 12.7 - lint = lint.augment(tree.sym.attributes_field); 12.8 + lint = lint.augment(tree.sym.annotations); 12.9 12.10 try { 12.11 // process all the static initializers 12.12 @@ -442,7 +442,7 @@ 12.13 if (tree.body == null) return; 12.14 Lint lintPrev = lint; 12.15 12.16 - lint = lint.augment(tree.sym.attributes_field); 12.17 + lint = lint.augment(tree.sym.annotations); 12.18 12.19 Assert.check(pendingExits.isEmpty()); 12.20 12.21 @@ -468,7 +468,7 @@ 12.22 public void visitVarDef(JCVariableDecl tree) { 12.23 if (tree.init != null) { 12.24 Lint lintPrev = lint; 12.25 - lint = lint.augment(tree.sym.attributes_field); 12.26 + lint = lint.augment(tree.sym.annotations); 12.27 try{ 12.28 scan(tree.init); 12.29 } finally { 12.30 @@ -783,7 +783,7 @@ 12.31 } 12.32 classDef = tree; 12.33 thrown = List.nil(); 12.34 - lint = lint.augment(tree.sym.attributes_field); 12.35 + lint = lint.augment(tree.sym.annotations); 12.36 12.37 try { 12.38 // process all the static initializers 12.39 @@ -863,7 +863,7 @@ 12.40 List<Type> mthrown = tree.sym.type.getThrownTypes(); 12.41 Lint lintPrev = lint; 12.42 12.43 - lint = lint.augment(tree.sym.attributes_field); 12.44 + lint = lint.augment(tree.sym.annotations); 12.45 12.46 Assert.check(pendingExits.isEmpty()); 12.47 12.48 @@ -902,7 +902,7 @@ 12.49 public void visitVarDef(JCVariableDecl tree) { 12.50 if (tree.init != null) { 12.51 Lint lintPrev = lint; 12.52 - lint = lint.augment(tree.sym.attributes_field); 12.53 + lint = lint.augment(tree.sym.annotations); 12.54 try{ 12.55 scan(tree.init); 12.56 } finally { 12.57 @@ -1491,7 +1491,7 @@ 12.58 firstadr = nextadr; 12.59 } 12.60 classDef = tree; 12.61 - lint = lint.augment(tree.sym.attributes_field); 12.62 + lint = lint.augment(tree.sym.annotations); 12.63 12.64 try { 12.65 // define all the static fields 12.66 @@ -1558,7 +1558,7 @@ 12.67 int firstadrPrev = firstadr; 12.68 Lint lintPrev = lint; 12.69 12.70 - lint = lint.augment(tree.sym.attributes_field); 12.71 + lint = lint.augment(tree.sym.annotations); 12.72 12.73 Assert.check(pendingExits.isEmpty()); 12.74 12.75 @@ -1609,7 +1609,7 @@ 12.76 if (track && tree.sym.owner.kind == MTH) newVar(tree.sym); 12.77 if (tree.init != null) { 12.78 Lint lintPrev = lint; 12.79 - lint = lint.augment(tree.sym.attributes_field); 12.80 + lint = lint.augment(tree.sym.annotations); 12.81 try{ 12.82 scanExpr(tree.init); 12.83 if (track) letInit(tree.pos(), tree.sym);
13.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Sat Sep 08 22:43:38 2012 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Sat Sep 08 22:54:21 2012 -0700 13.3 @@ -2257,7 +2257,7 @@ 13.4 null, List.<JCExpression>nil(), List.<JCTree>nil()); 13.5 ClassSymbol c = tree.packge.package_info; 13.6 c.flags_field |= flags; 13.7 - c.attributes_field = tree.packge.attributes_field; 13.8 + c.annotations.setAttributes(tree.packge.annotations); 13.9 ClassType ctype = (ClassType) c.type; 13.10 ctype.supertype_field = syms.objectType; 13.11 ctype.interfaces_field = List.nil(); 13.12 @@ -2274,7 +2274,8 @@ 13.13 case LEGACY: 13.14 return tree.packageAnnotations.nonEmpty(); 13.15 case NONEMPTY: 13.16 - for (Attribute.Compound a: tree.packge.attributes_field) { 13.17 + for (Attribute.Compound a : 13.18 + tree.packge.annotations.getAttributes()) { 13.19 Attribute.RetentionPolicy p = types.getRetention(a); 13.20 if (p != Attribute.RetentionPolicy.SOURCE) 13.21 return true;
14.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Sep 08 22:43:38 2012 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sat Sep 08 22:54:21 2012 -0700 14.3 @@ -76,11 +76,10 @@ 14.4 private final Annotate annotate; 14.5 private final Types types; 14.6 private final JCDiagnostic.Factory diags; 14.7 + private final Source source; 14.8 private final Target target; 14.9 private final DeferredLintHandler deferredLintHandler; 14.10 14.11 - private final boolean skipAnnotations; 14.12 - 14.13 public static MemberEnter instance(Context context) { 14.14 MemberEnter instance = context.get(memberEnterKey); 14.15 if (instance == null) 14.16 @@ -102,10 +101,9 @@ 14.17 annotate = Annotate.instance(context); 14.18 types = Types.instance(context); 14.19 diags = JCDiagnostic.Factory.instance(context); 14.20 + source = Source.instance(context); 14.21 target = Target.instance(context); 14.22 deferredLintHandler = DeferredLintHandler.instance(context); 14.23 - Options options = Options.instance(context); 14.24 - skipAnnotations = options.isSet("skipAnnotations"); 14.25 } 14.26 14.27 /** A queue for classes whose members still need to be entered into the 14.28 @@ -690,7 +688,7 @@ 14.29 14.30 public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) { 14.31 Env<AttrContext> mEnv = methodEnv(tree, env); 14.32 - mEnv.info.lint = mEnv.info.lint.augment(tree.sym.attributes_field, tree.sym.flags()); 14.33 + mEnv.info.lint = mEnv.info.lint.augment(tree.sym.annotations, tree.sym.flags()); 14.34 for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) 14.35 mEnv.info.scope.enterIfAbsent(l.head.type.tsym); 14.36 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) 14.37 @@ -727,18 +725,24 @@ 14.38 void annotateLater(final List<JCAnnotation> annotations, 14.39 final Env<AttrContext> localEnv, 14.40 final Symbol s) { 14.41 - if (annotations.isEmpty()) return; 14.42 - if (s.kind != PCK) s.attributes_field = null; // mark it incomplete for now 14.43 - annotate.later(new Annotate.Annotator() { 14.44 + if (annotations.isEmpty()) { 14.45 + return; 14.46 + } 14.47 + if (s.kind != PCK) { 14.48 + s.annotations.reset(); // mark Annotations as incomplete for now 14.49 + } 14.50 + annotate.normal(new Annotate.Annotator() { 14.51 + @Override 14.52 public String toString() { 14.53 return "annotate " + annotations + " onto " + s + " in " + s.owner; 14.54 } 14.55 + 14.56 + @Override 14.57 public void enterAnnotation() { 14.58 - Assert.check(s.kind == PCK || s.attributes_field == null); 14.59 + Assert.check(s.kind == PCK || s.annotations.pendingCompletion()); 14.60 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 14.61 try { 14.62 - if (s.attributes_field != null && 14.63 - s.attributes_field.nonEmpty() && 14.64 + if (!s.annotations.isEmpty() && 14.65 annotations.nonEmpty()) 14.66 log.error(annotations.head.pos, 14.67 "already.annotated", 14.68 @@ -756,7 +760,7 @@ 14.69 * java.lang.Deprecated. 14.70 **/ 14.71 private boolean hasDeprecatedAnnotation(List<JCAnnotation> annotations) { 14.72 - for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) { 14.73 + for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { 14.74 JCAnnotation a = al.head; 14.75 if (a.annotationType.type == syms.deprecatedType && a.args.isEmpty()) 14.76 return true; 14.77 @@ -764,42 +768,62 @@ 14.78 return false; 14.79 } 14.80 14.81 - 14.82 /** Enter a set of annotations. */ 14.83 private void enterAnnotations(List<JCAnnotation> annotations, 14.84 Env<AttrContext> env, 14.85 Symbol s) { 14.86 - ListBuffer<Attribute.Compound> buf = 14.87 - new ListBuffer<Attribute.Compound>(); 14.88 - Set<TypeSymbol> annotated = new HashSet<TypeSymbol>(); 14.89 - if (!skipAnnotations) 14.90 - for (List<JCAnnotation> al = annotations; al.nonEmpty(); al = al.tail) { 14.91 + Map<TypeSymbol, ListBuffer<Attribute.Compound>> annotated = 14.92 + new LinkedHashMap<TypeSymbol, ListBuffer<Attribute.Compound>>(); 14.93 + Map<Attribute.Compound, DiagnosticPosition> pos = 14.94 + new HashMap<Attribute.Compound, DiagnosticPosition>(); 14.95 + 14.96 + for (List<JCAnnotation> al = annotations; !al.isEmpty(); al = al.tail) { 14.97 JCAnnotation a = al.head; 14.98 Attribute.Compound c = annotate.enterAnnotation(a, 14.99 syms.annotationType, 14.100 env); 14.101 - if (c == null) continue; 14.102 - buf.append(c); 14.103 + if (c == null) { 14.104 + continue; 14.105 + } 14.106 + 14.107 + if (annotated.containsKey(a.type.tsym)) { 14.108 + if (source.allowRepeatedAnnotations()) { 14.109 + ListBuffer<Attribute.Compound> l = annotated.get(a.type.tsym); 14.110 + l = l.append(c); 14.111 + annotated.put(a.type.tsym, l); 14.112 + pos.put(c, a.pos()); 14.113 + } else { 14.114 + log.error(a.pos(), "duplicate.annotation"); 14.115 + } 14.116 + } else { 14.117 + annotated.put(a.type.tsym, ListBuffer.of(c)); 14.118 + pos.put(c, a.pos()); 14.119 + } 14.120 + 14.121 // Note: @Deprecated has no effect on local variables and parameters 14.122 if (!c.type.isErroneous() 14.123 && s.owner.kind != MTH 14.124 - && types.isSameType(c.type, syms.deprecatedType)) 14.125 + && types.isSameType(c.type, syms.deprecatedType)) { 14.126 s.flags_field |= Flags.DEPRECATED; 14.127 - if (!annotated.add(a.type.tsym)) 14.128 - log.error(a.pos, "duplicate.annotation"); 14.129 } 14.130 - s.attributes_field = buf.toList(); 14.131 + } 14.132 + 14.133 + s.annotations.setAttributesWithCompletion( 14.134 + annotate.new AnnotateRepeatedContext(env, annotated, pos, log)); 14.135 } 14.136 14.137 /** Queue processing of an attribute default value. */ 14.138 void annotateDefaultValueLater(final JCExpression defaultValue, 14.139 final Env<AttrContext> localEnv, 14.140 final MethodSymbol m) { 14.141 - annotate.later(new Annotate.Annotator() { 14.142 + annotate.normal(new Annotate.Annotator() { 14.143 + @Override 14.144 public String toString() { 14.145 return "annotate " + m.owner + "." + 14.146 m + " default " + defaultValue; 14.147 } 14.148 + 14.149 + @Override 14.150 public void enterAnnotation() { 14.151 JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); 14.152 try {
15.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sat Sep 08 22:43:38 2012 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sat Sep 08 22:54:21 2012 -0700 15.3 @@ -1321,7 +1321,7 @@ 15.4 else 15.5 proxies.append(proxy); 15.6 } 15.7 - annotate.later(new AnnotationCompleter(sym, proxies.toList())); 15.8 + annotate.normal(new AnnotationCompleter(sym, proxies.toList())); 15.9 } 15.10 } 15.11 15.12 @@ -1347,7 +1347,7 @@ 15.13 void attachAnnotationDefault(final Symbol sym) { 15.14 final MethodSymbol meth = (MethodSymbol)sym; // only on methods 15.15 final Attribute value = readAttributeValue(); 15.16 - annotate.later(new AnnotationDefaultCompleter(meth, value)); 15.17 + annotate.normal(new AnnotationDefaultCompleter(meth, value)); 15.18 } 15.19 15.20 Type readTypeOrClassSymbol(int i) { 15.21 @@ -1693,10 +1693,13 @@ 15.22 JavaFileObject previousClassFile = currentClassFile; 15.23 try { 15.24 currentClassFile = classFile; 15.25 + Annotations annotations = sym.annotations; 15.26 List<Attribute.Compound> newList = deproxyCompoundList(l); 15.27 - sym.attributes_field = ((sym.attributes_field == null) 15.28 - ? newList 15.29 - : newList.prependList(sym.attributes_field)); 15.30 + if (annotations.pendingCompletion()) { 15.31 + annotations.setAttributes(newList); 15.32 + } else { 15.33 + annotations.append(newList); 15.34 + } 15.35 } finally { 15.36 currentClassFile = previousClassFile; 15.37 }
16.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Sat Sep 08 22:43:38 2012 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Sat Sep 08 22:54:21 2012 -0700 16.3 @@ -825,7 +825,7 @@ 16.4 } 16.5 public void visitClass(Attribute.Class clazz) { 16.6 databuf.appendByte('c'); 16.7 - databuf.appendChar(pool.put(typeSig(clazz.type))); 16.8 + databuf.appendChar(pool.put(typeSig(clazz.classType))); 16.9 } 16.10 public void visitCompound(Attribute.Compound compound) { 16.11 databuf.appendByte('@');
17.1 --- a/src/share/classes/com/sun/tools/javac/jvm/JNIWriter.java Sat Sep 08 22:43:38 2012 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/JNIWriter.java Sat Sep 08 22:54:21 2012 -0700 17.3 @@ -157,7 +157,7 @@ 17.4 if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0) 17.5 return false; 17.6 17.7 - for (Attribute.Compound a: c.attributes_field) { 17.8 + for (Attribute.Compound a: c.annotations.getAttributes()) { 17.9 if (a.type.tsym == syms.nativeHeaderType.tsym) 17.10 return true; 17.11 }
18.1 --- a/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Sat Sep 08 22:43:38 2012 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Sat Sep 08 22:54:21 2012 -0700 18.3 @@ -1,5 +1,5 @@ 18.4 /* 18.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 18.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 18.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.8 * 18.9 * This code is free software; you can redistribute it and/or modify it 18.10 @@ -177,7 +177,7 @@ 18.11 } 18.12 18.13 public void visitClass(Attribute.Class c) { 18.14 - value = new MirroredTypeExceptionProxy(c.type); 18.15 + value = new MirroredTypeExceptionProxy(c.classType); 18.16 } 18.17 18.18 public void visitArray(Attribute.Array a) { 18.19 @@ -187,7 +187,7 @@ 18.20 // Construct a proxy for a MirroredTypesException 18.21 ListBuffer<TypeMirror> elems = new ListBuffer<TypeMirror>(); 18.22 for (Attribute value : a.values) { 18.23 - Type elem = ((Attribute.Class) value).type; 18.24 + Type elem = ((Attribute.Class) value).classType; 18.25 elems.append(elem); 18.26 } 18.27 value = new MirroredTypesExceptionProxy(elems.toList());
19.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Sat Sep 08 22:43:38 2012 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Sat Sep 08 22:54:21 2012 -0700 19.3 @@ -1072,8 +1072,10 @@ 19.4 Assert.checkNonNull(tokens); 19.5 next.put(Tokens.tokensKey, tokens); 19.6 19.7 + Log nextLog = Log.instance(next); 19.8 // propogate the log's writers directly, instead of going through context 19.9 - Log.instance(next).setWriters(log); 19.10 + nextLog.setWriters(log); 19.11 + nextLog.setSourceMap(log); 19.12 19.13 JavaCompiler oldCompiler = JavaCompiler.instance(context); 19.14 JavaCompiler nextCompiler = JavaCompiler.instance(next);
20.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sat Sep 08 22:43:38 2012 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sat Sep 08 22:54:21 2012 -0700 20.3 @@ -250,6 +250,70 @@ 20.4 compiler.err.duplicate.annotation.member.value=\ 20.5 duplicate annotation member value {0} in {1} 20.6 20.7 +# 0: type 20.8 +compiler.err.duplicate.annotation.missing.container=\ 20.9 + duplicate annotation, the declaration of {0} does not have a ContainedBy annotation 20.10 + 20.11 +# 0: type, 1: type 20.12 +compiler.err.invalid.container.no.containedby=\ 20.13 + invalid contained repeatable annotation, {0} is not annotated with {1} 20.14 + 20.15 +# 0: type, 1: type 20.16 +compiler.err.invalid.container.wrong.containedby=\ 20.17 + invalid contained repeatable annotation, {0} does not match {1} 20.18 + 20.19 +# 0: type, 1: type 20.20 +compiler.err.invalid.container.no.containerfor=\ 20.21 + invalid container for repeating annotations, {0} is not annotated with {1} 20.22 + 20.23 +# 0: type, 1: type 20.24 +compiler.err.invalid.container.wrong.containerfor=\ 20.25 + invalid container for repeating annotations, {0} does not match {1} 20.26 + 20.27 +# 0: type 20.28 +compiler.err.invalid.containedby.annotation=\ 20.29 + duplicate annotation, {0} is annotated with an invalid ContainedBy annotation 20.30 + 20.31 +# 0: type 20.32 +compiler.err.invalid.containedby.annotation.no.value=\ 20.33 + duplicate annotation, {0} is not a valid ContainedBy, no value element method declared 20.34 + 20.35 +# 0: type, 1: number 20.36 +compiler.err.invalid.containedby.annotation.multiple.values=\ 20.37 + duplicate annotation, {0} is not a valid ContainedBy, {1} value element methods declared 20.38 + 20.39 +# 0: type 20.40 +compiler.err.invalid.containedby.annotation.invalid.value=\ 20.41 + duplicate annotation, {0} is not a valid ContainedBy, invalid value element, need a method 20.42 + 20.43 +# 0: type, 1: type, 2: type 20.44 +compiler.err.invalid.containedby.annotation.value.return=\ 20.45 + duplicate annotation, value element of containing annotation {0} should have type {2}, found {1} 20.46 + 20.47 +# 0: type, 1: symbol 20.48 +compiler.err.invalid.containedby.annotation.elem.nondefault=\ 20.49 + duplicate annotation, element {1} in containing annotation {0} does not have a default value 20.50 + 20.51 +# 0: symbol, 1: type, 2: symbol, 3: type 20.52 +compiler.err.invalid.containedby.annotation.retention=\ 20.53 + containing annotation {0} has shorter retention ({1}) than the contained annotation {2} with retention {3} 20.54 + 20.55 +# 0: symbol, 1: symbol 20.56 +compiler.err.invalid.containedby.annotation.not.documented=\ 20.57 + containing annotation type, {0}, is not @Documented while repeated annotation type, {1}, is 20.58 + 20.59 +# 0: symbol, 1: symbol 20.60 +compiler.err.invalid.containedby.annotation.not.inherited=\ 20.61 + containing annotation type, {0}, is not @Inherited while repeated annotation type, {1}, is 20.62 + 20.63 +# 0: symbol, 1: symbol 20.64 +compiler.err.invalid.containedby.annotation.incompatible.target=\ 20.65 + target of container annotation {0} is not a subset of target of repeated annotation {1} 20.66 + 20.67 +# 0: symbol 20.68 +compiler.err.invalid.containedby.annotation.repeated.and.container.present=\ 20.69 + container {0} must not be present at the same time as the element it contains 20.70 + 20.71 # 0: name 20.72 compiler.err.duplicate.class=\ 20.73 duplicate class: {0}
21.1 --- a/src/share/classes/com/sun/tools/javac/sym/CreateSymbols.java Sat Sep 08 22:43:38 2012 -0700 21.2 +++ b/src/share/classes/com/sun/tools/javac/sym/CreateSymbols.java Sat Sep 08 22:54:21 2012 -0700 21.3 @@ -1,5 +1,5 @@ 21.4 /* 21.5 - * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. 21.6 + * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 21.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.8 * 21.9 * This code is free software; you can redistribute it and/or modify it 21.10 @@ -206,9 +206,7 @@ 21.11 } 21.12 ClassSymbol cs = (ClassSymbol) sym; 21.13 if (addLegacyAnnotation) { 21.14 - cs.attributes_field = (cs.attributes_field == null) 21.15 - ? List.of(proprietary) 21.16 - : cs.attributes_field.prepend(proprietary); 21.17 + cs.annotations.prepend(List.of(proprietary)); 21.18 } 21.19 writeClass(pool, cs, writer); 21.20 }
22.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Sat Sep 08 22:43:38 2012 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Sat Sep 08 22:54:21 2012 -0700 22.3 @@ -1,5 +1,5 @@ 22.4 /* 22.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 22.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 22.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.8 * 22.9 * This code is free software; you can redistribute it and/or modify it 22.10 @@ -740,7 +740,7 @@ 22.11 result = Literal(v.value); 22.12 } 22.13 public void visitClass(Attribute.Class clazz) { 22.14 - result = ClassLiteral(clazz.type).setType(syms.classType); 22.15 + result = ClassLiteral(clazz.classType).setType(syms.classType); 22.16 } 22.17 public void visitEnum(Attribute.Enum e) { 22.18 result = QualIdent(e.value);
23.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Sat Sep 08 22:43:38 2012 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Sat Sep 08 22:54:21 2012 -0700 23.3 @@ -301,6 +301,10 @@ 23.4 this.errWriter = other.errWriter; 23.5 } 23.6 23.7 + public void setSourceMap(Log other) { 23.8 + this.sourceMap = other.sourceMap; 23.9 + } 23.10 + 23.11 /** Flush the logs 23.12 */ 23.13 public void flush() {
24.1 --- a/src/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java Sat Sep 08 22:43:38 2012 -0700 24.2 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java Sat Sep 08 22:54:21 2012 -0700 24.3 @@ -1,5 +1,5 @@ 24.4 /* 24.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 24.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 24.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.8 * 24.9 * This code is free software; you can redistribute it and/or modify it 24.10 @@ -83,7 +83,7 @@ 24.11 24.12 public void visitClass(Attribute.Class c) { 24.13 value = TypeMaker.getType(env, 24.14 - env.types.erasure(c.type)); 24.15 + env.types.erasure(c.classType)); 24.16 } 24.17 24.18 public void visitEnum(Attribute.Enum e) {
25.1 --- a/src/share/classes/com/sun/tools/javah/JavahTask.java Sat Sep 08 22:43:38 2012 -0700 25.2 +++ b/src/share/classes/com/sun/tools/javah/JavahTask.java Sat Sep 08 22:54:21 2012 -0700 25.3 @@ -1,5 +1,5 @@ 25.4 /* 25.5 - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. 25.6 + * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. 25.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.8 * 25.9 * This code is free software; you can redistribute it and/or modify it 25.10 @@ -506,7 +506,7 @@ 25.11 List<String> opts = new ArrayList<String>(); 25.12 opts.add("-proc:only"); 25.13 opts.addAll(javac_extras); 25.14 - CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, internalize(classes), null); 25.15 + CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, classes, null); 25.16 JavahProcessor p = new JavahProcessor(g); 25.17 t.setProcessors(Collections.singleton(p)); 25.18 25.19 @@ -516,14 +516,6 @@ 25.20 return ok; 25.21 } 25.22 25.23 - private List<String> internalize(List<String> classes) { 25.24 - List<String> l = new ArrayList<String>(); 25.25 - for (String c: classes) { 25.26 - l.add(c.replace('$', '.')); 25.27 - } 25.28 - return l; 25.29 - } 25.30 - 25.31 private List<File> pathToFiles(String path) { 25.32 List<File> files = new ArrayList<File>(); 25.33 for (String f: path.split(File.pathSeparator)) {
26.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Sat Sep 08 22:43:38 2012 -0700 26.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Sat Sep 08 22:54:21 2012 -0700 26.3 @@ -1,5 +1,5 @@ 26.4 /* 26.5 - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. 26.6 + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 26.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.8 * 26.9 * This code is free software; you can redistribute it and/or modify it 26.10 @@ -374,8 +374,8 @@ 26.11 task_locale = locale; 26.12 } 26.13 26.14 - public void setLog(PrintWriter log) { 26.15 - this.log = log; 26.16 + public void setLog(Writer log) { 26.17 + this.log = getPrintWriterForWriter(log); 26.18 } 26.19 26.20 public void setLog(OutputStream s) { 26.21 @@ -383,7 +383,7 @@ 26.22 } 26.23 26.24 private static PrintWriter getPrintWriterForStream(OutputStream s) { 26.25 - return new PrintWriter(s, true); 26.26 + return new PrintWriter(s == null ? System.err : s, true); 26.27 } 26.28 26.29 private static PrintWriter getPrintWriterForWriter(Writer w) {
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/BasicRepeatingAnnotations.java Sat Sep 08 22:54:21 2012 -0700 27.3 @@ -0,0 +1,79 @@ 27.4 +/* 27.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + */ 27.26 + 27.27 +/** 27.28 + * @test 27.29 + * @summary Smoke test for repeating annotations 27.30 + * @bug 7151010 27.31 + * 27.32 + * @run clean BasicRepeatingAnnotations BasicRepeatingAnnos BasicNonRepeatingAnno Foo Foos Bar 27.33 + * @run compile BasicRepeatingAnnotations.java 27.34 + * @run main BasicRepeatingAnnotations 27.35 + */ 27.36 + 27.37 +import java.lang.annotation.*; 27.38 + 27.39 +@Retention(RetentionPolicy.RUNTIME) 27.40 +@ContainedBy(Foos.class) 27.41 +@interface Foo {} 27.42 + 27.43 +@ContainerFor(Foo.class) 27.44 +@Retention(RetentionPolicy.RUNTIME) 27.45 +@interface Foos { 27.46 + Foo[] value(); 27.47 +} 27.48 + 27.49 +@interface Bar {} 27.50 + 27.51 +@Foo @Foo 27.52 +@Foo 27.53 +@Bar 27.54 +@Foo 27.55 +@Foo 27.56 +@Foo 27.57 +@Foo 27.58 +@Foo @Foo 27.59 +@Foo 27.60 +class BasicRepeatingAnnos {} 27.61 + 27.62 +@Foo 27.63 +class BasicNonRepeatingAnno {} 27.64 + 27.65 +public class BasicRepeatingAnnotations { 27.66 + public static void main(String[] args) throws Exception { 27.67 + Annotation a = BasicRepeatingAnnos.class.getAnnotation(Foos.class); 27.68 + if (a == null) { 27.69 + throw new RuntimeException("Container annotation missing"); 27.70 + } 27.71 + 27.72 + // verify that container not present on nonrepeating 27.73 + a = BasicNonRepeatingAnno.class.getAnnotation(Foos.class); 27.74 + if (a != null) { 27.75 + throw new RuntimeException("Container annotation present"); 27.76 + } 27.77 + a = BasicNonRepeatingAnno.class.getAnnotation(Foo.class); 27.78 + if (a == null) { 27.79 + throw new RuntimeException("Repeated annoation not directly present"); 27.80 + } 27.81 + } 27.82 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/CheckTargets.java Sat Sep 08 22:54:21 2012 -0700 28.3 @@ -0,0 +1,67 @@ 28.4 +/* 28.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.23 + * or visit www.oracle.com if you need additional information or have any 28.24 + * questions. 28.25 + */ 28.26 + 28.27 +/** 28.28 + * @test 28.29 + * @summary Smoke test for repeating annotations 28.30 + * @bug 7151010 28.31 + * 28.32 + * @run clean Foos Foo Bars Bar Baz Bazs CheckTargets 28.33 + * @run compile CheckTargets.java 28.34 + */ 28.35 + 28.36 +import java.lang.annotation.*; 28.37 + 28.38 +@ContainedBy(Foos.class) 28.39 +@Target(ElementType.TYPE) 28.40 +@interface Foo {} 28.41 + 28.42 +@ContainerFor(Foo.class) 28.43 +@Target(ElementType.ANNOTATION_TYPE) 28.44 +@interface Foos { 28.45 + Foo[] value(); 28.46 +} 28.47 + 28.48 +@ContainedBy(Bars.class) 28.49 +@Target(ElementType.TYPE) 28.50 +@interface Bar {} 28.51 + 28.52 +@ContainerFor(Bar.class) 28.53 +@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE }) 28.54 +@interface Bars { 28.55 + Bar[] value(); 28.56 +} 28.57 + 28.58 + 28.59 +@ContainedBy(Bazs.class) 28.60 +@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE }) 28.61 +@interface Baz {} 28.62 + 28.63 +@ContainerFor(Baz.class) 28.64 +@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE }) 28.65 +@interface Bazs { 28.66 + Baz[] value(); 28.67 +} 28.68 + 28.69 + 28.70 +public class CheckTargets {}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/ContainerHasRepeatedContained.java Sat Sep 08 22:54:21 2012 -0700 29.3 @@ -0,0 +1,46 @@ 29.4 +/* 29.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.7 + * 29.8 + * This code is free software; you can redistribute it and/or modify it 29.9 + * under the terms of the GNU General Public License version 2 only, as 29.10 + * published by the Free Software Foundation. 29.11 + * 29.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 29.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 29.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 29.15 + * version 2 for more details (a copy is included in the LICENSE file that 29.16 + * accompanied this code). 29.17 + * 29.18 + * You should have received a copy of the GNU General Public License version 29.19 + * 2 along with this work; if not, write to the Free Software Foundation, 29.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 29.21 + * 29.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 29.23 + * or visit www.oracle.com if you need additional information or have any 29.24 + * questions. 29.25 + */ 29.26 + 29.27 +/** 29.28 + * @test 29.29 + * @summary Smoke test for repeating annotations 29.30 + * @bug 7151010 29.31 + * 29.32 + * @run clean Bar BarContainer ContainerHasRepeatedContained 29.33 + * @run compile ContainerHasRepeatedContained.java 29.34 + */ 29.35 + 29.36 +import java.lang.annotation.ContainedBy; 29.37 +import java.lang.annotation.ContainerFor; 29.38 + 29.39 +@ContainedBy(BarContainer.class) 29.40 +@interface Bar {} 29.41 + 29.42 +@Bar 29.43 +@Bar 29.44 +@ContainerFor(Bar.class) 29.45 +@interface BarContainer { 29.46 + Bar[] value(); 29.47 +} 29.48 + 29.49 +public class ContainerHasRepeatedContained {}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/DelayRepeatedContainer.java Sat Sep 08 22:54:21 2012 -0700 30.3 @@ -0,0 +1,50 @@ 30.4 +/* 30.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 + * 30.8 + * This code is free software; you can redistribute it and/or modify it 30.9 + * under the terms of the GNU General Public License version 2 only, as 30.10 + * published by the Free Software Foundation. 30.11 + * 30.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 30.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.15 + * version 2 for more details (a copy is included in the LICENSE file that 30.16 + * accompanied this code). 30.17 + * 30.18 + * You should have received a copy of the GNU General Public License version 30.19 + * 2 along with this work; if not, write to the Free Software Foundation, 30.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.21 + * 30.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 30.23 + * or visit www.oracle.com if you need additional information or have any 30.24 + * questions. 30.25 + */ 30.26 + 30.27 +/** 30.28 + * @test 30.29 + * @summary Smoke test for repeating annotations 30.30 + * @bug 7151010 30.31 + * 30.32 + * @run clean DelayRepeatedContainer Bar BarContainer 30.33 + * @run compile DelayRepeatedContainer.java 30.34 + */ 30.35 + 30.36 +import java.lang.annotation.*; 30.37 + 30.38 +public class DelayRepeatedContainer { 30.39 + @Bar("apa") @Bar("banan") 30.40 + String meh() { return "meh"; } 30.41 +} 30.42 + 30.43 +@Bar("katt") 30.44 +@Bar("lol") 30.45 +@ContainedBy(BarContainer.class) 30.46 +@interface Bar { 30.47 + String value(); 30.48 +} 30.49 + 30.50 +@ContainerFor(Bar.class) 30.51 +@interface BarContainer { 30.52 + Bar[] value(); 30.53 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/InvalidTarget.java Sat Sep 08 22:54:21 2012 -0700 31.3 @@ -0,0 +1,45 @@ 31.4 +/* 31.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. 31.11 + * 31.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.15 + * version 2 for more details (a copy is included in the LICENSE file that 31.16 + * accompanied this code). 31.17 + * 31.18 + * You should have received a copy of the GNU General Public License version 31.19 + * 2 along with this work; if not, write to the Free Software Foundation, 31.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.21 + * 31.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 31.23 + * or visit www.oracle.com if you need additional information or have any 31.24 + * questions. 31.25 + */ 31.26 + 31.27 +/** 31.28 + * @test 31.29 + * @summary Smoke test for repeating annotations 31.30 + * @bug 7151010 31.31 + * 31.32 + * @run clean Foos Foo 31.33 + * @run compile/fail InvalidTarget.java 31.34 + */ 31.35 + 31.36 +import java.lang.annotation.*; 31.37 + 31.38 +@ContainedBy(Foos.class) 31.39 +@Target(ElementType.ANNOTATION_TYPE) 31.40 +@interface Foo {} 31.41 + 31.42 +@ContainerFor(Foo.class) 31.43 +@Target(ElementType.TYPE) 31.44 +@interface Foos { 31.45 + Foo[] value(); 31.46 +} 31.47 + 31.48 +public class InvalidTargets {}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/MissingContainedBy.java Sat Sep 08 22:54:21 2012 -0700 32.3 @@ -0,0 +1,39 @@ 32.4 +/* 32.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. 32.11 + * 32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 + * version 2 for more details (a copy is included in the LICENSE file that 32.16 + * accompanied this code). 32.17 + * 32.18 + * You should have received a copy of the GNU General Public License version 32.19 + * 2 along with this work; if not, write to the Free Software Foundation, 32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 + * 32.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.23 + * or visit www.oracle.com if you need additional information or have any 32.24 + * questions. 32.25 + */ 32.26 + 32.27 +/** 32.28 + * @test 32.29 + * @summary Smoke test for repeating annotations 32.30 + * @compile/fail MissingContainedBy.java 32.31 + * @bug 7151010 32.32 + */ 32.33 + 32.34 +import java.lang.annotation.*; 32.35 + 32.36 + 32.37 +@ContainerFor(MissingContainedBy.class) 32.38 +@interface Foos { 32.39 + MissingContainedBy[] value(); 32.40 +} 32.41 + 32.42 +public @interface MissingContainedBy {}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/MissingContainerFor.java Sat Sep 08 22:54:21 2012 -0700 33.3 @@ -0,0 +1,38 @@ 33.4 +/* 33.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.23 + * or visit www.oracle.com if you need additional information or have any 33.24 + * questions. 33.25 + */ 33.26 + 33.27 +/** 33.28 + * @test 33.29 + * @summary Smoke test for repeating annotations 33.30 + * @compile/fail MissingContainerFor.java 33.31 + * @bug 7151010 33.32 + */ 33.33 + 33.34 +import java.lang.annotation.*; 33.35 + 33.36 +@interface Foos { 33.37 + MissingContainerFor[] value(); 33.38 +} 33.39 + 33.40 +@ContainedBy(Foos.class) 33.41 +public @interface MissingContainerFor {}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/NestedContainers.java Sat Sep 08 22:54:21 2012 -0700 34.3 @@ -0,0 +1,74 @@ 34.4 +/* 34.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. 34.11 + * 34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 + * version 2 for more details (a copy is included in the LICENSE file that 34.16 + * accompanied this code). 34.17 + * 34.18 + * You should have received a copy of the GNU General Public License version 34.19 + * 2 along with this work; if not, write to the Free Software Foundation, 34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 + * 34.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.23 + * or visit www.oracle.com if you need additional information or have any 34.24 + * questions. 34.25 + */ 34.26 + 34.27 +/** 34.28 + * @test 34.29 + * @summary Smoke test for repeating annotations 34.30 + * @bug 7151010 34.31 + * 34.32 + * @run clean NestedContainers BasicRepeatingAnnos BasicRepeatingAnnos2 Foo Foos FoosFoos 34.33 + * @run compile NestedContainers.java 34.34 + * @run main NestedContainers 34.35 + */ 34.36 + 34.37 +import java.lang.annotation.*; 34.38 + 34.39 +@Retention(RetentionPolicy.RUNTIME) 34.40 +@ContainedBy(Foos.class) 34.41 +@interface Foo {} 34.42 + 34.43 +@Retention(RetentionPolicy.RUNTIME) 34.44 +@ContainedBy(FoosFoos.class) 34.45 +@ContainerFor(Foo.class) 34.46 +@interface Foos { 34.47 + Foo[] value(); 34.48 +} 34.49 + 34.50 +@ContainerFor(Foos.class) 34.51 +@Retention(RetentionPolicy.RUNTIME) 34.52 +@interface FoosFoos { 34.53 + Foos[] value(); 34.54 +} 34.55 + 34.56 +@Foo 34.57 +@Foo 34.58 +class BasicRepeatingAnnos {} 34.59 + 34.60 +@Foos({}) 34.61 +@Foos({}) 34.62 +class BasicRepeatingAnnos2 {} 34.63 + 34.64 +public class NestedContainers { 34.65 + public static void main(String[] args) throws Exception { 34.66 + Annotation a = BasicRepeatingAnnos.class.getAnnotation(Foos.class); 34.67 + if (a == null) { 34.68 + throw new RuntimeException("Container annotation missing"); 34.69 + } 34.70 + 34.71 + // Check 2:nd level container 34.72 + a = BasicRepeatingAnnos2.class.getAnnotation(FoosFoos.class); 34.73 + if (a == null) { 34.74 + throw new RuntimeException("Container annotation missing"); 34.75 + } 34.76 + } 34.77 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/RepMemberAnno.java Sat Sep 08 22:54:21 2012 -0700 35.3 @@ -0,0 +1,49 @@ 35.4 +/* 35.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +/** 35.28 + * @test 35.29 + * @summary Smoke test for repeating annotations 35.30 + * @bug 7151010 35.31 + * 35.32 + * @run clean RepMemberAnno Bar BarContainer 35.33 + * @run compile RepMemberAnno.java 35.34 + */ 35.35 + 35.36 +import java.lang.annotation.ContainedBy; 35.37 +import java.lang.annotation.ContainerFor; 35.38 + 35.39 +public class RepMemberAnno { 35.40 + @Bar("Apa") @Bar("Banan") 35.41 + public void meh() {} 35.42 +} 35.43 + 35.44 +@ContainedBy(BarContainer.class) 35.45 +@interface Bar { 35.46 + String value(); 35.47 +} 35.48 + 35.49 +@ContainerFor(Bar.class) 35.50 +@interface BarContainer { 35.51 + Bar[] value(); 35.52 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/RepSelfMemberAnno.java Sat Sep 08 22:54:21 2012 -0700 36.3 @@ -0,0 +1,60 @@ 36.4 +/* 36.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. 36.11 + * 36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.15 + * version 2 for more details (a copy is included in the LICENSE file that 36.16 + * accompanied this code). 36.17 + * 36.18 + * You should have received a copy of the GNU General Public License version 36.19 + * 2 along with this work; if not, write to the Free Software Foundation, 36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.21 + * 36.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.23 + * or visit www.oracle.com if you need additional information or have any 36.24 + * questions. 36.25 + */ 36.26 + 36.27 +/** 36.28 + * @test 36.29 + * @summary Smoke test for repeating annotations 36.30 + * @bug 7151010 36.31 + * 36.32 + * @run clean RepSelfMemberAnno BarContainer BarContainerContainer 36.33 + * @run compile RepSelfMemberAnno.java 36.34 + */ 36.35 + 36.36 +import java.lang.annotation.*; 36.37 + 36.38 + 36.39 +@Retention(RetentionPolicy.RUNTIME) 36.40 +@ContainedBy(BarContainer.class) 36.41 +public @interface RepSelfMemberAnno { 36.42 + @RepSelfMemberAnno @RepSelfMemberAnno 36.43 + String meh() default "banan"; 36.44 +} 36.45 + 36.46 + 36.47 +@ContainedBy(BarContainerContainer.class) 36.48 +@Retention(RetentionPolicy.RUNTIME) 36.49 +@ContainerFor(RepSelfMemberAnno.class) 36.50 +@interface BarContainer { 36.51 + RepSelfMemberAnno[] value(); 36.52 +} 36.53 + 36.54 +@ContainerFor(BarContainer.class) 36.55 +@Retention(RetentionPolicy.RUNTIME) 36.56 +@interface BarContainerContainer { 36.57 + BarContainer[] value(); 36.58 + String meh() default "apa"; 36.59 +} 36.60 + 36.61 +@BarContainer(value={}) 36.62 +@BarContainer(value={}) 36.63 +@interface Bar {}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/RepeatingAndContainerPresent.java Sat Sep 08 22:54:21 2012 -0700 37.3 @@ -0,0 +1,44 @@ 37.4 +/* 37.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. 37.11 + * 37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.15 + * version 2 for more details (a copy is included in the LICENSE file that 37.16 + * accompanied this code). 37.17 + * 37.18 + * You should have received a copy of the GNU General Public License version 37.19 + * 2 along with this work; if not, write to the Free Software Foundation, 37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.21 + * 37.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.23 + * or visit www.oracle.com if you need additional information or have any 37.24 + * questions. 37.25 + */ 37.26 + 37.27 +/** 37.28 + * @test 37.29 + * @summary Smoke test for repeating annotations 37.30 + * @compile/fail RepeatingAndContainerPresent.java 37.31 + * @bug 7151010 37.32 + */ 37.33 + 37.34 +import java.lang.annotation.*; 37.35 + 37.36 +@ContainedBy(Foos.class) 37.37 +@interface Foo {} 37.38 + 37.39 +@interface Foos { 37.40 + Foo[] value(); 37.41 +} 37.42 + 37.43 + 37.44 +@Foo 37.45 +@Foo 37.46 +@Foos({}) 37.47 +public class RepeatingAndContainerPresent {}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/SelfRepeatingAnnotations.java Sat Sep 08 22:54:21 2012 -0700 38.3 @@ -0,0 +1,55 @@ 38.4 +/* 38.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/** 38.28 + * @test 38.29 + * @summary Smoke test for repeating annotations 38.30 + * @bug 7151010 38.31 + * 38.32 + * @run clean SelfRepeatingAnnotations Foos SelfRepeatingAnno 38.33 + * @run compile SelfRepeatingAnnotations.java 38.34 + * @run main SelfRepeatingAnnotations 38.35 + */ 38.36 + 38.37 +import java.lang.annotation.*; 38.38 + 38.39 +@ContainerFor(SelfRepeatingAnno.class) 38.40 +@Retention(RetentionPolicy.RUNTIME) 38.41 +@interface Foos { 38.42 + SelfRepeatingAnno[] value(); 38.43 +} 38.44 + 38.45 +@SelfRepeatingAnno 38.46 +@Retention(RetentionPolicy.RUNTIME) 38.47 +@SelfRepeatingAnno 38.48 +@ContainedBy(Foos.class) 38.49 +@interface SelfRepeatingAnno {} 38.50 + 38.51 +public class SelfRepeatingAnnotations { 38.52 + public static void main(String[] args) throws Exception { 38.53 + Annotation a = SelfRepeatingAnno.class.getAnnotation(Foos.class); 38.54 + if (a == null) { 38.55 + throw new RuntimeException("Container annotation missing"); 38.56 + } 38.57 + } 38.58 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/SingleRepeatingAndContainer.java Sat Sep 08 22:54:21 2012 -0700 39.3 @@ -0,0 +1,43 @@ 39.4 +/* 39.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. 39.11 + * 39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.15 + * version 2 for more details (a copy is included in the LICENSE file that 39.16 + * accompanied this code). 39.17 + * 39.18 + * You should have received a copy of the GNU General Public License version 39.19 + * 2 along with this work; if not, write to the Free Software Foundation, 39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.21 + * 39.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.23 + * or visit www.oracle.com if you need additional information or have any 39.24 + * questions. 39.25 + */ 39.26 + 39.27 +/** 39.28 + * @test 39.29 + * @summary Smoke test for repeating annotations 39.30 + * @compile SingleRepeatingAndContainer.java 39.31 + * @bug 7151010 39.32 + */ 39.33 + 39.34 +import java.lang.annotation.*; 39.35 + 39.36 +@ContainedBy(Foos.class) 39.37 +@interface Foo {} 39.38 + 39.39 +@ContainerFor(Foo.class) 39.40 +@interface Foos { 39.41 + Foo[] value(); 39.42 +} 39.43 + 39.44 +@Foo 39.45 +@Foos({}) 39.46 +public class SingleRepeatingAndContainer {}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/UseWrongContainedBy.java Sat Sep 08 22:54:21 2012 -0700 40.3 @@ -0,0 +1,42 @@ 40.4 +/* 40.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/** 40.28 + * @test 40.29 + * @summary Smoke test for repeating annotations 40.30 + * @compile/fail UseWrongContainedBy.java 40.31 + * @bug 7151010 40.32 + */ 40.33 + 40.34 +import java.lang.annotation.*; 40.35 + 40.36 +@ContainerFor(UseWrongContainedBy.class) 40.37 +@interface Foos { 40.38 + UseWrongContainedBy[] value(); 40.39 +} 40.40 + 40.41 +@ContainedBy(Target.class) 40.42 +public @interface UseWrongContainedBy {} 40.43 + 40.44 +@UseWrongContainedBy @UseWrongContainedBy 40.45 +@interface Foo {}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/UseWrongContainerFor.java Sat Sep 08 22:54:21 2012 -0700 41.3 @@ -0,0 +1,42 @@ 41.4 +/* 41.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. 41.11 + * 41.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.15 + * version 2 for more details (a copy is included in the LICENSE file that 41.16 + * accompanied this code). 41.17 + * 41.18 + * You should have received a copy of the GNU General Public License version 41.19 + * 2 along with this work; if not, write to the Free Software Foundation, 41.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.21 + * 41.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.23 + * or visit www.oracle.com if you need additional information or have any 41.24 + * questions. 41.25 + */ 41.26 + 41.27 +/** 41.28 + * @test 41.29 + * @summary Smoke test for repeating annotations 41.30 + * @compile/fail UseWrongContainerFor.java 41.31 + * @bug 7151010 41.32 + */ 41.33 + 41.34 +import java.lang.annotation.*; 41.35 + 41.36 +@ContainerFor(Retention.class) 41.37 +@interface Foos { 41.38 + UseWrongContainerFor[] value(); 41.39 +} 41.40 + 41.41 +@ContainedBy(Foos.class) 41.42 +public @interface UseWrongContainerFor {} 41.43 + 41.44 +@UseWrongContainerFor @UseWrongContainerFor 41.45 +@interface Foo {}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/WrongContainedBy.java Sat Sep 08 22:54:21 2012 -0700 42.3 @@ -0,0 +1,39 @@ 42.4 +/* 42.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. 42.11 + * 42.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.15 + * version 2 for more details (a copy is included in the LICENSE file that 42.16 + * accompanied this code). 42.17 + * 42.18 + * You should have received a copy of the GNU General Public License version 42.19 + * 2 along with this work; if not, write to the Free Software Foundation, 42.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.21 + * 42.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 42.23 + * or visit www.oracle.com if you need additional information or have any 42.24 + * questions. 42.25 + */ 42.26 + 42.27 +/** 42.28 + * @test 42.29 + * @summary Smoke test for repeating annotations 42.30 + * @compile/fail WrongContainedBy.java 42.31 + * @bug 7151010 42.32 + */ 42.33 + 42.34 +import java.lang.annotation.*; 42.35 + 42.36 +@ContainerFor(WrongContainedBy.class) 42.37 +@interface Foos { 42.38 + WrongContainedBy[] value(); 42.39 +} 42.40 + 42.41 +@ContainedBy(Target.class) 42.42 +public @interface WrongContainedBy {}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/WrongContainerFor.java Sat Sep 08 22:54:21 2012 -0700 43.3 @@ -0,0 +1,39 @@ 43.4 +/* 43.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43.7 + * 43.8 + * This code is free software; you can redistribute it and/or modify it 43.9 + * under the terms of the GNU General Public License version 2 only, as 43.10 + * published by the Free Software Foundation. 43.11 + * 43.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 43.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 43.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 43.15 + * version 2 for more details (a copy is included in the LICENSE file that 43.16 + * accompanied this code). 43.17 + * 43.18 + * You should have received a copy of the GNU General Public License version 43.19 + * 2 along with this work; if not, write to the Free Software Foundation, 43.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 43.21 + * 43.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 43.23 + * or visit www.oracle.com if you need additional information or have any 43.24 + * questions. 43.25 + */ 43.26 + 43.27 +/** 43.28 + * @test 43.29 + * @summary Smoke test for repeating annotations 43.30 + * @compile/fail WrongContainerFor.java 43.31 + * @bug 7151010 43.32 + */ 43.33 + 43.34 +import java.lang.annotation.*; 43.35 + 43.36 +@ContainerFor(Retention.class) 43.37 +@interface Foos { 43.38 + WrongContainerFor[] value(); 43.39 +} 43.40 + 43.41 +@ContainedBy(Foos.class) 43.42 +public @interface WrongContainerFor {}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/tools/javac/api/EndPositions.java Sat Sep 08 22:54:21 2012 -0700 44.3 @@ -0,0 +1,98 @@ 44.4 +/* 44.5 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. 44.11 + * 44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.15 + * version 2 for more details (a copy is included in the LICENSE file that 44.16 + * accompanied this code). 44.17 + * 44.18 + * You should have received a copy of the GNU General Public License version 44.19 + * 2 along with this work; if not, write to the Free Software Foundation, 44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.21 + * 44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.23 + * or visit www.oracle.com if you need additional information or have any 44.24 + * questions. 44.25 + */ 44.26 + 44.27 +/* 44.28 + * @test 44.29 + * @bug 7196760 44.30 + * @summary javac doesn't report Diagnostic end positions properly when 44.31 + * an annotation processor is present 44.32 + */ 44.33 + 44.34 +import com.sun.source.tree.ClassTree; 44.35 +import com.sun.source.tree.CompilationUnitTree; 44.36 +import com.sun.source.tree.Tree; 44.37 +import com.sun.source.util.JavacTask; 44.38 +import com.sun.source.util.Trees; 44.39 +import java.io.IOException; 44.40 +import java.net.URI; 44.41 +import java.util.Arrays; 44.42 +import java.util.Collections; 44.43 +import java.util.List; 44.44 +import java.util.Set; 44.45 +import javax.annotation.processing.*; 44.46 +import javax.lang.model.*; 44.47 +import javax.lang.model.element.*; 44.48 +import javax.tools.JavaCompiler; 44.49 +import javax.tools.JavaFileObject; 44.50 +import javax.tools.SimpleJavaFileObject; 44.51 +import javax.tools.Diagnostic; 44.52 +import javax.tools.DiagnosticCollector; 44.53 +import static javax.tools.JavaFileObject.Kind.SOURCE; 44.54 +import javax.tools.ToolProvider; 44.55 + 44.56 +@SupportedAnnotationTypes("*") 44.57 +public class EndPositions extends AbstractProcessor { 44.58 + public static void main(String... args) throws IOException { 44.59 + class MyFileObject extends SimpleJavaFileObject { 44.60 + MyFileObject() { 44.61 + super(URI.create("myfo:///Test.java"), SOURCE); 44.62 + } 44.63 + @Override 44.64 + public String getCharContent(boolean ignoreEncodingErrors) { 44.65 + // 0 1 2 3 44.66 + // 012345678901234567890123456789012345 44.67 + return "class Test { String s = 1234; }"; 44.68 + } 44.69 + } 44.70 + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); 44.71 + List<JavaFileObject> compilationUnits = 44.72 + Collections.<JavaFileObject>singletonList(new MyFileObject()); 44.73 + DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); 44.74 + List<String> options = Arrays.asList("-processor", EndPositions.class.getCanonicalName()); 44.75 + JavacTask task = (JavacTask)javac.getTask(null, null, diagnostics, options, null, compilationUnits); 44.76 + boolean valid = task.call(); 44.77 + if (valid) 44.78 + throw new AssertionError("Compilation succeeded unexpectedly"); 44.79 + 44.80 + List<Diagnostic<? extends JavaFileObject>> errors = diagnostics.getDiagnostics(); 44.81 + if (errors.size() != 1) 44.82 + throw new AssertionError("Expected one error only, but found " + errors.size() + " errors"); 44.83 + 44.84 + Diagnostic<?> error = errors.get(0); 44.85 + if (error.getStartPosition() >= error.getEndPosition()) 44.86 + throw new AssertionError("Expected start to be less than end position: start [" + 44.87 + error.getStartPosition() + "], end [" + error.getEndPosition() +"]"); 44.88 + 44.89 + System.out.println("All is good!"); 44.90 + } 44.91 + 44.92 + @Override 44.93 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 44.94 + return true; 44.95 + } 44.96 + 44.97 + @Override 44.98 + public SourceVersion getSupportedSourceVersion() { 44.99 + return SourceVersion.latest(); 44.100 + } 44.101 +}
45.1 --- a/test/tools/javac/diags/examples.not-yet.txt Sat Sep 08 22:43:38 2012 -0700 45.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Sat Sep 08 22:54:21 2012 -0700 45.3 @@ -5,6 +5,9 @@ 45.4 compiler.err.cant.read.file # (apt.JavaCompiler?) 45.5 compiler.err.cant.select.static.class.from.param.type 45.6 compiler.err.illegal.char.for.encoding 45.7 +compiler.err.invalid.containedby.annotation # should not happen 45.8 +compiler.err.invalid.containedby.annotation.invalid.value # "can't" happen 45.9 +compiler.err.invalid.containedby.annotation.multiple.values # can't happen 45.10 compiler.err.io.exception # (javah.JavahTask?) 45.11 compiler.err.limit.code # Code 45.12 compiler.err.limit.code.too.large.for.try.stmt # Gen
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/tools/javac/diags/examples/ContainedByDocumentedMismatch.java Sat Sep 08 22:54:21 2012 -0700 46.3 @@ -0,0 +1,37 @@ 46.4 +/* 46.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. 46.11 + * 46.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.15 + * version 2 for more details (a copy is included in the LICENSE file that 46.16 + * accompanied this code). 46.17 + * 46.18 + * You should have received a copy of the GNU General Public License version 46.19 + * 2 along with this work; if not, write to the Free Software Foundation, 46.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.21 + * 46.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.23 + * or visit www.oracle.com if you need additional information or have any 46.24 + * questions. 46.25 + */ 46.26 + 46.27 +// key: compiler.err.invalid.containedby.annotation.not.documented 46.28 + 46.29 +import java.lang.annotation.*; 46.30 + 46.31 +@Documented 46.32 +@ContainedBy(Annos.class) 46.33 +@interface Anno { } 46.34 + 46.35 +@ContainerFor(Anno.class) 46.36 +@interface Annos { Anno[] value(); } 46.37 + 46.38 +@Anno 46.39 +@Anno 46.40 +class ContainedByDocumentedMismatch { }
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/diags/examples/ContainedByInheritedMismatch.java Sat Sep 08 22:54:21 2012 -0700 47.3 @@ -0,0 +1,37 @@ 47.4 +/* 47.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +// key: compiler.err.invalid.containedby.annotation.not.inherited 47.28 + 47.29 +import java.lang.annotation.*; 47.30 + 47.31 +@Inherited 47.32 +@ContainedBy(Annos.class) 47.33 +@interface Anno { } 47.34 + 47.35 +@ContainerFor(Anno.class) 47.36 +@interface Annos { Anno[] value(); } 47.37 + 47.38 +@Anno 47.39 +@Anno 47.40 +class ContainedByInheritedMismatch { }
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/test/tools/javac/diags/examples/ContainedByNoValue.java Sat Sep 08 22:54:21 2012 -0700 48.3 @@ -0,0 +1,36 @@ 48.4 +/* 48.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. 48.11 + * 48.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.15 + * version 2 for more details (a copy is included in the LICENSE file that 48.16 + * accompanied this code). 48.17 + * 48.18 + * You should have received a copy of the GNU General Public License version 48.19 + * 2 along with this work; if not, write to the Free Software Foundation, 48.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.21 + * 48.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.23 + * or visit www.oracle.com if you need additional information or have any 48.24 + * questions. 48.25 + */ 48.26 + 48.27 +// key: compiler.err.invalid.containedby.annotation.no.value 48.28 + 48.29 +import java.lang.annotation.*; 48.30 + 48.31 +@ContainedBy(Annos.class) 48.32 +@interface Anno { } 48.33 + 48.34 +@ContainerFor(Anno.class) 48.35 +@interface Annos {} 48.36 + 48.37 +@Anno 48.38 +@Anno 48.39 +class ContainedByNoValue { }
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/diags/examples/ContainedByNonDefault.java Sat Sep 08 22:54:21 2012 -0700 49.3 @@ -0,0 +1,36 @@ 49.4 +/* 49.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +// key: compiler.err.invalid.containedby.annotation.elem.nondefault 49.28 + 49.29 +import java.lang.annotation.*; 49.30 + 49.31 +@ContainedBy(Annos.class) 49.32 +@interface Anno { } 49.33 + 49.34 +@ContainerFor(Anno.class) 49.35 +@interface Annos { Anno[] value(); String foo(); } 49.36 + 49.37 +@Anno 49.38 +@Anno 49.39 +class ContainedByNonDefault { }
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/diags/examples/ContainedByRetentionMismatch.java Sat Sep 08 22:54:21 2012 -0700 50.3 @@ -0,0 +1,37 @@ 50.4 +/* 50.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +// key: compiler.err.invalid.containedby.annotation.retention 50.28 + 50.29 +import java.lang.annotation.*; 50.30 + 50.31 +@Retention(RetentionPolicy.RUNTIME) 50.32 +@ContainedBy(Annos.class) 50.33 +@interface Anno { } 50.34 + 50.35 +@ContainerFor(Anno.class) 50.36 +@interface Annos { Anno[] value(); } 50.37 + 50.38 +@Anno 50.39 +@Anno 50.40 +class ContainedByRetentionMismatch { }
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/diags/examples/ContainedByTargetMismatch.java Sat Sep 08 22:54:21 2012 -0700 51.3 @@ -0,0 +1,35 @@ 51.4 +/* 51.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +// key: compiler.err.invalid.containedby.annotation.incompatible.target 51.28 + 51.29 +import java.lang.annotation.*; 51.30 + 51.31 +@ContainedBy(Annos.class) 51.32 +@Target(ElementType.METHOD) 51.33 +@interface Anno { } 51.34 + 51.35 +@ContainerFor(Anno.class) 51.36 +@interface Annos { Anno[] value(); } 51.37 + 51.38 +class ContainedByTargetMismatch { }
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/tools/javac/diags/examples/ContainedByWrongValueType.java Sat Sep 08 22:54:21 2012 -0700 52.3 @@ -0,0 +1,36 @@ 52.4 +/* 52.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. 52.11 + * 52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.15 + * version 2 for more details (a copy is included in the LICENSE file that 52.16 + * accompanied this code). 52.17 + * 52.18 + * You should have received a copy of the GNU General Public License version 52.19 + * 2 along with this work; if not, write to the Free Software Foundation, 52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.21 + * 52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.23 + * or visit www.oracle.com if you need additional information or have any 52.24 + * questions. 52.25 + */ 52.26 + 52.27 +// key: compiler.err.invalid.containedby.annotation.value.return 52.28 + 52.29 +import java.lang.annotation.*; 52.30 + 52.31 +@ContainedBy(Annos.class) 52.32 +@interface Anno { } 52.33 + 52.34 +@ContainerFor(Anno.class) 52.35 +@interface Annos { String value(); } 52.36 + 52.37 +@Anno 52.38 +@Anno 52.39 +class ContainedByWrongValueType { }
53.1 --- a/test/tools/javac/diags/examples/DuplicateAnnotation.java Sat Sep 08 22:43:38 2012 -0700 53.2 +++ b/test/tools/javac/diags/examples/DuplicateAnnotation.java Sat Sep 08 22:54:21 2012 -0700 53.3 @@ -1,5 +1,5 @@ 53.4 /* 53.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 53.6 + * Copyright (c) 2010, 2012 Oracle and/or its affiliates. All rights reserved. 53.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.8 * 53.9 * This code is free software; you can redistribute it and/or modify it 53.10 @@ -22,6 +22,8 @@ 53.11 */ 53.12 53.13 // key: compiler.err.duplicate.annotation 53.14 +// key: compiler.warn.source.no.bootclasspath 53.15 +// options: -source 7 53.16 53.17 @interface Anno { } 53.18
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javac/diags/examples/DuplicateAnnotationJava8.java Sat Sep 08 22:54:21 2012 -0700 54.3 @@ -0,0 +1,30 @@ 54.4 +/* 54.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +// key: compiler.err.duplicate.annotation.missing.container 54.28 + 54.29 +@interface Anno { } 54.30 + 54.31 +@Anno 54.32 +@Anno 54.33 +class DuplicateAnnotationJava8 { }
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javac/diags/examples/RepeatingAnnotationAndContainer.java Sat Sep 08 22:54:21 2012 -0700 55.3 @@ -0,0 +1,37 @@ 55.4 +/* 55.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +// key: compiler.err.invalid.containedby.annotation.repeated.and.container.present 55.28 + 55.29 +import java.lang.annotation.*; 55.30 + 55.31 +@ContainedBy(Annos.class) 55.32 +@interface Anno { } 55.33 + 55.34 +@ContainerFor(Anno.class) 55.35 +@interface Annos { Anno[] value(); } 55.36 + 55.37 +@Anno 55.38 +@Anno 55.39 +@Annos(@Anno) 55.40 +class RepeatingAnnotationAndContainer { }
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/tools/javac/diags/examples/WrongContainedBy.java Sat Sep 08 22:54:21 2012 -0700 56.3 @@ -0,0 +1,35 @@ 56.4 +/* 56.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. 56.11 + * 56.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.15 + * version 2 for more details (a copy is included in the LICENSE file that 56.16 + * accompanied this code). 56.17 + * 56.18 + * You should have received a copy of the GNU General Public License version 56.19 + * 2 along with this work; if not, write to the Free Software Foundation, 56.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.21 + * 56.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.23 + * or visit www.oracle.com if you need additional information or have any 56.24 + * questions. 56.25 + */ 56.26 + 56.27 +// key: compiler.err.invalid.container.no.containerfor 56.28 +// key: compiler.err.invalid.container.wrong.containedby 56.29 + 56.30 +import java.lang.annotation.*; 56.31 + 56.32 +@ContainerFor(WrongContainedBy.class) 56.33 +@interface Foos { 56.34 + WrongContainedBy[] value(); 56.35 +} 56.36 + 56.37 +@ContainedBy(Target.class) 56.38 +public @interface WrongContainedBy {}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/test/tools/javac/diags/examples/WrongContainerFor.java Sat Sep 08 22:54:21 2012 -0700 57.3 @@ -0,0 +1,35 @@ 57.4 +/* 57.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. 57.11 + * 57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.15 + * version 2 for more details (a copy is included in the LICENSE file that 57.16 + * accompanied this code). 57.17 + * 57.18 + * You should have received a copy of the GNU General Public License version 57.19 + * 2 along with this work; if not, write to the Free Software Foundation, 57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.21 + * 57.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 57.23 + * or visit www.oracle.com if you need additional information or have any 57.24 + * questions. 57.25 + */ 57.26 + 57.27 +// key: compiler.err.invalid.container.wrong.containerfor 57.28 +// key: compiler.err.invalid.container.no.containedby 57.29 + 57.30 +import java.lang.annotation.*; 57.31 + 57.32 +@ContainerFor(Retention.class) 57.33 +@interface Foos { 57.34 + WrongContainerFor[] value(); 57.35 +} 57.36 + 57.37 +@ContainedBy(Foos.class) 57.38 +public @interface WrongContainerFor {}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/test/tools/javah/T7185778.java Sat Sep 08 22:54:21 2012 -0700 58.3 @@ -0,0 +1,56 @@ 58.4 +/* 58.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 + * 58.8 + * This code is free software; you can redistribute it and/or modify it 58.9 + * under the terms of the GNU General Public License version 2 only, as 58.10 + * published by the Free Software Foundation. 58.11 + * 58.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 58.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.15 + * version 2 for more details (a copy is included in the LICENSE file that 58.16 + * accompanied this code). 58.17 + * 58.18 + * You should have received a copy of the GNU General Public License version 58.19 + * 2 along with this work; if not, write to the Free Software Foundation, 58.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.21 + * 58.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 58.23 + * or visit www.oracle.com if you need additional information or have any 58.24 + * questions. 58.25 + */ 58.26 + 58.27 +/* 58.28 + * @test 58.29 + * @bug 7185778 58.30 + * @summary javah error "Not a valid class name" on class names with dollar signs 58.31 + * The first two tests are on an inner class name whose name does not contain $. 58.32 + * The second two tests are on an inner class name whose name does contain $. 58.33 + * The last test is on an outer class whose name contains $. 58.34 + * @run main T7185778 T7185778$inner 58.35 + * @run main T7185778 T7185778.inner 58.36 + * @run main T7185778 T7185778$inner$ 58.37 + * @run main T7185778 T7185778.inner$ 58.38 + * @run main T7185778 xx$yy 58.39 + */ 58.40 + 58.41 +public class T7185778 { 58.42 + class inner { 58.43 + native byte[] xxxxx(String name); 58.44 + } 58.45 + class inner$ { 58.46 + native byte[] xxxxx(String name); 58.47 + } 58.48 + 58.49 + static public void main(String[] args) { 58.50 + int rc = com.sun.tools.javah.Main.run(args, null); 58.51 + if ( rc != 0) { 58.52 + throw new Error("javah returned non zero: " + rc); 58.53 + } 58.54 + } 58.55 +} 58.56 + 58.57 +class xx$yy { 58.58 + native byte[] xxxxx(String name); 58.59 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/test/tools/javap/T7186925.java Sat Sep 08 22:54:21 2012 -0700 59.3 @@ -0,0 +1,78 @@ 59.4 +/* 59.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. 59.11 + * 59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.15 + * version 2 for more details (a copy is included in the LICENSE file that 59.16 + * accompanied this code). 59.17 + * 59.18 + * You should have received a copy of the GNU General Public License version 59.19 + * 2 along with this work; if not, write to the Free Software Foundation, 59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.21 + * 59.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 59.23 + * or visit www.oracle.com if you need additional information or have any 59.24 + * questions. 59.25 + */ 59.26 + 59.27 +/* 59.28 + * @test 59.29 + * @bug 7186925 59.30 + * @summary JavapTask passes null to java.io.Writer 59.31 + */ 59.32 + 59.33 +import java.io.*; 59.34 +import java.util.*; 59.35 +import javax.tools.*; 59.36 +import com.sun.tools.javap.*; 59.37 + 59.38 +public class T7186925 59.39 +{ 59.40 + public static void main(String... args) { 59.41 + new T7186925().run(); 59.42 + } 59.43 + 59.44 + void run() { 59.45 + verify("java.lang.Object"); 59.46 + if (errors > 0) 59.47 + throw new Error(errors + " found."); 59.48 + } 59.49 + 59.50 + void verify(String className) { 59.51 + try { 59.52 + JavaFileManager fileManager = JavapFileManager.create(null, null); 59.53 + JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); 59.54 + if (fo == null) { 59.55 + error("Can't find " + className); 59.56 + } else { 59.57 + JavapTask t = new JavapTask(null, fileManager, null); 59.58 + t.handleOptions(new String[] { "-sysinfo", className }); 59.59 + JavapTask.ClassFileInfo cfInfo = t.read(fo); 59.60 + expectEqual(cfInfo.cf.byteLength(), cfInfo.size); 59.61 + } 59.62 + } catch (NullPointerException ee) { 59.63 + ee.printStackTrace(); 59.64 + error("Exception: " + ee); 59.65 + } catch (Exception ee) { 59.66 + System.err.println("Caught exception: " + ee); 59.67 + } 59.68 + } 59.69 + 59.70 + void expectEqual(int found, int expected) { 59.71 + if (found != expected) 59.72 + error("bad value found: " + found + " expected: " + expected); 59.73 + } 59.74 + 59.75 + void error(String msg) { 59.76 + System.err.println(msg); 59.77 + errors++; 59.78 + } 59.79 + 59.80 + int errors; 59.81 +}