OpenJDK / type-annotations / type-annotations / langtools
changeset 2840:33b2650c7c31
Automated merge with http://hg.openjdk.java.net/jdk8/tl/langtools
author | wmdietl |
---|---|
date | Sat, 07 Sep 2013 15:40:19 -0700 |
parents | e84587462a47 a8c716a4a39f |
children | 72fbc57f0919 |
files | .hgtags src/share/classes/com/sun/tools/javac/comp/Lower.java src/share/classes/com/sun/tools/javac/jvm/Gen.java |
diffstat | 16 files changed, 605 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Fri Sep 06 17:10:02 2013 -0700 +++ b/.hgtags Sat Sep 07 15:40:19 2013 -0700 @@ -140,6 +140,7 @@ 1cbe86c11ba69521875c0b0357d7540781eb334d jdk8-b17 ec2c0973cc31e143cffc05ceb63d98fae76f97d4 jdk8-b16 ab1b1cc7857716914f2bb20b3128e5a8978290f7 jdk8-b18 +2a2d6ac056cfde7326f309ab73b8cddf518cc729 308-jdk8-sync 77b2c066084cbc75150efc6603a713c558329813 jdk8-b19 ffd294128a48cbb90ce8f0569f82b61f1f164a18 jdk8-b20 bcb21abf1c4177baf4574f99709513dcd4474727 jdk8-b21
--- a/make/build.properties Fri Sep 06 17:10:02 2013 -0700 +++ b/make/build.properties Sat Sep 07 15:40:19 2013 -0700 @@ -167,7 +167,7 @@ sjavac.tests = \ tools/sjavac - + # # The following files require the latest JDK to be available.
--- a/make/build.xml Fri Sep 06 17:10:02 2013 -0700 +++ b/make/build.xml Sat Sep 07 15:40:19 2013 -0700 @@ -89,7 +89,7 @@ build-classes-TOOL build the classes for the tool build-TOOL build the jar file and script for the tool jtreg-TOOL build the tool and run the appropriate tests - findbugs-TOOL run findbugs on the tool's source oode + findbugs-TOOL run findbugs on the tool's source code TOOL build the tool, run the tests, and run findbugs - utility definitions -->
--- a/src/share/classes/com/sun/tools/javac/code/Type.java Fri Sep 06 17:10:02 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Sat Sep 07 15:40:19 2013 -0700 @@ -219,6 +219,10 @@ public Type baseType() { return this; } + + public Type annotatedType(List<Attribute.TypeCompound> annos) { + return new AnnotatedType(annos, this); + } public boolean isAnnotated() { return false; @@ -233,7 +237,7 @@ } @Override - public List<? extends Attribute.TypeCompound> getAnnotationMirrors() { + public List<Attribute.TypeCompound> getAnnotationMirrors() { return List.nil(); } @@ -1837,7 +1841,7 @@ } @Override - public List<? extends Attribute.TypeCompound> getAnnotationMirrors() { + public List<Attribute.TypeCompound> getAnnotationMirrors() { return typeAnnotations; } @@ -1970,10 +1974,8 @@ public TypeMirror getComponentType() { return ((ArrayType)underlyingType).getComponentType(); } // The result is an ArrayType, but only in the model sense, not the Type sense. - public AnnotatedType makeVarargs() { - AnnotatedType atype = new AnnotatedType(((ArrayType)underlyingType).makeVarargs()); - atype.typeAnnotations = this.typeAnnotations; - return atype; + public Type makeVarargs() { + return ((ArrayType) underlyingType).makeVarargs().annotatedType(typeAnnotations); } @Override
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Fri Sep 06 17:10:02 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Sat Sep 07 15:40:19 2013 -0700 @@ -360,25 +360,15 @@ return type; } if (type.hasTag(TypeTag.ARRAY)) { + Type.ArrayType arType = (Type.ArrayType) type.unannotatedType(); + Type.ArrayType tomodify = new Type.ArrayType(null, arType.tsym); Type toreturn; - Type.ArrayType tomodify; - Type.ArrayType arType; - { - Type touse = type; - if (type.isAnnotated()) { - Type.AnnotatedType atype = (Type.AnnotatedType)type; - toreturn = new Type.AnnotatedType(atype.underlyingType); - ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations; - touse = atype.underlyingType; - arType = (Type.ArrayType) touse; - tomodify = new Type.ArrayType(null, arType.tsym); - ((Type.AnnotatedType)toreturn).underlyingType = tomodify; - } else { - arType = (Type.ArrayType) touse; - tomodify = new Type.ArrayType(null, arType.tsym); - toreturn = tomodify; - } + if (type.isAnnotated()) { + toreturn = tomodify.annotatedType(type.getAnnotationMirrors()); + } else { + toreturn = tomodify; } + JCArrayTypeTree arTree = arrayTypeTree(typetree); ListBuffer<TypePathEntry> depth = ListBuffer.lb(); @@ -386,9 +376,8 @@ while (arType.elemtype.hasTag(TypeTag.ARRAY)) { if (arType.elemtype.isAnnotated()) { Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype; - Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType); + Type.AnnotatedType newAT = (Type.AnnotatedType) aelemtype.underlyingType.annotatedType(arType.elemtype.getAnnotationMirrors()); tomodify.elemtype = newAT; - newAT.typeAnnotations = aelemtype.typeAnnotations; arType = (Type.ArrayType) aelemtype.underlyingType; tomodify = new Type.ArrayType(null, arType.tsym); newAT.underlyingType = tomodify; @@ -542,7 +531,7 @@ // assert that t.constValue() == null? if (t == stopAt || t.getEnclosingType() == Type.noType) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } else { ClassType ret = new ClassType(t.getEnclosingType().accept(this, s), t.typarams_field, t.tsym); @@ -557,12 +546,12 @@ @Override public Type visitAnnotatedType(AnnotatedType t, List<TypeCompound> s) { - return new AnnotatedType(t.typeAnnotations, t.underlyingType.accept(this, s)); + return t.underlyingType.accept(this, s).annotatedType(t.typeAnnotations); } @Override public Type visitWildcardType(WildcardType t, List<TypeCompound> s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override @@ -585,12 +574,12 @@ @Override public Type visitTypeVar(TypeVar t, List<TypeCompound> s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override public Type visitCapturedType(CapturedType t, List<TypeCompound> s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override @@ -607,12 +596,12 @@ @Override public Type visitErrorType(ErrorType t, List<TypeCompound> s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } @Override public Type visitType(Type t, List<TypeCompound> s) { - return new AnnotatedType(s, t); + return t.annotatedType(s); } };
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Fri Sep 06 17:10:02 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Sat Sep 07 15:40:19 2013 -0700 @@ -2216,7 +2216,7 @@ // on the bound. erased = ((AnnotatedType)erased).underlyingType; } - return new AnnotatedType(t.typeAnnotations, erased); + return erased.annotatedType(t.typeAnnotations); } };
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Sep 06 17:10:02 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Sep 07 15:40:19 2013 -0700 @@ -3963,7 +3963,7 @@ TypeVar typeVar = (TypeVar) tree.type; if (tree.annotations != null && tree.annotations.nonEmpty()) { - AnnotatedType antype = new AnnotatedType(typeVar); + Type antype = typeVar.annotatedType(List.<Attribute.TypeCompound>nil()); annotateType(antype, tree.annotations); tree.type = antype; } @@ -4066,7 +4066,7 @@ public void visitAnnotatedType(JCAnnotatedType tree) { Type underlyingType = attribType(tree.getUnderlyingType(), env); this.attribAnnotationTypes(tree.annotations, env); - AnnotatedType antype = new AnnotatedType(underlyingType); + Type antype = underlyingType.annotatedType(List.<Attribute.TypeCompound>nil()); annotateType(antype, tree.annotations); result = tree.type = antype; } @@ -4074,7 +4074,8 @@ /** * Apply the annotations to the particular type. */ - public void annotateType(final AnnotatedType type, final List<JCAnnotation> annotations) { + public void annotateType(final Type type, final List<JCAnnotation> annotations) { + Assert.check(type instanceof AnnotatedType); if (annotations.isEmpty()) return; annotate.typeAnnotation(new Annotate.Annotator() { @@ -4085,7 +4086,7 @@ @Override public void enterAnnotation() { List<Attribute.TypeCompound> compounds = fromAnnotations(annotations); - type.typeAnnotations = compounds; + ((AnnotatedType) type).typeAnnotations = compounds; } }); }
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Sep 06 17:10:02 2013 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Sat Sep 07 15:40:19 2013 -0700 @@ -2811,8 +2811,7 @@ } else { // Create a new AnnotatedType to have the correct tag. AnnotatedType oldat = (AnnotatedType) tree.type; - tree.type = new AnnotatedType(tree.underlyingType.type); - ((AnnotatedType) tree.type).typeAnnotations = oldat.typeAnnotations; + tree.type = tree.underlyingType.type.annotatedType(oldat.typeAnnotations); } } result = tree;
--- a/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java Fri Sep 06 17:10:02 2013 -0700 +++ b/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java Sat Sep 07 15:40:19 2013 -0700 @@ -51,24 +51,12 @@ {BUG_ID + FS + "pkg" + FS + "T0x06.html", "@DA"}, {BUG_ID + FS + "pkg" + FS + "T0x0B.html", "@DA"}, {BUG_ID + FS + "pkg" + FS + "T0x0F.html", "@DA"}, - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x20.html", "@DA"}, - */ - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x20A.html", "@DTPA"}, - */ - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x20B.html", "@DA"}, - */ - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x22.html", "@DA"}, - */ - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x22A.html", "@DTPA"}, - */ - /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java {BUG_ID + FS + "pkg" + FS + "T0x22B.html", "@DA"}, - */ {BUG_ID + FS + "pkg" + FS + "T0x10.html", "@DA"}, {BUG_ID + FS + "pkg" + FS + "T0x10A.html", "@DA"}, {BUG_ID + FS + "pkg" + FS + "T0x12.html", "@DA"},
--- a/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java Fri Sep 06 17:10:02 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java Sat Sep 07 15:40:19 2013 -0700 @@ -24,7 +24,6 @@ /* * @test * @bug 8008762 - * @ignore 8013409: test failures for type annotations * @summary Type annotation on inner class in anonymous class * shows up as regular annotation */ @@ -62,12 +61,12 @@ static class Test { Object mtest( Test t){ return null; } public void test() { - mtest( new Test() { + mtest( new Test() { class InnerAnon { // Test1$1$InnerAnon.class - @A @B String ai_data = null; - @A @B String ai_m(){ return null; }; + @A @B String ai_data = null; + @A @B String ai_m(){ return null; }; } - InnerAnon IA = new InnerAnon(); + InnerAnon IA = new InnerAnon(); }); } @Retention(RUNTIME) @Target(TYPE_USE) @interface A { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java Sat Sep 07 15:40:19 2013 -0700 @@ -0,0 +1,414 @@ +/* + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8005085 8008762 8008751 8013065 8015323 8015257 + * @summary Type annotations on anonymous and inner class. + * Six TYPE_USE annotations are repeated(or not); Four combinations create + * four test files, and each results in the test class and 2 anonymous classes. + * Each element of these three classes is checked for expected number of the + * four annotation Attributes. Expected annotation counts depend on type of + * annotation place on type of element (a FIELD&TYPE_USE element on a field + * results in 2). Elements with no annotations expect 0. + * Source template is read in from testanoninner.template + * + */ +import java.lang.annotation.*; +import java.io.*; +import java.util.List; +import com.sun.tools.classfile.*; +import java.nio.file.Files; +import java.nio.charset.*; +import java.io.File; +import java.io.IOException; + + +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; + +/* + * A source template is read in and testname and annotations are inserted + * via replace(). + */ +public class TestAnonInnerClasses extends ClassfileTestHelper { + // tally errors and test cases + int errors = 0; + int checks = 0; + //Note expected test count in case of skips due to bugs. + int tc = 0, xtc = 180; // 45 x 4 variations of repeated annotations. + File testSrc = new File(System.getProperty("test.src")); + + String[] AnnoAttributes = { + Attribute.RuntimeVisibleTypeAnnotations, + Attribute.RuntimeInvisibleTypeAnnotations, + Attribute.RuntimeVisibleAnnotations, + Attribute.RuntimeInvisibleAnnotations + }; + + // template for source files + String srcTemplate = "testanoninner.template"; + + // Four test files generated based on combinations of repeating annotations. + Boolean As= false, Bs=true, Cs=false, Ds=false, TAs=false,TBs=false; + Boolean [][] bRepeat = new Boolean[][]{ + /* no repeats */ {false, false, false, false, false, false}, + /* repeat A,C,TA */ {true, false, true, false, true, false}, + /* repeat B,D,TB */ {false, true, false, true, false, true}, + /* repeat all */ {true, true, true, true, true, true} + }; + // Save descriptions of failed test case; does not terminate upon a failure. + List<String> failed = new java.util.LinkedList<>(); + + public static void main(String[] args) throws Exception { + new TestAnonInnerClasses().run(); + } + + // Check annotation counts and make reports sufficiently descriptive to + // easily diagnose. + void check(String testcase, int vtaX, int itaX, int vaX, int iaX, + int vtaA, int itaA, int vaA, int iaA) { + + String descr = " checking " + testcase+" _TYPE_, expected: " + + vtaX + ", " + itaX + ", " + vaX + ", " + iaX + "; actual: " + + vtaA + ", " + itaA + ", " + vaA + ", " + iaA; + String description; + description=descr.replace("_TYPE_","RuntimeVisibleTypeAnnotations"); + if(vtaX != vtaA) { + errors++; + failed.add(++checks + " " + testcase + ": (vtaX) " + vtaX + + " != " + vtaA + " (vtaA)"); + println(checks + " FAIL: " + description); + } else println(++checks + " PASS: " + description); + description=descr.replace("_TYPE_","RuntimeInvisibleTypeAnnotations"); + if(itaX != itaA) { + errors++; + failed.add(++checks + " " + testcase + ": (itaX) " + itaX + " != " + + itaA + " (itaA)"); + println(checks + " FAIL: " + description); + } else println(++checks + " PASS: " + description); + description=descr.replace("_TYPE_","RuntimeVisibleAnnotations"); + if(vaX != vaA) { + errors++; + failed.add(++checks + " " + testcase + ": (vaX) " + vaX + " != " + + vaA + " (vaA)"); + println(checks + " FAIL: " + description); + } else println(++checks + " PASS: " + description); + description=descr.replace("_TYPE_","RuntimeInvisibleAnnotations"); + if(iaX != iaA) { + errors++; + failed.add(++checks + " " + testcase + ": (iaX) " + iaX + " != " + + iaA + " (iaA)"); + println(checks + " FAIL: " + description); + } else println(++checks + " PASS: " + description); + println(""); + } + + // Print failed cases (if any) and throw exception for fail. + void report() { + if(errors!=0) { + System.err.println("Failed tests: " + errors + + "\nfailed test cases:\n"); + for(String t: failed) System.err.println(" " + t); + throw new RuntimeException("FAIL: There were test failures."); + } else + System.out.println("PASSED all tests."); + } + + void test(String ttype, ClassFile cf, Method m, Field f, boolean visible) { + int vtaActual = 0, itaActual = 0, vaActual = 0, iaActual = 0, + vtaExp = 0, itaExp = 0, vaExp = 0, iaExp = 0, + index = 0, index2 = 0; + String memberName = null, testcase = "undefined", testClassName = null; + Attribute attr = null, cattr = null; + Code_attribute CAttr = null; + // Get counts of 4 annotation Attributes on element being checked. + for (String AnnoType : AnnoAttributes) { + try { + switch(ttype) { + case "METHOD": + index = m.attributes.getIndex(cf.constant_pool, + AnnoType); + memberName = m.getName(cf.constant_pool); + if(index != -1) + attr = m.attributes.get(index); + //fetch index annotations from code attribute. + index2 = m.attributes.getIndex(cf.constant_pool, + Attribute.Code); + if(index2 != -1) { + cattr = m.attributes.get(index2); + assert cattr instanceof Code_attribute; + CAttr = (Code_attribute)cattr; + index2 = CAttr.attributes.getIndex(cf.constant_pool, + AnnoType); + if(index2 != -1) + cattr = CAttr.attributes.get(index2); + } + break; + case "FIELD": + index = f.attributes.getIndex(cf.constant_pool, + AnnoType); + memberName = f.getName(cf.constant_pool); + if(index != -1) + attr = f.attributes.get(index); + //fetch index annotations from code attribute. + index2 = cf.attributes.getIndex(cf.constant_pool, + Attribute.Code); + if(index2!= -1) { + cattr = cf.attributes.get(index2); + assert cattr instanceof Code_attribute; + CAttr = (Code_attribute)cattr; + index2 = CAttr.attributes.getIndex(cf.constant_pool, + AnnoType); + if(index2!= -1) + cattr = CAttr.attributes.get(index2); + } + break; + + default: + memberName = cf.getName(); + index = cf.attributes.getIndex(cf.constant_pool, + AnnoType); + if(index!= -1) attr = cf.attributes.get(index); + break; + } + } catch(ConstantPoolException cpe) { cpe.printStackTrace(); } + try { + testClassName=cf.getName(); + testcase = ttype + ": " + testClassName + ": " + + memberName + ", "; + } catch(ConstantPoolException cpe) { cpe.printStackTrace(); } + if(index != -1) { + switch(AnnoType) { + case Attribute.RuntimeVisibleTypeAnnotations: + //count RuntimeVisibleTypeAnnotations + RuntimeVisibleTypeAnnotations_attribute RVTAa = + (RuntimeVisibleTypeAnnotations_attribute)attr; + vtaActual += RVTAa.annotations.length; + break; + case Attribute.RuntimeVisibleAnnotations: + //count RuntimeVisibleAnnotations + RuntimeVisibleAnnotations_attribute RVAa = + (RuntimeVisibleAnnotations_attribute)attr; + vaActual += RVAa.annotations.length; + break; + case Attribute.RuntimeInvisibleTypeAnnotations: + //count RuntimeInvisibleTypeAnnotations + RuntimeInvisibleTypeAnnotations_attribute RITAa = + (RuntimeInvisibleTypeAnnotations_attribute)attr; + itaActual += RITAa.annotations.length; + break; + case Attribute.RuntimeInvisibleAnnotations: + //count RuntimeInvisibleAnnotations + RuntimeInvisibleAnnotations_attribute RIAa = + (RuntimeInvisibleAnnotations_attribute)attr; + iaActual += RIAa.annotations.length; + break; + } + } + // annotations from code attribute. + if(index2 != -1) { + switch(AnnoType) { + case Attribute.RuntimeVisibleTypeAnnotations: + //count RuntimeVisibleTypeAnnotations + RuntimeVisibleTypeAnnotations_attribute RVTAa = + (RuntimeVisibleTypeAnnotations_attribute)cattr; + vtaActual += RVTAa.annotations.length; + break; + case Attribute.RuntimeVisibleAnnotations: + //count RuntimeVisibleAnnotations + RuntimeVisibleAnnotations_attribute RVAa = + (RuntimeVisibleAnnotations_attribute)cattr; + vaActual += RVAa.annotations.length; + break; + case Attribute.RuntimeInvisibleTypeAnnotations: + //count RuntimeInvisibleTypeAnnotations + RuntimeInvisibleTypeAnnotations_attribute RITAa = + (RuntimeInvisibleTypeAnnotations_attribute)cattr; + itaActual += RITAa.annotations.length; + break; + case Attribute.RuntimeInvisibleAnnotations: + //count RuntimeInvisibleAnnotations + RuntimeInvisibleAnnotations_attribute RIAa = + (RuntimeInvisibleAnnotations_attribute)cattr; + iaActual += RIAa.annotations.length; + break; + } + } + } + + switch ( memberName ) { + //METHODs + case "test" : vtaExp=4; itaExp=4; vaExp=0; iaExp=0; tc++; break; + case "mtest": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "m1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "m2": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "m3": vtaExp=10; itaExp=10; vaExp=1; iaExp=1; tc++; break; + case "tm": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //inner class + case "i_m1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "i_m2": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "i_um": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //local class + case "l_m1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "l_m2": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "l_um": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //anon class + case "mm_m1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "mm_m2": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "mm_m3": vtaExp=10; itaExp=10;vaExp=1; iaExp=1; tc++; break; + case "mm_tm": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //InnerAnon class + case "ia_m1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "ia_m2": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "ia_um": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //FIELDs + case "data": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "odata1": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "pdata1": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "tdata": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "sa1": vtaExp = 6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + //inner class + case "i_odata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "i_pdata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "i_udata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "i_sa1": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + case "i_tdata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + //local class + case "l_odata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "l_pdata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "l_udata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "l_sa1": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + case "l_tdata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + //anon class + case "mm_odata1": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "mm_pdata1": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "mm_sa1": vtaExp = 6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + case "mm_tdata": vtaExp = 2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + // InnerAnon class + case "ia_odata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "ia_pdata1": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "ia_udata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "ia_sa1": vtaExp=6; itaExp=6; vaExp=1; iaExp=1; tc++; break; + case "ia_tdata": vtaExp=2; itaExp=2; vaExp=1; iaExp=1; tc++; break; + case "IA": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + case "IN": vtaExp=4; itaExp=4; vaExp=1; iaExp=1; tc++; break; + // default cases are <init>, this$0, this$1, mmtest, atest + default: vtaExp = 0; itaExp=0; vaExp=0; iaExp=0; break; + } + check(testcase,vtaExp, itaExp, vaExp, iaExp, + vtaActual,itaActual,vaActual,iaActual); + } + + public void run() { + ClassFile cf = null; + InputStream in = null; + int testcount = 1; + File testFile = null; + // Generate source, check methods and fields for each combination. + for(Boolean[] bCombo : bRepeat) { + As=bCombo[0]; Bs=bCombo[1]; Cs=bCombo[2]; + Ds=bCombo[3]; TAs=bCombo[4]; TBs=bCombo[5]; + String testname = "Test" + testcount++; + println("Combinations: " + As + ", " + Bs + ", " + Cs + ", " + Ds + + ", " + TAs + ", " + TBs + + "; see " + testname + ".java"); + String[] classes = {testname + ".class", + testname + "$Inner.class", + testname + "$1Local1.class", + testname + "$1.class", + testname + "$1$1.class", + testname + "$1$InnerAnon.class" + }; + // Create test source, create and compile File. + String sourceString = getSource(srcTemplate, testname, + As, Bs, Cs, Ds, TAs, TBs); + System.out.println(sourceString); + try { + testFile = writeTestFile(testname+".java", sourceString); + } catch( java.io.IOException ioe) { ioe.printStackTrace(); } + // Compile test source and read classfile. + File classFile = null; + try { + classFile = compile(testFile); + } catch (Error err) { + System.err.println("FAILED compile. Source:\n" + sourceString); + throw err; + } + String testloc = classFile.getAbsolutePath().substring( + 0,classFile.getAbsolutePath().indexOf(classFile.getPath())); + for(String clazz : classes) { + try { + cf = ClassFile.read(new File(testloc+clazz)); + } catch(Exception e) { e.printStackTrace(); } + // Test for all methods and fields + for (Method m: cf.methods) { + test("METHOD", cf, m, null, true); + } + for (Field f: cf.fields) { + test("FIELD", cf, null, f, true); + } + } + } + report(); + if(tc!=xtc) System.out.println("Test Count: " + tc + " != " + + "expected: " + xtc); + } + + + String getSrcTemplate(String sTemplate) { + List<String> tmpl = null; + String sTmpl = ""; + try { + tmpl = Files.readAllLines( new File(testSrc,sTemplate).toPath(), + Charset.defaultCharset()); + } catch ( IOException ioe ) { + String error = "FAILED: Test failed to read template" + sTemplate; + ioe.printStackTrace(); + throw new RuntimeException(error); + } + for(String l : tmpl) + sTmpl=sTmpl.concat(l).concat("\n"); + return sTmpl; + } + + // test class template + String getSource(String templateName, String testname, + Boolean Arepeats, Boolean Brepeats, + Boolean Crepeats, Boolean Drepeats, + Boolean TArepeats, Boolean TBrepeats ) { + String As = Arepeats ? "@A @A":"@A", + Bs = Brepeats ? "@B @B":"@B", + Cs = Crepeats ? "@C @C":"@C", + Ds = Drepeats ? "@D @D":"@D", + TAs = TArepeats ? "@TA @TA":"@TA", + TBs = TBrepeats ? "@TB @TB":"@TB"; + + // split up replace() lines for readability + String testsource = getSrcTemplate(templateName).replace("testname",testname); + testsource = testsource.replace("_As",As).replace("_Bs",Bs).replace("_Cs",Cs); + testsource = testsource.replace("_Ds",Ds).replace("_TAs",TAs).replace("_TBs",TBs); + return testsource; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/testanoninner.template Sat Sep 07 15:40:19 2013 -0700 @@ -0,0 +1,108 @@ +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; +import java.util.List; + +class testname <T> { // TestN.class + _As _Bs _Cs _Ds String data = "test"; + _As _Bs _Cs _Ds Object mtest( _As _Bs _Cs _Ds testname <T> t){ return null; } + Object mmtest( testname<T> t){ return null; } + + class Inner<U> { // TestN$1$Inner.class + _As _Bs _Cs _Ds String i_odata1 = "test"; + _As _Bs _Cs _Ds int i_pdata1 = 0; + _As _Bs _Cs _Ds U i_udata = null; +//8015257 + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds [] _As _Bs _Cs _Ds [] i_sa1 = null; + _As _Bs _Cs _Ds T i_tdata = null; + _As _Bs _Cs _Ds String i_m1(){ return null; }; + _As _Bs _Cs _Ds int i_m2( _As _Bs _Cs _Ds Object o){return 0;} + _As _Bs _Cs _Ds + <_TAs _TBs _Cs _Ds U> Object i_um( _As _Bs _Cs _Ds U u) { return null; } + } +//8015323 + _As _Bs _Cs _Ds Inner< _As _Bs _Cs _Ds String> IN = new Inner< String>(); + + public void test() { + + class Local1<U> { // TestN$Local1.class + _As _Bs _Cs _Ds String l_odata1 = "test"; + _As _Bs _Cs _Ds int l_pdata1 = 0; + _As _Bs _Cs _Ds U l_udata = null; +//8015257 + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] l_sa1 = null; + _TAs _TBs _Cs _Ds T l_tdata = null; + _As _Bs _Cs _Ds String l_m1(){ return null; }; + _As _Bs _Cs _Ds int l_m2(_As _Bs _Cs _Ds Object o){return 0;} + _As _Bs _Cs _Ds + <_TAs _TBs _Cs _Ds U> Object l_um(_As _Bs _Cs _Ds U u) { return null; } + } + // The below, as a local variable, will show up on test() + _As _Bs _Cs _Ds Local1<_As _Bs _Cs _Ds String> LC = new Local1<String>(); + + mtest( new testname<T>() { // TestN$1 + class InnerAnon<U> { // TestN$1$InnerAnon.class + _As _Bs _Cs _Ds String ia_odata1 = "test"; + _As _Bs _Cs _Ds int ia_pdata1 = 0; + _As _Bs _Cs _Ds U ia_udata = null; +//8015257 + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] ia_sa1 = null; + _TAs _TBs _Cs _Ds T ia_tdata = null; + _As _Bs _Cs _Ds String ia_m1(){ return null; }; + _As _Bs _Cs _Ds int ia_m2(_As _Bs _Cs _Ds Object o){return 0;} + _As _Bs _Cs _Ds + <_TAs _TBs _Cs _Ds U> Object ia_um(_As _Bs _Cs _Ds U u) { return null; } + } +//8015257 + _As _Bs _Cs _Ds InnerAnon<_As _Bs _Cs _Ds String> IA = new InnerAnon< String>(); + + _As _Bs _Cs _Ds String odata1 = "test"; + _As _Bs _Cs _Ds int pdata1 = 0; +//8015257 + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] sa1 = null; + _As _Bs _Cs _Ds T tdata = null; + + _As _Bs _Cs _Ds String m1(){ return null; }; + _As _Bs _Cs _Ds int m2(_As _Bs _Cs _Ds Object o){return 0;} + + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds [] _As _Bs _Cs _Ds [] + m3(String _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] sa){ return null; } + + _As _Bs _Cs _Ds + <_TAs _TBs _Cs _Ds T> Object tm(_As _Bs _Cs _Ds T t) { return null; } + + public void atest( testname<T> t){ + t.mmtest( new testname<T>() { // TestN$1$1.class + _As _Bs _Cs _Ds String mm_odata1 = "test"; + _As _Bs _Cs _Ds int mm_pdata1 = 0; +//8015257 + _As _Bs _Cs _Ds Object _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] mm_sa1 = null; + _TAs _TBs _Cs _Ds T mm_tdata = null; + + _As _Bs _Cs _Ds String mm_m1(){ return null; }; + _As _Bs _Cs _Ds int mm_m2(_As _Bs _Cs _Ds Object o){return 0;} + + _As _Bs _Cs _Ds String _As _Bs _Cs _Ds [] _As _Bs _Cs _Ds [] + mm_m3(String _As _Bs _Cs _Ds []_As _Bs _Cs _Ds [] sa){ return null; } + + _As _Bs _Cs _Ds + <_TAs _TBs _Cs _Ds T> Object mm_tm(_As _Bs _Cs _Ds T t) { return null; } + }); + } + }); + } +} +@Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @Repeatable( AC.class ) @interface A { } +@Retention(RUNTIME) @Target({TYPE_USE,METHOD}) @Repeatable( BC.class ) @interface B { } +@Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @interface AC { A[] value(); } +@Retention(RUNTIME) @Target({TYPE_USE,METHOD}) @interface BC { B[] value(); } + +@Retention(CLASS) @Target({TYPE_USE,FIELD}) @Repeatable( CC.class ) @interface C { } +@Retention(CLASS) @Target({TYPE_USE,METHOD}) @Repeatable( DC.class ) @interface D { } +@Retention(CLASS) @Target({TYPE_USE,FIELD}) @interface CC { C[] value(); } +@Retention(CLASS) @Target({TYPE_USE,METHOD}) @interface DC { D[] value(); } + +@Retention(RUNTIME) @Target({TYPE_USE,TYPE_PARAMETER,FIELD}) @Repeatable( TAC.class ) @interface TA { } +@Retention(RUNTIME) @Target({TYPE_USE,TYPE_PARAMETER,METHOD}) @Repeatable( TBC.class ) @interface TB { } +@Retention(RUNTIME) @Target({TYPE_USE,TYPE_PARAMETER,FIELD}) @interface TAC { TA[] value(); } +@Retention(RUNTIME) @Target({TYPE_USE,TYPE_PARAMETER,METHOD}) @interface TBC { TB[] value(); }
--- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java Fri Sep 06 17:10:02 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java Sat Sep 07 15:40:19 2013 -0700 @@ -1,7 +1,6 @@ /* * @test /nodynamiccopyright/ * @bug 8006733 8006775 - * @ignore 8013409: test failures for type annotations * @summary A static outer class cannot be annotated. * @author Werner Dietl * @compile/fail/ref=CantAnnotateStaticClass.out -XDrawDiagnostics CantAnnotateStaticClass.java @@ -18,7 +17,7 @@ class Inner {} } - // 8 errors: + // Errors: @A Outer.Inner f1; @A Outer.Inner f1r() { return null; } void f1p(@A Outer.Inner p) { } @@ -33,6 +32,8 @@ Object l = (List<@A Outer.Inner>) o; } + @A CantAnnotateStaticClass . Outer fo; + // OK: @A Outer g1; List<@A Outer> g2;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/failures/TypeVariableMissingTA.java Sat Sep 07 15:40:19 2013 -0700 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 1234567 + * @summary A missing annotation type in a type variable bound + * should result in the same errors with and without an + * annotation processor. + * @author Werner Dietl + * + * @compile DummyProcessor.java + * @compile/fail/ref=TypeVariableMissingTA.out -XDrawDiagnostics TypeVariableMissingTA.java + * @compile/fail/ref=TypeVariableMissingTA.out -XDrawDiagnostics -cp . -processor DummyProcessor TypeVariableMissingTA.java + */ + +import java.lang.annotation.*; + +class TypeVariableMissingTA<T extends @MISSING Object> {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/failures/TypeVariableMissingTA.out Sat Sep 07 15:40:19 2013 -0700 @@ -0,0 +1,3 @@ +TypeVariableMissingTA.java:39:40: compiler.err.cant.resolve: kindname.class, MISSING, , +TypeVariableMissingTA.java:39:39: compiler.err.annotation.type.not.applicable +2 errors \ No newline at end of file
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java Fri Sep 06 17:10:02 2013 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java Sat Sep 07 15:40:19 2013 -0700 @@ -867,7 +867,7 @@ }) @TestClass("Test$1Nested") public String testNestedInMethod1() { - return "class Test {\n" + + return "class Test {\n" + " void foobar() {\n" + " class Nested<@TA X extends @TB Object> {\n" + " @TC List<@TD Object> f;\n" +