8013852: update reference impl for type-annotations

Tue, 14 May 2013 15:04:06 -0700

author
jjg
date
Tue, 14 May 2013 15:04:06 -0700
changeset 1755
ddb4a2bfcd82
parent 1754
0384683c64be
child 1756
53b389eb39c1

8013852: update reference impl for type-annotations
Reviewed-by: jjg
Contributed-by: wdietl@gmail.com, steve.sides@oracle.com, joel.franck@oracle.com, alex.buckley@oracle.com

src/share/classes/com/sun/tools/classfile/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/classfile/TypeAnnotation.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Annotations.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Attribute.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Printer.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Type.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Annotate.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Lower.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Code.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/Gen.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/parser/JavacParser.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/JCTree.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/Pretty.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/TreeCopier.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/TreeMaker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/TreeScanner.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/List.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/JavadocEnter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/Messager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/TypeMaker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testTypeAnnotations/TestTypeAnnotations.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/typeAnnotations/smoke/pkg/TargetTypes.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest3.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/DeadCode.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/NewTypeArguments.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/T8008769.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/T8010015.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/TypeCasts.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/classfile/Wildcards.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/LintCast.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/T8008751.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/T8009360.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/T8011722.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.out file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/newlocations/AnonymousClass.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/newlocations/Lambda.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java file | annotate | diff | comparison | revisions
test/tools/javac/annotations/typeAnnotations/referenceinfos/Test.java file | annotate | diff | comparison | revisions
test/tools/javac/api/TestJavacTaskScanner.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/ArrayAndReceiver.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/IncorrectConstructorReceiverName.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/IncorrectConstructorReceiverType.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/IncorrectReceiverName.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/ReceiverParameterNotApplicableConstructor.java file | annotate | diff | comparison | revisions
test/tools/javac/diags/examples/VarargsAndReceiver.java file | annotate | diff | comparison | revisions
test/tools/javac/lib/DPrinter.java file | annotate | diff | comparison | revisions
test/tools/javac/processing/model/type/BasicAnnoTests.java file | annotate | diff | comparison | revisions
test/tools/javac/tree/SourceTreeScannerTest.java file | annotate | diff | comparison | revisions
test/tools/javap/output/RepeatingTypeAnnotations.java file | annotate | diff | comparison | revisions
test/tools/javap/typeAnnotations/NewArray.java file | annotate | diff | comparison | revisions
test/tools/javap/typeAnnotations/Presence.java file | annotate | diff | comparison | revisions
test/tools/javap/typeAnnotations/TypeCasts.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Tue May 14 13:55:35 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/classfile/ClassWriter.java	Tue May 14 15:04:06 2013 -0700
     1.3 @@ -751,7 +751,7 @@
     1.4                  break;
     1.5              // exception parameter
     1.6              case EXCEPTION_PARAMETER:
     1.7 -                out.writeByte(p.exception_index);
     1.8 +                out.writeShort(p.exception_index);
     1.9                  break;
    1.10              // method receiver
    1.11              case METHOD_RECEIVER:
    1.12 @@ -770,11 +770,11 @@
    1.13                  break;
    1.14              // class extends or implements clause
    1.15              case CLASS_EXTENDS:
    1.16 -                out.writeByte(p.type_index);
    1.17 +                out.writeShort(p.type_index);
    1.18                  break;
    1.19              // throws
    1.20              case THROWS:
    1.21 -                out.writeByte(p.type_index);
    1.22 +                out.writeShort(p.type_index);
    1.23                  break;
    1.24              // method parameter
    1.25              case METHOD_FORMAL_PARAMETER:
     2.1 --- a/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Tue May 14 13:55:35 2013 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Tue May 14 15:04:06 2013 -0700
     2.3 @@ -111,7 +111,7 @@
     2.4              break;
     2.5          // exception parameter
     2.6          case EXCEPTION_PARAMETER:
     2.7 -            position.exception_index = cr.readUnsignedByte();
     2.8 +            position.exception_index = cr.readUnsignedShort();
     2.9              break;
    2.10          // method receiver
    2.11          case METHOD_RECEIVER:
    2.12 @@ -198,7 +198,7 @@
    2.13              break;
    2.14          // exception parameter
    2.15          case EXCEPTION_PARAMETER:
    2.16 -            n += 1; // exception_index
    2.17 +            n += 2; // exception_index
    2.18              break;
    2.19          // method receiver
    2.20          case METHOD_RECEIVER:
     3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 13:55:35 2013 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 15:04:06 2013 -0700
     3.3 @@ -1726,7 +1726,7 @@
     3.4          return text;
     3.5      }
     3.6  
     3.7 -    static Set<String> blockTags = new HashSet<String>();
     3.8 +    static final Set<String> blockTags = new HashSet<String>();
     3.9      static {
    3.10          for (HtmlTag t: HtmlTag.values()) {
    3.11              if (t.blockType == HtmlTag.BlockType.BLOCK)
    3.12 @@ -1771,7 +1771,7 @@
    3.13          return result.toString();
    3.14      }
    3.15  
    3.16 -    private static final boolean isHtmlTagLetterOrDigit(char ch) {
    3.17 +    private static boolean isHtmlTagLetterOrDigit(char ch) {
    3.18          return ('a' <= ch && ch <= 'z') ||
    3.19                  ('A' <= ch && ch <= 'Z') ||
    3.20                  ('1' <= ch && ch <= '6');
     4.1 --- a/src/share/classes/com/sun/tools/javac/code/Annotations.java	Tue May 14 13:55:35 2013 -0700
     4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Annotations.java	Tue May 14 15:04:06 2013 -0700
     4.3 @@ -76,11 +76,24 @@
     4.4      private List<Attribute.Compound> attributes = DECL_NOT_STARTED;
     4.5  
     4.6      /*
     4.7 -     * This field should never be null
     4.8 +     * Type attributes for this symbol.
     4.9 +     * This field should never be null.
    4.10       */
    4.11      private List<Attribute.TypeCompound> type_attributes = List.<Attribute.TypeCompound>nil();
    4.12  
    4.13      /*
    4.14 +     * Type attributes of initializers in this class.
    4.15 +     * Unused if the current symbol is not a ClassSymbol.
    4.16 +     */
    4.17 +    private List<Attribute.TypeCompound> init_type_attributes = List.<Attribute.TypeCompound>nil();
    4.18 +
    4.19 +    /*
    4.20 +     * Type attributes of class initializers in this class.
    4.21 +     * Unused if the current symbol is not a ClassSymbol.
    4.22 +     */
    4.23 +    private List<Attribute.TypeCompound> clinit_type_attributes = List.<Attribute.TypeCompound>nil();
    4.24 +
    4.25 +    /*
    4.26       * The Symbol this Annotations instance belongs to
    4.27       */
    4.28      private final Symbol sym;
    4.29 @@ -97,6 +110,14 @@
    4.30          return type_attributes;
    4.31      }
    4.32  
    4.33 +    public List<Attribute.TypeCompound> getInitTypeAttributes() {
    4.34 +        return init_type_attributes;
    4.35 +    }
    4.36 +
    4.37 +    public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
    4.38 +        return clinit_type_attributes;
    4.39 +    }
    4.40 +
    4.41      public void setDeclarationAttributes(List<Attribute.Compound> a) {
    4.42          Assert.check(pendingCompletion() || !isStarted());
    4.43          if (a == null) {
    4.44 @@ -112,12 +133,28 @@
    4.45          type_attributes = a;
    4.46      }
    4.47  
    4.48 +    public void setInitTypeAttributes(List<Attribute.TypeCompound> a) {
    4.49 +        if (a == null) {
    4.50 +            throw new NullPointerException();
    4.51 +        }
    4.52 +        init_type_attributes = a;
    4.53 +    }
    4.54 +
    4.55 +    public void setClassInitTypeAttributes(List<Attribute.TypeCompound> a) {
    4.56 +        if (a == null) {
    4.57 +            throw new NullPointerException();
    4.58 +        }
    4.59 +        clinit_type_attributes = a;
    4.60 +    }
    4.61 +
    4.62      public void setAttributes(Annotations other) {
    4.63          if (other == null) {
    4.64              throw new NullPointerException();
    4.65          }
    4.66          setDeclarationAttributes(other.getDeclarationAttributes());
    4.67          setTypeAttributes(other.getTypeAttributes());
    4.68 +        setInitTypeAttributes(other.getInitTypeAttributes());
    4.69 +        setClassInitTypeAttributes(other.getClassInitTypeAttributes());
    4.70      }
    4.71  
    4.72      public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
    4.73 @@ -232,6 +269,28 @@
    4.74          return this;
    4.75      }
    4.76  
    4.77 +    public Annotations appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
    4.78 +        if (l.isEmpty()) {
    4.79 +            ; // no-op
    4.80 +        } else if (init_type_attributes.isEmpty()) {
    4.81 +            init_type_attributes = l;
    4.82 +        } else {
    4.83 +            init_type_attributes = init_type_attributes.appendList(l);
    4.84 +        }
    4.85 +        return this;
    4.86 +    }
    4.87 +
    4.88 +    public Annotations appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
    4.89 +        if (l.isEmpty()) {
    4.90 +            ; // no-op
    4.91 +        } else if (clinit_type_attributes.isEmpty()) {
    4.92 +            clinit_type_attributes = l;
    4.93 +        } else {
    4.94 +            clinit_type_attributes = clinit_type_attributes.appendList(l);
    4.95 +        }
    4.96 +        return this;
    4.97 +    }
    4.98 +
    4.99      public Annotations prepend(List<Attribute.Compound> l) {
   4.100          attributes = filterDeclSentinels(attributes);
   4.101  
     5.1 --- a/src/share/classes/com/sun/tools/javac/code/Attribute.java	Tue May 14 13:55:35 2013 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Attribute.java	Tue May 14 15:04:06 2013 -0700
     5.3 @@ -230,6 +230,42 @@
     5.4              this.position = position;
     5.5          }
     5.6  
     5.7 +        public boolean hasUnknownPosition() {
     5.8 +            return position == null || position.type == TargetType.UNKNOWN;
     5.9 +        }
    5.10 +
    5.11 +        public boolean isContainerTypeCompound() {
    5.12 +            if (isSynthesized() && values.size() == 1)
    5.13 +                return getFirstEmbeddedTC() != null;
    5.14 +            return false;
    5.15 +        }
    5.16 +
    5.17 +        private TypeCompound getFirstEmbeddedTC() {
    5.18 +            if (values.size() == 1) {
    5.19 +                Pair<MethodSymbol, Attribute> val = values.get(0);
    5.20 +                if (val.fst.getSimpleName().contentEquals("value")
    5.21 +                        && val.snd instanceof Array) {
    5.22 +                    Array arr = (Array) val.snd;
    5.23 +                    if (arr.values.length != 0
    5.24 +                            && arr.values[0] instanceof Attribute.TypeCompound)
    5.25 +                        return (Attribute.TypeCompound) arr.values[0];
    5.26 +                }
    5.27 +            }
    5.28 +            return null;
    5.29 +        }
    5.30 +
    5.31 +        public boolean tryFixPosition() {
    5.32 +            if (!isContainerTypeCompound())
    5.33 +                return false;
    5.34 +
    5.35 +            TypeCompound from = getFirstEmbeddedTC();
    5.36 +            if (from != null && from.position != null &&
    5.37 +                    from.position.type != TargetType.UNKNOWN) {
    5.38 +                position = from.position;
    5.39 +                return true;
    5.40 +            }
    5.41 +            return false;
    5.42 +        }
    5.43      }
    5.44  
    5.45      /** The value for an annotation element of an array type.
     6.1 --- a/src/share/classes/com/sun/tools/javac/code/Printer.java	Tue May 14 13:55:35 2013 -0700
     6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java	Tue May 14 15:04:06 2013 -0700
     6.3 @@ -31,6 +31,7 @@
     6.4  
     6.5  import com.sun.tools.javac.api.Messages;
     6.6  import com.sun.tools.javac.code.Type.AnnotatedType;
     6.7 +import com.sun.tools.javac.code.Type.ArrayType;
     6.8  import com.sun.tools.javac.code.Symbol.*;
     6.9  import com.sun.tools.javac.code.Type.*;
    6.10  import com.sun.tools.javac.util.List;
    6.11 @@ -127,7 +128,7 @@
    6.12      }
    6.13  
    6.14      /**
    6.15 -     * Get a localized string represenation for a given type.
    6.16 +     * Get a localized string representation for a given type.
    6.17       *
    6.18       * @param t type to be displayed
    6.19       * @param locale the locale in which the string is to be rendered
    6.20 @@ -138,7 +139,7 @@
    6.21      }
    6.22  
    6.23      /**
    6.24 -     * Get a localized string represenation for a given symbol.
    6.25 +     * Get a localized string representation for a given symbol.
    6.26       *
    6.27       * @param s symbol to be displayed
    6.28       * @param locale the locale in which the string is to be rendered
    6.29 @@ -182,7 +183,33 @@
    6.30  
    6.31      @Override
    6.32      public String visitArrayType(ArrayType t, Locale locale) {
    6.33 -        return visit(t.elemtype, locale) + "[]";
    6.34 +        StringBuilder res = new StringBuilder();
    6.35 +        printBaseElementType(t, res, locale);
    6.36 +        printBrackets(t, res, locale);
    6.37 +        return res.toString();
    6.38 +    }
    6.39 +
    6.40 +    void printBaseElementType(Type t, StringBuilder sb, Locale locale) {
    6.41 +        Type arrel = t;
    6.42 +        while (arrel.getKind() == TypeKind.ARRAY) {
    6.43 +            arrel = arrel.unannotatedType();
    6.44 +            arrel = ((ArrayType) arrel).elemtype;
    6.45 +        }
    6.46 +        sb.append(visit(arrel, locale));
    6.47 +    }
    6.48 +
    6.49 +    void printBrackets(Type t, StringBuilder sb, Locale locale) {
    6.50 +        Type arrel = t;
    6.51 +        while (arrel.getKind() == TypeKind.ARRAY) {
    6.52 +            if (arrel.isAnnotated()) {
    6.53 +                sb.append(' ');
    6.54 +                sb.append(arrel.getAnnotationMirrors());
    6.55 +                sb.append(' ');
    6.56 +            }
    6.57 +            sb.append("[]");
    6.58 +            arrel = arrel.unannotatedType();
    6.59 +            arrel = ((ArrayType) arrel).elemtype;
    6.60 +        }
    6.61      }
    6.62  
    6.63      @Override
    6.64 @@ -237,10 +264,22 @@
    6.65      public String visitAnnotatedType(AnnotatedType t, Locale locale) {
    6.66          if (t.typeAnnotations != null &&
    6.67                  t.typeAnnotations.nonEmpty()) {
    6.68 -            // TODO: better logic for arrays, ...
    6.69 -            return "(" + t.typeAnnotations + " :: " + visit(t.underlyingType, locale) + ")";
    6.70 +            if (t.underlyingType.getKind() == TypeKind.ARRAY) {
    6.71 +                StringBuilder res = new StringBuilder();
    6.72 +                printBaseElementType(t, res, locale);
    6.73 +                printBrackets(t, res, locale);
    6.74 +                return res.toString();
    6.75 +            } else if (t.underlyingType.getKind() == TypeKind.DECLARED &&
    6.76 +                    t.underlyingType.getEnclosingType() != Type.noType) {
    6.77 +                return visit(t.underlyingType.getEnclosingType(), locale) +
    6.78 +                        ". " +
    6.79 +                        t.typeAnnotations +
    6.80 +                        " " + className((ClassType)t.underlyingType, false, locale);
    6.81 +            } else {
    6.82 +                return t.typeAnnotations + " " + visit(t.underlyingType, locale);
    6.83 +            }
    6.84          } else {
    6.85 -            return "({} :: " + visit(t.underlyingType, locale) + ")";
    6.86 +            return visit(t.underlyingType, locale);
    6.87          }
    6.88      }
    6.89  
    6.90 @@ -253,7 +292,7 @@
    6.91  
    6.92      /**
    6.93       * Converts a class name into a (possibly localized) string. Anonymous
    6.94 -     * inner classes gets converted into a localized string.
    6.95 +     * inner classes get converted into a localized string.
    6.96       *
    6.97       * @param t the type of the class whose name is to be rendered
    6.98       * @param longform if set, the class' fullname is displayed - if unset the
    6.99 @@ -266,7 +305,7 @@
   6.100          if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
   6.101              StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
   6.102              for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
   6.103 -                s.append("&");
   6.104 +                s.append('&');
   6.105                  s.append(visit(is.head, locale));
   6.106              }
   6.107              return s.toString();
     7.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Tue May 14 13:55:35 2013 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Tue May 14 15:04:06 2013 -0700
     7.3 @@ -25,8 +25,6 @@
     7.4  
     7.5  package com.sun.tools.javac.code;
     7.6  
     7.7 -import com.sun.tools.javac.model.JavacAnnoConstructs;
     7.8 -import com.sun.tools.javac.model.JavacTypes;
     7.9  import java.lang.annotation.Annotation;
    7.10  import java.util.Collections;
    7.11  import java.util.EnumMap;
    7.12 @@ -34,10 +32,10 @@
    7.13  import java.util.Map;
    7.14  import java.util.Set;
    7.15  
    7.16 -import javax.lang.model.element.AnnotationMirror;
    7.17  import javax.lang.model.type.*;
    7.18  
    7.19  import com.sun.tools.javac.code.Symbol.*;
    7.20 +import com.sun.tools.javac.model.JavacAnnoConstructs;
    7.21  import com.sun.tools.javac.util.*;
    7.22  import static com.sun.tools.javac.code.BoundKind.*;
    7.23  import static com.sun.tools.javac.code.Flags.*;
    7.24 @@ -729,7 +727,7 @@
    7.25                      return s.toString();
    7.26                  } else if (sym.name.isEmpty()) {
    7.27                      String s;
    7.28 -                    ClassType norm = (ClassType) tsym.type;
    7.29 +                    ClassType norm = (ClassType) tsym.type.unannotatedType();
    7.30                      if (norm == null) {
    7.31                          s = Log.getLocalizedString("anonymous.class", (Object)null);
    7.32                      } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
    7.33 @@ -781,7 +779,7 @@
    7.34              return
    7.35                  getEnclosingType().isErroneous() ||
    7.36                  isErroneous(getTypeArguments()) ||
    7.37 -                this != tsym.type && tsym.type.isErroneous();
    7.38 +                this != tsym.type.unannotatedType() && tsym.type.isErroneous();
    7.39          }
    7.40  
    7.41          public boolean isParameterized() {
    7.42 @@ -1693,7 +1691,10 @@
    7.43  
    7.44          @Override
    7.45          public String toString() {
    7.46 -            // TODO more logic for arrays, etc.
    7.47 +            // This method is only used for internal debugging output.
    7.48 +            // See
    7.49 +            // com.sun.tools.javac.code.Printer.visitAnnotatedType(AnnotatedType, Locale)
    7.50 +            // for the user-visible logic.
    7.51              if (typeAnnotations != null &&
    7.52                      !typeAnnotations.isEmpty()) {
    7.53                  return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")";
    7.54 @@ -1705,9 +1706,13 @@
    7.55          @Override
    7.56          public boolean contains(Type t)          { return underlyingType.contains(t); }
    7.57  
    7.58 -        // TODO: attach annotations?
    7.59          @Override
    7.60 -        public Type withTypeVar(Type t)          { return underlyingType.withTypeVar(t); }
    7.61 +        public Type withTypeVar(Type t) {
    7.62 +            // Don't create a new AnnotatedType, as 'this' will
    7.63 +            // get its annotations set later.
    7.64 +            underlyingType = underlyingType.withTypeVar(t);
    7.65 +            return this;
    7.66 +        }
    7.67  
    7.68          // TODO: attach annotations?
    7.69          @Override
     8.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Tue May 14 13:55:35 2013 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java	Tue May 14 15:04:06 2013 -0700
     8.3 @@ -27,6 +27,7 @@
     8.4  
     8.5  import java.util.Iterator;
     8.6  
     8.7 +import com.sun.tools.javac.tree.JCTree.JCLambda;
     8.8  import com.sun.tools.javac.util.*;
     8.9  
    8.10  /** A type annotation position.
    8.11 @@ -145,9 +146,18 @@
    8.12      // For class extends, implements, and throws clauses
    8.13      public int type_index = Integer.MIN_VALUE;
    8.14  
    8.15 -    // For exception parameters, index into exception table
    8.16 +    // For exception parameters, index into exception table.
    8.17 +    // In com.sun.tools.javac.jvm.Gen.genCatch we first set the type_index
    8.18 +    // to the catch type index - that value is only temporary.
    8.19 +    // Then in com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions
    8.20 +    // we use that value to determine the exception table index.
    8.21      public int exception_index = Integer.MIN_VALUE;
    8.22  
    8.23 +    // If this type annotation is within a lambda expression,
    8.24 +    // store a pointer to the lambda expression tree in order
    8.25 +    // to allow a later translation to the right method.
    8.26 +    public JCLambda onLambda = null;
    8.27 +
    8.28      public TypeAnnotationPosition() {}
    8.29  
    8.30      @Override
    8.31 @@ -258,6 +268,11 @@
    8.32          sb.append(", pos = ");
    8.33          sb.append(pos);
    8.34  
    8.35 +        if (onLambda != null) {
    8.36 +            sb.append(", onLambda hash = ");
    8.37 +            sb.append(onLambda.hashCode());
    8.38 +        }
    8.39 +
    8.40          sb.append(']');
    8.41          return sb.toString();
    8.42      }
    8.43 @@ -271,6 +286,17 @@
    8.44          return !type.isLocal() || isValidOffset;
    8.45      }
    8.46  
    8.47 +
    8.48 +    public boolean matchesPos(int pos) {
    8.49 +        return this.pos == pos;
    8.50 +    }
    8.51 +
    8.52 +    public void updatePosOffset(int to) {
    8.53 +        offset = to;
    8.54 +        lvarOffset = new int[]{to};
    8.55 +        isValidOffset = true;
    8.56 +    }
    8.57 +
    8.58      /**
    8.59       * Decode the binary representation for a type path and set
    8.60       * the {@code location} field.
     9.1 --- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Tue May 14 13:55:35 2013 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Tue May 14 15:04:06 2013 -0700
     9.3 @@ -49,12 +49,16 @@
     9.4  import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
     9.5  import com.sun.tools.javac.code.TypeTag;
     9.6  import com.sun.tools.javac.code.Symbol.VarSymbol;
     9.7 +import com.sun.tools.javac.code.Symbol.MethodSymbol;
     9.8 +import com.sun.tools.javac.comp.Annotate;
     9.9  import com.sun.tools.javac.comp.Annotate.Annotator;
    9.10  import com.sun.tools.javac.tree.JCTree;
    9.11  import com.sun.tools.javac.tree.JCTree.JCBlock;
    9.12  import com.sun.tools.javac.tree.JCTree.JCClassDecl;
    9.13  import com.sun.tools.javac.tree.JCTree.JCExpression;
    9.14 +import com.sun.tools.javac.tree.JCTree.JCLambda;
    9.15  import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
    9.16 +import com.sun.tools.javac.tree.JCTree.JCNewClass;
    9.17  import com.sun.tools.javac.tree.JCTree.JCTypeApply;
    9.18  import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
    9.19  import com.sun.tools.javac.tree.TreeScanner;
    9.20 @@ -81,17 +85,18 @@
    9.21       * determine the correct positions for type annotations.
    9.22       * This version only visits types in signatures and should be
    9.23       * called from MemberEnter.
    9.24 -     * The method returns the Annotator object that should be added
    9.25 -     * to the correct Annotate queue for later processing.
    9.26 +     * The method takes the Annotate object as parameter and
    9.27 +     * adds an Annotator to the correct Annotate queue for
    9.28 +     * later processing.
    9.29       */
    9.30 -    public static Annotator organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
    9.31 -            final Log log, final JCClassDecl tree) {
    9.32 -        return new Annotator() {
    9.33 +    public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
    9.34 +            final Log log, final JCClassDecl tree, Annotate annotate) {
    9.35 +        annotate.afterRepeated( new Annotator() {
    9.36              @Override
    9.37              public void enterAnnotation() {
    9.38                  new TypeAnnotationPositions(syms, names, log, true).scan(tree);
    9.39              }
    9.40 -        };
    9.41 +        } );
    9.42      }
    9.43  
    9.44      /**
    9.45 @@ -102,10 +107,104 @@
    9.46          new TypeAnnotationPositions(syms, names, log, false).scan(tree);
    9.47      }
    9.48  
    9.49 +    public enum AnnotationType { DECLARATION, TYPE, BOTH };
    9.50 +
    9.51 +    /**
    9.52 +     * Determine whether an annotation is a declaration annotation,
    9.53 +     * a type annotation, or both.
    9.54 +     */
    9.55 +    public static AnnotationType annotationType(Symtab syms, Names names,
    9.56 +            Attribute.Compound a, Symbol s) {
    9.57 +        Attribute.Compound atTarget =
    9.58 +            a.type.tsym.attribute(syms.annotationTargetType.tsym);
    9.59 +        if (atTarget == null) {
    9.60 +            return inferTargetMetaInfo(a, s);
    9.61 +        }
    9.62 +        Attribute atValue = atTarget.member(names.value);
    9.63 +        if (!(atValue instanceof Attribute.Array)) {
    9.64 +            Assert.error("annotationType(): bad @Target argument " + atValue +
    9.65 +                    " (" + atValue.getClass() + ")");
    9.66 +            return AnnotationType.DECLARATION; // error recovery
    9.67 +        }
    9.68 +        Attribute.Array arr = (Attribute.Array) atValue;
    9.69 +        boolean isDecl = false, isType = false;
    9.70 +        for (Attribute app : arr.values) {
    9.71 +            if (!(app instanceof Attribute.Enum)) {
    9.72 +                Assert.error("annotationType(): unrecognized Attribute kind " + app +
    9.73 +                        " (" + app.getClass() + ")");
    9.74 +                isDecl = true;
    9.75 +                continue;
    9.76 +            }
    9.77 +            Attribute.Enum e = (Attribute.Enum) app;
    9.78 +            if (e.value.name == names.TYPE) {
    9.79 +                if (s.kind == Kinds.TYP)
    9.80 +                    isDecl = true;
    9.81 +            } else if (e.value.name == names.FIELD) {
    9.82 +                if (s.kind == Kinds.VAR &&
    9.83 +                        s.owner.kind != Kinds.MTH)
    9.84 +                    isDecl = true;
    9.85 +            } else if (e.value.name == names.METHOD) {
    9.86 +                if (s.kind == Kinds.MTH &&
    9.87 +                        !s.isConstructor())
    9.88 +                    isDecl = true;
    9.89 +            } else if (e.value.name == names.PARAMETER) {
    9.90 +                if (s.kind == Kinds.VAR &&
    9.91 +                        s.owner.kind == Kinds.MTH &&
    9.92 +                        (s.flags() & Flags.PARAMETER) != 0)
    9.93 +                    isDecl = true;
    9.94 +            } else if (e.value.name == names.CONSTRUCTOR) {
    9.95 +                if (s.kind == Kinds.MTH &&
    9.96 +                        s.isConstructor())
    9.97 +                    isDecl = true;
    9.98 +            } else if (e.value.name == names.LOCAL_VARIABLE) {
    9.99 +                if (s.kind == Kinds.VAR &&
   9.100 +                        s.owner.kind == Kinds.MTH &&
   9.101 +                        (s.flags() & Flags.PARAMETER) == 0)
   9.102 +                    isDecl = true;
   9.103 +            } else if (e.value.name == names.ANNOTATION_TYPE) {
   9.104 +                if (s.kind == Kinds.TYP &&
   9.105 +                        (s.flags() & Flags.ANNOTATION) != 0)
   9.106 +                    isDecl = true;
   9.107 +            } else if (e.value.name == names.PACKAGE) {
   9.108 +                if (s.kind == Kinds.PCK)
   9.109 +                    isDecl = true;
   9.110 +            } else if (e.value.name == names.TYPE_USE) {
   9.111 +                if (s.kind == Kinds.TYP ||
   9.112 +                        s.kind == Kinds.VAR ||
   9.113 +                        (s.kind == Kinds.MTH && !s.isConstructor() &&
   9.114 +                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
   9.115 +                        (s.kind == Kinds.MTH && s.isConstructor()))
   9.116 +                    isType = true;
   9.117 +            } else if (e.value.name == names.TYPE_PARAMETER) {
   9.118 +                /* Irrelevant in this case */
   9.119 +                // TYPE_PARAMETER doesn't aid in distinguishing between
   9.120 +                // Type annotations and declaration annotations on an
   9.121 +                // Element
   9.122 +            } else {
   9.123 +                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
   9.124 +                        " (" + e.value.name.getClass() + ")");
   9.125 +                isDecl = true;
   9.126 +            }
   9.127 +        }
   9.128 +        if (isDecl && isType) {
   9.129 +            return AnnotationType.BOTH;
   9.130 +        } else if (isType) {
   9.131 +            return AnnotationType.TYPE;
   9.132 +        } else {
   9.133 +            return AnnotationType.DECLARATION;
   9.134 +        }
   9.135 +    }
   9.136 +
   9.137 +    /** Infer the target annotation kind, if none is give.
   9.138 +     * We only infer declaration annotations.
   9.139 +     */
   9.140 +    private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
   9.141 +        return AnnotationType.DECLARATION;
   9.142 +    }
   9.143 +
   9.144 +
   9.145      private static class TypeAnnotationPositions extends TreeScanner {
   9.146  
   9.147 -        private enum AnnotationType { DECLARATION, TYPE, BOTH };
   9.148 -
   9.149          private final Symtab syms;
   9.150          private final Names names;
   9.151          private final Log log;
   9.152 @@ -154,7 +253,7 @@
   9.153              ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>();
   9.154  
   9.155              for (Attribute.Compound a : annotations) {
   9.156 -                switch (annotationType(a, sym)) {
   9.157 +                switch (annotationType(syms, names, a, sym)) {
   9.158                  case DECLARATION:
   9.159                      declAnnos.append(a);
   9.160                      break;
   9.161 @@ -175,6 +274,10 @@
   9.162              sym.annotations.reset();
   9.163              sym.annotations.setDeclarationAttributes(declAnnos.toList());
   9.164  
   9.165 +            if (typeAnnos.isEmpty()) {
   9.166 +                return;
   9.167 +            }
   9.168 +
   9.169              List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
   9.170  
   9.171              if (type == null) {
   9.172 @@ -190,16 +293,33 @@
   9.173  
   9.174              if (sym.getKind() == ElementKind.METHOD) {
   9.175                  sym.type.asMethodType().restype = type;
   9.176 +            } else if (sym.getKind() == ElementKind.PARAMETER) {
   9.177 +                sym.type = type;
   9.178 +                if (sym.getQualifiedName().equals(names._this)) {
   9.179 +                    sym.owner.type.asMethodType().recvtype = type;
   9.180 +                    // note that the typeAnnotations will also be added to the owner below.
   9.181 +                } else {
   9.182 +                    MethodType methType = sym.owner.type.asMethodType();
   9.183 +                    List<VarSymbol> params = ((MethodSymbol)sym.owner).params;
   9.184 +                    List<Type> oldArgs = methType.argtypes;
   9.185 +                    ListBuffer<Type> newArgs = new ListBuffer<Type>();
   9.186 +                    while (params.nonEmpty()) {
   9.187 +                        if (params.head == sym) {
   9.188 +                            newArgs.add(type);
   9.189 +                        } else {
   9.190 +                            newArgs.add(oldArgs.head);
   9.191 +                        }
   9.192 +                        oldArgs = oldArgs.tail;
   9.193 +                        params = params.tail;
   9.194 +                    }
   9.195 +                    methType.argtypes = newArgs.toList();
   9.196 +                }
   9.197              } else {
   9.198                  sym.type = type;
   9.199              }
   9.200  
   9.201              sym.annotations.appendUniqueTypes(typeAnnotations);
   9.202 -            if (sym.getKind() == ElementKind.PARAMETER &&
   9.203 -                    sym.getQualifiedName().equals(names._this)) {
   9.204 -                sym.owner.type.asMethodType().recvtype = type;
   9.205 -                // note that the typeAnnotations will also be added to the owner below.
   9.206 -            }
   9.207 +
   9.208              if (sym.getKind() == ElementKind.PARAMETER ||
   9.209                      sym.getKind() == ElementKind.LOCAL_VARIABLE ||
   9.210                      sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
   9.211 @@ -276,10 +396,21 @@
   9.212                      TypeAnnotationPosition p = a.position;
   9.213                      p.location = p.location.prependList(depth.toList());
   9.214                  }
   9.215 +                typetree.type = toreturn;
   9.216                  return toreturn;
   9.217              } else if (type.hasTag(TypeTag.TYPEVAR)) {
   9.218                  // Nothing to do for type variables.
   9.219                  return type;
   9.220 +            } else if (type.getKind() == TypeKind.UNION) {
   9.221 +                // There is a TypeKind, but no TypeTag.
   9.222 +                JCTypeUnion tutree = (JCTypeUnion) typetree;
   9.223 +                JCExpression fst = tutree.alternatives.get(0);
   9.224 +                Type res = typeWithAnnotations(fst, fst.type, annotations, log);
   9.225 +                fst.type = res;
   9.226 +                // TODO: do we want to set res as first element in uct.alternatives?
   9.227 +                // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
   9.228 +                // Return the un-annotated union-type.
   9.229 +                return type;
   9.230              } else {
   9.231                  Type enclTy = type;
   9.232                  Element enclEl = type.asElement();
   9.233 @@ -357,6 +488,7 @@
   9.234                  }
   9.235  
   9.236                  Type ret = typeWithAnnotations(type, enclTy, annotations);
   9.237 +                typetree.type = ret;
   9.238                  return ret;
   9.239              }
   9.240          }
   9.241 @@ -480,94 +612,6 @@
   9.242              return new Attribute.TypeCompound(a, p);
   9.243          }
   9.244  
   9.245 -        private AnnotationType annotationType(Attribute.Compound a, Symbol s) {
   9.246 -            Attribute.Compound atTarget =
   9.247 -                a.type.tsym.attribute(syms.annotationTargetType.tsym);
   9.248 -            if (atTarget == null) {
   9.249 -                return inferTargetMetaInfo(a, s);
   9.250 -            }
   9.251 -            Attribute atValue = atTarget.member(names.value);
   9.252 -            if (!(atValue instanceof Attribute.Array)) {
   9.253 -                Assert.error("annotationType(): bad @Target argument " + atValue +
   9.254 -                        " (" + atValue.getClass() + ")");
   9.255 -                return AnnotationType.DECLARATION; // error recovery
   9.256 -            }
   9.257 -            Attribute.Array arr = (Attribute.Array) atValue;
   9.258 -            boolean isDecl = false, isType = false;
   9.259 -            for (Attribute app : arr.values) {
   9.260 -                if (!(app instanceof Attribute.Enum)) {
   9.261 -                    Assert.error("annotationType(): unrecognized Attribute kind " + app +
   9.262 -                            " (" + app.getClass() + ")");
   9.263 -                    isDecl = true;
   9.264 -                    continue;
   9.265 -                }
   9.266 -                Attribute.Enum e = (Attribute.Enum) app;
   9.267 -                if (e.value.name == names.TYPE) {
   9.268 -                    if (s.kind == Kinds.TYP)
   9.269 -                        isDecl = true;
   9.270 -                } else if (e.value.name == names.FIELD) {
   9.271 -                    if (s.kind == Kinds.VAR &&
   9.272 -                            s.owner.kind != Kinds.MTH)
   9.273 -                        isDecl = true;
   9.274 -                } else if (e.value.name == names.METHOD) {
   9.275 -                    if (s.kind == Kinds.MTH &&
   9.276 -                            !s.isConstructor())
   9.277 -                        isDecl = true;
   9.278 -                } else if (e.value.name == names.PARAMETER) {
   9.279 -                    if (s.kind == Kinds.VAR &&
   9.280 -                            s.owner.kind == Kinds.MTH &&
   9.281 -                            (s.flags() & Flags.PARAMETER) != 0)
   9.282 -                        isDecl = true;
   9.283 -                } else if (e.value.name == names.CONSTRUCTOR) {
   9.284 -                    if (s.kind == Kinds.MTH &&
   9.285 -                            s.isConstructor())
   9.286 -                        isDecl = true;
   9.287 -                } else if (e.value.name == names.LOCAL_VARIABLE) {
   9.288 -                    if (s.kind == Kinds.VAR &&
   9.289 -                            s.owner.kind == Kinds.MTH &&
   9.290 -                            (s.flags() & Flags.PARAMETER) == 0)
   9.291 -                        isDecl = true;
   9.292 -                } else if (e.value.name == names.ANNOTATION_TYPE) {
   9.293 -                    if (s.kind == Kinds.TYP &&
   9.294 -                            (s.flags() & Flags.ANNOTATION) != 0)
   9.295 -                        isDecl = true;
   9.296 -                } else if (e.value.name == names.PACKAGE) {
   9.297 -                    if (s.kind == Kinds.PCK)
   9.298 -                        isDecl = true;
   9.299 -                } else if (e.value.name == names.TYPE_USE) {
   9.300 -                    if (s.kind == Kinds.TYP ||
   9.301 -                            s.kind == Kinds.VAR ||
   9.302 -                            (s.kind == Kinds.MTH && !s.isConstructor() &&
   9.303 -                            !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
   9.304 -                            (s.kind == Kinds.MTH && s.isConstructor()))
   9.305 -                        isType = true;
   9.306 -                } else if (e.value.name == names.TYPE_PARAMETER) {
   9.307 -                    /* Irrelevant in this case */
   9.308 -                    // TYPE_PARAMETER doesn't aid in distinguishing between
   9.309 -                    // Type annotations and declaration annotations on an
   9.310 -                    // Element
   9.311 -                } else {
   9.312 -                    Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
   9.313 -                            " (" + e.value.name.getClass() + ")");
   9.314 -                    isDecl = true;
   9.315 -                }
   9.316 -            }
   9.317 -            if (isDecl && isType) {
   9.318 -                return AnnotationType.BOTH;
   9.319 -            } else if (isType) {
   9.320 -                return AnnotationType.TYPE;
   9.321 -            } else {
   9.322 -                return AnnotationType.DECLARATION;
   9.323 -            }
   9.324 -        }
   9.325 -
   9.326 -        /** Infer the target annotation kind, if none is give.
   9.327 -         * We only infer declaration annotations.
   9.328 -         */
   9.329 -        private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
   9.330 -            return AnnotationType.DECLARATION;
   9.331 -        }
   9.332 -
   9.333  
   9.334          /* This is the beginning of the second part of organizing
   9.335           * type annotations: determine the type annotation positions.
   9.336 @@ -585,7 +629,13 @@
   9.337  
   9.338              switch (frame.getKind()) {
   9.339                  case TYPE_CAST:
   9.340 +                    JCTypeCast frameTC = (JCTypeCast) frame;
   9.341                      p.type = TargetType.CAST;
   9.342 +                    if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
   9.343 +                        // This case was already handled by INTERSECTION_TYPE
   9.344 +                    } else {
   9.345 +                        p.type_index = 0;
   9.346 +                    }
   9.347                      p.pos = frame.pos;
   9.348                      return;
   9.349  
   9.350 @@ -595,8 +645,22 @@
   9.351                      return;
   9.352  
   9.353                  case NEW_CLASS:
   9.354 -                    JCNewClass frameNewClass = (JCNewClass)frame;
   9.355 -                    if (frameNewClass.typeargs.contains(tree)) {
   9.356 +                    JCNewClass frameNewClass = (JCNewClass) frame;
   9.357 +                    if (frameNewClass.def != null) {
   9.358 +                        // Special handling for anonymous class instantiations
   9.359 +                        JCClassDecl frameClassDecl = frameNewClass.def;
   9.360 +                        if (frameClassDecl.extending == tree) {
   9.361 +                            p.type = TargetType.CLASS_EXTENDS;
   9.362 +                            p.type_index = -1;
   9.363 +                        } else if (frameClassDecl.implementing.contains(tree)) {
   9.364 +                            p.type = TargetType.CLASS_EXTENDS;
   9.365 +                            p.type_index = frameClassDecl.implementing.indexOf(tree);
   9.366 +                        } else {
   9.367 +                            // In contrast to CLASS below, typarams cannot occur here.
   9.368 +                            Assert.error("Could not determine position of tree " + tree +
   9.369 +                                    " within frame " + frame);
   9.370 +                        }
   9.371 +                    } else if (frameNewClass.typeargs.contains(tree)) {
   9.372                          p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
   9.373                          p.type_index = frameNewClass.typeargs.indexOf(tree);
   9.374                      } else {
   9.375 @@ -649,6 +713,8 @@
   9.376                  }
   9.377  
   9.378                  case PARAMETERIZED_TYPE: {
   9.379 +                    List<JCTree> newPath = path.tail;
   9.380 +
   9.381                      if (((JCTypeApply)frame).clazz == tree) {
   9.382                          // generic: RAW; noop
   9.383                      } else if (((JCTypeApply)frame).arguments.contains(tree)) {
   9.384 @@ -656,13 +722,21 @@
   9.385                          int arg = taframe.arguments.indexOf(tree);
   9.386                          p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
   9.387  
   9.388 -                        locateNestedTypes(taframe.type, p);
   9.389 +                        Type typeToUse;
   9.390 +                        if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
   9.391 +                            // If we are within an anonymous class instantiation, use its type,
   9.392 +                            // because it contains a correctly nested type.
   9.393 +                            typeToUse = newPath.tail.head.type;
   9.394 +                        } else {
   9.395 +                            typeToUse = taframe.type;
   9.396 +                        }
   9.397 +
   9.398 +                        locateNestedTypes(typeToUse, p);
   9.399                      } else {
   9.400                          Assert.error("Could not determine type argument position of tree " + tree +
   9.401                                  " within frame " + frame);
   9.402                      }
   9.403  
   9.404 -                    List<JCTree> newPath = path.tail;
   9.405                      resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   9.406                      return;
   9.407                  }
   9.408 @@ -780,6 +854,9 @@
   9.409                          default:
   9.410                              Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
   9.411                      }
   9.412 +                    if (v.getKind() != ElementKind.FIELD) {
   9.413 +                        v.owner.annotations.appendUniqueTypes(v.getRawTypeAttributes());
   9.414 +                    }
   9.415                      return;
   9.416  
   9.417                  case ANNOTATED_TYPE: {
   9.418 @@ -789,6 +866,11 @@
   9.419                          // not care about inner types.
   9.420                          JCAnnotatedType atypetree = (JCAnnotatedType) frame;
   9.421                          final Type utype = atypetree.underlyingType.type;
   9.422 +                        if (utype == null) {
   9.423 +                            // This might happen during DeferredAttr;
   9.424 +                            // we will be back later.
   9.425 +                            return;
   9.426 +                        }
   9.427                          Symbol tsym = utype.tsym;
   9.428                          if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) ||
   9.429                                  utype.getKind().equals(TypeKind.WILDCARD) ||
   9.430 @@ -806,8 +888,6 @@
   9.431                  }
   9.432  
   9.433                  case UNION_TYPE: {
   9.434 -                    // TODO: can we store any information here to help in
   9.435 -                    // determining the final position?
   9.436                      List<JCTree> newPath = path.tail;
   9.437                      resolveFrame(newPath.head, newPath.tail.head, newPath, p);
   9.438                      return;
   9.439 @@ -873,11 +953,20 @@
   9.440  
   9.441          private static int methodParamIndex(List<JCTree> path, JCTree param) {
   9.442              List<JCTree> curr = path;
   9.443 -            while (curr.head.getTag() != Tag.METHODDEF) {
   9.444 +            while (curr.head.getTag() != Tag.METHODDEF &&
   9.445 +                    curr.head.getTag() != Tag.LAMBDA) {
   9.446                  curr = curr.tail;
   9.447              }
   9.448 -            JCMethodDecl method = (JCMethodDecl)curr.head;
   9.449 -            return method.params.indexOf(param);
   9.450 +            if (curr.head.getTag() == Tag.METHODDEF) {
   9.451 +                JCMethodDecl method = (JCMethodDecl)curr.head;
   9.452 +                return method.params.indexOf(param);
   9.453 +            } else if (curr.head.getTag() == Tag.LAMBDA) {
   9.454 +                JCLambda lambda = (JCLambda)curr.head;
   9.455 +                return lambda.params.indexOf(param);
   9.456 +            } else {
   9.457 +                Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
   9.458 +                return -1;
   9.459 +            }
   9.460          }
   9.461  
   9.462          // Each class (including enclosed inner classes) is visited separately.
   9.463 @@ -889,6 +978,7 @@
   9.464              if (isInClass)
   9.465                  return;
   9.466              isInClass = true;
   9.467 +
   9.468              if (sigOnly) {
   9.469                  scan(tree.mods);
   9.470                  scan(tree.typarams);
   9.471 @@ -910,7 +1000,9 @@
   9.472                  return;
   9.473              }
   9.474              if (sigOnly) {
   9.475 -                {
   9.476 +                if (!tree.mods.annotations.isEmpty()) {
   9.477 +                    // Nothing to do for separateAnnotationsKinds if
   9.478 +                    // there are no annotations of either kind.
   9.479                      TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.480                      pos.type = TargetType.METHOD_RETURN;
   9.481                      if (tree.sym.isConstructor()) {
   9.482 @@ -923,7 +1015,10 @@
   9.483                                  tree.sym, pos);
   9.484                      }
   9.485                  }
   9.486 -                if (tree.recvparam != null && tree.recvparam.sym != null) {
   9.487 +                if (tree.recvparam != null && tree.recvparam.sym != null &&
   9.488 +                        !tree.recvparam.mods.annotations.isEmpty()) {
   9.489 +                    // Nothing to do for separateAnnotationsKinds if
   9.490 +                    // there are no annotations of either kind.
   9.491                      // TODO: make sure there are no declaration annotations.
   9.492                      TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.493                      pos.type = TargetType.METHOD_RECEIVER;
   9.494 @@ -933,11 +1028,15 @@
   9.495                  }
   9.496                  int i = 0;
   9.497                  for (JCVariableDecl param : tree.params) {
   9.498 -                    TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.499 -                    pos.type = TargetType.METHOD_FORMAL_PARAMETER;
   9.500 -                    pos.parameter_index = i;
   9.501 -                    pos.pos = param.vartype.pos;
   9.502 -                    separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
   9.503 +                    if (!param.mods.annotations.isEmpty()) {
   9.504 +                        // Nothing to do for separateAnnotationsKinds if
   9.505 +                        // there are no annotations of either kind.
   9.506 +                        TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.507 +                        pos.type = TargetType.METHOD_FORMAL_PARAMETER;
   9.508 +                        pos.parameter_index = i;
   9.509 +                        pos.pos = param.vartype.pos;
   9.510 +                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
   9.511 +                    }
   9.512                      ++i;
   9.513                  }
   9.514              }
   9.515 @@ -958,16 +1057,53 @@
   9.516              pop();
   9.517          }
   9.518  
   9.519 +        /* Store a reference to the current lambda expression, to
   9.520 +         * be used by all type annotations within this expression.
   9.521 +         */
   9.522 +        private JCLambda currentLambda = null;
   9.523 +
   9.524 +        public void visitLambda(JCLambda tree) {
   9.525 +            JCLambda prevLambda = currentLambda;
   9.526 +            try {
   9.527 +                currentLambda = tree;
   9.528 +
   9.529 +                int i = 0;
   9.530 +                for (JCVariableDecl param : tree.params) {
   9.531 +                    if (!param.mods.annotations.isEmpty()) {
   9.532 +                        // Nothing to do for separateAnnotationsKinds if
   9.533 +                        // there are no annotations of either kind.
   9.534 +                        TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.535 +                        pos.type = TargetType.METHOD_FORMAL_PARAMETER;
   9.536 +                        pos.parameter_index = i;
   9.537 +                        pos.pos = param.vartype.pos;
   9.538 +                        pos.onLambda = tree;
   9.539 +                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
   9.540 +                    }
   9.541 +                    ++i;
   9.542 +                }
   9.543 +
   9.544 +                push(tree);
   9.545 +                scan(tree.body);
   9.546 +                scan(tree.params);
   9.547 +                pop();
   9.548 +            } finally {
   9.549 +                currentLambda = prevLambda;
   9.550 +            }
   9.551 +        }
   9.552 +
   9.553          /**
   9.554           * Resolve declaration vs. type annotations in variable declarations and
   9.555           * then determine the positions.
   9.556           */
   9.557          @Override
   9.558          public void visitVarDef(final JCVariableDecl tree) {
   9.559 -            if (tree.sym == null) {
   9.560 +            if (tree.mods.annotations.isEmpty()) {
   9.561 +                // Nothing to do for separateAnnotationsKinds if
   9.562 +                // there are no annotations of either kind.
   9.563 +            } else if (tree.sym == null) {
   9.564                  // Something is wrong already. Quietly ignore.
   9.565              } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
   9.566 -                // Parameters are handled in visitMethodDef above.
   9.567 +                // Parameters are handled in visitMethodDef or visitLambda.
   9.568              } else if (tree.sym.getKind() == ElementKind.FIELD) {
   9.569                  if (sigOnly) {
   9.570                      TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.571 @@ -979,16 +1115,19 @@
   9.572                  TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.573                  pos.type = TargetType.LOCAL_VARIABLE;
   9.574                  pos.pos = tree.pos;
   9.575 +                pos.onLambda = currentLambda;
   9.576                  separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
   9.577              } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
   9.578                  TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.579                  pos.type = TargetType.EXCEPTION_PARAMETER;
   9.580                  pos.pos = tree.pos;
   9.581 +                pos.onLambda = currentLambda;
   9.582                  separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
   9.583              } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
   9.584                  TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.585                  pos.type = TargetType.RESOURCE_VARIABLE;
   9.586                  pos.pos = tree.pos;
   9.587 +                pos.onLambda = currentLambda;
   9.588                  separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
   9.589              } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
   9.590                  // No type annotations can occur here.
   9.591 @@ -1031,6 +1170,40 @@
   9.592          }
   9.593  
   9.594          @Override
   9.595 +        public void visitNewClass(JCNewClass tree) {
   9.596 +            if (tree.def != null &&
   9.597 +                    !tree.def.mods.annotations.isEmpty()) {
   9.598 +                JCClassDecl classdecl = tree.def;
   9.599 +                TypeAnnotationPosition pos = new TypeAnnotationPosition();
   9.600 +                pos.type = TargetType.CLASS_EXTENDS;
   9.601 +                pos.pos = tree.pos;
   9.602 +                if (classdecl.extending == tree.clazz) {
   9.603 +                    pos.type_index = -1;
   9.604 +                } else if (classdecl.implementing.contains(tree.clazz)) {
   9.605 +                    pos.type_index = classdecl.implementing.indexOf(tree.clazz);
   9.606 +                } else {
   9.607 +                    // In contrast to CLASS elsewhere, typarams cannot occur here.
   9.608 +                    Assert.error("Could not determine position of tree " + tree);
   9.609 +                }
   9.610 +                Type before = classdecl.sym.type;
   9.611 +                separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
   9.612 +
   9.613 +                // classdecl.sym.type now contains an annotated type, which
   9.614 +                // is not what we want there.
   9.615 +                // TODO: should we put this type somewhere in the superclass/interface?
   9.616 +                classdecl.sym.type = before;
   9.617 +            }
   9.618 +
   9.619 +            scan(tree.encl);
   9.620 +            scan(tree.typeargs);
   9.621 +            scan(tree.clazz);
   9.622 +            scan(tree.args);
   9.623 +
   9.624 +            // The class body will already be scanned.
   9.625 +            // scan(tree.def);
   9.626 +        }
   9.627 +
   9.628 +        @Override
   9.629          public void visitNewArray(JCNewArray tree) {
   9.630              findPosition(tree, tree, tree.annotations);
   9.631              int dimAnnosCount = tree.dimAnnotations.size();
   9.632 @@ -1040,6 +1213,7 @@
   9.633              for (int i = 0; i < dimAnnosCount; ++i) {
   9.634                  TypeAnnotationPosition p = new TypeAnnotationPosition();
   9.635                  p.pos = tree.pos;
   9.636 +                p.onLambda = currentLambda;
   9.637                  p.type = TargetType.NEW;
   9.638                  if (i != 0) {
   9.639                      depth = depth.append(TypePathEntry.ARRAY);
   9.640 @@ -1053,18 +1227,23 @@
   9.641              // int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
   9.642              // TODO: is depth.size == i here?
   9.643              JCExpression elemType = tree.elemtype;
   9.644 +            depth = depth.append(TypePathEntry.ARRAY);
   9.645              while (elemType != null) {
   9.646                  if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
   9.647                      JCAnnotatedType at = (JCAnnotatedType)elemType;
   9.648                      TypeAnnotationPosition p = new TypeAnnotationPosition();
   9.649                      p.type = TargetType.NEW;
   9.650                      p.pos = tree.pos;
   9.651 -                    p.location = p.location.appendList(depth.toList());
   9.652 +                    p.onLambda = currentLambda;
   9.653 +                    locateNestedTypes(elemType.type, p);
   9.654 +                    p.location = p.location.prependList(depth.toList());
   9.655                      setTypeAnnotationPos(at.annotations, p);
   9.656                      elemType = at.underlyingType;
   9.657                  } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
   9.658                      depth = depth.append(TypePathEntry.ARRAY);
   9.659                      elemType = ((JCArrayTypeTree)elemType).elemtype;
   9.660 +                } else if (elemType.hasTag(JCTree.Tag.SELECT)) {
   9.661 +                    elemType = ((JCFieldAccess)elemType).selected;
   9.662                  } else {
   9.663                      break;
   9.664                  }
   9.665 @@ -1076,10 +1255,11 @@
   9.666              if (!annotations.isEmpty()) {
   9.667                  /*
   9.668                  System.out.println("Finding pos for: " + annotations);
   9.669 -                System.out.println("    tree: " + tree);
   9.670 -                System.out.println("    frame: " + frame);
   9.671 +                System.out.println("    tree: " + tree + " kind: " + tree.getKind());
   9.672 +                System.out.println("    frame: " + frame + " kind: " + frame.getKind());
   9.673                  */
   9.674                  TypeAnnotationPosition p = new TypeAnnotationPosition();
   9.675 +                p.onLambda = currentLambda;
   9.676                  resolveFrame(tree, frame, frames.toList(), p);
   9.677                  setTypeAnnotationPos(annotations, p);
   9.678              }
   9.679 @@ -1088,8 +1268,17 @@
   9.680          private static void setTypeAnnotationPos(List<JCAnnotation> annotations,
   9.681                  TypeAnnotationPosition position) {
   9.682              for (JCAnnotation anno : annotations) {
   9.683 -                ((Attribute.TypeCompound) anno.attribute).position = position;
   9.684 +                // attribute might be null during DeferredAttr;
   9.685 +                // we will be back later.
   9.686 +                if (anno.attribute != null) {
   9.687 +                    ((Attribute.TypeCompound) anno.attribute).position = position;
   9.688 +                }
   9.689              }
   9.690          }
   9.691 +
   9.692 +        @Override
   9.693 +        public String toString() {
   9.694 +            return super.toString() + ": sigOnly: " + sigOnly;
   9.695 +        }
   9.696      }
   9.697  }
    10.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue May 14 13:55:35 2013 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue May 14 15:04:06 2013 -0700
    10.3 @@ -26,7 +26,6 @@
    10.4  package com.sun.tools.javac.code;
    10.5  
    10.6  import java.lang.ref.SoftReference;
    10.7 -import java.util.Comparator;
    10.8  import java.util.HashSet;
    10.9  import java.util.HashMap;
   10.10  import java.util.Locale;
   10.11 @@ -34,8 +33,6 @@
   10.12  import java.util.Set;
   10.13  import java.util.WeakHashMap;
   10.14  
   10.15 -import javax.lang.model.type.TypeKind;
   10.16 -
   10.17  import com.sun.tools.javac.code.Attribute.RetentionPolicy;
   10.18  import com.sun.tools.javac.code.Lint.LintCategory;
   10.19  import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
   10.20 @@ -204,7 +201,7 @@
   10.21                      WildcardType unb = new WildcardType(syms.objectType,
   10.22                                                          BoundKind.UNBOUND,
   10.23                                                          syms.boundClass,
   10.24 -                                                        (TypeVar)parms.head);
   10.25 +                                                        (TypeVar)parms.head.unannotatedType());
   10.26                      if (!containsType(args.head, unb))
   10.27                          return false;
   10.28                      parms = parms.tail;
   10.29 @@ -268,7 +265,7 @@
   10.30                          List<Type> opens = openVars.toList();
   10.31                          ListBuffer<Type> qs = new ListBuffer<Type>();
   10.32                          for (List<Type> iter = opens; iter.nonEmpty(); iter = iter.tail) {
   10.33 -                            qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass, (TypeVar) iter.head));
   10.34 +                            qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass, (TypeVar) iter.head.unannotatedType()));
   10.35                          }
   10.36                          res = subst(res, opens, qs.toList());
   10.37                      }
   10.38 @@ -581,12 +578,12 @@
   10.39              //simply replace the wildcards with its bound
   10.40              for (Type t : formalInterface.getTypeArguments()) {
   10.41                  if (actualTypeargs.head.hasTag(WILDCARD)) {
   10.42 -                    WildcardType wt = (WildcardType)actualTypeargs.head;
   10.43 +                    WildcardType wt = (WildcardType)actualTypeargs.head.unannotatedType();
   10.44                      Type bound;
   10.45                      switch (wt.kind) {
   10.46                          case EXTENDS:
   10.47                          case UNBOUND:
   10.48 -                            CapturedType capVar = (CapturedType)capturedTypeargs.head;
   10.49 +                            CapturedType capVar = (CapturedType)capturedTypeargs.head.unannotatedType();
   10.50                              //use declared bound if it doesn't depend on formal type-args
   10.51                              bound = capVar.bound.containsAny(capturedSite.getTypeArguments()) ?
   10.52                                      wt.type : capVar.bound;
   10.53 @@ -964,6 +961,9 @@
   10.54                  isSameTypeStrict.visit(t, s) :
   10.55                  isSameTypeLoose.visit(t, s);
   10.56      }
   10.57 +    public boolean isSameAnnotatedType(Type t, Type s) {
   10.58 +        return isSameAnnotatedType.visit(t, s);
   10.59 +    }
   10.60      // where
   10.61          abstract class SameTypeVisitor extends TypeRelation {
   10.62  
   10.63 @@ -982,7 +982,7 @@
   10.64                      if (s.tag == TYPEVAR) {
   10.65                          //type-substitution does not preserve type-var types
   10.66                          //check that type var symbols and bounds are indeed the same
   10.67 -                        return sameTypeVars((TypeVar)t, (TypeVar)s);
   10.68 +                        return sameTypeVars((TypeVar)t.unannotatedType(), (TypeVar)s.unannotatedType());
   10.69                      }
   10.70                      else {
   10.71                          //special case for s == ? super X, where upper(s) = u
   10.72 @@ -1096,7 +1096,9 @@
   10.73           * Standard type-equality relation - type variables are considered
   10.74           * equals if they share the same type symbol.
   10.75           */
   10.76 -        TypeRelation isSameTypeLoose = new SameTypeVisitor() {
   10.77 +        TypeRelation isSameTypeLoose = new LooseSameTypeVisitor();
   10.78 +
   10.79 +        private class LooseSameTypeVisitor extends SameTypeVisitor {
   10.80              @Override
   10.81              boolean sameTypeVars(TypeVar tv1, TypeVar tv2) {
   10.82                  return tv1.tsym == tv2.tsym && visit(tv1.getUpperBound(), tv2.getUpperBound());
   10.83 @@ -1126,12 +1128,29 @@
   10.84                  if (!s.hasTag(WILDCARD)) {
   10.85                      return false;
   10.86                  } else {
   10.87 -                    WildcardType t2 = (WildcardType)s;
   10.88 +                    WildcardType t2 = (WildcardType)s.unannotatedType();
   10.89                      return t.kind == t2.kind &&
   10.90                              isSameType(t.type, t2.type, true);
   10.91                  }
   10.92              }
   10.93          };
   10.94 +
   10.95 +        /**
   10.96 +         * A version of LooseSameTypeVisitor that takes AnnotatedTypes
   10.97 +         * into account.
   10.98 +         */
   10.99 +        TypeRelation isSameAnnotatedType = new LooseSameTypeVisitor() {
  10.100 +            @Override
  10.101 +            public Boolean visitAnnotatedType(AnnotatedType t, Type s) {
  10.102 +                if (!s.isAnnotated())
  10.103 +                    return false;
  10.104 +                if (!t.getAnnotationMirrors().containsAll(s.getAnnotationMirrors()))
  10.105 +                    return false;
  10.106 +                if (!s.getAnnotationMirrors().containsAll(t.getAnnotationMirrors()))
  10.107 +                    return false;
  10.108 +                return visit(t.underlyingType, s);
  10.109 +            }
  10.110 +        };
  10.111      // </editor-fold>
  10.112  
  10.113      // <editor-fold defaultstate="collapsed" desc="Contains Type">
  10.114 @@ -1140,7 +1159,7 @@
  10.115          case UNDETVAR:
  10.116              if (s.tag == WILDCARD) {
  10.117                  UndetVar undetvar = (UndetVar)t;
  10.118 -                WildcardType wt = (WildcardType)s;
  10.119 +                WildcardType wt = (WildcardType)s.unannotatedType();
  10.120                  switch(wt.kind) {
  10.121                      case UNBOUND: //similar to ? extends Object
  10.122                      case EXTENDS: {
  10.123 @@ -1207,7 +1226,7 @@
  10.124  
  10.125              private Type U(Type t) {
  10.126                  while (t.tag == WILDCARD) {
  10.127 -                    WildcardType w = (WildcardType)t;
  10.128 +                    WildcardType w = (WildcardType)t.unannotatedType();
  10.129                      if (w.isSuperBound())
  10.130                          return w.bound == null ? syms.objectType : w.bound.bound;
  10.131                      else
  10.132 @@ -1218,7 +1237,7 @@
  10.133  
  10.134              private Type L(Type t) {
  10.135                  while (t.tag == WILDCARD) {
  10.136 -                    WildcardType w = (WildcardType)t;
  10.137 +                    WildcardType w = (WildcardType)t.unannotatedType();
  10.138                      if (w.isExtendsBound())
  10.139                          return syms.botType;
  10.140                      else
  10.141 @@ -1276,15 +1295,15 @@
  10.142          };
  10.143  
  10.144      public boolean isCaptureOf(Type s, WildcardType t) {
  10.145 -        if (s.tag != TYPEVAR || !((TypeVar)s).isCaptured())
  10.146 +        if (s.tag != TYPEVAR || !((TypeVar)s.unannotatedType()).isCaptured())
  10.147              return false;
  10.148 -        return isSameWildcard(t, ((CapturedType)s).wildcard);
  10.149 +        return isSameWildcard(t, ((CapturedType)s.unannotatedType()).wildcard);
  10.150      }
  10.151  
  10.152      public boolean isSameWildcard(WildcardType t, Type s) {
  10.153          if (s.tag != WILDCARD)
  10.154              return false;
  10.155 -        WildcardType w = (WildcardType)s;
  10.156 +        WildcardType w = (WildcardType)s.unannotatedType();
  10.157          return w.kind == t.kind && w.type == t.type;
  10.158      }
  10.159  
  10.160 @@ -1373,8 +1392,8 @@
  10.161  
  10.162                  if (t.isCompound() || s.isCompound()) {
  10.163                      return !t.isCompound() ?
  10.164 -                            visitIntersectionType((IntersectionClassType)s, t, true) :
  10.165 -                            visitIntersectionType((IntersectionClassType)t, s, false);
  10.166 +                            visitIntersectionType((IntersectionClassType)s.unannotatedType(), t, true) :
  10.167 +                            visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false);
  10.168                  }
  10.169  
  10.170                  if (s.tag == CLASS || s.tag == ARRAY) {
  10.171 @@ -3070,7 +3089,7 @@
  10.172              for (Type t : tvars) {
  10.173                  if (!first) s.append(", ");
  10.174                  first = false;
  10.175 -                appendTyparamString(((TypeVar)t), s);
  10.176 +                appendTyparamString(((TypeVar)t.unannotatedType()), s);
  10.177              }
  10.178              s.append('>');
  10.179              return s.toString();
  10.180 @@ -3710,9 +3729,9 @@
  10.181                 !currentS.isEmpty()) {
  10.182              if (currentS.head != currentT.head) {
  10.183                  captured = true;
  10.184 -                WildcardType Ti = (WildcardType)currentT.head;
  10.185 +                WildcardType Ti = (WildcardType)currentT.head.unannotatedType();
  10.186                  Type Ui = currentA.head.getUpperBound();
  10.187 -                CapturedType Si = (CapturedType)currentS.head;
  10.188 +                CapturedType Si = (CapturedType)currentS.head.unannotatedType();
  10.189                  if (Ui == null)
  10.190                      Ui = syms.objectType;
  10.191                  switch (Ti.kind) {
  10.192 @@ -3749,6 +3768,7 @@
  10.193              ListBuffer<Type> result = lb();
  10.194              for (Type t : types) {
  10.195                  if (t.tag == WILDCARD) {
  10.196 +                    t = t.unannotatedType();
  10.197                      Type bound = ((WildcardType)t).getExtendsBound();
  10.198                      if (bound == null)
  10.199                          bound = syms.objectType;
  10.200 @@ -3842,7 +3862,7 @@
  10.201  
  10.202      private boolean giveWarning(Type from, Type to) {
  10.203          List<Type> bounds = to.isCompound() ?
  10.204 -                ((IntersectionClassType)to).getComponents() : List.of(to);
  10.205 +                ((IntersectionClassType)to.unannotatedType()).getComponents() : List.of(to);
  10.206          for (Type b : bounds) {
  10.207              Type subFrom = asSub(from, b.tsym);
  10.208              if (b.isParameterized() &&
  10.209 @@ -4107,7 +4127,7 @@
  10.210  
  10.211          Type B(Type t) {
  10.212              while (t.tag == WILDCARD) {
  10.213 -                WildcardType w = (WildcardType)t;
  10.214 +                WildcardType w = (WildcardType)t.unannotatedType();
  10.215                  t = high ?
  10.216                      w.getExtendsBound() :
  10.217                      w.getSuperBound();
  10.218 @@ -4182,7 +4202,7 @@
  10.219  
  10.220          public boolean equals(Object obj) {
  10.221              return (obj instanceof UniqueType) &&
  10.222 -                types.isSameType(type, ((UniqueType)obj).type);
  10.223 +                types.isSameAnnotatedType(type, ((UniqueType)obj).type);
  10.224          }
  10.225  
  10.226          public String toString() {
    11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Tue May 14 13:55:35 2013 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Tue May 14 15:04:06 2013 -0700
    11.3 @@ -216,18 +216,42 @@
    11.4      Attribute.Compound enterAnnotation(JCAnnotation a,
    11.5                                         Type expected,
    11.6                                         Env<AttrContext> env) {
    11.7 +        return enterAnnotation(a, expected, env, false);
    11.8 +    }
    11.9 +
   11.10 +    Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
   11.11 +            Type expected,
   11.12 +            Env<AttrContext> env) {
   11.13 +        return (Attribute.TypeCompound) enterAnnotation(a, expected, env, true);
   11.14 +    }
   11.15 +
   11.16 +    // boolean typeAnnotation determines whether the method returns
   11.17 +    // a Compound (false) or TypeCompound (true).
   11.18 +    Attribute.Compound enterAnnotation(JCAnnotation a,
   11.19 +            Type expected,
   11.20 +            Env<AttrContext> env,
   11.21 +            boolean typeAnnotation) {
   11.22          // The annotation might have had its type attributed (but not checked)
   11.23          // by attr.attribAnnotationTypes during MemberEnter, in which case we do not
   11.24          // need to do it again.
   11.25          Type at = (a.annotationType.type != null ? a.annotationType.type
   11.26                    : attr.attribType(a.annotationType, env));
   11.27          a.type = chk.checkType(a.annotationType.pos(), at, expected);
   11.28 -        if (a.type.isErroneous())
   11.29 -            return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
   11.30 +        if (a.type.isErroneous()) {
   11.31 +            if (typeAnnotation) {
   11.32 +                return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
   11.33 +            } else {
   11.34 +                return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
   11.35 +            }
   11.36 +        }
   11.37          if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) {
   11.38              log.error(a.annotationType.pos(),
   11.39                        "not.annotation.type", a.type.toString());
   11.40 -            return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
   11.41 +            if (typeAnnotation) {
   11.42 +                return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
   11.43 +            } else {
   11.44 +                return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
   11.45 +            }
   11.46          }
   11.47          List<JCExpression> args = a.args;
   11.48          if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
   11.49 @@ -266,12 +290,21 @@
   11.50                             ((MethodSymbol)method, value));
   11.51              t.type = result;
   11.52          }
   11.53 -        // TODO: this should be a TypeCompound if "a" is a JCTypeAnnotation.
   11.54 -        // However, how do we find the correct position?
   11.55 -        Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList());
   11.56 -        // TODO: is this something we want? Who would use it?
   11.57 -        // a.attribute = ac;
   11.58 -        return ac;
   11.59 +        if (typeAnnotation) {
   11.60 +            if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) {
   11.61 +                // Create a new TypeCompound
   11.62 +                Attribute.TypeCompound tc = new Attribute.TypeCompound(a.type, buf.toList(), new TypeAnnotationPosition());
   11.63 +                a.attribute = tc;
   11.64 +                return tc;
   11.65 +            } else {
   11.66 +                // Use an existing TypeCompound
   11.67 +                return a.attribute;
   11.68 +            }
   11.69 +        } else {
   11.70 +            Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList());
   11.71 +            a.attribute = ac;
   11.72 +            return ac;
   11.73 +        }
   11.74      }
   11.75  
   11.76      Attribute enterAttributeValue(Type expected,
   11.77 @@ -354,15 +387,6 @@
   11.78          return new Attribute.Error(attr.attribExpr(tree, env, expected));
   11.79      }
   11.80  
   11.81 -    Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
   11.82 -            Type expected,
   11.83 -            Env<AttrContext> env) {
   11.84 -        Attribute.Compound c = enterAnnotation(a, expected, env);
   11.85 -        Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, new TypeAnnotationPosition());
   11.86 -        a.attribute = tc;
   11.87 -        return tc;
   11.88 -    }
   11.89 -
   11.90      /* *********************************
   11.91       * Support for repeating annotations
   11.92       ***********************************/
    12.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue May 14 13:55:35 2013 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue May 14 15:04:06 2013 -0700
    12.3 @@ -768,7 +768,12 @@
    12.4          JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
    12.5  
    12.6          try {
    12.7 -            memberEnter.typeAnnotate(initializer, env, env.info.enclVar);
    12.8 +            // Use null as symbol to not attach the type annotation to any symbol.
    12.9 +            // The initializer will later also be visited and then we'll attach
   12.10 +            // to the symbol.
   12.11 +            // This prevents having multiple type annotations, just because of
   12.12 +            // lazy constant value evaluation.
   12.13 +            memberEnter.typeAnnotate(initializer, env, null);
   12.14              annotate.flush();
   12.15              Type itype = attribExpr(initializer, env, type);
   12.16              if (itype.constValue() != null)
   12.17 @@ -935,11 +940,6 @@
   12.18                  Env<AttrContext> newEnv = memberEnter.methodEnv(tree, env);
   12.19                  attribType(tree.recvparam, newEnv);
   12.20                  chk.validate(tree.recvparam, newEnv);
   12.21 -                if (!(tree.recvparam.type == m.owner.type || types.isSameType(tree.recvparam.type, m.owner.type))) {
   12.22 -                    // The == covers the common non-generic case, but for generic classes we need isSameType;
   12.23 -                    // note that equals didn't work.
   12.24 -                    log.error(tree.recvparam.pos(), "incorrect.receiver.type");
   12.25 -                }
   12.26              }
   12.27  
   12.28              // annotation method checks
   12.29 @@ -1112,6 +1112,18 @@
   12.30              memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner);
   12.31              annotate.flush();
   12.32  
   12.33 +            {
   12.34 +                // Store init and clinit type annotations with the ClassSymbol
   12.35 +                // to allow output in Gen.normalizeDefs.
   12.36 +                ClassSymbol cs = (ClassSymbol)env.info.scope.owner;
   12.37 +                List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes();
   12.38 +                if ((tree.flags & STATIC) != 0) {
   12.39 +                    cs.annotations.appendClassInitTypeAttributes(tas);
   12.40 +                } else {
   12.41 +                    cs.annotations.appendInitTypeAttributes(tas);
   12.42 +                }
   12.43 +            }
   12.44 +
   12.45              attribStats(tree.stats, localEnv);
   12.46          } else {
   12.47              // Create a new local environment with a local scope.
   12.48 @@ -2131,6 +2143,11 @@
   12.49                      tree.constructor,
   12.50                      localEnv,
   12.51                      new ResultInfo(VAL, newMethodTemplate(syms.voidType, argtypes, typeargtypes)));
   12.52 +            } else {
   12.53 +                if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
   12.54 +                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
   12.55 +                            tree.clazz.type.tsym);
   12.56 +                }
   12.57              }
   12.58  
   12.59              if (tree.constructor != null && tree.constructor.kind == MTH)
   12.60 @@ -2195,6 +2212,20 @@
   12.61                  }
   12.62              }
   12.63  
   12.64 +    private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
   12.65 +            Symbol sym) {
   12.66 +        // Ensure that no declaration annotations are present.
   12.67 +        // Note that a tree type might be an AnnotatedType with
   12.68 +        // empty annotations, if only declaration annotations were given.
   12.69 +        // This method will raise an error for such a type.
   12.70 +        for (JCAnnotation ai : annotations) {
   12.71 +            if (TypeAnnotations.annotationType(syms, names, ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
   12.72 +                log.error(ai.pos(), "annotation.type.not.applicable");
   12.73 +            }
   12.74 +        }
   12.75 +    }
   12.76 +
   12.77 +
   12.78      /** Make an attributed null check tree.
   12.79       */
   12.80      public JCExpression makeNullCheck(JCExpression arg) {
   12.81 @@ -2221,6 +2252,10 @@
   12.82                  attribExpr(l.head, localEnv, syms.intType);
   12.83                  owntype = new ArrayType(owntype, syms.arrayClass);
   12.84              }
   12.85 +            if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
   12.86 +                checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
   12.87 +                        tree.elemtype.type.tsym);
   12.88 +            }
   12.89          } else {
   12.90              // we are seeing an untyped aggregate { ... }
   12.91              // this is allowed only if the prototype is an array
   12.92 @@ -3763,6 +3798,12 @@
   12.93                      }
   12.94                  }
   12.95                  owntype = new ClassType(clazzOuter, actuals, clazztype.tsym);
   12.96 +                if (clazztype.isAnnotated()) {
   12.97 +                    // Use the same AnnotatedType, because it will have
   12.98 +                    // its annotations set later.
   12.99 +                    ((AnnotatedType)clazztype).underlyingType = owntype;
  12.100 +                    owntype = clazztype;
  12.101 +                }
  12.102              } else {
  12.103                  if (formals.length() != 0) {
  12.104                      log.error(tree.pos(), "wrong.number.type.args",
  12.105 @@ -3961,7 +4002,14 @@
  12.106  
  12.107          ListBuffer<Attribute.TypeCompound> buf = ListBuffer.lb();
  12.108          for (JCAnnotation anno : annotations) {
  12.109 -            buf.append((Attribute.TypeCompound) anno.attribute);
  12.110 +            if (anno.attribute != null) {
  12.111 +                // TODO: this null-check is only needed for an obscure
  12.112 +                // ordering issue, where annotate.flush is called when
  12.113 +                // the attribute is not set yet. For an example failure
  12.114 +                // try the referenceinfos/NestedTypes.java test.
  12.115 +                // Any better solutions?
  12.116 +                buf.append((Attribute.TypeCompound) anno.attribute);
  12.117 +            }
  12.118          }
  12.119          return buf.toList();
  12.120      }
  12.121 @@ -4266,15 +4314,12 @@
  12.122          tree.accept(typeAnnotationsValidator);
  12.123      }
  12.124      //where
  12.125 -    private final JCTree.Visitor typeAnnotationsValidator =
  12.126 -        new TreeScanner() {
  12.127 +    private final JCTree.Visitor typeAnnotationsValidator = new TreeScanner() {
  12.128 +
  12.129 +        private boolean checkAllAnnotations = false;
  12.130 +
  12.131          public void visitAnnotation(JCAnnotation tree) {
  12.132 -            if (tree.hasTag(TYPE_ANNOTATION)) {
  12.133 -                // TODO: It seems to WMD as if the annotation in
  12.134 -                // parameters, in particular also the recvparam, are never
  12.135 -                // of type JCTypeAnnotation and therefore never checked!
  12.136 -                // Luckily this check doesn't really do anything that isn't
  12.137 -                // also done elsewhere.
  12.138 +            if (tree.hasTag(TYPE_ANNOTATION) || checkAllAnnotations) {
  12.139                  chk.validateTypeAnnotation(tree, false);
  12.140              }
  12.141              super.visitAnnotation(tree);
  12.142 @@ -4288,15 +4333,10 @@
  12.143              // super.visitTypeParameter(tree);
  12.144          }
  12.145          public void visitMethodDef(JCMethodDecl tree) {
  12.146 -            // Static methods cannot have receiver type annotations.
  12.147 -            // In test case FailOver15.java, the nested method getString has
  12.148 -            // a null sym, because an unknown class is instantiated.
  12.149 -            // I would say it's safe to skip.
  12.150 -            if (tree.sym != null && (tree.sym.flags() & Flags.STATIC) != 0) {
  12.151 -                if (tree.recvparam != null) {
  12.152 -                    // TODO: better error message. Is the pos good?
  12.153 -                    log.error(tree.recvparam.pos(), "annotation.type.not.applicable");
  12.154 -                }
  12.155 +            if (tree.recvparam != null &&
  12.156 +                    tree.recvparam.vartype.type.getKind() != TypeKind.ERROR) {
  12.157 +                checkForDeclarationAnnotations(tree.recvparam.mods.annotations,
  12.158 +                        tree.recvparam.vartype.type.tsym);
  12.159              }
  12.160              if (tree.restype != null && tree.restype.type != null) {
  12.161                  validateAnnotatedType(tree.restype, tree.restype.type);
  12.162 @@ -4318,9 +4358,30 @@
  12.163                  validateAnnotatedType(tree.clazz, tree.clazz.type);
  12.164              super.visitTypeTest(tree);
  12.165          }
  12.166 -        // TODO: what else do we need?
  12.167 -        // public void visitNewClass(JCNewClass tree) {
  12.168 -        // public void visitNewArray(JCNewArray tree) {
  12.169 +        public void visitNewClass(JCNewClass tree) {
  12.170 +            if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
  12.171 +                boolean prevCheck = this.checkAllAnnotations;
  12.172 +                try {
  12.173 +                    this.checkAllAnnotations = true;
  12.174 +                    scan(((JCAnnotatedType)tree.clazz).annotations);
  12.175 +                } finally {
  12.176 +                    this.checkAllAnnotations = prevCheck;
  12.177 +                }
  12.178 +            }
  12.179 +            super.visitNewClass(tree);
  12.180 +        }
  12.181 +        public void visitNewArray(JCNewArray tree) {
  12.182 +            if (tree.elemtype != null && tree.elemtype.hasTag(ANNOTATED_TYPE)) {
  12.183 +                boolean prevCheck = this.checkAllAnnotations;
  12.184 +                try {
  12.185 +                    this.checkAllAnnotations = true;
  12.186 +                    scan(((JCAnnotatedType)tree.elemtype).annotations);
  12.187 +                } finally {
  12.188 +                    this.checkAllAnnotations = prevCheck;
  12.189 +                }
  12.190 +            }
  12.191 +            super.visitNewArray(tree);
  12.192 +        }
  12.193  
  12.194          /* I would want to model this after
  12.195           * com.sun.tools.javac.comp.Check.Validator.visitSelectInternal(JCFieldAccess)
    13.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue May 14 13:55:35 2013 -0700
    13.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue May 14 15:04:06 2013 -0700
    13.3 @@ -1213,7 +1213,7 @@
    13.4  
    13.5      /** Validate a type expression. That is,
    13.6       *  check that all type arguments of a parametric type are within
    13.7 -     *  their bounds. This must be done in a second phase after type attributon
    13.8 +     *  their bounds. This must be done in a second phase after type attribution
    13.9       *  since a class might have a subclass as type parameter bound. E.g:
   13.10       *
   13.11       *  <pre>{@code
    14.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue May 14 13:55:35 2013 -0700
    14.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue May 14 15:04:06 2013 -0700
    14.3 @@ -25,12 +25,12 @@
    14.4  package com.sun.tools.javac.comp;
    14.5  
    14.6  import com.sun.tools.javac.tree.*;
    14.7 -import com.sun.tools.javac.tree.JCTree;
    14.8  import com.sun.tools.javac.tree.JCTree.*;
    14.9  import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
   14.10  import com.sun.tools.javac.tree.TreeMaker;
   14.11  import com.sun.tools.javac.tree.TreeScanner;
   14.12  import com.sun.tools.javac.tree.TreeTranslator;
   14.13 +import com.sun.tools.javac.code.Attribute;
   14.14  import com.sun.tools.javac.code.Kinds;
   14.15  import com.sun.tools.javac.code.Scope;
   14.16  import com.sun.tools.javac.code.Symbol;
   14.17 @@ -46,7 +46,6 @@
   14.18  import com.sun.tools.javac.comp.Lower.BasicFreeVarCollector;
   14.19  import com.sun.tools.javac.jvm.*;
   14.20  import com.sun.tools.javac.util.*;
   14.21 -import com.sun.tools.javac.util.List;
   14.22  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
   14.23  import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
   14.24  
   14.25 @@ -238,6 +237,24 @@
   14.26          MethodSymbol sym = (MethodSymbol)localContext.translatedSym;
   14.27          MethodType lambdaType = (MethodType) sym.type;
   14.28  
   14.29 +        {
   14.30 +            MethodSymbol owner = (MethodSymbol) localContext.owner;
   14.31 +            ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<Attribute.TypeCompound>();
   14.32 +            ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<Attribute.TypeCompound>();
   14.33 +
   14.34 +            for (Attribute.TypeCompound tc : owner.getRawTypeAttributes()) {
   14.35 +                if (tc.position.onLambda == tree) {
   14.36 +                    lambdaTypeAnnos.append(tc);
   14.37 +                } else {
   14.38 +                    ownerTypeAnnos.append(tc);
   14.39 +                }
   14.40 +            }
   14.41 +            if (lambdaTypeAnnos.nonEmpty()) {
   14.42 +                owner.annotations.setTypeAttributes(ownerTypeAnnos.toList());
   14.43 +                sym.annotations.setTypeAttributes(lambdaTypeAnnos.toList());
   14.44 +            }
   14.45 +        }
   14.46 +
   14.47          //create the method declaration hoisting the lambda body
   14.48          JCMethodDecl lambdaDecl = make.MethodDef(make.Modifiers(sym.flags_field),
   14.49                  sym.name,
   14.50 @@ -373,12 +390,15 @@
   14.51              if (lambdaContext.getSymbolMap(PARAM).containsKey(tree.sym)) {
   14.52                  Symbol translatedSym = lambdaContext.getSymbolMap(PARAM).get(tree.sym);
   14.53                  result = make.Ident(translatedSym).setType(tree.type);
   14.54 +                translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes());
   14.55              } else if (lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) {
   14.56                  Symbol translatedSym = lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym);
   14.57                  result = make.Ident(translatedSym).setType(tree.type);
   14.58 +                translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes());
   14.59              } else if (lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) {
   14.60                  Symbol translatedSym = lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym);
   14.61                  result = make.Ident(translatedSym).setType(translatedSym.type);
   14.62 +                translatedSym.annotations.setTypeAttributes(tree.sym.getRawTypeAttributes());
   14.63              } else if (lambdaContext.getSymbolMap(CAPTURED_VAR).containsKey(tree.sym)) {
   14.64                  Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym);
   14.65                  result = make.Ident(translatedSym).setType(tree.type);
   14.66 @@ -1676,24 +1696,33 @@
   14.67               * synthetic lambda body
   14.68               */
   14.69              Symbol translate(Name name, final Symbol sym, LambdaSymbolKind skind) {
   14.70 +                Symbol ret;
   14.71                  switch (skind) {
   14.72                      case CAPTURED_THIS:
   14.73 -                        return sym;  // self represented
   14.74 +                        ret = sym;  // self represented
   14.75 +                        break;
   14.76                      case TYPE_VAR:
   14.77                          // Just erase the type var
   14.78 -                        return new VarSymbol(sym.flags(), name,
   14.79 +                        ret = new VarSymbol(sym.flags(), name,
   14.80                                  types.erasure(sym.type), sym.owner);
   14.81 +                        break;
   14.82                      case CAPTURED_VAR:
   14.83 -                        return new VarSymbol(SYNTHETIC | FINAL, name, types.erasure(sym.type), translatedSym) {
   14.84 +                        ret = new VarSymbol(SYNTHETIC | FINAL, name, types.erasure(sym.type), translatedSym) {
   14.85                              @Override
   14.86                              public Symbol baseSymbol() {
   14.87                                  //keep mapping with original captured symbol
   14.88                                  return sym;
   14.89                              }
   14.90                          };
   14.91 +                        break;
   14.92                      default:
   14.93 -                        return makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym);
   14.94 +                        ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym);
   14.95                  }
   14.96 +                if (ret != sym) {
   14.97 +                    ret.annotations.setDeclarationAttributes(sym.getRawAttributes());
   14.98 +                    ret.annotations.setTypeAttributes(sym.getRawTypeAttributes());
   14.99 +                }
  14.100 +                return ret;
  14.101              }
  14.102  
  14.103              void addSymbol(Symbol sym, LambdaSymbolKind skind) {
    15.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue May 14 13:55:35 2013 -0700
    15.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Tue May 14 15:04:06 2013 -0700
    15.3 @@ -28,6 +28,7 @@
    15.4  import java.util.*;
    15.5  
    15.6  import com.sun.tools.javac.code.*;
    15.7 +import com.sun.tools.javac.code.Type.AnnotatedType;
    15.8  import com.sun.tools.javac.jvm.*;
    15.9  import com.sun.tools.javac.main.Option.PkgInfo;
   15.10  import com.sun.tools.javac.tree.*;
   15.11 @@ -2767,10 +2768,28 @@
   15.12          }
   15.13  
   15.14      public void visitAnnotatedType(JCAnnotatedType tree) {
   15.15 -        // No need to retain type annotations any longer.
   15.16 +        // No need to retain type annotations in the tree
   15.17          // tree.annotations = translate(tree.annotations);
   15.18 +        tree.annotations = List.nil();
   15.19          tree.underlyingType = translate(tree.underlyingType);
   15.20 -        result = tree.underlyingType;
   15.21 +        // but maintain type annotations in the type.
   15.22 +        if (tree.type.isAnnotated()) {
   15.23 +            if (tree.underlyingType.type.isAnnotated()) {
   15.24 +                // The erasure of a type variable might be annotated.
   15.25 +                // Merge all annotations.
   15.26 +                AnnotatedType newat = (AnnotatedType) tree.underlyingType.type;
   15.27 +                AnnotatedType at = (AnnotatedType) tree.type;
   15.28 +                at.underlyingType = newat.underlyingType;
   15.29 +                newat.typeAnnotations = at.typeAnnotations.appendList(newat.typeAnnotations);
   15.30 +                tree.type = newat;
   15.31 +            } else {
   15.32 +                // Create a new AnnotatedType to have the correct tag.
   15.33 +                AnnotatedType oldat = (AnnotatedType) tree.type;
   15.34 +                tree.type = new AnnotatedType(tree.underlyingType.type);
   15.35 +                ((AnnotatedType) tree.type).typeAnnotations = oldat.typeAnnotations;
   15.36 +            }
   15.37 +        }
   15.38 +        result = tree;
   15.39      }
   15.40  
   15.41      public void visitTypeCast(JCTypeCast tree) {
    16.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue May 14 13:55:35 2013 -0700
    16.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue May 14 15:04:06 2013 -0700
    16.3 @@ -31,7 +31,6 @@
    16.4  import java.util.Map;
    16.5  import java.util.Set;
    16.6  
    16.7 -import javax.lang.model.type.TypeKind;
    16.8  import javax.tools.JavaFileObject;
    16.9  
   16.10  import com.sun.tools.javac.code.*;
   16.11 @@ -617,7 +616,26 @@
   16.12              if (TreeInfo.isEnumInit(tree)) {
   16.13                  attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
   16.14              } else {
   16.15 +                // Make sure type annotations are processed.
   16.16 +                // But we don't have a symbol to attach them to yet - use null.
   16.17 +                typeAnnotate(tree.vartype, env, null);
   16.18                  attr.attribType(tree.vartype, localEnv);
   16.19 +                if (tree.nameexpr != null) {
   16.20 +                    attr.attribExpr(tree.nameexpr, localEnv);
   16.21 +                    MethodSymbol m = localEnv.enclMethod.sym;
   16.22 +                    if (m.isConstructor()) {
   16.23 +                        Type outertype = m.owner.owner.type;
   16.24 +                        if (outertype.hasTag(TypeTag.CLASS)) {
   16.25 +                            checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
   16.26 +                            checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
   16.27 +                        } else {
   16.28 +                            log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
   16.29 +                        }
   16.30 +                    } else {
   16.31 +                        checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
   16.32 +                        checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
   16.33 +                    }
   16.34 +                }
   16.35              }
   16.36          } finally {
   16.37              chk.setDeferredLintHandler(prevLintHandler);
   16.38 @@ -651,10 +669,16 @@
   16.39              enclScope.enter(v);
   16.40          }
   16.41          annotateLater(tree.mods.annotations, localEnv, v);
   16.42 -        typeAnnotate(tree.vartype, env, tree.sym);
   16.43 +        typeAnnotate(tree.vartype, env, v);
   16.44          annotate.flush();
   16.45          v.pos = tree.pos;
   16.46      }
   16.47 +    // where
   16.48 +    void checkType(JCTree tree, Type type, String diag) {
   16.49 +        if (!tree.type.isErroneous() && !types.isSameType(tree.type, type)) {
   16.50 +            log.error(tree, diag, type, tree.type);
   16.51 +        }
   16.52 +    }
   16.53  
   16.54      /** Create a fresh environment for a variable's initializer.
   16.55       *  If the variable is a field, the owner of the environment's scope
   16.56 @@ -1040,9 +1064,12 @@
   16.57                  isFirst = true;
   16.58              }
   16.59          }
   16.60 -        annotate.afterRepeated(TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree));
   16.61 +        TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree, annotate);
   16.62      }
   16.63  
   16.64 +    /*
   16.65 +     * If the symbol is non-null, attach the type annotation to it.
   16.66 +     */
   16.67      private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
   16.68              final Env<AttrContext> env,
   16.69              final Symbol s) {
   16.70 @@ -1075,8 +1102,10 @@
   16.71              }
   16.72          }
   16.73  
   16.74 -        s.annotations.appendTypeAttributesWithCompletion(
   16.75 -                annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
   16.76 +        if (s != null) {
   16.77 +            s.annotations.appendTypeAttributesWithCompletion(
   16.78 +                    annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
   16.79 +        }
   16.80      }
   16.81  
   16.82      public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym) {
   16.83 @@ -1150,6 +1179,33 @@
   16.84              // Do not annotate the body, just the signature.
   16.85              // scan(tree.body);
   16.86          }
   16.87 +
   16.88 +        @Override
   16.89 +        public void visitVarDef(final JCVariableDecl tree) {
   16.90 +            if (sym != null && sym.kind == Kinds.VAR) {
   16.91 +                // Don't visit a parameter once when the sym is the method
   16.92 +                // and once when the sym is the parameter.
   16.93 +                scan(tree.mods);
   16.94 +                scan(tree.vartype);
   16.95 +            }
   16.96 +            scan(tree.init);
   16.97 +        }
   16.98 +
   16.99 +        @Override
  16.100 +        public void visitClassDef(JCClassDecl tree) {
  16.101 +            // We can only hit a classdef if it is declared within
  16.102 +            // a method. Ignore it - the class will be visited
  16.103 +            // separately later.
  16.104 +        }
  16.105 +
  16.106 +        @Override
  16.107 +        public void visitNewClass(JCNewClass tree) {
  16.108 +            if (tree.def == null) {
  16.109 +                // For an anonymous class instantiation the class
  16.110 +                // will be visited separately.
  16.111 +                super.visitNewClass(tree);
  16.112 +            }
  16.113 +        }
  16.114      }
  16.115  
  16.116  
    17.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue May 14 13:55:35 2013 -0700
    17.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue May 14 15:04:06 2013 -0700
    17.3 @@ -1518,7 +1518,7 @@
    17.4              break;
    17.5          // exception parameter
    17.6          case EXCEPTION_PARAMETER:
    17.7 -            position.exception_index = nextByte();
    17.8 +            position.exception_index = nextChar();
    17.9              break;
   17.10          // method receiver
   17.11          case METHOD_RECEIVER:
    18.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue May 14 13:55:35 2013 -0700
    18.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Tue May 14 15:04:06 2013 -0700
    18.3 @@ -632,7 +632,7 @@
    18.4              acount++;
    18.5          }
    18.6          acount += writeJavaAnnotations(sym.getRawAttributes());
    18.7 -        acount += writeTypeAnnotations(sym.getRawTypeAttributes());
    18.8 +        acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false);
    18.9          return acount;
   18.10      }
   18.11  
   18.12 @@ -759,44 +759,30 @@
   18.13          return attrCount;
   18.14      }
   18.15  
   18.16 -    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) {
   18.17 +    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos, boolean inCode) {
   18.18          if (typeAnnos.isEmpty()) return 0;
   18.19  
   18.20          ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
   18.21          ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
   18.22  
   18.23          for (Attribute.TypeCompound tc : typeAnnos) {
   18.24 -            if (tc.position == null || tc.position.type == TargetType.UNKNOWN) {
   18.25 -                boolean found = false;
   18.26 -                // TODO: the position for the container annotation of a
   18.27 -                // repeating type annotation has to be set.
   18.28 -                // This cannot be done when the container is created, because
   18.29 -                // then the position is not determined yet.
   18.30 -                // How can we link these pieces better together?
   18.31 -                if (tc.values.size() == 1) {
   18.32 -                    Pair<MethodSymbol, Attribute> val = tc.values.get(0);
   18.33 -                    if (val.fst.getSimpleName().contentEquals("value") &&
   18.34 -                            val.snd instanceof Attribute.Array) {
   18.35 -                        Attribute.Array arr = (Attribute.Array) val.snd;
   18.36 -                        if (arr.values.length != 0 &&
   18.37 -                                arr.values[0] instanceof Attribute.TypeCompound) {
   18.38 -                            TypeCompound atycomp = (Attribute.TypeCompound) arr.values[0];
   18.39 -                            if (atycomp.position.type != TargetType.UNKNOWN) {
   18.40 -                                tc.position = atycomp.position;
   18.41 -                                found = true;
   18.42 -                            }
   18.43 -                        }
   18.44 -                    }
   18.45 -                }
   18.46 -                if (!found) {
   18.47 +            if (tc.hasUnknownPosition()) {
   18.48 +                boolean fixed = tc.tryFixPosition();
   18.49 +
   18.50 +                // Could we fix it?
   18.51 +                if (!fixed) {
   18.52                      // This happens for nested types like @A Outer. @B Inner.
   18.53                      // For method parameters we get the annotation twice! Once with
   18.54                      // a valid position, once unknown.
   18.55                      // TODO: find a cleaner solution.
   18.56 -                    // System.err.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
   18.57 +                    PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
   18.58 +                    pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
   18.59                      continue;
   18.60                  }
   18.61              }
   18.62 +
   18.63 +            if (tc.position.type.isLocal() != inCode)
   18.64 +                continue;
   18.65              if (!tc.position.emitToClassfile())
   18.66                  continue;
   18.67              switch (types.getRetention(tc)) {
   18.68 @@ -936,7 +922,7 @@
   18.69              break;
   18.70          // exception parameter
   18.71          case EXCEPTION_PARAMETER:
   18.72 -            databuf.appendByte(p.exception_index);
   18.73 +            databuf.appendChar(p.exception_index);
   18.74              break;
   18.75          // method receiver
   18.76          case METHOD_RECEIVER:
   18.77 @@ -1241,6 +1227,9 @@
   18.78              endAttr(alenIdx);
   18.79              acount++;
   18.80          }
   18.81 +
   18.82 +        acount += writeTypeAnnotations(code.meth.getRawTypeAttributes(), true);
   18.83 +
   18.84          endAttrs(acountIdx, acount);
   18.85      }
   18.86      //where
   18.87 @@ -1627,7 +1616,7 @@
   18.88              out = null;
   18.89          } finally {
   18.90              if (out != null) {
   18.91 -                // if we are propogating an exception, delete the file
   18.92 +                // if we are propagating an exception, delete the file
   18.93                  out.close();
   18.94                  outFile.delete();
   18.95                  outFile = null;
   18.96 @@ -1741,7 +1730,7 @@
   18.97  
   18.98          acount += writeFlagAttrs(c.flags());
   18.99          acount += writeJavaAnnotations(c.getRawAttributes());
  18.100 -        acount += writeTypeAnnotations(c.getRawTypeAttributes());
  18.101 +        acount += writeTypeAnnotations(c.getRawTypeAttributes(), false);
  18.102          acount += writeEnclosingMethodAttribute(c);
  18.103          acount += writeExtraClassAttributes(c);
  18.104  
    19.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java	Tue May 14 13:55:35 2013 -0700
    19.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java	Tue May 14 15:04:06 2013 -0700
    19.3 @@ -1010,7 +1010,16 @@
    19.4              state.pop(((Symbol)(pool.pool[od])).erasure(types));
    19.5              break;
    19.6          case new_:
    19.7 -            state.push(uninitializedObject(((Symbol)(pool.pool[od])).erasure(types), cp-3));
    19.8 +            Symbol sym;
    19.9 +            if (pool.pool[od] instanceof UniqueType) {
   19.10 +                // Required by change in Gen.makeRef to allow
   19.11 +                // annotated types.
   19.12 +                // TODO: is this needed anywhere else?
   19.13 +                sym = ((UniqueType)(pool.pool[od])).type.tsym;
   19.14 +            } else {
   19.15 +                sym = (Symbol)(pool.pool[od]);
   19.16 +            }
   19.17 +            state.push(uninitializedObject(sym.erasure(types), cp-3));
   19.18              break;
   19.19          case sipush:
   19.20              state.push(syms.intType);
   19.21 @@ -1972,25 +1981,38 @@
   19.22              if (lv == null || lv.sym == null
   19.23                      || lv.sym.annotations.isTypesEmpty()
   19.24                      || !lv.sym.isExceptionParameter())
   19.25 -                return;
   19.26 -
   19.27 -            int exidx = findExceptionIndex(lv);
   19.28 +                continue;
   19.29  
   19.30              for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
   19.31                  TypeAnnotationPosition p = ta.position;
   19.32 -                p.exception_index = exidx;
   19.33 +                // At this point p.type_index contains the catch type index.
   19.34 +                // Use that index to determine the exception table index.
   19.35 +                // We can afterwards discard the type_index.
   19.36 +                // A TA position is shared for all type annotations in the
   19.37 +                // same location; updating one is enough.
   19.38 +                // Use -666 as a marker that the exception_index was already updated.
   19.39 +                if (p.type_index != -666) {
   19.40 +                    p.exception_index = findExceptionIndex(p.type_index);
   19.41 +                    p.type_index = -666;
   19.42 +                }
   19.43              }
   19.44          }
   19.45      }
   19.46  
   19.47 -    private int findExceptionIndex(LocalVar lv) {
   19.48 +    private int findExceptionIndex(int catchType) {
   19.49 +        if (catchType == Integer.MIN_VALUE) {
   19.50 +            // We didn't set the catch type index correctly.
   19.51 +            // This shouldn't happen.
   19.52 +            // TODO: issue error?
   19.53 +            return -1;
   19.54 +        }
   19.55          List<char[]> iter = catchInfo.toList();
   19.56          int len = catchInfo.length();
   19.57          for (int i = 0; i < len; ++i) {
   19.58              char[] catchEntry = iter.head;
   19.59              iter = iter.tail;
   19.60 -            char handlerpc = catchEntry[2];
   19.61 -            if (lv.start_pc == handlerpc + 1) {
   19.62 +            char ct = catchEntry[3];
   19.63 +            if (catchType == ct) {
   19.64                  return i;
   19.65              }
   19.66          }
    20.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue May 14 13:55:35 2013 -0700
    20.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Tue May 14 15:04:06 2013 -0700
    20.3 @@ -30,6 +30,8 @@
    20.4  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    20.5  import com.sun.tools.javac.util.List;
    20.6  import com.sun.tools.javac.code.*;
    20.7 +import com.sun.tools.javac.code.Attribute.TypeCompound;
    20.8 +import com.sun.tools.javac.code.Symbol.VarSymbol;
    20.9  import com.sun.tools.javac.comp.*;
   20.10  import com.sun.tools.javac.tree.*;
   20.11  
   20.12 @@ -47,7 +49,6 @@
   20.13  import static com.sun.tools.javac.jvm.CRTFlags.*;
   20.14  import static com.sun.tools.javac.main.Option.*;
   20.15  import static com.sun.tools.javac.tree.JCTree.Tag.*;
   20.16 -import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
   20.17  
   20.18  /** This pass maps flat Java (i.e. without inner classes) to bytecodes.
   20.19   *
   20.20 @@ -308,7 +309,15 @@
   20.21       */
   20.22      int makeRef(DiagnosticPosition pos, Type type) {
   20.23          checkDimension(pos, type);
   20.24 -        return pool.put(type.hasTag(CLASS) ? (Object)type.tsym : (Object)type);
   20.25 +        if (type.isAnnotated()) {
   20.26 +            // Treat annotated types separately - we don't want
   20.27 +            // to collapse all of them - at least for annotated
   20.28 +            // exceptions.
   20.29 +            // TODO: review this.
   20.30 +            return pool.put((Object)type);
   20.31 +        } else {
   20.32 +            return pool.put(type.hasTag(CLASS) ? (Object)type.tsym : (Object)type);
   20.33 +        }
   20.34      }
   20.35  
   20.36      /** Check if the given type is an array with too many dimensions.
   20.37 @@ -456,7 +465,9 @@
   20.38       */
   20.39      List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) {
   20.40          ListBuffer<JCStatement> initCode = new ListBuffer<JCStatement>();
   20.41 +        ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<Attribute.TypeCompound>();
   20.42          ListBuffer<JCStatement> clinitCode = new ListBuffer<JCStatement>();
   20.43 +        ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<Attribute.TypeCompound>();
   20.44          ListBuffer<JCTree> methodDefs = new ListBuffer<JCTree>();
   20.45          // Sort definitions into three listbuffers:
   20.46          //  - initCode for instance initializers
   20.47 @@ -486,6 +497,7 @@
   20.48                              Assignment(sym, vdef.init);
   20.49                          initCode.append(init);
   20.50                          endPosTable.replaceTree(vdef, init);
   20.51 +                        initTAs.addAll(getAndRemoveNonFieldTAs(sym));
   20.52                      } else if (sym.getConstValue() == null) {
   20.53                          // Initialize class (static) variables only if
   20.54                          // they are not compile-time constants.
   20.55 @@ -493,6 +505,7 @@
   20.56                              Assignment(sym, vdef.init);
   20.57                          clinitCode.append(init);
   20.58                          endPosTable.replaceTree(vdef, init);
   20.59 +                        clinitTAs.addAll(getAndRemoveNonFieldTAs(sym));
   20.60                      } else {
   20.61                          checkStringConstant(vdef.init.pos(), sym.getConstValue());
   20.62                      }
   20.63 @@ -505,8 +518,10 @@
   20.64          // Insert any instance initializers into all constructors.
   20.65          if (initCode.length() != 0) {
   20.66              List<JCStatement> inits = initCode.toList();
   20.67 +            initTAs.addAll(c.annotations.getInitTypeAttributes());
   20.68 +            List<Attribute.TypeCompound> initTAlist = initTAs.toList();
   20.69              for (JCTree t : methodDefs) {
   20.70 -                normalizeMethod((JCMethodDecl)t, inits);
   20.71 +                normalizeMethod((JCMethodDecl)t, inits, initTAlist);
   20.72              }
   20.73          }
   20.74          // If there are class initializers, create a <clinit> method
   20.75 @@ -524,11 +539,31 @@
   20.76              JCBlock block = make.at(clinitStats.head.pos()).Block(0, clinitStats);
   20.77              block.endpos = TreeInfo.endPos(clinitStats.last());
   20.78              methodDefs.append(make.MethodDef(clinit, block));
   20.79 +
   20.80 +            if (!clinitTAs.isEmpty())
   20.81 +                clinit.annotations.appendUniqueTypes(clinitTAs.toList());
   20.82 +            if (!c.annotations.getClassInitTypeAttributes().isEmpty())
   20.83 +                clinit.annotations.appendUniqueTypes(c.annotations.getClassInitTypeAttributes());
   20.84          }
   20.85          // Return all method definitions.
   20.86          return methodDefs.toList();
   20.87      }
   20.88  
   20.89 +    private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) {
   20.90 +        List<TypeCompound> tas = sym.getRawTypeAttributes();
   20.91 +        ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<Attribute.TypeCompound>();
   20.92 +        ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<Attribute.TypeCompound>();
   20.93 +        for (TypeCompound ta : tas) {
   20.94 +            if (ta.position.type == TargetType.FIELD) {
   20.95 +                fieldTAs.add(ta);
   20.96 +            } else {
   20.97 +                nonfieldTAs.add(ta);
   20.98 +            }
   20.99 +        }
  20.100 +        sym.annotations.setTypeAttributes(fieldTAs.toList());
  20.101 +        return nonfieldTAs.toList();
  20.102 +    }
  20.103 +
  20.104      /** Check a constant value and report if it is a string that is
  20.105       *  too large.
  20.106       */
  20.107 @@ -546,8 +581,9 @@
  20.108       *  @param md        The tree potentially representing a
  20.109       *                   constructor's definition.
  20.110       *  @param initCode  The list of instance initializer statements.
  20.111 +     *  @param initTAs  Type annotations from the initializer expression.
  20.112       */
  20.113 -    void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode) {
  20.114 +    void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) {
  20.115          if (md.name == names.init && TreeInfo.isInitialConstructor(md)) {
  20.116              // We are seeing a constructor that does not call another
  20.117              // constructor of the same class.
  20.118 @@ -581,6 +617,8 @@
  20.119              md.body.stats = newstats.toList();
  20.120              if (md.body.endpos == Position.NOPOS)
  20.121                  md.body.endpos = TreeInfo.endPos(md.body.stats.last());
  20.122 +
  20.123 +            md.sym.annotations.appendUniqueTypes(initTAs);
  20.124          }
  20.125      }
  20.126  
  20.127 @@ -1527,6 +1565,11 @@
  20.128                          registerCatch(tree.pos(),
  20.129                                        startpc,  end, code.curPc(),
  20.130                                        catchType);
  20.131 +                        if (subCatch.type.isAnnotated()) {
  20.132 +                            // All compounds share the same position, simply update the
  20.133 +                            // first one.
  20.134 +                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
  20.135 +                        }
  20.136                      }
  20.137                      gaps = gaps.tail;
  20.138                      startpc = gaps.head.intValue();
  20.139 @@ -1538,6 +1581,11 @@
  20.140                          registerCatch(tree.pos(),
  20.141                                        startpc, endpc, code.curPc(),
  20.142                                        catchType);
  20.143 +                        if (subCatch.type.isAnnotated()) {
  20.144 +                            // All compounds share the same position, simply update the
  20.145 +                            // first one.
  20.146 +                            subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
  20.147 +                        }
  20.148                      }
  20.149                  }
  20.150                  VarSymbol exparam = tree.param.sym;
  20.151 @@ -1783,42 +1831,44 @@
  20.152          result = items.makeStackItem(pt);
  20.153      }
  20.154  
  20.155 -   private void setTypeAnnotationPositions(int treePos) {
  20.156 -       MethodSymbol meth = code.meth;
  20.157 +    private void setTypeAnnotationPositions(int treePos) {
  20.158 +        MethodSymbol meth = code.meth;
  20.159 +        boolean initOrClinit = code.meth.getKind() == javax.lang.model.element.ElementKind.CONSTRUCTOR
  20.160 +                || code.meth.getKind() == javax.lang.model.element.ElementKind.STATIC_INIT;
  20.161  
  20.162 -       for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) {
  20.163 -           if (ta.position.pos == treePos) {
  20.164 -               ta.position.offset = code.cp;
  20.165 -               ta.position.lvarOffset = new int[] { code.cp };
  20.166 -               ta.position.isValidOffset = true;
  20.167 -           }
  20.168 -       }
  20.169 +        for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) {
  20.170 +            if (ta.hasUnknownPosition())
  20.171 +                ta.tryFixPosition();
  20.172  
  20.173 -       if (code.meth.getKind() != javax.lang.model.element.ElementKind.CONSTRUCTOR
  20.174 -               && code.meth.getKind() != javax.lang.model.element.ElementKind.STATIC_INIT)
  20.175 -           return;
  20.176 +            if (ta.position.matchesPos(treePos))
  20.177 +                ta.position.updatePosOffset(code.cp);
  20.178 +        }
  20.179  
  20.180 -       for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) {
  20.181 -           if (ta.position.pos == treePos) {
  20.182 -               ta.position.offset = code.cp;
  20.183 -               ta.position.lvarOffset = new int[] { code.cp };
  20.184 -               ta.position.isValidOffset = true;
  20.185 -           }
  20.186 -       }
  20.187 +        if (!initOrClinit)
  20.188 +            return;
  20.189  
  20.190 -       ClassSymbol clazz = meth.enclClass();
  20.191 -       for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
  20.192 -           if (!s.getKind().isField())
  20.193 -               continue;
  20.194 -           for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) {
  20.195 -               if (ta.position.pos == treePos) {
  20.196 -                   ta.position.offset = code.cp;
  20.197 -                   ta.position.lvarOffset = new int[] { code.cp };
  20.198 -                   ta.position.isValidOffset = true;
  20.199 -               }
  20.200 -           }
  20.201 -       }
  20.202 -   }
  20.203 +        for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) {
  20.204 +            if (ta.hasUnknownPosition())
  20.205 +                ta.tryFixPosition();
  20.206 +
  20.207 +            if (ta.position.matchesPos(treePos))
  20.208 +                ta.position.updatePosOffset(code.cp);
  20.209 +        }
  20.210 +
  20.211 +        ClassSymbol clazz = meth.enclClass();
  20.212 +        for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
  20.213 +            if (!s.getKind().isField())
  20.214 +                continue;
  20.215 +
  20.216 +            for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) {
  20.217 +                if (ta.hasUnknownPosition())
  20.218 +                    ta.tryFixPosition();
  20.219 +
  20.220 +                if (ta.position.matchesPos(treePos))
  20.221 +                    ta.position.updatePosOffset(code.cp);
  20.222 +            }
  20.223 +        }
  20.224 +    }
  20.225  
  20.226      public void visitNewClass(JCNewClass tree) {
  20.227          // Enclosing instances or anonymous classes should have been eliminated
    21.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue May 14 13:55:35 2013 -0700
    21.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Tue May 14 15:04:06 2013 -0700
    21.3 @@ -25,7 +25,6 @@
    21.4  
    21.5  package com.sun.tools.javac.main;
    21.6  
    21.7 -import com.sun.tools.javac.comp.CompileStates;
    21.8  import java.io.*;
    21.9  import java.util.HashMap;
   21.10  import java.util.HashSet;
   21.11 @@ -55,6 +54,7 @@
   21.12  import com.sun.tools.javac.code.Lint.LintCategory;
   21.13  import com.sun.tools.javac.code.Symbol.*;
   21.14  import com.sun.tools.javac.comp.*;
   21.15 +import com.sun.tools.javac.comp.CompileStates.CompileState;
   21.16  import com.sun.tools.javac.file.JavacFileManager;
   21.17  import com.sun.tools.javac.jvm.*;
   21.18  import com.sun.tools.javac.parser.*;
   21.19 @@ -62,7 +62,6 @@
   21.20  import com.sun.tools.javac.tree.*;
   21.21  import com.sun.tools.javac.tree.JCTree.*;
   21.22  import com.sun.tools.javac.util.*;
   21.23 -import com.sun.tools.javac.comp.CompileStates.CompileState;
   21.24  import com.sun.tools.javac.util.Log.WriterKind;
   21.25  
   21.26  import static com.sun.tools.javac.code.TypeTag.CLASS;
   21.27 @@ -484,7 +483,7 @@
   21.28       */
   21.29      protected boolean werror;
   21.30  
   21.31 -    /** Switch: is annotation processing requested explitly via
   21.32 +    /** Switch: is annotation processing requested explicitly via
   21.33       * CompilationTask.setProcessors?
   21.34       */
   21.35      protected boolean explicitAnnotationProcessingRequested = false;
    22.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue May 14 13:55:35 2013 -0700
    22.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Tue May 14 15:04:06 2013 -0700
    22.3 @@ -2013,7 +2013,7 @@
    22.4      /** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
    22.5       */
    22.6      JCExpression creator(int newpos, List<JCExpression> typeArgs) {
    22.7 -        List<JCAnnotation> newAnnotations = typeAnnotationsOpt();
    22.8 +        List<JCAnnotation> newAnnotations = annotationsOpt(Tag.ANNOTATION);
    22.9  
   22.10          switch (token.kind) {
   22.11          case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
   22.12 @@ -2030,11 +2030,6 @@
   22.13          }
   22.14          JCExpression t = qualident(true);
   22.15  
   22.16 -        // handle type annotations for non primitive arrays
   22.17 -        if (newAnnotations.nonEmpty()) {
   22.18 -            t = insertAnnotationsToMostInner(t, newAnnotations, false);
   22.19 -        }
   22.20 -
   22.21          int oldmode = mode;
   22.22          mode = TYPE;
   22.23          boolean diamondFound = false;
   22.24 @@ -2068,6 +2063,11 @@
   22.25          }
   22.26          mode = oldmode;
   22.27          if (token.kind == LBRACKET || token.kind == MONKEYS_AT) {
   22.28 +            // handle type annotations for non primitive arrays
   22.29 +            if (newAnnotations.nonEmpty()) {
   22.30 +                t = insertAnnotationsToMostInner(t, newAnnotations, false);
   22.31 +            }
   22.32 +
   22.33              JCExpression e = arrayCreatorRest(newpos, t);
   22.34              if (diamondFound) {
   22.35                  reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond");
   22.36 @@ -2092,8 +2092,18 @@
   22.37              if (newClass.def != null) {
   22.38                  assert newClass.def.mods.annotations.isEmpty();
   22.39                  if (newAnnotations.nonEmpty()) {
   22.40 +                    // Add type and declaration annotations to the new class;
   22.41 +                    // com.sun.tools.javac.code.TypeAnnotations.TypeAnnotationPositions.visitNewClass(JCNewClass)
   22.42 +                    // will later remove all type annotations and only leave the
   22.43 +                    // declaration annotations.
   22.44                      newClass.def.mods.pos = earlier(newClass.def.mods.pos, newAnnotations.head.pos);
   22.45 -                    newClass.def.mods.annotations = List.convert(JCAnnotation.class, newAnnotations);
   22.46 +                    newClass.def.mods.annotations = newAnnotations;
   22.47 +                }
   22.48 +            } else {
   22.49 +                // handle type annotations for instantiations
   22.50 +                if (newAnnotations.nonEmpty()) {
   22.51 +                    t = insertAnnotationsToMostInner(t, newAnnotations, false);
   22.52 +                    newClass.clazz = t;
   22.53                  }
   22.54              }
   22.55              return newClass;
   22.56 @@ -2987,7 +2997,22 @@
   22.57              syntaxError(pos, "expected", IDENTIFIER);
   22.58              name = token.name();
   22.59          } else {
   22.60 -            name = ident();
   22.61 +            if (allowThisIdent) {
   22.62 +                JCExpression pn = qualident(false);
   22.63 +                if (pn.hasTag(Tag.IDENT) && ((JCIdent)pn).name != names._this) {
   22.64 +                    name = ((JCIdent)pn).name;
   22.65 +                } else {
   22.66 +                    if ((mods.flags & Flags.VARARGS) != 0) {
   22.67 +                        log.error(token.pos, "varargs.and.receiver");
   22.68 +                    }
   22.69 +                    if (token.kind == LBRACKET) {
   22.70 +                        log.error(token.pos, "array.and.receiver");
   22.71 +                    }
   22.72 +                    return toP(F.at(pos).ReceiverVarDef(mods, pn, type));
   22.73 +                }
   22.74 +            } else {
   22.75 +                name = ident();
   22.76 +            }
   22.77          }
   22.78          if ((mods.flags & Flags.VARARGS) != 0 &&
   22.79                  token.kind == LBRACKET) {
   22.80 @@ -3526,18 +3551,24 @@
   22.81          ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>();
   22.82  
   22.83          List<JCAnnotation> typeAnnos = typeAnnotationsOpt();
   22.84 -        if (!typeAnnos.isEmpty())
   22.85 -            ts.append(toP(F.at(typeAnnos.head.pos).AnnotatedType(typeAnnos, qualident(true))));
   22.86 -        else
   22.87 -            ts.append(qualident(true));
   22.88 +        JCExpression qi = qualident(true);
   22.89 +        if (!typeAnnos.isEmpty()) {
   22.90 +            JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
   22.91 +            ts.append(at);
   22.92 +        } else {
   22.93 +            ts.append(qi);
   22.94 +        }
   22.95          while (token.kind == COMMA) {
   22.96              nextToken();
   22.97  
   22.98              typeAnnos = typeAnnotationsOpt();
   22.99 -            if (!typeAnnos.isEmpty())
  22.100 -                ts.append(toP(F.at(typeAnnos.head.pos).AnnotatedType(typeAnnos, qualident(true))));
  22.101 -            else
  22.102 -                ts.append(qualident(true));
  22.103 +            qi = qualident(true);
  22.104 +            if (!typeAnnos.isEmpty()) {
  22.105 +                JCExpression at = insertAnnotationsToMostInner(qi, typeAnnos, false);
  22.106 +                ts.append(at);
  22.107 +            } else {
  22.108 +                ts.append(qi);
  22.109 +            }
  22.110          }
  22.111          return ts.toList();
  22.112      }
  22.113 @@ -3601,7 +3632,7 @@
  22.114          if (token.kind != RPAREN) {
  22.115              this.allowThisIdent = true;
  22.116              lastParam = formalParameter(lambdaParameters);
  22.117 -            if (lastParam.name.contentEquals(TokenKind.THIS.name)) {
  22.118 +            if (lastParam.nameexpr != null) {
  22.119                  this.receiverParam = lastParam;
  22.120              } else {
  22.121                  params.append(lastParam);
    23.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue May 14 13:55:35 2013 -0700
    23.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue May 14 15:04:06 2013 -0700
    23.3 @@ -221,7 +221,7 @@
    23.4      bad intersection type target for lambda or method reference\n\
    23.5      {0}
    23.6  
    23.7 -# 0: type
    23.8 +# 0: symbol or type
    23.9  compiler.misc.not.an.intf.component=\
   23.10      component type {0} is not an interface
   23.11  
   23.12 @@ -331,29 +331,29 @@
   23.13  
   23.14  # 0: type, 1: type
   23.15  compiler.err.duplicate.annotation.missing.container=\
   23.16 -    duplicate annotation, the declaration of {0} does not have a valid {1} annotation
   23.17 +    duplicate annotation: the declaration of {0} does not have a valid {1} annotation
   23.18  
   23.19  # 0: type
   23.20  compiler.err.invalid.repeatable.annotation=\
   23.21 -    duplicate annotation, {0} is annotated with an invalid Repeatable annotation
   23.22 -
   23.23 -# 0: type
   23.24 +    duplicate annotation: {0} is annotated with an invalid Repeatable annotation
   23.25 +
   23.26 +# 0: symbol or type
   23.27  compiler.err.invalid.repeatable.annotation.no.value=\
   23.28 -    duplicate annotation, {0} is not a valid Repeatable, no value element method declared
   23.29 +    duplicate annotation: {0} is not a valid Repeatable, no value element method declared
   23.30  
   23.31  # 0: type, 1: number
   23.32  compiler.err.invalid.repeatable.annotation.multiple.values=\
   23.33 -    duplicate annotation, {0} is not a valid Repeatable, {1} value element methods declared
   23.34 +    duplicate annotation: {0} is not a valid Repeatable, {1} value element methods declared
   23.35  
   23.36  # 0: type
   23.37  compiler.err.invalid.repeatable.annotation.invalid.value=\
   23.38 -    duplicate annotation, {0} is not a valid Repeatable, invalid value element, need a method
   23.39 -
   23.40 -# 0: type, 1: type, 2: type
   23.41 +    duplicate annotation: {0} is not a valid Repeatable: invalid value element
   23.42 +
   23.43 +# 0: symbol type, 1: type, 2: type
   23.44  compiler.err.invalid.repeatable.annotation.value.return=\
   23.45 -    duplicate annotation, value element of containing annotation {0} should have type {2}, found {1}
   23.46 -
   23.47 -# 0: type, 1: symbol
   23.48 +    duplicate annotation: value element of containing annotation {0} should have type {2}, found {1}
   23.49 +
   23.50 +# 0: symbol or type, 1: symbol
   23.51  compiler.err.invalid.repeatable.annotation.elem.nondefault=\
   23.52      containing annotation {0} does not have a default value for element {1}
   23.53  
   23.54 @@ -592,6 +592,12 @@
   23.55  compiler.err.varargs.and.old.array.syntax=\
   23.56      legacy array notation not allowed on variable-arity parameter
   23.57  
   23.58 +compiler.err.varargs.and.receiver =\
   23.59 +    varargs notation not allowed on receiver parameter
   23.60 +
   23.61 +compiler.err.array.and.receiver =\
   23.62 +    legacy array notation not allowed on receiver parameter
   23.63 +
   23.64  compiler.err.variable.not.allowed=\
   23.65      variable declaration not allowed here
   23.66  
   23.67 @@ -659,6 +665,7 @@
   23.68  compiler.err.missing.ret.stmt=\
   23.69      missing return statement
   23.70  
   23.71 +# 0: unused
   23.72  compiler.misc.missing.ret.val=\
   23.73      missing return value
   23.74  
   23.75 @@ -983,7 +990,7 @@
   23.76  compiler.misc.overridden.default=\
   23.77      method {0} is overridden in {1}
   23.78  
   23.79 -# 0: symbol, 1: symbol
   23.80 +# 0: symbol, 1: type or symbol
   23.81  compiler.misc.redundant.supertype=\
   23.82      redundant interface {0} is extended by {1}
   23.83  
   23.84 @@ -1896,11 +1903,10 @@
   23.85  
   23.86  #####
   23.87  
   23.88 -# 0: type, 1: file name
   23.89 +# 0: symbol or type, 1: file name
   23.90  compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file=\
   23.91      auxiliary class {0} in {1} should not be accessed from outside its own source file
   23.92  
   23.93 -
   23.94  ## The first argument ({0}) is a "kindname".
   23.95  # 0: symbol kind, 1: symbol, 2: symbol
   23.96  compiler.err.abstract.cant.be.accessed.directly=\
   23.97 @@ -2185,15 +2191,42 @@
   23.98  compiler.err.this.as.identifier=\
   23.99      as of release 8, ''this'' is allowed as the parameter name for the receiver type only, which has to be the first parameter
  23.100  
  23.101 +# 0: symbol
  23.102 +compiler.err.receiver.parameter.not.applicable.constructor.toplevel.class=\
  23.103 +    receiver parameter not applicable for constructor of top-level class
  23.104 +
  23.105  # TODO 308: make a better error message
  23.106  compiler.err.cant.annotate.static.class=\
  23.107      enclosing static nested class cannot be annotated
  23.108 +
  23.109  # TODO 308: make a better error message
  23.110 +# 0: unused
  23.111  compiler.err.cant.annotate.nested.type=\
  23.112      nested type cannot be annotated
  23.113  
  23.114 +# 0: type, 1: type
  23.115 +compiler.err.incorrect.receiver.name=\
  23.116 +    the receiver name does not match the enclosing class type\n\
  23.117 +    required: {0}\n\
  23.118 +    found: {1}
  23.119 +
  23.120 +# 0: type, 1: type
  23.121  compiler.err.incorrect.receiver.type=\
  23.122 -    the receiver type does not match the enclosing class type
  23.123 +    the receiver type does not match the enclosing class type\n\
  23.124 +    required: {0}\n\
  23.125 +    found: {1}
  23.126 +
  23.127 +# 0: type, 1: type
  23.128 +compiler.err.incorrect.constructor.receiver.type=\
  23.129 +    the receiver type does not match the enclosing outer class type\n\
  23.130 +    required: {0}\n\
  23.131 +    found: {1}
  23.132 +
  23.133 +# 0: type, 1: type
  23.134 +compiler.err.incorrect.constructor.receiver.name=\
  23.135 +    the receiver name does not match the enclosing outer class type\n\
  23.136 +    required: {0}\n\
  23.137 +    found: {1}
  23.138  
  23.139  compiler.err.no.annotations.on.dot.class=\
  23.140      no annotations are allowed in the type of a class literal
    24.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue May 14 13:55:35 2013 -0700
    24.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue May 14 15:04:06 2013 -0700
    24.3 @@ -42,7 +42,6 @@
    24.4  import com.sun.tools.javac.util.*;
    24.5  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    24.6  import com.sun.tools.javac.util.List;
    24.7 -import static com.sun.tools.javac.code.BoundKind.*;
    24.8  import static com.sun.tools.javac.tree.JCTree.Tag.*;
    24.9  
   24.10  /**
   24.11 @@ -807,12 +806,15 @@
   24.12          public JCModifiers mods;
   24.13          /** variable name */
   24.14          public Name name;
   24.15 +        /** variable name expression */
   24.16 +        public JCExpression nameexpr;
   24.17          /** type of the variable */
   24.18          public JCExpression vartype;
   24.19          /** variable's initial value */
   24.20          public JCExpression init;
   24.21          /** symbol */
   24.22          public VarSymbol sym;
   24.23 +
   24.24          protected JCVariableDecl(JCModifiers mods,
   24.25                           Name name,
   24.26                           JCExpression vartype,
   24.27 @@ -824,12 +826,27 @@
   24.28              this.init = init;
   24.29              this.sym = sym;
   24.30          }
   24.31 +
   24.32 +        protected JCVariableDecl(JCModifiers mods,
   24.33 +                         JCExpression nameexpr,
   24.34 +                         JCExpression vartype) {
   24.35 +            this(mods, null, vartype, null, null);
   24.36 +            this.nameexpr = nameexpr;
   24.37 +            if (nameexpr.hasTag(Tag.IDENT)) {
   24.38 +                this.name = ((JCIdent)nameexpr).name;
   24.39 +            } else {
   24.40 +                // Only other option is qualified name x.y.this;
   24.41 +                this.name = ((JCFieldAccess)nameexpr).name;
   24.42 +            }
   24.43 +        }
   24.44 +
   24.45          @Override
   24.46          public void accept(Visitor v) { v.visitVarDef(this); }
   24.47  
   24.48          public Kind getKind() { return Kind.VARIABLE; }
   24.49          public JCModifiers getModifiers() { return mods; }
   24.50          public Name getName() { return name; }
   24.51 +        public JCExpression getNameExpression() { return nameexpr; }
   24.52          public JCTree getType() { return vartype; }
   24.53          public JCExpression getInitializer() {
   24.54              return init;
   24.55 @@ -845,7 +862,7 @@
   24.56          }
   24.57      }
   24.58  
   24.59 -      /**
   24.60 +    /**
   24.61       * A no-op statement ";".
   24.62       */
   24.63      public static class JCSkip extends JCStatement implements EmptyStatementTree {
    25.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Tue May 14 13:55:35 2013 -0700
    25.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Tue May 14 15:04:06 2013 -0700
    25.3 @@ -261,8 +261,6 @@
    25.4      }
    25.5  
    25.6      public void printTypeAnnotations(List<JCAnnotation> trees) throws IOException {
    25.7 -        if (trees.nonEmpty())
    25.8 -            print(" ");
    25.9          for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) {
   25.10              printExpr(l.head);
   25.11              print(" ");
   25.12 @@ -564,8 +562,10 @@
   25.13                          vartype = ((JCAnnotatedType)vartype).underlyingType;
   25.14                      }
   25.15                      printExpr(((JCArrayTypeTree) vartype).elemtype);
   25.16 -                    if (tas != null)
   25.17 +                    if (tas != null) {
   25.18 +                        print(' ');
   25.19                          printTypeAnnotations(tas);
   25.20 +                    }
   25.21                      print("... " + tree.name);
   25.22                  } else {
   25.23                      printExpr(tree.vartype);
   25.24 @@ -918,6 +918,9 @@
   25.25                  printExprs(tree.typeargs);
   25.26                  print(">");
   25.27              }
   25.28 +            if (tree.def != null && tree.def.mods.annotations.nonEmpty()) {
   25.29 +                printTypeAnnotations(tree.def.mods.annotations);
   25.30 +            }
   25.31              printExpr(tree.clazz);
   25.32              print("(");
   25.33              printExprs(tree.args);
   25.34 @@ -948,7 +951,8 @@
   25.35                  int i = 0;
   25.36                  List<List<JCAnnotation>> da = tree.dimAnnotations;
   25.37                  for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
   25.38 -                    if (da.size() > i) {
   25.39 +                    if (da.size() > i && !da.get(i).isEmpty()) {
   25.40 +                        print(' ');
   25.41                          printTypeAnnotations(da.get(i));
   25.42                      }
   25.43                      print("[");
   25.44 @@ -958,6 +962,7 @@
   25.45                  }
   25.46                  if (tree.elems != null) {
   25.47                      if (isElemAnnoType) {
   25.48 +                        print(' ');
   25.49                          printTypeAnnotations(((JCAnnotatedType)tree.elemtype).annotations);
   25.50                      }
   25.51                      print("[]");
   25.52 @@ -1264,6 +1269,7 @@
   25.53                  JCAnnotatedType atype = (JCAnnotatedType) elem;
   25.54                  elem = atype.underlyingType;
   25.55                  if (!elem.hasTag(TYPEARRAY)) break;
   25.56 +                print(' ');
   25.57                  printTypeAnnotations(atype.annotations);
   25.58              }
   25.59              print("[]");
   25.60 @@ -1301,6 +1307,9 @@
   25.61  
   25.62      public void visitTypeParameter(JCTypeParameter tree) {
   25.63          try {
   25.64 +            if (tree.annotations.nonEmpty()) {
   25.65 +                this.printTypeAnnotations(tree.annotations);
   25.66 +            }
   25.67              print(tree.name);
   25.68              if (tree.bounds.nonEmpty()) {
   25.69                  print(" extends ");
   25.70 @@ -1379,6 +1388,7 @@
   25.71              } else if (tree.underlyingType.getKind() == JCTree.Kind.ARRAY_TYPE) {
   25.72                  JCArrayTypeTree array = (JCArrayTypeTree) tree.underlyingType;
   25.73                  printBaseElementType(tree);
   25.74 +                print(' ');
   25.75                  printTypeAnnotations(tree.annotations);
   25.76                  print("[]");
   25.77                  JCExpression elem = array.elemtype;
    26.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Tue May 14 13:55:35 2013 -0700
    26.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Tue May 14 15:04:06 2013 -0700
    26.3 @@ -422,8 +422,13 @@
    26.4          JCVariableDecl t = (JCVariableDecl) node;
    26.5          JCModifiers mods = copy(t.mods, p);
    26.6          JCExpression vartype = copy(t.vartype, p);
    26.7 -        JCExpression init = copy(t.init, p);
    26.8 -        return M.at(t.pos).VarDef(mods, t.name, vartype, init);
    26.9 +        if (t.nameexpr == null) {
   26.10 +            JCExpression init = copy(t.init, p);
   26.11 +            return M.at(t.pos).VarDef(mods, t.name, vartype, init);
   26.12 +        } else {
   26.13 +            JCExpression nameexpr = copy(t.nameexpr, p);
   26.14 +            return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);
   26.15 +        }
   26.16      }
   26.17  
   26.18      public JCTree visitWhileLoop(WhileLoopTree node, P p) {
    27.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue May 14 13:55:35 2013 -0700
    27.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue May 14 15:04:06 2013 -0700
    27.3 @@ -204,6 +204,12 @@
    27.4          return tree;
    27.5      }
    27.6  
    27.7 +    public JCVariableDecl ReceiverVarDef(JCModifiers mods, JCExpression name, JCExpression vartype) {
    27.8 +        JCVariableDecl tree = new JCVariableDecl(mods, name, vartype);
    27.9 +        tree.pos = pos;
   27.10 +        return tree;
   27.11 +    }
   27.12 +
   27.13      public JCSkip Skip() {
   27.14          JCSkip tree = new JCSkip();
   27.15          tree.pos = pos;
    28.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Tue May 14 13:55:35 2013 -0700
    28.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Tue May 14 15:04:06 2013 -0700
    28.3 @@ -94,6 +94,7 @@
    28.4      public void visitVarDef(JCVariableDecl tree) {
    28.5          scan(tree.mods);
    28.6          scan(tree.vartype);
    28.7 +        scan(tree.nameexpr);
    28.8          scan(tree.init);
    28.9      }
   28.10  
    29.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Tue May 14 13:55:35 2013 -0700
    29.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Tue May 14 15:04:06 2013 -0700
    29.3 @@ -148,6 +148,7 @@
    29.4  
    29.5      public void visitVarDef(JCVariableDecl tree) {
    29.6          tree.mods = translate(tree.mods);
    29.7 +        tree.nameexpr = translate(tree.nameexpr);
    29.8          tree.vartype = translate(tree.vartype);
    29.9          tree.init = translate(tree.init);
   29.10          result = tree;
    30.1 --- a/src/share/classes/com/sun/tools/javac/util/List.java	Tue May 14 13:55:35 2013 -0700
    30.2 +++ b/src/share/classes/com/sun/tools/javac/util/List.java	Tue May 14 15:04:06 2013 -0700
    30.3 @@ -1,5 +1,5 @@
    30.4  /*
    30.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    30.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
    30.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.8   *
    30.9   * This code is free software; you can redistribute it and/or modify it
   30.10 @@ -37,7 +37,7 @@
   30.11  /** A class for generic linked lists. Links are supposed to be
   30.12   *  immutable, the only exception being the incremental construction of
   30.13   *  lists via ListBuffers.  List is the main container class in
   30.14 - *  GJC. Most data structures and algorthms in GJC use lists rather
   30.15 + *  GJC. Most data structures and algorithms in GJC use lists rather
   30.16   *  than arrays.
   30.17   *
   30.18   *  <p>Lists are always trailed by a sentinel element, whose head and tail
    31.1 --- a/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java	Tue May 14 13:55:35 2013 -0700
    31.2 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java	Tue May 14 15:04:06 2013 -0700
    31.3 @@ -1,5 +1,5 @@
    31.4  /*
    31.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
    31.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
    31.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    31.8   *
    31.9   * This code is free software; you can redistribute it and/or modify it
   31.10 @@ -31,9 +31,7 @@
   31.11  import com.sun.tools.javac.code.Kinds;
   31.12  import com.sun.tools.javac.code.Scope;
   31.13  import com.sun.tools.javac.code.Symbol.*;
   31.14 -import com.sun.tools.javac.tree.JCTree.*;
   31.15  import com.sun.tools.javac.util.List;
   31.16 -import com.sun.tools.javac.util.Names;
   31.17  
   31.18  /**
   31.19   * Represents an annotation type.
   31.20 @@ -92,7 +90,6 @@
   31.21       * Elements are always public, so no need to filter them.
   31.22       */
   31.23      public AnnotationTypeElementDoc[] elements() {
   31.24 -        Names names = tsym.name.table.names;
   31.25          List<AnnotationTypeElementDoc> elements = List.nil();
   31.26          for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
   31.27              if (e.sym != null && e.sym.kind == Kinds.MTH) {
    32.1 --- a/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java	Tue May 14 13:55:35 2013 -0700
    32.2 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java	Tue May 14 15:04:06 2013 -0700
    32.3 @@ -1,5 +1,5 @@
    32.4  /*
    32.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
    32.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
    32.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.8   *
    32.9   * This code is free software; you can redistribute it and/or modify it
   32.10 @@ -29,7 +29,6 @@
   32.11  
   32.12  import com.sun.source.util.TreePath;
   32.13  import com.sun.tools.javac.code.Symbol.*;
   32.14 -import com.sun.tools.javac.tree.JCTree.*;
   32.15  
   32.16  /**
   32.17   * Represents an element of an annotation type.
    33.1 --- a/src/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java	Tue May 14 13:55:35 2013 -0700
    33.2 +++ b/src/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java	Tue May 14 15:04:06 2013 -0700
    33.3 @@ -1,5 +1,5 @@
    33.4  /*
    33.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
    33.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
    33.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.8   *
    33.9   * This code is free software; you can redistribute it and/or modify it
   33.10 @@ -28,7 +28,6 @@
   33.11  import com.sun.javadoc.*;
   33.12  
   33.13  import com.sun.tools.javac.code.Attribute;
   33.14 -import com.sun.tools.javac.code.Symbol.*;
   33.15  
   33.16  import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
   33.17  
    34.1 --- a/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Tue May 14 13:55:35 2013 -0700
    34.2 +++ b/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Tue May 14 15:04:06 2013 -0700
    34.3 @@ -28,14 +28,10 @@
    34.4  import java.lang.reflect.Modifier;
    34.5  import java.text.CollationKey;
    34.6  
    34.7 -import javax.lang.model.type.TypeKind;
    34.8 -
    34.9  import com.sun.javadoc.*;
   34.10  
   34.11  import com.sun.source.util.TreePath;
   34.12 -import com.sun.tools.javac.code.Attribute;
   34.13  import com.sun.tools.javac.code.Flags;
   34.14 -import com.sun.tools.javac.code.Attribute.Compound;
   34.15  import com.sun.tools.javac.code.Symbol.*;
   34.16  import com.sun.tools.javac.code.Type;
   34.17  import com.sun.tools.javac.util.List;
    35.1 --- a/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Tue May 14 13:55:35 2013 -0700
    35.2 +++ b/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Tue May 14 15:04:06 2013 -0700
    35.3 @@ -34,10 +34,6 @@
    35.4  import com.sun.tools.javac.code.Symbol.ClassSymbol;
    35.5  import com.sun.tools.javac.code.Symbol.VarSymbol;
    35.6  
    35.7 -import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
    35.8 -
    35.9 -import com.sun.tools.javac.util.Position;
   35.10 -
   35.11  import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
   35.12  
   35.13  /**
    36.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java	Tue May 14 13:55:35 2013 -0700
    36.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java	Tue May 14 15:04:06 2013 -0700
    36.3 @@ -1,5 +1,5 @@
    36.4  /*
    36.5 - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
    36.6 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
    36.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.8   *
    36.9   * This code is free software; you can redistribute it and/or modify it
   36.10 @@ -25,10 +25,8 @@
   36.11  
   36.12  package com.sun.tools.javadoc;
   36.13  
   36.14 -
   36.15  import javax.tools.JavaFileObject;
   36.16  
   36.17 -import com.sun.source.util.TreePath;
   36.18  import com.sun.tools.javac.code.Kinds;
   36.19  import com.sun.tools.javac.code.Symbol.*;
   36.20  import com.sun.tools.javac.comp.Enter;
    37.1 --- a/src/share/classes/com/sun/tools/javadoc/Messager.java	Tue May 14 13:55:35 2013 -0700
    37.2 +++ b/src/share/classes/com/sun/tools/javadoc/Messager.java	Tue May 14 15:04:06 2013 -0700
    37.3 @@ -26,9 +26,7 @@
    37.4  package com.sun.tools.javadoc;
    37.5  
    37.6  import java.io.PrintWriter;
    37.7 -import java.text.MessageFormat;
    37.8  import java.util.Locale;
    37.9 -import java.util.ResourceBundle;
   37.10  
   37.11  import com.sun.javadoc.*;
   37.12  import com.sun.tools.javac.util.Context;
    38.1 --- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Tue May 14 13:55:35 2013 -0700
    38.2 +++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Tue May 14 15:04:06 2013 -0700
    38.3 @@ -25,8 +25,6 @@
    38.4  
    38.5  package com.sun.tools.javadoc;
    38.6  
    38.7 -import javax.lang.model.type.TypeKind;
    38.8 -
    38.9  import com.sun.javadoc.*;
   38.10  import com.sun.tools.javac.code.Symbol;
   38.11  import com.sun.tools.javac.code.Symbol.ClassSymbol;
   38.12 @@ -64,12 +62,9 @@
   38.13          if (env.legacyDoclet) {
   38.14              t = env.types.erasure(t);
   38.15          }
   38.16 -        if (considerAnnotations
   38.17 -                && t.isAnnotated()) {
   38.18 -            return new AnnotatedTypeImpl(env, (com.sun.tools.javac.code.Type.AnnotatedType) t);
   38.19 -        }
   38.20  
   38.21 -        if (t.isAnnotated()) {
   38.22 +        if (considerAnnotations &&
   38.23 +                t.isAnnotated()) {
   38.24              Type.AnnotatedType at = (Type.AnnotatedType) t;
   38.25              return new AnnotatedTypeImpl(env, at);
   38.26          }
    39.1 --- a/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Tue May 14 13:55:35 2013 -0700
    39.2 +++ b/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Tue May 14 15:04:06 2013 -0700
    39.3 @@ -25,8 +25,6 @@
    39.4  
    39.5  package com.sun.tools.javadoc;
    39.6  
    39.7 -import javax.lang.model.type.TypeKind;
    39.8 -
    39.9  import com.sun.javadoc.*;
   39.10  
   39.11  import com.sun.tools.javac.code.Attribute;
    40.1 --- a/test/com/sun/javadoc/testTypeAnnotations/TestTypeAnnotations.java	Tue May 14 13:55:35 2013 -0700
    40.2 +++ b/test/com/sun/javadoc/testTypeAnnotations/TestTypeAnnotations.java	Tue May 14 15:04:06 2013 -0700
    40.3 @@ -45,7 +45,6 @@
    40.4      private static final String[][] NEGATED_TEST = NO_TEST;
    40.5      private static final String[][] TEST = {
    40.6          // Test for type annotations on Class Extends (ClassExtends.java).
    40.7 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
    40.8          {BUG_ID + FS + "typeannos" + FS + "MyClass.html",
    40.9              "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation " +
   40.10              "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/ParameterizedClass.html\" " +
   40.11 @@ -53,8 +52,6 @@
   40.12              "../typeannos/ClassExtB.html\" title=\"annotation in typeannos\">" +
   40.13              "@ClassExtB</a> java.lang.String&gt;"
   40.14          },
   40.15 -        */
   40.16 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.17          {BUG_ID + FS + "typeannos" + FS + "MyClass.html",
   40.18              "implements <a href=\"../typeannos/ClassExtB.html\" title=\"" +
   40.19              "annotation in typeannos\">@ClassExtB</a> java.lang.CharSequence, " +
   40.20 @@ -64,8 +61,6 @@
   40.21              "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in " +
   40.22              "typeannos\">@ClassExtB</a> java.lang.String&gt;</pre>"
   40.23          },
   40.24 -        */
   40.25 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.26          {BUG_ID + FS + "typeannos" + FS + "MyInterface.html",
   40.27              "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation " +
   40.28              "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/" +
   40.29 @@ -75,7 +70,6 @@
   40.30              "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in " +
   40.31              "typeannos\">@ClassExtB</a> java.lang.CharSequence</pre>"
   40.32          },
   40.33 -        */
   40.34  
   40.35          // Test for type annotations on Class Parameters (ClassParameters.java).
   40.36          {BUG_ID + FS + "typeannos" + FS + "ExtendsBound.html",
   40.37 @@ -83,7 +77,6 @@
   40.38              "href=\"../typeannos/ClassParamA.html\" title=\"annotation in " +
   40.39              "typeannos\">@ClassParamA</a> java.lang.String&gt;</span>"
   40.40          },
   40.41 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.42          {BUG_ID + FS + "typeannos" + FS + "ExtendsGeneric.html",
   40.43              "<pre> class <span class=\"strong\">ExtendsGeneric&lt;K extends " +
   40.44              "<a href=\"../typeannos/ClassParamA.html\" title=\"annotation in " +
   40.45 @@ -92,7 +85,6 @@
   40.46              "../typeannos/ClassParamB.html\" title=\"annotation in typeannos\">" +
   40.47              "@ClassParamB</a> java.lang.String&gt;&gt;</span>"
   40.48          },
   40.49 -        */
   40.50          {BUG_ID + FS + "typeannos" + FS + "TwoBounds.html",
   40.51              "<pre> class <span class=\"strong\">TwoBounds&lt;K extends <a href=\"" +
   40.52              "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" +
   40.53 @@ -119,7 +111,6 @@
   40.54          },
   40.55  
   40.56          // Test for type annotations on fields (Fields.java).
   40.57 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.58          {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html",
   40.59              "<pre><a href=\"../typeannos/Parameterized.html\" title=\"class in " +
   40.60              "typeannos\">Parameterized</a>&lt;<a href=\"../typeannos/FldA.html\" " +
   40.61 @@ -127,7 +118,6 @@
   40.62              "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">" +
   40.63              "@FldB</a> java.lang.String&gt; bothTypeArgs</pre>"
   40.64          },
   40.65 -        */
   40.66          {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html",
   40.67              "<pre><a href=\"../typeannos/FldA.html\" title=\"annotation in " +
   40.68              "typeannos\">@FldA</a> java.lang.String <a href=\"../typeannos/" +
   40.69 @@ -147,7 +137,6 @@
   40.70              "typeannos\">@FldC</a> <a href=\"../typeannos/FldB.html\" title=\"" +
   40.71              "annotation in typeannos\">@FldB</a> [] array2Deep</pre>"
   40.72          },
   40.73 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.74          {BUG_ID + FS + "typeannos" + FS + "ModifiedScoped.html",
   40.75              "<pre>public final&nbsp;<a href=\"../typeannos/Parameterized.html\" " +
   40.76              "title=\"class in typeannos\">Parameterized</a>&lt;<a href=\"../" +
   40.77 @@ -160,7 +149,6 @@
   40.78              "title=\"annotation in typeannos\">@FldB</a> java.lang.String&gt; " +
   40.79              "nestedParameterized</pre>"
   40.80          },
   40.81 -        */
   40.82          {BUG_ID + FS + "typeannos" + FS + "ModifiedScoped.html",
   40.83              "<pre>public final&nbsp;<a href=\"../typeannos/FldA.html\" " +
   40.84              "title=\"annotation in typeannos\">@FldA</a> java.lang.String[][] " +
   40.85 @@ -184,7 +172,6 @@
   40.86              "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in " +
   40.87              "typeannos\">@MRtnA</a> java.lang.String[][]&nbsp;array2()</pre>"
   40.88          },
   40.89 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
   40.90          {BUG_ID + FS + "typeannos" + FS + "MtdModifiedScoped.html",
   40.91              "<pre>public final&nbsp;<a href=\"../typeannos/MtdParameterized.html\" " +
   40.92              "title=\"class in typeannos\">MtdParameterized</a>&lt;<a href=\"../" +
   40.93 @@ -197,7 +184,6 @@
   40.94              "MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> java." +
   40.95              "lang.String&gt;&nbsp;nestedMtdParameterized()</pre>"
   40.96          },
   40.97 -        */
   40.98  
   40.99          // Test for type annotations on method type parameters (MethodTypeParameters.java).
  40.100          {BUG_ID + FS + "typeannos" + FS + "UnscopedUnmodified.html",
  40.101 @@ -205,7 +191,6 @@
  40.102              "annotation in typeannos\">@MTyParamA</a> java.lang.String&gt;" +
  40.103              "&nbsp;void&nbsp;methodExtends()</pre>"
  40.104          },
  40.105 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
  40.106          {BUG_ID + FS + "typeannos" + FS + "UnscopedUnmodified.html",
  40.107              "<pre>&lt;K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" +
  40.108              "annotation in typeannos\">@MTyParamA</a> <a href=\"../typeannos/" +
  40.109 @@ -214,13 +199,11 @@
  40.110              "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" +
  40.111              "&gt;&gt;&nbsp;void&nbsp;nestedExtends()</pre>"
  40.112          },
  40.113 -        */
  40.114          {BUG_ID + FS + "typeannos" + FS + "PublicModifiedMethods.html",
  40.115              "<pre>public final&nbsp;&lt;K extends <a href=\"../typeannos/" +
  40.116              "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " +
  40.117              "java.lang.String&gt;&nbsp;void&nbsp;methodExtends()</pre>"
  40.118          },
  40.119 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
  40.120          {BUG_ID + FS + "typeannos" + FS + "PublicModifiedMethods.html",
  40.121              "<pre>public final&nbsp;&lt;K extends <a href=\"../typeannos/" +
  40.122              "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " +
  40.123 @@ -231,7 +214,6 @@
  40.124              "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" +
  40.125              "&gt;&gt;&nbsp;void&nbsp;dual()</pre>"
  40.126          },
  40.127 -        */
  40.128  
  40.129          // Test for type annotations on parameters (Parameters.java).
  40.130          {BUG_ID + FS + "typeannos" + FS + "Parameters.html",
  40.131 @@ -240,7 +222,6 @@
  40.132              "ParaParameterized</a>&lt;java.lang.String,java.lang.String&gt;" +
  40.133              "&nbsp;a)</pre>"
  40.134          },
  40.135 -        /* @ignore 8012173: javadoc does not receive all type annotations information from javac
  40.136          {BUG_ID + FS + "typeannos" + FS + "Parameters.html",
  40.137              "<pre>void&nbsp;nestedParaParameterized(<a href=\"../typeannos/" +
  40.138              "ParaParameterized.html\" title=\"class in typeannos\">" +
  40.139 @@ -254,7 +235,6 @@
  40.140              "typeannos/ParamB.html\" title=\"annotation in typeannos\">@ParamB" +
  40.141              "</a> java.lang.String&gt;&nbsp;a)</pre>"
  40.142          },
  40.143 -        */
  40.144          {BUG_ID + FS + "typeannos" + FS + "Parameters.html",
  40.145              "<pre>void&nbsp;array2Deep(<a href=\"../typeannos/ParamA.html\" " +
  40.146              "title=\"annotation in typeannos\">@ParamA</a> java.lang.String " +
    41.1 --- a/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Tue May 14 13:55:35 2013 -0700
    41.2 +++ b/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Tue May 14 15:04:06 2013 -0700
    41.3 @@ -24,7 +24,7 @@
    41.4  /*
    41.5   * @test
    41.6   * @bug 8006735
    41.7 - * @summary  Smoke test for ensuring that annotations are emited to javadoc
    41.8 + * @summary  Smoke test for ensuring that annotations are emitted to javadoc
    41.9   *
   41.10   * @author   Mahmood Ali <mali>
   41.11   * @library  ../../lib/
   41.12 @@ -46,37 +46,35 @@
   41.13      //Input for string search tests.
   41.14      private static final String[][] TEST = {
   41.15          {BUG_ID + FS + "pkg" + FS + "T0x1C.html", "@DA"},
   41.16 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.17          {BUG_ID + FS + "pkg" + FS + "T0x1D.html", "@DA"},
   41.18 -        */
   41.19 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.20          {BUG_ID + FS + "pkg" + FS + "T0x0D.html", "@DA"},
   41.21 -        */
   41.22          {BUG_ID + FS + "pkg" + FS + "T0x06.html", "@DA"},
   41.23 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.24          {BUG_ID + FS + "pkg" + FS + "T0x0B.html", "@DA"},
   41.25 -        */
   41.26 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.27          {BUG_ID + FS + "pkg" + FS + "T0x0F.html", "@DA"},
   41.28 -        */
   41.29          /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.30          {BUG_ID + FS + "pkg" + FS + "T0x20.html", "@DA"},
   41.31          */
   41.32          /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.33 +        {BUG_ID + FS + "pkg" + FS + "T0x20A.html", "@DTPA"},
   41.34 +        */
   41.35 +        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.36 +        {BUG_ID + FS + "pkg" + FS + "T0x20B.html", "@DA"},
   41.37 +        */
   41.38 +        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.39          {BUG_ID + FS + "pkg" + FS + "T0x22.html", "@DA"},
   41.40          */
   41.41 +        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.42 +        {BUG_ID + FS + "pkg" + FS + "T0x22A.html", "@DTPA"},
   41.43 +        */
   41.44 +        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.45 +        {BUG_ID + FS + "pkg" + FS + "T0x22B.html", "@DA"},
   41.46 +        */
   41.47          {BUG_ID + FS + "pkg" + FS + "T0x10.html", "@DA"},
   41.48          {BUG_ID + FS + "pkg" + FS + "T0x10A.html", "@DA"},
   41.49          {BUG_ID + FS + "pkg" + FS + "T0x12.html", "@DA"},
   41.50 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.51          {BUG_ID + FS + "pkg" + FS + "T0x11.html", "@DA"},
   41.52 -        */
   41.53 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.54          {BUG_ID + FS + "pkg" + FS + "T0x13.html", "@DA"},
   41.55 -        */
   41.56 -        /* @ignore 8013406: Test cases fail in javadoc test TestSmoke.java
   41.57          {BUG_ID + FS + "pkg" + FS + "T0x15.html", "@DA"},
   41.58 -        */
   41.59          {BUG_ID + FS + "pkg" + FS + "T0x14.html", "@DA"},
   41.60          {BUG_ID + FS + "pkg" + FS + "T0x16.html", "@DA"}
   41.61      };
   41.62 @@ -94,7 +92,11 @@
   41.63          {BUG_ID + FS + "pkg" + FS + "T0x0B.html", "@A"},
   41.64          {BUG_ID + FS + "pkg" + FS + "T0x0F.html", "@A"},
   41.65          {BUG_ID + FS + "pkg" + FS + "T0x20.html", "@A"},
   41.66 +        {BUG_ID + FS + "pkg" + FS + "T0x20A.html", "@A"},
   41.67 +        {BUG_ID + FS + "pkg" + FS + "T0x20B.html", "@A"},
   41.68          {BUG_ID + FS + "pkg" + FS + "T0x22.html", "@A"},
   41.69 +        {BUG_ID + FS + "pkg" + FS + "T0x22A.html", "@A"},
   41.70 +        {BUG_ID + FS + "pkg" + FS + "T0x22B.html", "@A"},
   41.71          {BUG_ID + FS + "pkg" + FS + "T0x10.html", "@A"},
   41.72          {BUG_ID + FS + "pkg" + FS + "T0x10A.html", "@A"},
   41.73          {BUG_ID + FS + "pkg" + FS + "T0x12.html", "@A"},
    42.1 --- a/test/com/sun/javadoc/typeAnnotations/smoke/pkg/TargetTypes.java	Tue May 14 13:55:35 2013 -0700
    42.2 +++ b/test/com/sun/javadoc/typeAnnotations/smoke/pkg/TargetTypes.java	Tue May 14 15:04:06 2013 -0700
    42.3 @@ -1,5 +1,5 @@
    42.4  /*
    42.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    42.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    42.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    42.8   *
    42.9   * This code is free software; you can redistribute it and/or modify it
   42.10 @@ -36,24 +36,19 @@
   42.11   * @author Yuri Gaevsky
   42.12   */
   42.13  
   42.14 -@Target({TYPE_USE})
   42.15 +@Target(TYPE_USE)
   42.16  @Retention(RetentionPolicy.RUNTIME)
   42.17  @interface A {}
   42.18  
   42.19 -@Target({TYPE_USE})
   42.20 +@Target(TYPE_USE)
   42.21  @Retention(RetentionPolicy.RUNTIME)
   42.22  @Documented
   42.23  @interface DA {}
   42.24  
   42.25 -/** wildcard bound */
   42.26 -class T0x1C {
   42.27 -    void m0x1C(List<? extends @A @DA String> lst) {}
   42.28 -}
   42.29 -
   42.30 -/** wildcard bound generic/array */
   42.31 -class T0x1D<T> {
   42.32 -    void m0x1D(List<? extends @A @DA List<int[]>> lst) {}
   42.33 -}
   42.34 +@Target(TYPE_PARAMETER)
   42.35 +@Retention(RetentionPolicy.RUNTIME)
   42.36 +@Documented
   42.37 +@interface DTPA {}
   42.38  
   42.39  /** typecast */
   42.40  class T0x00 {
   42.41 @@ -76,6 +71,13 @@
   42.42      }
   42.43  }
   42.44  
   42.45 +/** type test (instanceof) generic/array */
   42.46 +class T0x03<T> {
   42.47 +    void m0x03(T typeObj, Object obj) {
   42.48 +        boolean ok = obj instanceof String @A @DA [];
   42.49 +    }
   42.50 +}
   42.51 +
   42.52  /** object creation (new) */
   42.53  class T0x04 {
   42.54      void m0x04() {
   42.55 @@ -83,80 +85,22 @@
   42.56      }
   42.57  }
   42.58  
   42.59 -/** local variable */
   42.60 -class T0x08 {
   42.61 -    void m0x08() {
   42.62 -      @A @DA String s = null;
   42.63 +/** object creation (new) generic/array */
   42.64 +class T0x05<T> {
   42.65 +    void m0x05() {
   42.66 +        new ArrayList<@A @DA T>();
   42.67      }
   42.68  }
   42.69  
   42.70 -/** method parameter generic/array */
   42.71 -class T0x0D {
   42.72 -    void m0x0D(HashMap<@A @DA Object, List<@A @DA List<@A @DA Class>>> s1) {}
   42.73 -}
   42.74 -
   42.75  /** method receiver */
   42.76  class T0x06 {
   42.77      void m0x06(@A @DA T0x06 this) {}
   42.78  }
   42.79  
   42.80 -/** method return type generic/array */
   42.81 -class T0x0B {
   42.82 -    Class<@A @DA Object> m0x0B() { return null; }
   42.83 -}
   42.84 -
   42.85 -/** field generic/array */
   42.86 -class T0x0F {
   42.87 -    HashMap<@A @DA Object, @A @DA Object> c1;
   42.88 -}
   42.89 -
   42.90 -/** method type parameter */
   42.91 -class T0x20<T, U> {
   42.92 -    <@A @DA T, @A @DA U> void m0x20() {}
   42.93 -}
   42.94 -
   42.95 -/** class type parameter */
   42.96 -class T0x22<@A @DA T, @A @DA U> {
   42.97 -}
   42.98 -
   42.99 -/** class type parameter bound */
  42.100 -class T0x10<T extends @A @DA Cloneable> {
  42.101 -}
  42.102 -
  42.103 -class T0x10A<T extends @A @DA Object> {
  42.104 -}
  42.105 -
  42.106 -/** method type parameter bound */
  42.107 -class T0x12<T> {
  42.108 -    <T extends @A @DA Cloneable> void m0x12() {}
  42.109 -}
  42.110 -
  42.111 -/** class type parameter bound generic/array */
  42.112 -class T0x11<T extends List<@A @DA T>> {
  42.113 -}
  42.114 -
  42.115 -/** method type parameter bound generic/array */
  42.116 -class T0x13 {
  42.117 -    static <T extends Comparable<@A @DA T>> T m0x13() {
  42.118 -        return null;
  42.119 -    }
  42.120 -}
  42.121 -
  42.122 -/** class extends/implements generic/array */
  42.123 -class T0x15<T> extends ArrayList<@A @DA T> {
  42.124 -}
  42.125 -
  42.126 -/** type test (instanceof) generic/array */
  42.127 -class T0x03<T> {
  42.128 -    void m0x03(T typeObj, Object obj) {
  42.129 -        boolean ok = obj instanceof String @A @DA [];
  42.130 -    }
  42.131 -}
  42.132 -
  42.133 -/** object creation (new) generic/array */
  42.134 -class T0x05<T> {
  42.135 -    void m0x05() {
  42.136 -        new ArrayList<@A @DA T>();
  42.137 +/** local variable */
  42.138 +class T0x08 {
  42.139 +    void m0x08() {
  42.140 +      @A @DA String s = null;
  42.141      }
  42.142  }
  42.143  
  42.144 @@ -171,20 +115,55 @@
  42.145      }
  42.146  }
  42.147  
  42.148 -/** type argument in constructor call generic/array */
  42.149 -class T0x19 {
  42.150 -    <T> T0x19() {}
  42.151 +/** method return type generic/array */
  42.152 +class T0x0B {
  42.153 +    Class<@A @DA Object> m0x0B() { return null; }
  42.154 +}
  42.155  
  42.156 -    void g() {
  42.157 -       new <List<@A @DA String>> T0x19();
  42.158 +/** method parameter generic/array */
  42.159 +class T0x0D {
  42.160 +    void m0x0D(HashMap<@A @DA Object, List<@A @DA List<@A @DA Class>>> s1) {}
  42.161 +}
  42.162 +
  42.163 +/** field generic/array */
  42.164 +class T0x0F {
  42.165 +    HashMap<@A @DA Object, @A @DA Object> c1;
  42.166 +}
  42.167 +
  42.168 +/** class type parameter bound */
  42.169 +class T0x10<T extends @A @DA Cloneable> {
  42.170 +}
  42.171 +
  42.172 +class T0x10A<T extends @A @DA Object> {
  42.173 +}
  42.174 +
  42.175 +/** class type parameter bound generic/array */
  42.176 +class T0x11<T extends List<@A @DA T>> {
  42.177 +}
  42.178 +
  42.179 +/** method type parameter bound */
  42.180 +class T0x12<T> {
  42.181 +    <T extends @A @DA Cloneable> void m0x12() {}
  42.182 +}
  42.183 +
  42.184 +/** method type parameter bound generic/array */
  42.185 +class T0x13 {
  42.186 +    static <T extends Comparable<@A @DA T>> T m0x13() {
  42.187 +        return null;
  42.188      }
  42.189  }
  42.190  
  42.191 -/** type argument in method call generic/array */
  42.192 -class T0x1B<T> {
  42.193 -    void m0x1B() {
  42.194 -        Collections.<T @A @DA []>emptyList();
  42.195 -    }
  42.196 +/** class extends/implements */
  42.197 +class T0x14 extends @A @DA Thread implements @A @DA Serializable, @A @DA Cloneable {
  42.198 +}
  42.199 +
  42.200 +/** class extends/implements generic/array */
  42.201 +class T0x15<T> extends ArrayList<@A @DA T> {
  42.202 +}
  42.203 +
  42.204 +/** exception type in throws */
  42.205 +class T0x16 {
  42.206 +    void m0x16() throws @A @DA Exception {}
  42.207  }
  42.208  
  42.209  /** type argument in constructor call */
  42.210 @@ -196,6 +175,15 @@
  42.211      }
  42.212  }
  42.213  
  42.214 +/** type argument in constructor call generic/array */
  42.215 +class T0x19 {
  42.216 +    <T> T0x19() {}
  42.217 +
  42.218 +    void g() {
  42.219 +       new <List<@A @DA String>> T0x19();
  42.220 +    }
  42.221 +}
  42.222 +
  42.223  /** type argument in method call */
  42.224  class T0x1A<T,U> {
  42.225      public static <T, U> T m() { return null; }
  42.226 @@ -204,11 +192,43 @@
  42.227      }
  42.228  }
  42.229  
  42.230 -/** class extends/implements */
  42.231 -class T0x14 extends @A @DA Thread implements @A @DA Serializable, @A @DA Cloneable {
  42.232 +/** type argument in method call generic/array */
  42.233 +class T0x1B<T> {
  42.234 +    void m0x1B() {
  42.235 +        Collections.<T @A @DA []>emptyList();
  42.236 +    }
  42.237  }
  42.238  
  42.239 -/** exception type in throws */
  42.240 -class T0x16 {
  42.241 -    void m0x16() throws @A @DA Exception {}
  42.242 +/** wildcard bound */
  42.243 +class T0x1C {
  42.244 +    void m0x1C(List<? extends @A @DA String> lst) {}
  42.245  }
  42.246 +
  42.247 +/** wildcard bound generic/array */
  42.248 +class T0x1D<T> {
  42.249 +    void m0x1D(List<? extends @A @DA List<int[]>> lst) {}
  42.250 +}
  42.251 +
  42.252 +/** method type parameter */
  42.253 +class T0x20 {
  42.254 +    <@A @DA T> void m0x20() {}
  42.255 +}
  42.256 +
  42.257 +class T0x20A {
  42.258 +    <@A @DTPA T> void m0x20A() {}
  42.259 +}
  42.260 +
  42.261 +class T0x20B {
  42.262 +    <T> void m0x20B(@A @DA T p) {}
  42.263 +}
  42.264 +
  42.265 +/** class type parameter */
  42.266 +class T0x22<@A @DA T> {
  42.267 +}
  42.268 +
  42.269 +class T0x22A<@A @DTPA T> {
  42.270 +}
  42.271 +
  42.272 +class T0x22B<T> {
  42.273 +    @A @DA T f;
  42.274 +}
    43.1 --- a/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Tue May 14 13:55:35 2013 -0700
    43.2 +++ b/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Tue May 14 15:04:06 2013 -0700
    43.3 @@ -28,11 +28,17 @@
    43.4   * @author Mahmood Ali
    43.5   * @compile Scopes.java
    43.6   */
    43.7 +
    43.8 +import java.lang.annotation.ElementType;
    43.9 +import java.lang.annotation.Target;
   43.10 +
   43.11  class Scopes {
   43.12  
   43.13    void test(@A(VALUE) Scopes this) { }
   43.14    void test1(@A(value=VALUE) Scopes this) { }
   43.15  
   43.16    private static final int VALUE = 1;
   43.17 +
   43.18 +  @Target(ElementType.TYPE_USE)
   43.19    @interface A { int value(); }
   43.20  }
    44.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java	Tue May 14 13:55:35 2013 -0700
    44.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java	Tue May 14 15:04:06 2013 -0700
    44.3 @@ -66,12 +66,12 @@
    44.4      }
    44.5  
    44.6      ClassFile getClassFile(URL url) throws IOException, ConstantPoolException {
    44.7 -            InputStream in = url.openStream();
    44.8 -            try {
    44.9 -                return ClassFile.read(in);
   44.10 -            } finally {
   44.11 -                in.close();
   44.12 -            }
   44.13 +        InputStream in = url.openStream();
   44.14 +        try {
   44.15 +            return ClassFile.read(in);
   44.16 +        } finally {
   44.17 +            in.close();
   44.18 +        }
   44.19      }
   44.20  
   44.21      /************ Helper annotations counting methods ******************/
   44.22 @@ -83,20 +83,43 @@
   44.23          test("CLASS",cf, null, null, Attribute.RuntimeInvisibleAnnotations, false);
   44.24      }
   44.25  
   44.26 -    void test(ClassFile cf, Method m) {
   44.27 -        test("METHOD",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.28 -        test("METHOD",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.29 -        test("METHOD",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
   44.30 -        test("METHOD",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
   44.31 +    void test(ClassFile cf, Field f, Boolean local) {
   44.32 +        if (!local) {
   44.33 +            test("FIELD",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.34 +            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.35 +            test("FIELD",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
   44.36 +            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
   44.37 +        } else {
   44.38 +            test("CODE",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.39 +            test("CODE",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.40 +            test("CODE",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
   44.41 +            test("CODE",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
   44.42 +        }
   44.43      }
   44.44  
   44.45      void test(ClassFile cf, Field f) {
   44.46 -        test("FIELD",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.47 -        test("FIELD",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.48 -        test("FIELD",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
   44.49 -        test("FIELD",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
   44.50 +        test(cf, f, false);
   44.51      }
   44.52  
   44.53 +    // 'local' determines whether to look for annotations in code attribute or not.
   44.54 +    void test(ClassFile cf, Method m, Boolean local) {
   44.55 +        if (!local) {
   44.56 +            test("METHOD",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.57 +            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.58 +            test("METHOD",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
   44.59 +            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
   44.60 +        } else  {
   44.61 +            test("MCODE",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
   44.62 +            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
   44.63 +            test("MCODE",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
   44.64 +            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
   44.65 +        }
   44.66 +    }
   44.67 +
   44.68 +    // default to not looking in code attribute
   44.69 +    void test(ClassFile cf, Method m ) {
   44.70 +        test(cf, m, false);
   44.71 +    }
   44.72  
   44.73      // Test the result of Attributes.getIndex according to expectations
   44.74      // encoded in the class/field/method name; increment annotations counts.
   44.75 @@ -105,18 +128,47 @@
   44.76          String name = null;
   44.77          int index = -1;
   44.78          Attribute attr = null;
   44.79 +        Code_attribute cAttr = null;
   44.80          boolean isTAattr = annName.contains("TypeAnnotations");
   44.81          try {
   44.82              switch(testtype) {
   44.83                  case "FIELD":
   44.84                      name = f.getName(cf.constant_pool);
   44.85                      index = f.attributes.getIndex(cf.constant_pool, annName);
   44.86 -                    if(index!= -1) attr = f.attributes.get(index);
   44.87 +                    if(index!= -1)
   44.88 +                        attr = f.attributes.get(index);
   44.89 +                    break;
   44.90 +                case "CODE":
   44.91 +                    name = f.getName(cf.constant_pool);
   44.92 +                    //fetch index of and code attribute and annotations from code attribute.
   44.93 +                    index = cf.attributes.getIndex(cf.constant_pool, Attribute.Code);
   44.94 +                    if(index!= -1) {
   44.95 +                        attr = cf.attributes.get(index);
   44.96 +                        assert attr instanceof Code_attribute;
   44.97 +                        cAttr = (Code_attribute)attr;
   44.98 +                        index = cAttr.attributes.getIndex(cf.constant_pool, annName);
   44.99 +                        if(index!= -1)
  44.100 +                            attr = cAttr.attributes.get(index);
  44.101 +                    }
  44.102                      break;
  44.103                  case "METHOD":
  44.104                      name = m.getName(cf.constant_pool);
  44.105                      index = m.attributes.getIndex(cf.constant_pool, annName);
  44.106 -                    if(index!= -1) attr = m.attributes.get(index);
  44.107 +                    if(index!= -1)
  44.108 +                        attr = m.attributes.get(index);
  44.109 +                    break;
  44.110 +                case "MCODE":
  44.111 +                    name = m.getName(cf.constant_pool);
  44.112 +                    //fetch index of and code attribute and annotations from code attribute.
  44.113 +                    index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
  44.114 +                    if(index!= -1) {
  44.115 +                        attr = m.attributes.get(index);
  44.116 +                        assert attr instanceof Code_attribute;
  44.117 +                        cAttr = (Code_attribute)attr;
  44.118 +                        index = cAttr.attributes.getIndex(cf.constant_pool, annName);
  44.119 +                        if(index!= -1)
  44.120 +                            attr = cAttr.attributes.get(index);
  44.121 +                    }
  44.122                      break;
  44.123                  default:
  44.124                      name = cf.getName();
  44.125 @@ -126,7 +178,6 @@
  44.126          } catch(ConstantPoolException cpe) { cpe.printStackTrace(); }
  44.127  
  44.128          if (index != -1) {
  44.129 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  44.130              if(isTAattr) { //count RuntimeTypeAnnotations
  44.131                  RuntimeTypeAnnotations_attribute tAttr =
  44.132                          (RuntimeTypeAnnotations_attribute)attr;
    45.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Tue May 14 13:55:35 2013 -0700
    45.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Tue May 14 15:04:06 2013 -0700
    45.3 @@ -24,7 +24,6 @@
    45.4  /*
    45.5   * @test
    45.6   * @bug 8005085 8005877 8004829 8005681 8006734 8006775
    45.7 - * @ignore 8013409: test failures for type annotations
    45.8   * @summary Combinations of Target ElementTypes on (repeated)type annotations.
    45.9   */
   45.10  
   45.11 @@ -32,10 +31,25 @@
   45.12  import java.io.File;
   45.13  
   45.14  public class CombinationsTargetTest1 extends ClassfileTestHelper {
   45.15 -    // Helps identify test case in event of failure.
   45.16 +
   45.17 +    // Test count helps identify test case in event of failure.
   45.18      int testcount = 0;
   45.19 -    int src1 = 1, src2 = 2, src4 = 4,
   45.20 -        src5 = 5, src6 = 6, src7 = 7;
   45.21 +
   45.22 +    // Base test case template descriptions
   45.23 +    enum srce  {
   45.24 +        src1("(repeating) type annotations at class level"),
   45.25 +        src2("(repeating) type annotations on method"),
   45.26 +        src3("(repeating) type annotations on wildcard, type arguments in anonymous class"),
   45.27 +        src4("(repeating) type annotations on type parameters, bounds and  type arguments on class decl"),
   45.28 +        src5("(repeating) type annotations on type parameters, bounds and  type arguments on method"),
   45.29 +        src6("(repeating) type annotations on type parameters, bounds and  type arguments in method");
   45.30 +
   45.31 +        String description;
   45.32 +
   45.33 +        srce(String desc) {
   45.34 +            this.description = this + ": " +desc;
   45.35 +        }
   45.36 +    }
   45.37  
   45.38      String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
   45.39                       "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
   45.40 @@ -52,7 +66,6 @@
   45.41          // Determines which repeat and order in source(ABMix).
   45.42          Boolean As= false, BDs=true, ABMix=false;
   45.43          int testrun=0;
   45.44 -        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
   45.45          Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
   45.46                                                 {true,false,false}, //repeat @A
   45.47                                                 {false,true,false}, //repeat @B
   45.48 @@ -64,29 +77,29 @@
   45.49              for(String et : ETypes) {
   45.50                 switch(et) {
   45.51                     case "METHOD":
   45.52 -                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
   45.53 -                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src2);
   45.54 -                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src4);
   45.55 -                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src6);
   45.56 -                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
   45.57 -                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src2);
   45.58 -                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src4);
   45.59 -                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src6);
   45.60 +                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   45.61 +                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
   45.62 +                       test( 6,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
   45.63 +                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
   45.64 +                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
   45.65 +                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
   45.66 +                       test( 0,  6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
   45.67 +                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
   45.68                         break;
   45.69                     case "CONSTRUCTOR":
   45.70                     case "FIELD":
   45.71 -                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
   45.72 -                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
   45.73 -                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src7);
   45.74 -                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
   45.75 -                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
   45.76 -                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src7);
   45.77 +                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   45.78 +                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
   45.79 +                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src6);
   45.80 +                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
   45.81 +                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
   45.82 +                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
   45.83                         break;
   45.84                     default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
   45.85 -                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
   45.86 -                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
   45.87 -                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
   45.88 -                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
   45.89 +                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   45.90 +                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
   45.91 +                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
   45.92 +                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
   45.93                 }
   45.94              }
   45.95          }
   45.96 @@ -94,7 +107,7 @@
   45.97  
   45.98      public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
   45.99                       Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
  45.100 -                     Integer N, int source) throws Exception {
  45.101 +                     Integer N, srce source) throws Exception {
  45.102          ++testcount;
  45.103          expected_tvisibles = tvis;
  45.104          expected_tinvisibles = tinv;
  45.105 @@ -125,7 +138,8 @@
  45.106          //if sourcString() set hasInnerClass it also set innerClassname.
  45.107          if(hasInnerClass) {
  45.108              StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
  45.109 -            classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
  45.110 +            classFile=new File(sb.insert(sb.lastIndexOf(".class"),
  45.111 +                                         innerClassname).toString());
  45.112          }
  45.113          ClassFile cf = ClassFile.read(classFile);
  45.114  
  45.115 @@ -152,7 +166,7 @@
  45.116      //
  45.117      String sourceString(String testname, String retentn, String annot2,
  45.118                          Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
  45.119 -                        int src) {
  45.120 +                        srce src) {
  45.121  
  45.122          String As = "@A", Bs = "@B", Ds = "@D";
  45.123          if(Arepeats) As = "@A @A";
  45.124 @@ -201,11 +215,11 @@
  45.125  
  45.126              "@Retention("+retentn+")\n" +
  45.127              "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
  45.128 -            "@interface DC { D[] value(); }\n\n");
  45.129 +            "@interface DC { D[] value(); }\n");
  45.130  
  45.131          // Test case sources with sample generated source.
  45.132          switch(src) {
  45.133 -            case 1: // repeating type annotations at class level
  45.134 +            case src1: // repeating type annotations at class level
  45.135                      /*
  45.136                       * @A @B class Test1 {
  45.137                       * @A @B Test1(){}
  45.138 @@ -218,21 +232,21 @@
  45.139                       * }}
  45.140                       */
  45.141                  source = new String(
  45.142 -                "// (repeating) type annotations at class level. \n" +
  45.143 -                "_As_ _Bs_ class " + testname + " {\n" +
  45.144 -                "_As_ _Bs_ " + testname +"(){} \n" +
  45.145 -                "_As_ _Bs_ Integer i1 = 0; \n" +
  45.146 -                "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
  45.147 -                "// type usage in method body \n" +
  45.148 -                "String test("+testname+" this, " +
  45.149 -                   "String param, String ... vararg) { \n" +
  45.150 -                "    Object o = new  String  [3]; \n" +
  45.151 -                "    return (String) null; \n" +
  45.152 -                "} \n" +
  45.153 -                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  45.154 -                "\n\n";
  45.155 +                    "// " + src.description + "\n" +
  45.156 +                    "_As_ _Bs_ class " + testname + " {\n" +
  45.157 +                    "_As_ _Bs_ " + testname +"(){} \n" +
  45.158 +                    "_As_ _Bs_ Integer i1 = 0; \n" +
  45.159 +                    "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
  45.160 +                    "// type usage in method body \n" +
  45.161 +                    "String test("+testname+" this, " +
  45.162 +                       "String param, String ... vararg) { \n" +
  45.163 +                    "    Object o = new  String  [3]; \n" +
  45.164 +                    "    return (String) null; \n" +
  45.165 +                    "}\n" +
  45.166 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  45.167 +                    "\n";
  45.168                  break;
  45.169 -            case 2: // (repeating) type annotations on method.
  45.170 +            case src2: // (repeating) type annotations on method.
  45.171                      /*
  45.172                       * class Test12 {
  45.173                       * Test12(){}
  45.174 @@ -243,26 +257,26 @@
  45.175                       * }}
  45.176                       */
  45.177                  source = new String(
  45.178 -                "// (repeating) type annotations on method. \n" +
  45.179 -                "class " + testname + " {\n" +
  45.180 -                testname +"(){} \n" +
  45.181 -                "// type usage on method \n" +
  45.182 -                "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
  45.183 -                   "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
  45.184 -                "    Object o = new String [3]; \n" +
  45.185 -                "    return (String) null; \n" +
  45.186 -                "} \n" +
  45.187 -                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  45.188 -                "\n\n";
  45.189 +                    "// " + src.description + "\n" +
  45.190 +                    "class " + testname + " {\n" +
  45.191 +                    testname +"(){} \n" +
  45.192 +                    "// type usage on method \n" +
  45.193 +                    "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
  45.194 +                       "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
  45.195 +                    "    Object o = new String [3]; \n" +
  45.196 +                    "    return (String) null; \n" +
  45.197 +                    "}\n" +
  45.198 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  45.199 +                    "\n";
  45.200                  break;
  45.201 -            case 4: //(repeating) annotations on wildcard, type arguments in anonymous class.
  45.202 +            case src3: //(repeating) annotations on wildcard, type arguments in anonymous class.
  45.203                      /*
  45.204                       * class Test13<T extends Object> {
  45.205                       *     public T data = null;
  45.206                       *     T getData() { return data;}
  45.207                       *     String mtest( Test13<String> t){ return t.getData(); }
  45.208                       *     public void test() {
  45.209 -                     *         mtest( new Test13<@A @B String>() {
  45.210 +                     *         mtest( new Test13<String>() {
  45.211                       *                  void m1(List<@A @B ? extends @A @B  Object> lst) {}
  45.212                       *                  void m2() throws@A @B Exception { }
  45.213                       *                });
  45.214 @@ -270,22 +284,23 @@
  45.215                       * }
  45.216                       */
  45.217                  source = new String( source +
  45.218 -                "// (repeating) annotations on wildcard, type arguments in anonymous class. \n" +
  45.219 -                "class " + testname + "<T extends Object> {\n" +
  45.220 -                "    public T data = null;\n" +
  45.221 -                "    T getData() { return data;}\n" +
  45.222 -                "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
  45.223 -                "    public void test() {\n" +
  45.224 -                "        mtest( new " + testname + "<_As_ _Bs_ String>() {\n" +
  45.225 -                "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
  45.226 -                "                 void m2() throws_As_ _Bs_ Exception { }\n" +
  45.227 -                "               });\n" +
  45.228 -                "    }\n" +
  45.229 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + "\n\n";
  45.230 -                hasInnerClass=true;
  45.231 -                innerClassname="$1";
  45.232 +                    "// " + src.description + "\n" +
  45.233 +                    "class " + testname + "<T extends Object> {\n" +
  45.234 +                    "    public T data = null;\n" +
  45.235 +                    "    T getData() { return data;}\n" +
  45.236 +                    "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
  45.237 +                    "    public void test() {\n" +
  45.238 +                    "        mtest( new " + testname + "<String>() {\n" +
  45.239 +                    "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
  45.240 +                    "                 void m2() throws_As_ _Bs_ Exception { }\n" +
  45.241 +                    "               });\n" +
  45.242 +                    "    }\n" +
  45.243 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  45.244 +                    "\n";
  45.245 +                    hasInnerClass=true;
  45.246 +                    innerClassname="$1";
  45.247              break;
  45.248 -            case 5: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
  45.249 +            case src4: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
  45.250                      /*
  45.251                       * @A @B @D
  45.252                       * class Test2<@A @B @C @D T extends @A @B Object> {
  45.253 @@ -297,18 +312,18 @@
  45.254                       * }
  45.255                       */
  45.256                  source = new String( source +
  45.257 -                "// (repeating)annotations on type parameters, bounds and  type arguments on class decl. \n" +
  45.258 -                "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
  45.259 -                "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
  45.260 -                "    Map<List<String>, Integer> map =\n" +
  45.261 -                "        new HashMap<List< String>, Integer>();\n" +
  45.262 -                "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
  45.263 -                "    String test(" + testname + "<T> this) { return null;}\n" +
  45.264 -                "    <T> String genericMethod(T t) { return null; }\n" +
  45.265 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.266 -                "\n\n";
  45.267 -            break;
  45.268 -            case 6: // (repeating) annotations on type parameters, bounds and  type arguments on method.
  45.269 +                    "// " + src.description + "\n" +
  45.270 +                    "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
  45.271 +                    "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
  45.272 +                    "    Map<List<String>, Integer> map =\n" +
  45.273 +                    "        new HashMap<List< String>, Integer>();\n" +
  45.274 +                    "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
  45.275 +                    "    String test(" + testname + "<T> this) { return null;}\n" +
  45.276 +                    "    <T> String genericMethod(T t) { return null; }\n" +
  45.277 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.278 +                    "\n";
  45.279 +                break;
  45.280 +            case src5: // (repeating) annotations on type parameters, bounds and  type arguments on method.
  45.281                      /*
  45.282                       * class Test14<T extends Object> {
  45.283                       *     Map<List<String>, Integer> map =
  45.284 @@ -319,17 +334,17 @@
  45.285                       * }
  45.286                       */
  45.287                  source = new String( source +
  45.288 -                "// (repeating) annotations on type parameters, bounds and  type arguments on method. \n" +
  45.289 -                "class " + testname + "<T extends Object> {\n" +
  45.290 -                "    Map<List<String>, Integer> map =\n" +
  45.291 -                "        new HashMap<List<String>, Integer>();\n" +
  45.292 -                "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
  45.293 -                "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
  45.294 -                "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
  45.295 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.296 -                "\n\n";
  45.297 -            break;
  45.298 -            case 7: // repeating annotations on type parameters, bounds and  type arguments in method.
  45.299 +                    "// " + src.description + "\n" +
  45.300 +                    "class " + testname + "<T extends Object> {\n" +
  45.301 +                    "    Map<List<String>, Integer> map =\n" +
  45.302 +                    "        new HashMap<List<String>, Integer>();\n" +
  45.303 +                    "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
  45.304 +                    "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
  45.305 +                    "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
  45.306 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.307 +                    "\n";
  45.308 +                break;
  45.309 +            case src6: // repeating annotations on type parameters, bounds and  type arguments in method.
  45.310                      /*
  45.311                       * class Test7{
  45.312                       *     <E extends Comparable> Map<List<E>, E > foo(E e) {
  45.313 @@ -344,22 +359,22 @@
  45.314                       * }
  45.315                       */
  45.316                  source = new String( source +
  45.317 -                "// (repeating)annotations on type parameters of class, method return value in method. \n" +
  45.318 -                "class "+ testname + "{\n" +
  45.319 -                "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
  45.320 -                "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
  45.321 -                "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
  45.322 -                "                return new HashMap<List<E>,E>();\n" +
  45.323 -                "            }\n" +
  45.324 -                "        }\n" +
  45.325 -                "        return new maptest<E>().getMap();\n" +
  45.326 -                "   }\n" +
  45.327 -                "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
  45.328 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.329 -                "\n\n";
  45.330 -                hasInnerClass=true;
  45.331 -                innerClassname="$1maptest";
  45.332 -            break;
  45.333 +                    "// " + src.description + "\n" +
  45.334 +                    "class "+ testname + "{\n" +
  45.335 +                    "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
  45.336 +                    "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
  45.337 +                    "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
  45.338 +                    "                return new HashMap<List<E>,E>();\n" +
  45.339 +                    "            }\n" +
  45.340 +                    "        }\n" +
  45.341 +                    "        return new maptest<E>().getMap();\n" +
  45.342 +                    "   }\n" +
  45.343 +                    "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
  45.344 +                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  45.345 +                    "\n";
  45.346 +                    hasInnerClass=true;
  45.347 +                    innerClassname="$1maptest";
  45.348 +                break;
  45.349          }
  45.350          return imports + source;
  45.351      }
    46.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java	Tue May 14 13:55:35 2013 -0700
    46.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java	Tue May 14 15:04:06 2013 -0700
    46.3 @@ -23,8 +23,7 @@
    46.4  
    46.5  /*
    46.6   * @test
    46.7 - * @bug 8005085 8005877 8004829 8005681 8006734 8006775
    46.8 - * @ignore 8013409: test failures for type annotations
    46.9 + * @bug 8005085 8005877 8004829 8005681 8006734 8006775 8006507
   46.10   * @summary Combinations of Target ElementTypes on (repeated)type annotations.
   46.11   */
   46.12  
   46.13 @@ -32,9 +31,27 @@
   46.14  import java.io.File;
   46.15  
   46.16  public class CombinationsTargetTest2 extends ClassfileTestHelper {
   46.17 -    // Helps identify test case in event of failure.
   46.18 +
   46.19 +    // Test count helps identify test case in event of failure.
   46.20      int testcount = 0;
   46.21 -    int src3 = 3, src8 = 8, src9 = 9;
   46.22 +
   46.23 +    // Base test case template descriptions
   46.24 +    enum srce  {
   46.25 +        src1("(repeating) type annotations on on field in method body",true),
   46.26 +        src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
   46.27 +        src3("(repeating) type annotations on type parameters of class, method return value in method", true),
   46.28 +        src4("(repeating) type annotations on field in anonymous class", false),
   46.29 +        src5("(repeating) type annotations on field in anonymous class", false);
   46.30 +
   46.31 +        String description;
   46.32 +        Boolean local;
   46.33 +
   46.34 +        srce(String desc, Boolean b) {
   46.35 +            this.description = this + ": " +desc;
   46.36 +            this.local = b;
   46.37 +        }
   46.38 +    }
   46.39 +
   46.40  
   46.41      String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
   46.42                       "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
   46.43 @@ -51,31 +68,36 @@
   46.44          // Determines which repeat and order in source(ABMix).
   46.45          Boolean As= false, BDs=true, ABMix=false;
   46.46          int testrun=0;
   46.47 -        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
   46.48          Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
   46.49                                                 {true,false,false}, //repeat @A
   46.50                                                 {false,true,false}, //repeat @B
   46.51                                                 {true,true,false},  //repeat both
   46.52                                                 {false,false,true}  //repeat mix
   46.53          };
   46.54 +
   46.55          for(Boolean[] bCombo : bRepeat) {
   46.56              As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
   46.57              for(String et : ETypes) {
   46.58                 switch(et) {
   46.59                     case "METHOD":
   46.60 -                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src3);
   46.61 -                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3);
   46.62 +                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   46.63 +                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
   46.64 +                       test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
   46.65 +                       test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
   46.66                         break;
   46.67 -                   case "CONSTRUCTOR":
   46.68                     case "FIELD":
   46.69 -                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src3);
   46.70 -                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src8);
   46.71 -                       test( 6,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src9);
   46.72 -                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3);
   46.73 -                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src8);
   46.74 -                       test( 0,  6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src9);
   46.75 +                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
   46.76 +                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
   46.77 +                       test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
   46.78 +                       test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
   46.79 +                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
   46.80 +                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
   46.81 +                       test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
   46.82 +                       test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
   46.83                         break;
   46.84                     default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
   46.85 +                       test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
   46.86 +                       test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
   46.87                         break;
   46.88                 }
   46.89              }
   46.90 @@ -84,7 +106,7 @@
   46.91  
   46.92      public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
   46.93                       Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
   46.94 -                     Integer N, int source) throws Exception {
   46.95 +                     Integer N, srce source) throws Exception {
   46.96          ++testcount;
   46.97          expected_tvisibles = tvis;
   46.98          expected_tinvisibles = tinv;
   46.99 @@ -97,14 +119,19 @@
  46.100                  ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
  46.101                  ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
  46.102                  ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
  46.103 -                et2 + ", src=" + source;
  46.104 +                et2 + ", src=" + source + "\n    " + source.description;
  46.105  
  46.106 -// Uncomment this block to run the tests but skip failing scenarios.
  46.107 -//        // 8005681 - skip cases with repeated annotations on new, array, cast.
  46.108 -//        if((source==3 || source==8 || source==9) && (ABmix || (Arepeats && BDrepeats))) {
  46.109 -//            System.out.println(testDef+"\n8005681-skip repeated annotations on new,array,cast");
  46.110 -//            return;
  46.111 -//        }
  46.112 +        if(
  46.113 +// 8005681 - src1,2,3 - skip cases with repeated annotations on new, array, cast.
  46.114 +            (( source.equals(srce.src1) || source.equals(srce.src2) ||
  46.115 +              source.equals(srce.src3)) && (ABmix || (Arepeats && BDrepeats)))
  46.116 + // 8008928 - src4,5 - this change cause crash with t-a on anon class)
  46.117 +            || (source.equals(srce.src4) || source.equals(srce.src5))
  46.118 +          ) {
  46.119 +            System.out.println(testDef +
  46.120 +                       "\n    8005681-skip repeated annotations on new,array,cast");
  46.121 +            return;
  46.122 +        }
  46.123  
  46.124          println(testDef);
  46.125          // Create test source and File.
  46.126 @@ -123,6 +150,7 @@
  46.127          if(hasInnerClass) {
  46.128              StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
  46.129              classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
  46.130 +            println("classfile: " + classFile.getAbsolutePath());
  46.131          }
  46.132          ClassFile cf = ClassFile.read(classFile);
  46.133  
  46.134 @@ -130,10 +158,16 @@
  46.135          test(cf);
  46.136  
  46.137          for (Field f : cf.fields) {
  46.138 -            test(cf, f);
  46.139 +            if(source.local)
  46.140 +                test(cf, f, true);
  46.141 +            else
  46.142 +                test(cf,f);
  46.143          }
  46.144          for (Method m: cf.methods) {
  46.145 -            test(cf, m);
  46.146 +            if(source.local)
  46.147 +                test(cf, m, true);
  46.148 +            else
  46.149 +                test(cf, m);
  46.150          }
  46.151          countAnnotations();
  46.152          if (errors > 0) {
  46.153 @@ -149,7 +183,7 @@
  46.154      //
  46.155      String sourceString(String testname, String retentn, String annot2,
  46.156                          Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
  46.157 -                        int src) {
  46.158 +                        srce src) {
  46.159  
  46.160          String As = "@A", Bs = "@B", Ds = "@D";
  46.161          if(Arepeats) As = "@A @A";
  46.162 @@ -198,7 +232,7 @@
  46.163  
  46.164          // Test case sources with sample generated source
  46.165          switch(src) {
  46.166 -            case 3: // (repeating) type annotations on field in method body
  46.167 +            case src1: // (repeating) type annotations on field in method body
  46.168                      /*
  46.169                       * class Test1 {
  46.170                       * Test1(){}
  46.171 @@ -210,18 +244,19 @@
  46.172                       * }}
  46.173                        */
  46.174                  source = new String(
  46.175 -                "class " + testname + " {\n" +
  46.176 -                "" + testname +"(){} \n" +
  46.177 -                "// type usage in method body \n" +
  46.178 -                "String test("+testname+" this, " +
  46.179 -                   "String param, String ... vararg) { \n" +
  46.180 -                "    _As_ _Bs_\n    Object o = new _As_ _Bs_  String _As_ _Bs_  [3]; \n" +
  46.181 -                "        return (_As_ _Bs_  String) null; \n" +
  46.182 -                "} \n" +
  46.183 -                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.184 -                "\n\n";
  46.185 -                break;
  46.186 -            case 8: // (repeating) annotations on type parameters, bounds and  type arguments in new statement.
  46.187 +                    "// " + src.description + "\n" +
  46.188 +                    "class " + testname + " {\n" +
  46.189 +                    "" + testname +"(){} \n" +
  46.190 +                    "// type usage in method body \n" +
  46.191 +                    "String test("+testname+" this, " +
  46.192 +                       "String param, String ... vararg) { \n" +
  46.193 +                    "    _As_ _Bs_\n    Object o = new _As_ _Bs_  String _As_ _Bs_  [3]; \n" +
  46.194 +                    "        return (_As_ _Bs_  String) null; \n" +
  46.195 +                    "} \n" +
  46.196 +                    "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.197 +                    "\n\n";
  46.198 +                    break;
  46.199 +            case src2: // (repeating) annotations on type parameters, bounds and  type arguments in new statement.
  46.200                      /*
  46.201                       * class Test2<T extends Object> {
  46.202                       *     Map<List<String>, Integer> map =
  46.203 @@ -232,17 +267,17 @@
  46.204                       * }
  46.205                       */
  46.206                  source = new String( source +
  46.207 -                "// (repeating) annotations on type parameters, bounds and  type arguments. \n" +
  46.208 -                "class " + testname + "<T extends Object> {\n" +
  46.209 -                "    Map<List<String>, Integer> map =\n" +
  46.210 -                "        new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" +
  46.211 -                "    Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" +
  46.212 -                "    String test(" + testname + "<T> this) { return null;}\n" +
  46.213 -                "    <T> String genericMethod(T t) { return null; }\n" +
  46.214 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.215 -                "\n\n";
  46.216 -            break;
  46.217 -            case 9: // (repeating)annotations on type parameters of class, method return value in method.
  46.218 +                    "// " + src.description + "\n" +
  46.219 +                    "class " + testname + "<T extends Object> {\n" +
  46.220 +                    "    Map<List<String>, Integer> map =\n" +
  46.221 +                    "        new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" +
  46.222 +                    "    Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" +
  46.223 +                    "    String test(" + testname + "<T> this) { return null;}\n" +
  46.224 +                    "    <T> String genericMethod(T t) { return null; }\n" +
  46.225 +                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.226 +                    "\n\n";
  46.227 +                break;
  46.228 +            case src3: // (repeating)annotations on type parameters of class, method return value in method.
  46.229                      /*
  46.230                       * class Test3{
  46.231                       *     <E extends Comparable> Map<List<E>, E > foo(E e) {
  46.232 @@ -258,24 +293,72 @@
  46.233                       * }
  46.234                       */
  46.235                  source = new String( source +
  46.236 -                "// (repeating)annotations on type parameters of class, method return value in method. \n" +
  46.237 -                "class "+ testname + "{\n" +
  46.238 -                "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
  46.239 -                "        class maptest <E> {\n" +                  // inner class $1maptest
  46.240 -                "            Map<List<E>,E> getMap() { \n" +
  46.241 -                "                Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" +
  46.242 -                "                return Em;\n" +
  46.243 -                "            }\n" +
  46.244 -                "        }\n" +
  46.245 -                "        return new maptest<E>().getMap();\n" +
  46.246 -                "   }\n" +
  46.247 -                "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
  46.248 -                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  46.249 -                "\n\n";
  46.250 -                hasInnerClass=true;
  46.251 -                innerClassname="$1maptest";
  46.252 -            break;
  46.253 -
  46.254 +                    "// " + src.description + "\n" +
  46.255 +                    "class "+ testname + "{\n" +
  46.256 +                    "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
  46.257 +                    "        class maptest <E> {\n" +                  // inner class $1maptest
  46.258 +                    "            Map<List<E>,E> getMap() { \n" +
  46.259 +                    "                Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" +
  46.260 +                    "                return Em;\n" +
  46.261 +                    "            }\n" +
  46.262 +                    "        }\n" +
  46.263 +                    "        return new maptest<E>().getMap();\n" +
  46.264 +                    "   }\n" +
  46.265 +                    "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
  46.266 +                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  46.267 +                    "\n\n";
  46.268 +                    hasInnerClass=true;
  46.269 +                    innerClassname="$1maptest";
  46.270 +                break;
  46.271 +            case src4: // (repeating)annotations on field in anonymous class
  46.272 +                    /*
  46.273 +                     * class Test95{
  46.274 +                     *     void mtest( Test95 t){  }
  46.275 +                     *     public void test() {
  46.276 +                     *         mtest( new Test95() {
  46.277 +                     *             @A @A @B @B String data2 = "test";
  46.278 +                     *         });
  46.279 +                     *     }
  46.280 +                     * }
  46.281 +                     */
  46.282 +                source = new String( source +
  46.283 +                    "// " + src.description + "\n" +
  46.284 +                    "class "+ testname + "{\n" +
  46.285 +                    "    void mtest( "+ testname + " t){  }\n" +
  46.286 +                    "    public void test() {\n" +
  46.287 +                    "        mtest( new "+ testname + "() {\n" +
  46.288 +                    "            _As_ _Bs_ String data2 = \"test\";\n" +
  46.289 +                    "        });\n" +
  46.290 +                    "    }\n" +
  46.291 +                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.292 +                    "\n\n";
  46.293 +                    hasInnerClass=true;
  46.294 +                    innerClassname="$1";
  46.295 +                break;
  46.296 +            case src5: // (repeating)annotations on method in anonymous class
  46.297 +                    /*
  46.298 +                     * class Test120{
  46.299 +                     *     void mtest( Test120 t){  }
  46.300 +                     *     public void test() {
  46.301 +                     *         mtest( new Test120() {
  46.302 +                     *             @A @B @A @B String m2(){return null;};
  46.303 +                     *         });
  46.304 +                     *     }
  46.305 +                     */
  46.306 +                source = new String( source +
  46.307 +                    "// " + src.description + "\n" +
  46.308 +                    "class "+ testname + "{\n" +
  46.309 +                    "    void mtest( "+ testname + " t){  }\n" +
  46.310 +                    "    public void test() {\n" +
  46.311 +                    "        mtest( new "+ testname + "() {\n" +
  46.312 +                    "            _As_ _Bs_ String m2(){return null;};\n" +
  46.313 +                    "        });\n" +
  46.314 +                    "    }\n" +
  46.315 +                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  46.316 +                    "\n\n";
  46.317 +                    hasInnerClass=true;
  46.318 +                    innerClassname="$1";
  46.319 +                break;
  46.320          }
  46.321          return imports + source;
  46.322      }
    47.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest3.java	Tue May 14 15:04:06 2013 -0700
    47.3 @@ -0,0 +1,539 @@
    47.4 +/*
    47.5 + * Copyright (c) 2013, 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 +/*
   47.28 + * @test
   47.29 + * @bug 8005085 8005681 8008769 8010015
   47.30 + * @summary Check (repeating)type annotations on lambda usage.
   47.31 + * @run main CombinationsTargetTest3
   47.32 + */
   47.33 +
   47.34 +import com.sun.tools.classfile.*;
   47.35 +import java.io.File;
   47.36 +import java.util.Vector;
   47.37 +
   47.38 +public class CombinationsTargetTest3 extends ClassfileTestHelper {
   47.39 +
   47.40 +    // Helps identify test case in event of failure.
   47.41 +    int testcount = 0;
   47.42 +
   47.43 +    // Known failure cases due to open bugs.
   47.44 +    Vector<String> skippedTests = new Vector<>();
   47.45 +    void printSkips() {
   47.46 +        if(!skippedTests.isEmpty()) {
   47.47 +            println(skippedTests.size() + " tests were skipped:");
   47.48 +            for(String t : skippedTests)
   47.49 +                println("    " + t);
   47.50 +        }
   47.51 +    }
   47.52 +
   47.53 +    // Test case descriptions and expected annotation counts.
   47.54 +    enum srce  {
   47.55 +        src1("type annotations on lambda expression as method arg.",4,0),
   47.56 +        src2("type annotations on new in single line lambda expression",2,0),
   47.57 +        src3("type annotations in lambda expression code block",4,0),
   47.58 +        src4("type annotations in code block with recursion,cast",2,0),
   47.59 +        src5("type annotations in lambda expression code block",4,0),
   47.60 +        src6("type annotations on type parm in method reference",4,0),
   47.61 +        src7("type annotations on inner class field of lambda expression",2,2),
   47.62 +        src8("type annotations in inner class of lambda expression",4,2),
   47.63 +        src9("type annotations on static method of interface",4,2);
   47.64 +
   47.65 +        String description;
   47.66 +        // Expected annotation counts are same for Vis or Invis, but which one
   47.67 +        // depends on retention type.
   47.68 +        Integer[] exp = { 0, 0 };
   47.69 +
   47.70 +        // If class to test is inner class, this may be set in SourceString()
   47.71 +        String innerClassname = null ;
   47.72 +
   47.73 +        // If class to test is not main or inner class; set in sourceString()
   47.74 +        String altClassName = null;
   47.75 +
   47.76 +        srce(String desc, int e1, int e2) {
   47.77 +            description = this + ": " +desc;
   47.78 +            exp[0]=e1;
   47.79 +            exp[1]=e2;
   47.80 +        }
   47.81 +    }
   47.82 +
   47.83 +    // Check for RuntimeInvisible or RuntimeVisible annotations.
   47.84 +    String[] RType={"CLASS", "RUNTIME"};
   47.85 +
   47.86 +    // This can be a compile only test.
   47.87 +    static boolean compileonly=false;
   47.88 +
   47.89 +    // Collect failure for end of test report()
   47.90 +    Vector<String> vFailures = new Vector<>();
   47.91 +
   47.92 +    // pass/fail determined after all tests have run.
   47.93 +    void report() {
   47.94 +        if(vFailures.isEmpty()) {
   47.95 +            printSkips();
   47.96 +            println("PASS");
   47.97 +        } else {
   47.98 +           System.err.println("FAILED: There were failures:");
   47.99 +           for(String f : vFailures)
  47.100 +               System.err.println(f);
  47.101 +           throw new RuntimeException("There were failures. See test log.");
  47.102 +        }
  47.103 +    }
  47.104 +
  47.105 +    public static void main(String[] args) throws Exception {
  47.106 +        if(args.length>0 && args[0].compareTo("compileonly")==0)
  47.107 +            compileonly=true;
  47.108 +        new CombinationsTargetTest3().run();
  47.109 +    }
  47.110 +
  47.111 +    void run() throws Exception {
  47.112 +        // Determines which repeat and order in source(ABMix).
  47.113 +        Boolean As= false, BDs=true, ABMix=false;
  47.114 +        int testrun=0;
  47.115 +        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
  47.116 +        Boolean [][] bRepeat = new Boolean[][]{{false,false,false}, //no repeats
  47.117 +                                               {true,false,false}, //repeat @A
  47.118 +                                               {false,true,false}, //repeat @B
  47.119 +                                               {true,true,false},  //repeat both
  47.120 +                                               {false,false,true}  //repeat mix
  47.121 +        };
  47.122 +        // Added ElementType's. All set; not permuted (so far) for this test
  47.123 +        String et = "TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE";
  47.124 +
  47.125 +        // test loop
  47.126 +        for(Boolean[] bCombo : bRepeat) {
  47.127 +            As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
  47.128 +            for(srce src : srce.values())
  47.129 +                for( String rtype : RType ) {
  47.130 +                   switch( rtype ) {
  47.131 +                       case "RUNTIME":
  47.132 +                           test(0,src.exp[0],0,src.exp[1],As, BDs, ABMix,
  47.133 +                                "RUNTIME", et, ++testrun, src);
  47.134 +                           break;
  47.135 +                       case "CLASS":
  47.136 +                           test(src.exp[0],0,src.exp[1],0,As, BDs, ABMix,
  47.137 +                                "CLASS", et, ++testrun, src);
  47.138 +                           break;
  47.139 +                }
  47.140 +            }
  47.141 +        }
  47.142 +        report();
  47.143 +    }
  47.144 +
  47.145 +    // Filter out skipped cases, compile, pass class file to test method,
  47.146 +    // count annotations and asses results.
  47.147 +    public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
  47.148 +                     Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
  47.149 +                     Integer N, srce source) throws Exception {
  47.150 +        ++testcount;
  47.151 +        expected_tvisibles = tvis;
  47.152 +        expected_tinvisibles = tinv;
  47.153 +        expected_visibles = vis;
  47.154 +        expected_invisibles = inv;
  47.155 +        File testFile = null;
  47.156 +        String tname="Test" + N.toString();
  47.157 +        String testDef = "Test " + testcount + " parameters: tinv=" + tinv +
  47.158 +                ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
  47.159 +                ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
  47.160 +                ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
  47.161 +                et2 + ", src=" + source;
  47.162 +
  47.163 +        // Skip failing cases with bug ID's
  47.164 +        if ((source.equals(srce.src2) || source.equals(srce.src4) ||
  47.165 +            source.equals(srce.src5)) &&
  47.166 +            (ABmix || (Arepeats && BDrepeats))) {
  47.167 +                skippedTests.add(testDef +
  47.168 +                  "\n--8005681 repeated type-annotations on new/cast/array in" +
  47.169 +                  " inner class in lambda expression.");
  47.170 +            return;
  47.171 +        }//8008769 Repeated type-annotations on type parm of local variable
  47.172 +         else if (source.equals(srce.src6) &&
  47.173 +                   (ABmix || (Arepeats && BDrepeats))) {
  47.174 +            skippedTests.add(testDef +  "\n--8008769 Repeated " +
  47.175 +                             "type-annotations on type parm of local variable");
  47.176 +            return;
  47.177 +        }
  47.178 +
  47.179 +        println(testDef);
  47.180 +        // Create test source and File.
  47.181 +        String sourceString = sourceString(tname, rtn, et2, Arepeats,
  47.182 +                                           BDrepeats, ABmix, source);
  47.183 +        testFile = writeTestFile(tname+".java", sourceString);
  47.184 +        // Compile test source and read classfile.
  47.185 +        File classFile = null;
  47.186 +        try {
  47.187 +            classFile = compile(testFile);
  47.188 +            System.out.println("pass compile: " + tname + ".java");
  47.189 +        } catch (Error err) {
  47.190 +            System.err.println("fail compile. Source:\n" + sourceString);
  47.191 +            throw err;
  47.192 +        }
  47.193 +        if(!compileonly) {
  47.194 +            //check if innerClassname is set
  47.195 +            String classdir = classFile.getAbsolutePath();
  47.196 +            if(source.innerClassname != null) {
  47.197 +                StringBuffer sb = new StringBuffer(classdir);
  47.198 +                classFile=new File(sb.insert(sb.lastIndexOf(".class"),
  47.199 +                                   source.innerClassname).toString());
  47.200 +                source.innerClassname=null;
  47.201 +            } else if (source.altClassName != null) {
  47.202 +                classdir = classdir.substring(0,classdir.lastIndexOf("Test"));
  47.203 +                classFile=new File(classdir.concat(source.altClassName));
  47.204 +                source.innerClassname=null;
  47.205 +            }
  47.206 +            ClassFile cf = ClassFile.read(classFile);
  47.207 +
  47.208 +            println("Testing classfile: " + cf.getName());
  47.209 +            //Test class,fields and method counts.
  47.210 +            test(cf);
  47.211 +
  47.212 +            for (Field f : cf.fields) {
  47.213 +                test(cf, f);
  47.214 +                test(cf, f, true);
  47.215 +            }
  47.216 +            for (Method m: cf.methods) {
  47.217 +                test(cf, m);
  47.218 +                test(cf, m, true);
  47.219 +            }
  47.220 +
  47.221 +            countAnnotations(); // sets errors=0 before counting.
  47.222 +            if (errors > 0) {
  47.223 +                System.err.println( testDef );
  47.224 +                System.err.println( "Source:\n" + sourceString );
  47.225 +                vFailures.add(testDef);
  47.226 +            }
  47.227 +        }
  47.228 +        if(errors==0) println("Pass"); println("");
  47.229 +    }
  47.230 +
  47.231 +    /*
  47.232 +     * Source definitions for test cases.
  47.233 +     * To add a test:
  47.234 +     *   Add enum to srce(near top of file) with expected annotation counts.
  47.235 +     *   Add source defintion below.
  47.236 +     */
  47.237 +    String sourceString(String testname, String retentn, String annot2,
  47.238 +                        Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
  47.239 +                        srce src) {
  47.240 +
  47.241 +        String As = "@A", Bs = "@B", Ds = "@D";
  47.242 +        if(Arepeats) As = "@A @A";
  47.243 +        if(BDrepeats) {
  47.244 +            Bs = "@B @B";
  47.245 +            Ds = "@D @D";
  47.246 +        }
  47.247 +        if(ABmix) { As = "@A @B"; Bs = "@A @B"; Ds = "@D @D"; }
  47.248 +
  47.249 +        // Source to check for TYPE_USE and TYPE_PARAMETER annotations.
  47.250 +        // Source base (annotations) is same for all test cases.
  47.251 +        String source = new String();
  47.252 +        String imports = new String("import java.lang.annotation.*; \n" +
  47.253 +            "import static java.lang.annotation.RetentionPolicy.*; \n" +
  47.254 +            "import static java.lang.annotation.ElementType.*; \n" +
  47.255 +            "import java.util.List; \n" +
  47.256 +            "import java.util.ArrayList;\n\n");
  47.257 +
  47.258 +            String sourceBase = new String(
  47.259 +            "@Retention("+retentn+") @Target({TYPE_USE,_OTHER_}) @Repeatable( AC.class ) @interface A { }\n" +
  47.260 +            "@Retention("+retentn+") @Target({TYPE_USE,_OTHER_}) @interface AC { A[] value(); } \n" +
  47.261 +            "@Retention("+retentn+") @Target({TYPE_USE,_OTHER_}) @Repeatable( BC.class ) @interface B { }\n" +
  47.262 +            "@Retention("+retentn+") @Target({TYPE_USE,_OTHER_}) @interface BC { B[] value(); } \n" +
  47.263 +            "@Retention("+retentn+") @Target({TYPE_USE,TYPE_PARAMETER,_OTHER_}) @Repeatable(DC.class) @interface D { }\n" +
  47.264 +            "@Retention("+retentn+") @Target({TYPE_USE,TYPE_PARAMETER,_OTHER_}) @interface DC { D[] value(); }");
  47.265 +
  47.266 +        // Test case sources with sample generated source
  47.267 +        switch(src) {
  47.268 +            case src1: //(repeating) type annotations on lambda expressions.
  47.269 +                /*
  47.270 +                 * class Test1 {
  47.271 +                 * Test1(){}
  47.272 +                 * interface MapFun<T,R> {  R m( T n); }
  47.273 +                 * void meth( MapFun<String,Integer> mf ) {
  47.274 +                 *     assert( mf.m("four") == 4);
  47.275 +                 * }
  47.276 +                 * void test(Integer i) {
  47.277 +                 *     // lambda expression as method arg
  47.278 +                 *     meth( (@A @B String s) -> { @A @B Integer len = s.length(); return len; } );
  47.279 +                 * }}
  47.280 +                 */
  47.281 +                source = new String( source +
  47.282 +                "// " + src.description + "\n" +
  47.283 +                "class " + testname + " {\n" +
  47.284 +                "  " + testname +"(){} \n" +
  47.285 +                "  interface MapFun<T,R> {  R m( T n); }\n\n" +
  47.286 +                "  void meth( MapFun<String,Integer> mf ) {\n" +
  47.287 +                "    assert( mf.m(\"four\") == 4);\n" +
  47.288 +                "  }\n\n" +
  47.289 +                "  void test(Integer i) {\n" +
  47.290 +                "    // lambda expression as method arg\n" +
  47.291 +                "    meth( (_As_ _Bs_ String s) -> { _As_ _Bs_ Integer len = s.length(); return len; } );\n" +
  47.292 +                "}}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.293 +                "\n";
  47.294 +                break;
  47.295 +            case src2: //(repeating) type annotations on new in single line lambda expression.
  47.296 +                /*
  47.297 +                 * //case2: (repeating) type annotations on new in single lambda expressions.
  47.298 +                 * class Test2{
  47.299 +                 *   interface MapFun<T, R> {  R m( T n); }
  47.300 +                 *   MapFun<Integer, String> its;
  47.301 +                 * void test(Integer i) {
  47.302 +                 *   its = a -> "~"+new @A @B Integer(a).toString()+"~";
  47.303 +                 *   System.out.println("in: " + i + " out: " + its.m(i));
  47.304 +                 * }}
  47.305 +                 */
  47.306 +                source = new String( source +
  47.307 +                "// " + src.description + "\n" +
  47.308 +                "class " + testname + "{\n" +
  47.309 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.310 +                "  MapFun<Integer, String> its;\n" +
  47.311 +                "  void test(Integer i) {\n" +
  47.312 +                "    its = a -> \"~\"+new _As_ _Bs_ Integer(a).toString()+\"~\";\n" +
  47.313 +                "    System.out.println(\"in: \" + i + \" out: \" + its.m(i));\n" +
  47.314 +                "  }\n" +
  47.315 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.316 +                "\n";
  47.317 +            break;
  47.318 +            case src3: //(repeating) type annotations in lambda expression code block.
  47.319 +                /*
  47.320 +                 * class Test183{
  47.321 +                 *   interface MapFun<T, R> {  R m( T n); }
  47.322 +                 *   MapFun<List<Integer>, String> iLs;
  47.323 +                 *   void testm(Integer i) {
  47.324 +                 *       iLs = l -> { @A @B @A @B String ret = new String();
  47.325 +                 *                    for( @A @B @A @B Integer i2 : l)
  47.326 +                 *                        ret=ret.concat(i2.toString() + " ");
  47.327 +                 *                    return ret; };
  47.328 +                 *   List<Integer> li = new ArrayList<>();
  47.329 +                 *   for(int j=0; j<i; j++) li.add(j);
  47.330 +                 *   System.out.println(iLs.m(li) );
  47.331 +                 * }}
  47.332 +                 */
  47.333 +                source = new String( source +
  47.334 +                "// " + src.description + "\n" +
  47.335 +                "class "+ testname + "{\n" +
  47.336 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.337 +                "  MapFun<List<Integer>, String> iLs;\n" +
  47.338 +                "  void testm(Integer i) {\n" +
  47.339 +                "    iLs = l -> { _As_ _Bs_ String ret = new String();\n" +
  47.340 +                "                 for( _As_ _Bs_ Integer i2 : l)\n" +
  47.341 +                "                   ret=ret.concat(i2.toString() + \" \");\n" +
  47.342 +                "                 return ret; };\n" +
  47.343 +                "  List<Integer> li = new ArrayList<>();\n" +
  47.344 +                "  for(int j=0; j<i; j++) li.add(j);\n" +
  47.345 +                "  System.out.println(iLs.m(li) );\n" +
  47.346 +                "}\n" +
  47.347 +                "\n" +
  47.348 +                "    public static void main(String... args) {new " + testname + "().testm(5); }\n" +
  47.349 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.350 +                "\n";
  47.351 +            break;
  47.352 +            case src4: //(repeating) type annotations in code block with recursion,cast
  47.353 +                /*
  47.354 +                 * class Test194{
  47.355 +                 *   interface MapFun<T, R> {  R m( T n); }
  47.356 +                 *   MapFun<Integer, Double>  nf;
  47.357 +                 *   void testm(Integer i) {
  47.358 +                 *       nf = j -> { return j == 1 ? 1.0 : (@A @B @A @B  Double)(nf.m(j-1) * j); };
  47.359 +                 *       System.out.println( "nf.m(" + i + "): " + nf.m(i));
  47.360 +                 *   }
  47.361 +                 * }
  47.362 +                 */
  47.363 +                source = new String( source +
  47.364 +                "// " + src.description + "\n" +
  47.365 +                "class "+ testname + "{\n" +
  47.366 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.367 +                "  MapFun<Integer, Double>  nf;\n" +
  47.368 +                "  void testm(Integer i) {\n" +
  47.369 +                "    nf = j -> { return j == 1 ? 1.0 : (_As_ _Bs_  Double)(nf.m(j-1) * j); };\n" +
  47.370 +                "    System.out.println( \"nf.m(\" + i + \"): \" + nf.m(i));\n" +
  47.371 +                "  }\n" +
  47.372 +                "  public static void main(String... args) {new " + testname + "().testm(5); }\n" +
  47.373 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.374 +                "\n";
  47.375 +            break;
  47.376 +            case src5: //(repeating) type annotations in lambda expression code block.
  47.377 +                   /*
  47.378 +                    * class Test180 {
  47.379 +                    *   interface MapFun<T, R> {  R m( T n); }
  47.380 +                    *   MapFun<Integer,List<Integer>> iLi;
  47.381 +                    *   void test(Integer i) {
  47.382 +                    *     // type parameter use.
  47.383 +                    *     iLi = n -> { List<@A @B @A @B Integer> LI = new ArrayList<@A @B @A @B Integer>(n);
  47.384 +                    *                  for(int nn = n; nn >=0; nn--) LI.add(nn);
  47.385 +                    *                  return LI; };
  47.386 +                    *     List<Integer> li = iLi.m(i);
  47.387 +                    *     for(Integer k : li) System.out.print(k);
  47.388 +                    *   }
  47.389 +                    * }
  47.390 +                    */
  47.391 +                source = new String( source +
  47.392 +                "// " + src.description + "\n" +
  47.393 +                "class "+ testname + "{\n" +
  47.394 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.395 +                "  MapFun<Integer,List<Integer>> iLi;\n" +
  47.396 +                "  void test(Integer i) {\n" +
  47.397 +                "    // type parameter use.\n" +
  47.398 +                "    iLi = n -> { List<_As_ _Bs_ Integer> LI = new ArrayList<_As_ _Bs_ Integer>(n);\n" +
  47.399 +                "                 for(int nn = n; nn >=0; nn--) LI.add(nn);\n" +
  47.400 +                "                 return LI; };\n" +
  47.401 +                "    List<Integer> li = iLi.m(i);\n" +
  47.402 +                "    for(Integer k : li) System.out.print(k);\n" +
  47.403 +                "}\n" +
  47.404 +                "  public static void main(String... args) {new " + testname + "().test(5); }\n" +
  47.405 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
  47.406 +                "\n";
  47.407 +            break;
  47.408 +            case src6: //(repeating) type annotations on type parm in method reference.
  47.409 +                /*
  47.410 +                 * class Test240{
  47.411 +                 *   interface PrintString { void print(String s); }
  47.412 +                 *   public void printArray(Object[] oa, PrintString ps) {
  47.413 +                 *       for(Object o : oa ) ps.print(o.toString());
  47.414 +                 *   }
  47.415 +                 *   public void test() {
  47.416 +                 *       Integer[] intarray = {1,2,3,4,5};
  47.417 +                 *       printArray(intarray, @A @B @A @B TPrint::<@A @B @A @B String>print);
  47.418 +                 *   }
  47.419 +                 * }
  47.420 +                 * class TPrint {
  47.421 +                 *    public static <T> void print(T t) { System.out.println( t.toString()); }
  47.422 +                 * }
  47.423 +                 */
  47.424 +                source = new String( source +
  47.425 +                "// " + src.description + "\n" +
  47.426 +                "class "+ testname + "{\n" +
  47.427 +                "  interface PrintString { void print(String s); }\n" +
  47.428 +                "  public void printArray(Object[] oa, PrintString ps) {\n" +
  47.429 +                "      for(Object o : oa ) ps.print(o.toString());\n" +
  47.430 +                "  }\n" +
  47.431 +                "  public void test() {\n" +
  47.432 +                "    Integer[] intarray = {1,2,3,4,5};\n" +
  47.433 +                "    printArray(intarray, _As_ _Bs_ TPrint::<_As_ _Bs_ String>print);\n" +
  47.434 +                "  }\n" +
  47.435 +                "  public static void main(String... args) {new " + testname + "().test(); }\n" +
  47.436 +                "}\n\n" +
  47.437 +                "class TPrint {\n" +
  47.438 +                "  public static <T> void print(T t) { System.out.println( t.toString()); }\n" +
  47.439 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.440 +                "\n";
  47.441 +            break;
  47.442 +            case src7: //(repeating)type annotations in inner class of lambda expression.
  47.443 +                /*
  47.444 +                 * class Test2{
  47.445 +                 *   interface MapFun<T, R> {  R m( T n); }
  47.446 +                 *   MapFun<Class<?>,String> cs;
  47.447 +                 *   void test() {
  47.448 +                 *     cs = c -> {
  47.449 +                 *         class innerClass   {
  47.450 +                 *           @A @B Class<?> icc = null;
  47.451 +                 *           String getString() { return icc.toString(); }
  47.452 +                 *         }
  47.453 +                 *         return new innerClass().getString();
  47.454 +                 *     };
  47.455 +                 *     System.out.println("cs.m : " + cs.m(Integer.class));
  47.456 +                 *   }
  47.457 +                 * }
  47.458 +                 */
  47.459 +                source = new String( source +
  47.460 +                "// " + src.description + "\n" +
  47.461 +                "class "+ testname + "{\n" +
  47.462 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.463 +                "  MapFun<Class<?>,String> cs;\n" +
  47.464 +                "  void test() {\n" +
  47.465 +                "    cs = c -> {\n" +
  47.466 +                "        class innerClass   {\n" +
  47.467 +                "          _As_ _Bs_ Class<?> icc = null;\n" +
  47.468 +                "          innerClass(Class<?> _c) { icc = _c; }\n" +
  47.469 +                "          String getString() { return icc.toString(); }\n" +
  47.470 +                "        }\n" +
  47.471 +                "        return new innerClass(c).getString();\n" +
  47.472 +                "    };\n" +
  47.473 +                "    System.out.println(\"cs.m : \" + cs.m(Integer.class));\n" +
  47.474 +                "  }\n" +
  47.475 +                "\n" +
  47.476 +                "    public static void main(String... args) {new " + testname + "().test(); }\n" +
  47.477 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.478 +                "\n";
  47.479 +                src.innerClassname="$1innerClass";
  47.480 +            break;
  47.481 +            case src8: //(repeating)type annotations in inner class of lambda expression.
  47.482 +                /*
  47.483 +                 * class Test2{
  47.484 +                 *   interface MapFun<T, R> {  R m( T n); }
  47.485 +                 *   MapFun<Class<?>,String> cs;
  47.486 +                 *   void test() {
  47.487 +                 *     cs = c -> {
  47.488 +                 *         class innerClass   {
  47.489 +                 *             Class<?> icc;
  47.490 +                 *             innerClass(@A @B Class<?> _c) { icc = _c; }
  47.491 +                 *             @A @B String getString() { return icc.toString(); }
  47.492 +                 *         }
  47.493 +                 *         return new innerClass(c).getString();
  47.494 +                 *     };
  47.495 +                 *     System.out.println("cs.m : " + cs.m(Integer.class));
  47.496 +                 *   }
  47.497 +                 * }
  47.498 +                 */
  47.499 +                source = new String( source +
  47.500 +                "// " + src.description + "\n" +
  47.501 +                "class "+ testname + "{\n" +
  47.502 +                "  interface MapFun<T, R> {  R m( T n); }\n" +
  47.503 +                "  MapFun<Class<?>,String> cs;\n" +
  47.504 +                "  void test() {\n" +
  47.505 +                "    cs = c -> {\n" +
  47.506 +                "        class innerClass {\n" +
  47.507 +                "            Class<?> icc;\n" +
  47.508 +                "            innerClass(_As_ _Bs_ Class<?> _c) { icc = _c; }\n" +
  47.509 +                "            _As_ _Bs_ String getString() { return icc.toString(); }\n" +
  47.510 +                "        }\n" +
  47.511 +                "        return new innerClass(c).getString();\n" +
  47.512 +                "    };\n" +
  47.513 +                "    System.out.println(\"cs.m : \" + cs.m(Integer.class));\n" +
  47.514 +                "  }\n" +
  47.515 +                "\n" +
  47.516 +                "    public static void main(String... args) {new " + testname + "().test(); }\n" +
  47.517 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.518 +                "\n";
  47.519 +                src.innerClassname="$1innerClass";
  47.520 +            break;
  47.521 +            case src9: //(repeating)type annotations on static method of interface
  47.522 +                /*
  47.523 +                 *  class Test90{
  47.524 +                 *    interface I  {
  47.525 +                 *      static @A @B @A @B String m() { @A @B @A @B String ret = "I.m"; return ret; }
  47.526 +                 *    }
  47.527 +                 *  }
  47.528 +                 */
  47.529 +                source = new String( source +
  47.530 +                "// " + src.description + "\n" +
  47.531 +                "class "+ testname + "{\n" +
  47.532 +                "  interface I  { \n" +
  47.533 +                "    static _As_ _Bs_ String m() { _As_ _Bs_ String ret = \"I.m\"; return ret; }\n" +
  47.534 +                "  }\n" +
  47.535 +                "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
  47.536 +                "\n";
  47.537 +                src.innerClassname="$I";
  47.538 +            break;
  47.539 +        }
  47.540 +        return imports + source;
  47.541 +    }
  47.542 +}
    48.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/DeadCode.java	Tue May 14 13:55:35 2013 -0700
    48.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/DeadCode.java	Tue May 14 15:04:06 2013 -0700
    48.3 @@ -49,7 +49,7 @@
    48.4              test(cf, f);
    48.5          }
    48.6          for (Method m: cf.methods) {
    48.7 -            test(cf, m);
    48.8 +            test(cf, m, true);
    48.9          }
   48.10  
   48.11          countAnnotations();
    49.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/NewTypeArguments.java	Tue May 14 13:55:35 2013 -0700
    49.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/NewTypeArguments.java	Tue May 14 15:04:06 2013 -0700
    49.3 @@ -1,5 +1,5 @@
    49.4  /*
    49.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    49.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    49.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    49.8   *
    49.9   * This code is free software; you can redistribute it and/or modify it
   49.10 @@ -48,7 +48,7 @@
   49.11              test(cf, f);
   49.12          }
   49.13          for (Method m: cf.methods) {
   49.14 -            test(cf, m);
   49.15 +            test(cf, m, true);
   49.16          }
   49.17  
   49.18          countAnnotations();
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8008762.java	Tue May 14 15:04:06 2013 -0700
    50.3 @@ -0,0 +1,76 @@
    50.4 +/*
    50.5 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    50.7 + *
    50.8 + * This code is free software; you can redistribute it and/or modify it
    50.9 + * under the terms of the GNU General Public License version 2 only, as
   50.10 + * published by the Free Software Foundation.
   50.11 + *
   50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   50.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   50.15 + * version 2 for more details (a copy is included in the LICENSE file that
   50.16 + * accompanied this code).
   50.17 + *
   50.18 + * You should have received a copy of the GNU General Public License version
   50.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   50.21 + *
   50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   50.23 + * or visit www.oracle.com if you need additional information or have any
   50.24 + * questions.
   50.25 + */
   50.26 +
   50.27 +/*
   50.28 + * @test
   50.29 + * @bug 8008762
   50.30 + * @ignore 8013409: test failures for type annotations
   50.31 + * @summary Type annotation on inner class in anonymous class
   50.32 + *          shows up as regular annotation
   50.33 + */
   50.34 +import java.lang.annotation.*;
   50.35 +import static java.lang.annotation.RetentionPolicy.*;
   50.36 +import static java.lang.annotation.ElementType.*;
   50.37 +
   50.38 +import com.sun.tools.classfile.*;
   50.39 +
   50.40 +public class T8008762 extends ClassfileTestHelper{
   50.41 +    public static void main(String[] args) throws Exception {
   50.42 +        new T8008762().run();
   50.43 +    }
   50.44 +
   50.45 +    public void run() throws Exception {
   50.46 +        expected_tinvisibles = 0;
   50.47 +        expected_tvisibles = 4;
   50.48 +
   50.49 +        ClassFile cf = getClassFile("T8008762$Test$1$InnerAnon.class");
   50.50 +        test(cf);
   50.51 +        for (Field f : cf.fields) {
   50.52 +            test(cf, f, false);
   50.53 +        }
   50.54 +        for (Method m : cf.methods) {
   50.55 +            test(cf, m, false);
   50.56 +        }
   50.57 +        countAnnotations();
   50.58 +
   50.59 +        if (errors > 0)
   50.60 +            throw new Exception(errors + " errors found");
   50.61 +        System.out.println("PASSED");
   50.62 +    }
   50.63 +
   50.64 +    /*********************** Test class *************************/
   50.65 +    static class Test {
   50.66 +        Object mtest( Test t){ return null; }
   50.67 +        public void test() {
   50.68 +          mtest( new Test() {
   50.69 +                class InnerAnon { // Test1$1$InnerAnon.class
   50.70 +                  @A @B String ai_data = null;
   50.71 +                  @A @B String ai_m(){ return null; };
   50.72 +                }
   50.73 +               InnerAnon IA = new InnerAnon();
   50.74 +            });
   50.75 +        }
   50.76 +        @Retention(RUNTIME) @Target(TYPE_USE) @interface A { }
   50.77 +        @Retention(RUNTIME) @Target(TYPE_USE) @interface B { }
   50.78 +    }
   50.79 +}
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8008769.java	Tue May 14 15:04:06 2013 -0700
    51.3 @@ -0,0 +1,64 @@
    51.4 +/*
    51.5 + * Copyright (c) 2009, 2013, 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 + * @test
   51.28 + * @summary Repeated type-annotations on type parm of local variable
   51.29 + *          are not written to classfile.
   51.30 + * @bug 8008769
   51.31 + */
   51.32 +import java.lang.annotation.*;
   51.33 +import static java.lang.annotation.RetentionPolicy.*;
   51.34 +import static java.lang.annotation.ElementType.*;
   51.35 +import com.sun.tools.classfile.*;
   51.36 +
   51.37 +public class T8008769 extends ClassfileTestHelper{
   51.38 +    public static void main(String[] args) throws Exception {
   51.39 +        new T8008769().run();
   51.40 +    }
   51.41 +
   51.42 +    public void run() throws Exception {
   51.43 +        expected_tvisibles = 4;
   51.44 +        ClassFile cf = getClassFile("T8008769$Test.class");
   51.45 +        for (Method m : cf.methods) {
   51.46 +            test(cf, m, true);
   51.47 +        }
   51.48 +        countAnnotations();
   51.49 +
   51.50 +        if (errors > 0)
   51.51 +            throw new Exception(errors + " errors found");
   51.52 +        System.out.println("PASSED");
   51.53 +    }
   51.54 +
   51.55 +    /*********************** Test class *************************/
   51.56 +    static class Test<T> {
   51.57 +        public void test() {
   51.58 +            Test<@A @B String>    t0 = new Test<>(); // 2 ok
   51.59 +            Test<@B @B String>    t1 = new Test<>(); // 1 missing
   51.60 +            Test<@A @A @A String> t2 = new Test<>(); // 1 missing
   51.61 +       }
   51.62 +    }
   51.63 +    @Retention(RUNTIME) @Target(TYPE_USE) @Repeatable( AC.class ) @interface A { }
   51.64 +    @Retention(RUNTIME) @Target(TYPE_USE) @Repeatable( BC.class ) @interface B { }
   51.65 +    @Retention(RUNTIME) @Target(TYPE_USE) @interface AC { A[] value(); }
   51.66 +    @Retention(RUNTIME) @Target(TYPE_USE) @interface BC { B[] value(); }
   51.67 +}
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/T8010015.java	Tue May 14 15:04:06 2013 -0700
    52.3 @@ -0,0 +1,79 @@
    52.4 +/*
    52.5 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    52.7 + *
    52.8 + * This code is free software; you can redistribute it and/or modify it
    52.9 + * under the terms of the GNU General Public License version 2 only, as
   52.10 + * published by the Free Software Foundation.
   52.11 + *
   52.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   52.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   52.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   52.15 + * version 2 for more details (a copy is included in the LICENSE file that
   52.16 + * accompanied this code).
   52.17 + *
   52.18 + * You should have received a copy of the GNU General Public License version
   52.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   52.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   52.21 + *
   52.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   52.23 + * or visit www.oracle.com if you need additional information or have any
   52.24 + * questions.
   52.25 + */
   52.26 +
   52.27 +/*
   52.28 + * @test
   52.29 + * @summary Wrong classfile attribution in inner class of lambda expression.
   52.30 + * @bug 8010015
   52.31 + */
   52.32 +
   52.33 +import java.lang.annotation.*;
   52.34 +import static java.lang.annotation.RetentionPolicy.*;
   52.35 +import static java.lang.annotation.ElementType.*;
   52.36 +import com.sun.tools.classfile.*;
   52.37 +
   52.38 +/*
   52.39 + * A type-annotations on a field in an inner class not in a lambda expression
   52.40 + * results in RuntimeTypeAnnotations_attibute and RuntimeAnnotations_attribute.
   52.41 + * On a field in an innner class in a lambda expression, it leaves off the
   52.42 + * RuntimeAnnotations_attribute.
   52.43 + */
   52.44 +public class T8010015 extends ClassfileTestHelper{
   52.45 +    public static void main(String[] args) throws Exception {
   52.46 +        new T8010015().run();
   52.47 +    }
   52.48 +
   52.49 +    public void run() throws Exception {
   52.50 +        expected_tvisibles = 1;
   52.51 +        expected_visibles = 1;
   52.52 +        ClassFile cf = getClassFile("T8010015$Test$1innerClass.class");
   52.53 +        for (Field f : cf.fields) {
   52.54 +            test(cf, f);
   52.55 +        }
   52.56 +        countAnnotations();
   52.57 +
   52.58 +        if (errors > 0)
   52.59 +            throw new Exception(errors + " errors found");
   52.60 +        System.out.println("PASSED");
   52.61 +    }
   52.62 +
   52.63 +    /*********************** Test class **************************/
   52.64 +    interface MapFun<T, R> { R m( T n); }
   52.65 +    static class Test {
   52.66 +        MapFun<Class<?>,String> cs;
   52.67 +        void test() {
   52.68 +            cs = c -> {
   52.69 +                     class innerClass {
   52.70 +                         @A Class<?> icc = null;
   52.71 +                         innerClass(Class<?> _c) { icc = _c; }
   52.72 +                         String getString() { return icc.toString(); }
   52.73 +                     }
   52.74 +                     return new innerClass(c).getString();
   52.75 +            };
   52.76 +            System.out.println("cs.m : " + cs.m(Integer.class));
   52.77 +        }
   52.78 +
   52.79 +    public static void main(String... args) {new Test().test(); }
   52.80 +    }
   52.81 +    @Retention(RUNTIME) @Target({TYPE_USE,FIELD}) @interface A { }
   52.82 +}
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/TestNewCastArray.java	Tue May 14 15:04:06 2013 -0700
    53.3 @@ -0,0 +1,375 @@
    53.4 +/*
    53.5 + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
    53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    53.7 + *
    53.8 + * This code is free software; you can redistribute it and/or modify it
    53.9 + * under the terms of the GNU General Public License version 2 only, as
   53.10 + * published by the Free Software Foundation.
   53.11 + *
   53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   53.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   53.15 + * version 2 for more details (a copy is included in the LICENSE file that
   53.16 + * accompanied this code).
   53.17 + *
   53.18 + * You should have received a copy of the GNU General Public License version
   53.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   53.21 + *
   53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   53.23 + * or visit www.oracle.com if you need additional information or have any
   53.24 + * questions.
   53.25 + */
   53.26 +
   53.27 +/*
   53.28 + * @test
   53.29 + * @bug 8005681
   53.30 + * @summary Repeated annotations on new,array,cast.
   53.31 + */
   53.32 +import java.lang.annotation.*;
   53.33 +import java.io.*;
   53.34 +import java.util.List;
   53.35 +import com.sun.tools.classfile.*;
   53.36 +
   53.37 +import java.lang.annotation.*;
   53.38 +import static java.lang.annotation.RetentionPolicy.*;
   53.39 +import static java.lang.annotation.ElementType.*;
   53.40 +
   53.41 +public class TestNewCastArray {
   53.42 +    int errors = 0;
   53.43 +    List<String> failedTests = new java.util.LinkedList<>();
   53.44 +
   53.45 +    // 'b' tests fail with only even numbers of annotations (8005681).
   53.46 +    String[] testclasses = {"Test1",
   53.47 +        "Test2a", "Test3a", "Test4a", "Test5a",
   53.48 +        "Test2b", "Test3b", "Test4b", "Test5b"
   53.49 +    };
   53.50 +
   53.51 +    public static void main(String[] args) throws Exception {
   53.52 +        new TestNewCastArray().run();
   53.53 +    }
   53.54 +
   53.55 +    void check(String testcase, int expected, int actual) {
   53.56 +        String res = testcase + ": (expected) " + expected + ", " + actual + " (actual): ";
   53.57 +        if(expected == actual) {
   53.58 +            res = res.concat("PASS");
   53.59 +        } else {
   53.60 +            errors++;
   53.61 +            res = res.concat("FAIL");
   53.62 +            failedTests.add(res);
   53.63 +        }
   53.64 +        System.out.println(res);
   53.65 +    }
   53.66 +
   53.67 +    void report() {
   53.68 +        if(errors!=0) {
   53.69 +            System.err.println("Failed tests: " + errors +
   53.70 +                                   "\nfailed test cases:\n");
   53.71 +            for(String t: failedTests)
   53.72 +                System.err.println("  " + t);
   53.73 +           throw new RuntimeException("FAIL: There were test failures.");
   53.74 +           } else
   53.75 +            System.out.println("PASS");
   53.76 +    }
   53.77 +
   53.78 +    void test(String clazz, String ttype, ClassFile cf, Method m, Field f,
   53.79 +              String name, boolean codeattr) {
   53.80 +        int actual = 0;
   53.81 +        int expected = 0, cexpected = 0;
   53.82 +        int index = 0;
   53.83 +        String memberName = null;
   53.84 +        Attribute attr = null;
   53.85 +        Code_attribute cAttr = null;
   53.86 +        String testcase = "undefined";
   53.87 +        try {
   53.88 +        switch(ttype) {
   53.89 +            case "METHOD":
   53.90 +                index = m.attributes.getIndex(cf.constant_pool, name);
   53.91 +                memberName = m.getName(cf.constant_pool);
   53.92 +                if(index != -1)
   53.93 +                    attr = m.attributes.get(index);
   53.94 +                break;
   53.95 +            case "MCODE":
   53.96 +                memberName = m.getName(cf.constant_pool);
   53.97 +                //fetch index of and code attribute and annotations from code attribute.
   53.98 +                index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
   53.99 +                if(index!= -1) {
  53.100 +                    attr = m.attributes.get(index);
  53.101 +                    assert attr instanceof Code_attribute;
  53.102 +                    cAttr = (Code_attribute)attr;
  53.103 +                    index = cAttr.attributes.getIndex(cf.constant_pool, name);
  53.104 +                    if(index!= -1)
  53.105 +                        attr = cAttr.attributes.get(index);
  53.106 +                }
  53.107 +                break;
  53.108 +            case "FIELD":
  53.109 +                index = f.attributes.getIndex(cf.constant_pool, name);
  53.110 +                memberName = f.getName(cf.constant_pool);
  53.111 +                if(index != -1)
  53.112 +                    attr = f.attributes.get(index);
  53.113 +                break;
  53.114 +            case "CODE":
  53.115 +                memberName = f.getName(cf.constant_pool);
  53.116 +                //fetch index of and code attribute and annotations from code attribute.
  53.117 +                index = cf.attributes.getIndex(cf.constant_pool, Attribute.Code);
  53.118 +                if(index!= -1) {
  53.119 +                    attr = cf.attributes.get(index);
  53.120 +                    assert attr instanceof Code_attribute;
  53.121 +                    cAttr = (Code_attribute)attr;
  53.122 +                    index = cAttr.attributes.getIndex(cf.constant_pool, name);
  53.123 +                    if(index!= -1)
  53.124 +                        attr = cAttr.attributes.get(index);
  53.125 +                }
  53.126 +                break;
  53.127 +            default:
  53.128 +                break;
  53.129 +        }
  53.130 +        } catch(ConstantPoolException cpe) { cpe.printStackTrace(); }
  53.131 +        testcase = clazz+" "+ttype + ": " + memberName + ", " + name;
  53.132 +        if(index != -1) {
  53.133 +            //count RuntimeTypeAnnotations
  53.134 +            assert attr instanceof RuntimeTypeAnnotations_attribute;
  53.135 +            RuntimeTypeAnnotations_attribute tAttr =
  53.136 +                    (RuntimeTypeAnnotations_attribute)attr;
  53.137 +                actual += tAttr.annotations.length;
  53.138 +        }
  53.139 +        if(memberName.compareTo("<init>")==0) memberName=clazz+memberName;
  53.140 +        switch ( memberName ) {
  53.141 +            //METHOD:
  53.142 +            case "Test1<init>": expected=0; break;
  53.143 +            case "testr22_22": expected=4; break;
  53.144 +            case "testr11_11": expected=4; break;
  53.145 +            case "testr12_21": expected=4; break;
  53.146 +            case "testr20_02": expected=2; break;
  53.147 +
  53.148 +            case "Test2a<init>": cexpected=0; break;
  53.149 +            case "test00_00_11_11": cexpected=4; break;
  53.150 +            case "test21_12_21_12": cexpected=8; break;
  53.151 +            case "test_new1": cexpected=2; break;
  53.152 +            case "test_new2": cexpected=2; break;
  53.153 +            case "test_cast1": cexpected=2; break;
  53.154 +            case "test_cast2": cexpected=2; break;
  53.155 +
  53.156 +            case "Test2b<init>": cexpected=0; break;
  53.157 +            case "test20_02_20_02": cexpected=4; break;
  53.158 +            case "test22_22_22_22": cexpected=8; break;
  53.159 +            case "test_new3": cexpected=1; break;
  53.160 +            case "test_new4": cexpected=1; break;
  53.161 +            case "test_new5": cexpected=2; break;
  53.162 +            case "test_cast3": cexpected=1; break;
  53.163 +            case "test_cast4": cexpected=2; break;
  53.164 +
  53.165 +            case "Test3a<init>": cexpected=10; break;
  53.166 +            case "SA_21_12c": cexpected = 0; break;
  53.167 +            case "SA_01_10c": expected = 0; break;
  53.168 +            case "SA_11_11c": expected = 0; break;
  53.169 +
  53.170 +            case "Test3b<init>": cexpected=6; break;
  53.171 +            case "SA_22_22c": cexpected = 0; break;
  53.172 +            case "SA_20_02c": cexpected = 0; break;
  53.173 +
  53.174 +            case "Test3c<init>": cexpected=8; break;
  53.175 +            case "SA_10_10": cexpected = 0; break;
  53.176 +            case "SA_10_01": cexpected = 0; break;
  53.177 +            case "SA_21_12": cexpected = 0; break;
  53.178 +
  53.179 +            case "Test3d<init>": cexpected=6; break;
  53.180 +            case "SA_20_02": cexpected = 0; break;
  53.181 +            case "SA_22_22": cexpected = 0; break;
  53.182 +
  53.183 +            case "Test4a<init>": cexpected=4; break;
  53.184 +            case "nS_21": cexpected = 0; break;
  53.185 +            case "nS_12": cexpected = 0; break;
  53.186 +
  53.187 +            case "Test4b<init>": cexpected=4; break;
  53.188 +            case "nS20":  cexpected = 0; break;
  53.189 +            case "nS02":  cexpected = 0; break;
  53.190 +            case "nS22":  cexpected = 0; break;
  53.191 +
  53.192 +            case "Test5a<init>": cexpected=4; break;
  53.193 +            case "ci11": expected = 0; break;
  53.194 +            case "ci21": expected = 0; break;
  53.195 +
  53.196 +            case "Test5b<init>": cexpected=3; break;
  53.197 +            case "ci2":  expected = 0; break;
  53.198 +            case "ci22": expected = 0; break;
  53.199 +
  53.200 +            default: expected = 0; break;
  53.201 +        }
  53.202 +        if(codeattr)
  53.203 +            check(testcase, cexpected, actual);
  53.204 +        else
  53.205 +            check(testcase, expected, actual);
  53.206 +    }
  53.207 +
  53.208 +    public void run() {
  53.209 +        ClassFile cf = null;
  53.210 +        InputStream in = null;
  53.211 +        for( String clazz : testclasses) {
  53.212 +            String testclazz = "TestNewCastArray$" + clazz + ".class";
  53.213 +            System.out.println("Testing " + testclazz);
  53.214 +            try {
  53.215 +                in = getClass().getResource(testclazz).openStream();
  53.216 +                cf = ClassFile.read(in);
  53.217 +                in.close();
  53.218 +            } catch(Exception e) { e.printStackTrace();  }
  53.219 +
  53.220 +            if(clazz.startsWith("Test1")) {
  53.221 +                for (Field f: cf.fields)
  53.222 +                    test(clazz, "FIELD", cf, null, f, Attribute.RuntimeVisibleTypeAnnotations, false);
  53.223 +                for (Method m: cf.methods)
  53.224 +                    test(clazz, "METHOD", cf, m, null, Attribute.RuntimeVisibleTypeAnnotations, false);
  53.225 +            } else {
  53.226 +                for (Field f: cf.fields)
  53.227 +                    test(clazz, "CODE", cf, null, f, Attribute.RuntimeVisibleTypeAnnotations, true);
  53.228 +                for (Method m: cf.methods)
  53.229 +                    test(clazz, "MCODE", cf, m, null, Attribute.RuntimeVisibleTypeAnnotations, true);
  53.230 +            }
  53.231 +        }
  53.232 +        report();
  53.233 +    }
  53.234 +
  53.235 +    //////// test class //////////////////////////
  53.236 +    // "Test1" not in code attribute.
  53.237 +    // on arrays on and in method return
  53.238 +    static class Test1 {
  53.239 +        Test1(){}
  53.240 +        // OK expect 5, got 5
  53.241 +        String @A @A @B @B[] @A @A @B @B [] testr22_22(Test1 this, String param, String ... vararg) {
  53.242 +            String [][] sarray = new String [2][2];
  53.243 +            return sarray;
  53.244 +        }
  53.245 +        // OK expect 5, got 5
  53.246 +        String @A @B [] @A @B [] testr11_11(Test1 this, String param, String ... vararg) {
  53.247 +            String [][] sarray = new String [2][2];
  53.248 +            return sarray;
  53.249 +        }
  53.250 +        // OK expect 5, got 5
  53.251 +        String @A @B @B []@B @B @A[] testr12_21(Test1 this, String param, String ... vararg) {
  53.252 +            String [][] sarray = new String [2][2];
  53.253 +            return sarray;
  53.254 +        }
  53.255 +        // OK expect 3, got 3
  53.256 +        String @A @A [] @B @B [] testr20_02(Test1 this, String param, String ... vararg) {
  53.257 +            String [][] sarray = new String [2][2];
  53.258 +            return sarray;
  53.259 +        }
  53.260 +    }
  53.261 +
  53.262 +    // Inside method body (in method's code attribute)
  53.263 +    static class Test2a {
  53.264 +        Test2a(){}
  53.265 +        Object o = new Integer(1);
  53.266 +        // expect 4
  53.267 +        String[][] test00_00_11_11(Test2a this, String param, String ... vararg) {
  53.268 +            String [] [] sarray = new String @A @B[2] @A @B [2];
  53.269 +            return sarray;
  53.270 +        }
  53.271 +
  53.272 +        // expect 8
  53.273 +        String[][] test21_12_21_12(Test2a this, String param, String ... vararg) {
  53.274 +            String @A @A @B [] @A @B @B [] sarray = new String @A @A @B[2] @A @B @B [2];
  53.275 +            return sarray;
  53.276 +        }
  53.277 +
  53.278 +        void test_new1() { String nS_21 = new @A @A @B String("Hello");   }
  53.279 +        void test_new2() { String nS_12 = new @A @B @B String("Hello");   }
  53.280 +        void test_cast1() { String tcs11 = (@A @B String)o;      }
  53.281 +        void test_cast2() { String tcs21 = (@A @A @B String)o;   }
  53.282 +    }
  53.283 +
  53.284 +    static class Test2b {
  53.285 +        Test2b(){}
  53.286 +        Object o = new Integer(1);
  53.287 +        // expect 4
  53.288 +        String[][] test20_02_20_02(Test2b this, String param, String ... vararg) {
  53.289 +            String @A @A [] @B @B [] sarray = new String @A @A[2] @B @B [2];
  53.290 +            return sarray;
  53.291 +        }
  53.292 +
  53.293 +        // expect 8
  53.294 +        String[][] test22_22_22_22(Test2b this, String param, String ... vararg) {
  53.295 +            String @A @A @B @B [] @A @A @B @B [] sarray = new String @A @A @B @B [2] @A @A @B @B [2];
  53.296 +            return sarray;
  53.297 +        }
  53.298 +
  53.299 +        void test_new3() { String nS20 = new @A @A String("Hello");       }
  53.300 +        void test_new4() { String nS02 = new @B @B String("Hello");       }
  53.301 +        void test_new5() { String nS22 = new @A @A @B @B String("Hello"); }
  53.302 +        void test_cast3() { String tcs2 =  (@A @A String)o;      }
  53.303 +        void test_cast4() { String tcs22 = (@A @A @B @B String)o;}
  53.304 +    }
  53.305 +
  53.306 +    // array levels
  53.307 +    static class Test3a {
  53.308 +        Test3a(){}
  53.309 +        // expect 4+2+4=10
  53.310 +        String [][] SA_21_12c  = new  String @A @A @B [2] @A @B @B[2];
  53.311 +        String [][] SA_01_10c  = new  String @B [2] @A [2];
  53.312 +        String [][] SA_11_11c = new  String @A @B [2] @A @B [2];
  53.313 +    }
  53.314 +
  53.315 +    static class Test3b {
  53.316 +        Test3b(){}
  53.317 +        // expect 4+2=6
  53.318 +        String [][] SA_22_22c  = new  String @A @A @B @B[2] @A @A @B @B[2];
  53.319 +        String [][] SA_20_02c  = new  String @A @A [2] @B @B[2];
  53.320 +    }
  53.321 +    static class Test3c {
  53.322 +        Test3c(){}
  53.323 +        // OK expect 4
  53.324 +        String @A [] @A[] SA_10_10  = new  String [2][2];
  53.325 +        String @A [] @B[] SA_10_01  = new  String [2][2];
  53.326 +        String @A @A @B[] @A @B @B [] SA_21_12  = new  String [2][2];
  53.327 +    }
  53.328 +
  53.329 +    static class Test3d {
  53.330 +        Test3d(){}
  53.331 +        // OK expect 4
  53.332 +        String @A @A [] @B @B [] SA_20_02  = new  String [2][2];
  53.333 +        String @A @A @B @B[] @A @A @B @B [] SA_22_22  = new  String [2][2];
  53.334 +    }
  53.335 +
  53.336 +    // on new
  53.337 +    static class Test4a {
  53.338 +        Test4a(){}
  53.339 +        // expect 2+2=4
  53.340 +        String nS_21 = new @A @A @B String("Hello");
  53.341 +        String nS_12 = new @A @B @B String("Hello");
  53.342 +    }
  53.343 +
  53.344 +    static class Test4b {
  53.345 +        Test4b(){}
  53.346 +        // expect 1+1+2=4
  53.347 +        String nS20 = new @A @A String("Hello");
  53.348 +        String nS02 = new @B @B String("Hello");
  53.349 +        String nS22 = new @A @A @B @B String("Hello");
  53.350 +    }
  53.351 +
  53.352 +    // Cast expressions
  53.353 +    static class Test5a {
  53.354 +        Test5a(){}
  53.355 +        Object o = new Integer(1);
  53.356 +        // expect 2+2=4
  53.357 +        Integer ci11 = (@A @B Integer)o;       // OK expect 3, got 3
  53.358 +        Integer ci21 = (@A @A @B Integer)o;    // OK expect 3, got 3
  53.359 +    }
  53.360 +
  53.361 +    static class Test5b {
  53.362 +        Test5b(){}
  53.363 +        Object o = new Integer(1);
  53.364 +        // Cast expressions
  53.365 +        // expect 1+2=3
  53.366 +        Integer ci2 =  (@A @A Integer)o;       // FAIL expect 2, got 1
  53.367 +        Integer ci22 = (@A @A @B @B Integer)o; // FAIL expect 3, got 1
  53.368 +    }
  53.369 +
  53.370 +@Retention(RUNTIME) @Target({TYPE_USE}) @Repeatable( AC.class ) @interface A { }
  53.371 +@Retention(RUNTIME) @Target({TYPE_USE}) @Repeatable( BC.class ) @interface B { }
  53.372 +@Retention(RUNTIME) @Target({FIELD}) @Repeatable( FC.class ) @interface F { }
  53.373 +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AC { A[] value(); }
  53.374 +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BC { B[] value(); }
  53.375 +@Retention(RUNTIME) @Target({FIELD}) @interface FC { F[] value(); }
  53.376 +
  53.377 +}
  53.378 +
    54.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/TypeCasts.java	Tue May 14 13:55:35 2013 -0700
    54.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/TypeCasts.java	Tue May 14 15:04:06 2013 -0700
    54.3 @@ -1,5 +1,5 @@
    54.4  /*
    54.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    54.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    54.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    54.8   *
    54.9   * This code is free software; you can redistribute it and/or modify it
   54.10 @@ -50,7 +50,7 @@
   54.11              test(cf, f);
   54.12          }
   54.13          for (Method m: cf.methods) {
   54.14 -            test(cf, m);
   54.15 +            test(cf, m, true);
   54.16          }
   54.17  
   54.18          countAnnotations();
    55.1 --- a/test/tools/javac/annotations/typeAnnotations/classfile/Wildcards.java	Tue May 14 13:55:35 2013 -0700
    55.2 +++ b/test/tools/javac/annotations/typeAnnotations/classfile/Wildcards.java	Tue May 14 15:04:06 2013 -0700
    55.3 @@ -1,5 +1,5 @@
    55.4  /*
    55.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    55.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    55.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    55.8   *
    55.9   * This code is free software; you can redistribute it and/or modify it
   55.10 @@ -48,7 +48,7 @@
   55.11              test(cf, f);
   55.12          }
   55.13          for (Method m: cf.methods) {
   55.14 -            test(cf, m);
   55.15 +            test(cf, m,false);
   55.16          }
   55.17  
   55.18          countAnnotations();
    56.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Tue May 14 13:55:35 2013 -0700
    56.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Tue May 14 15:04:06 2013 -0700
    56.3 @@ -27,7 +27,7 @@
    56.4   * @summary Type annotations in a lazy constant need to be attributed
    56.5   *   in the correct order.
    56.6   * @author Werner Dietl
    56.7 - * @compile LazyConstantValue.java
    56.8 + * @compile/ref=LazyConstantValue.out LazyConstantValue.java
    56.9   */
   56.10  
   56.11  import java.lang.annotation.*;
   56.12 @@ -40,5 +40,9 @@
   56.13      static final String[] lcv = new @TA String[0];
   56.14  }
   56.15  
   56.16 +class ClassC {
   56.17 +    static final Object o = (@TA Object) null;
   56.18 +}
   56.19 +
   56.20  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   56.21  @interface TA {}
    57.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/LintCast.out	Tue May 14 13:55:35 2013 -0700
    57.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/LintCast.out	Tue May 14 15:04:06 2013 -0700
    57.3 @@ -1,11 +1,11 @@
    57.4  LintCast.java:15:21: compiler.warn.redundant.cast: java.lang.String
    57.5  LintCast.java:21:27: compiler.warn.redundant.cast: java.util.List<java.lang.String>
    57.6 -LintCast.java:27:20: compiler.warn.redundant.cast: (@A :: int[])
    57.7 +LintCast.java:27:20: compiler.warn.redundant.cast: int @A []
    57.8  LintCast.java:39:24: compiler.warn.redundant.cast: java.lang.String
    57.9  LintCast.java:40:26: compiler.warn.redundant.cast: java.lang.String
   57.10 -LintCast.java:45:23: compiler.warn.redundant.cast: (@A :: java.lang.Object[])
   57.11 +LintCast.java:45:23: compiler.warn.redundant.cast: java.lang.Object @A []
   57.12  LintCast.java:49:27: compiler.warn.redundant.cast: java.util.List<java.lang.String>
   57.13 -LintCast.java:53:27: compiler.warn.redundant.cast: java.util.List<java.lang.String>
   57.14 +LintCast.java:53:27: compiler.warn.redundant.cast: java.util.List<@A java.lang.String>
   57.15  LintCast.java:57:21: compiler.warn.redundant.cast: java.lang.Object
   57.16  LintCast.java:61:27: compiler.warn.redundant.cast: LintCast.Outer.Inner
   57.17  10 warnings
   57.18 \ No newline at end of file
    58.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Tue May 14 13:55:35 2013 -0700
    58.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Tue May 14 15:04:06 2013 -0700
    58.3 @@ -6,7 +6,7 @@
    58.4   * @compile/fail/ref=StaticMethods.out -XDrawDiagnostics StaticMethods.java
    58.5   */
    58.6  class StaticMethods {
    58.7 -  static void main(@A StaticMethods this) { }
    58.8 +  static void main(StaticMethods this) { }
    58.9  }
   58.10  
   58.11  @interface A { }
    59.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Tue May 14 13:55:35 2013 -0700
    59.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Tue May 14 15:04:06 2013 -0700
    59.3 @@ -1,2 +1,2 @@
    59.4 -StaticMethods.java:9:37: compiler.err.annotation.type.not.applicable
    59.5 +StaticMethods.java:9:34: compiler.err.non-static.cant.be.ref: kindname.variable, this
    59.6  1 error
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/T8008751.java	Tue May 14 15:04:06 2013 -0700
    60.3 @@ -0,0 +1,48 @@
    60.4 +/*
    60.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    60.7 + *
    60.8 + * This code is free software; you can redistribute it and/or modify it
    60.9 + * under the terms of the GNU General Public License version 2 only, as
   60.10 + * published by the Free Software Foundation.
   60.11 + *
   60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   60.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   60.15 + * version 2 for more details (a copy is included in the LICENSE file that
   60.16 + * accompanied this code).
   60.17 + *
   60.18 + * You should have received a copy of the GNU General Public License version
   60.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   60.21 + *
   60.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   60.23 + * or visit www.oracle.com if you need additional information or have any
   60.24 + * questions.
   60.25 + */
   60.26 +
   60.27 +/*
   60.28 + * @test
   60.29 + * @summary type-annotation on array level in nested class results in NPE
   60.30 + * @bug 8008751
   60.31 + * @compile T8008751.java
   60.32 + */
   60.33 +import java.lang.annotation.*;
   60.34 +import static java.lang.annotation.RetentionPolicy.*;
   60.35 +import static java.lang.annotation.ElementType.*;
   60.36 +import java.util.List;
   60.37 +
   60.38 +class T8008751 {
   60.39 +    Object mtest( T8008751 t){ return null;  }
   60.40 +    public void test() {
   60.41 +       mtest( new T8008751() {
   60.42 +                class InnerAnon {
   60.43 +                    @A("ok") String s = (@A("ok") String)( new @A("ok") Object());
   60.44 +                    @A("ok") Object @A("NPE")[] [] ia_sa1 = null;
   60.45 +                }
   60.46 +                // If not instanciated, no crash.
   60.47 +                InnerAnon IA = new InnerAnon();
   60.48 +           });
   60.49 +   }
   60.50 +}
   60.51 +@Retention(RUNTIME) @Target(TYPE_USE)  @interface A { String value(); }
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/T8009360.java	Tue May 14 15:04:06 2013 -0700
    61.3 @@ -0,0 +1,49 @@
    61.4 +/*
    61.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    61.7 + *
    61.8 + * This code is free software; you can redistribute it and/or modify it
    61.9 + * under the terms of the GNU General Public License version 2 only, as
   61.10 + * published by the Free Software Foundation.
   61.11 + *
   61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   61.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   61.15 + * version 2 for more details (a copy is included in the LICENSE file that
   61.16 + * accompanied this code).
   61.17 + *
   61.18 + * You should have received a copy of the GNU General Public License version
   61.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   61.21 + *
   61.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   61.23 + * or visit www.oracle.com if you need additional information or have any
   61.24 + * questions.
   61.25 + */
   61.26 +
   61.27 +/*
   61.28 + * @test
   61.29 + * @bug 8009360
   61.30 + * @summary AssertionError from type annotation on member of anonymous class
   61.31 + * @compile T8009360.java
   61.32 + */
   61.33 +import java.lang.annotation.*;
   61.34 +import static java.lang.annotation.RetentionPolicy.*;
   61.35 +import static java.lang.annotation.ElementType.*;
   61.36 +
   61.37 +class Test1<T> {
   61.38 +    Object mtest( Test1<T> t){ return null; }
   61.39 +    public void test() {
   61.40 +        mtest( new Test1<T>() {
   61.41 +                @A String data1 = "test";    // ok
   61.42 +                @A @A String data2 = "test"; // ok
   61.43 +                @A @B String data3 = "test"; // was AssertionError
   61.44 +                @B @C String data4 = "test"; // was AssertionError
   61.45 +           });
   61.46 +   }
   61.47 +}
   61.48 +
   61.49 +@Target({TYPE_USE,FIELD}) @Repeatable( AC.class) @interface A { }
   61.50 +@Target({TYPE_USE,FIELD}) @interface AC { A[] value(); }
   61.51 +@Target({TYPE_USE}) @interface B { }
   61.52 +@Target({TYPE_USE, FIELD}) @interface C { }
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/T8011722.java	Tue May 14 15:04:06 2013 -0700
    62.3 @@ -0,0 +1,38 @@
    62.4 +/*
    62.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    62.7 + *
    62.8 + * This code is free software; you can redistribute it and/or modify it
    62.9 + * under the terms of the GNU General Public License version 2 only, as
   62.10 + * published by the Free Software Foundation.
   62.11 + *
   62.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   62.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   62.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   62.15 + * version 2 for more details (a copy is included in the LICENSE file that
   62.16 + * accompanied this code).
   62.17 + *
   62.18 + * You should have received a copy of the GNU General Public License version
   62.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   62.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   62.21 + *
   62.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   62.23 + * or visit www.oracle.com if you need additional information or have any
   62.24 + * questions.
   62.25 + */
   62.26 +
   62.27 +/*
   62.28 + * @test
   62.29 + * @bug 8011722
   62.30 + * @summary AssertionError from type annotations on qualified type
   62.31 + * @compile T8011722.java
   62.32 + */
   62.33 +import java.lang.annotation.ElementType;
   62.34 +import java.lang.annotation.Target;
   62.35 +
   62.36 +public class T8011722 {
   62.37 +    class InnerException extends Exception { }
   62.38 +    void foo() throws @C T8011722.@C InnerException {    }
   62.39 +}
   62.40 +
   62.41 +@Target(ElementType.TYPE_USE) @interface C { }
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java	Tue May 14 15:04:06 2013 -0700
    63.3 @@ -0,0 +1,19 @@
    63.4 +/*
    63.5 + * @test /nodynamiccopyright/
    63.6 + * @bug 1234567
    63.7 + * @summary ensure that declaration annotations are not allowed on
    63.8 + *   new array expressions
    63.9 + * @author Werner Dietl
   63.10 + * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
   63.11 + */
   63.12 +class DeclarationAnnotation {
   63.13 +    Object e1 = new @DA int[5];
   63.14 +    Object e2 = new @DA String[42];
   63.15 +    Object e3 = new @DA Object();
   63.16 +
   63.17 +    // The declaration annotation is only allowed for
   63.18 +    // an anonymous class creation.
   63.19 +    Object ok = new @DA Object() { };
   63.20 +}
   63.21 +
   63.22 +@interface DA { }
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out	Tue May 14 15:04:06 2013 -0700
    64.3 @@ -0,0 +1,4 @@
    64.4 +DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable
    64.5 +DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable
    64.6 +DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable
    64.7 +3 errors
    64.8 \ No newline at end of file
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.java	Tue May 14 15:04:06 2013 -0700
    65.3 @@ -0,0 +1,21 @@
    65.4 +/*
    65.5 + * @test /nodynamiccopyright/
    65.6 + * @bug 1234567
    65.7 + * @summary ensure that declaration annotations are not allowed on
    65.8 + *   method receiver types
    65.9 + * @author Werner Dietl
   65.10 + * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
   65.11 + */
   65.12 +
   65.13 +import java.lang.annotation.ElementType;
   65.14 +import java.lang.annotation.Target;
   65.15 +
   65.16 +class DeclarationAnnotation {
   65.17 +    void bad(@DA DeclarationAnnotation this) {}
   65.18 +    void good(@TA DeclarationAnnotation this) {}
   65.19 +}
   65.20 +
   65.21 +@interface DA { }
   65.22 +
   65.23 +@Target(ElementType.TYPE_USE)
   65.24 +@interface TA { }
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.out	Tue May 14 15:04:06 2013 -0700
    66.3 @@ -0,0 +1,2 @@
    66.4 +DeclarationAnnotation.java:14:14: compiler.err.annotation.type.not.applicable
    66.5 +1 error
    67.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Tue May 14 13:55:35 2013 -0700
    67.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Tue May 14 15:04:06 2013 -0700
    67.3 @@ -28,6 +28,11 @@
    67.4   * @author Werner Dietl
    67.5   * @compile Nesting.java
    67.6   */
    67.7 +
    67.8 +import java.lang.annotation.ElementType;
    67.9 +import java.lang.annotation.Target;
   67.10 +
   67.11 +@Target(ElementType.TYPE_USE)
   67.12  @interface A { }
   67.13  
   67.14  class Nesting {
    68.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Tue May 14 13:55:35 2013 -0700
    68.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Tue May 14 15:04:06 2013 -0700
    68.3 @@ -1,5 +1,5 @@
    68.4 -StaticThings.java:52:32: compiler.err.annotation.type.not.applicable
    68.5 -StaticThings.java:54:37: compiler.err.annotation.type.not.applicable
    68.6 -StaticThings.java:33:26: compiler.err.annotation.type.not.applicable
    68.7 -StaticThings.java:36:28: compiler.err.annotation.type.not.applicable
    68.8 -4 errors
    68.9 \ No newline at end of file
   68.10 +StaticThings.java:33:26: compiler.err.non-static.cant.be.ref: kindname.variable, this
   68.11 +StaticThings.java:36:28: compiler.err.non-static.cant.be.ref: kindname.variable, this
   68.12 +StaticThings.java:52:32: compiler.err.non-static.cant.be.ref: kindname.variable, this
   68.13 +StaticThings.java:54:37: compiler.err.non-static.cant.be.ref: kindname.variable, this
   68.14 +4 errors
    69.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Tue May 14 13:55:35 2013 -0700
    69.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Tue May 14 15:04:06 2013 -0700
    69.3 @@ -29,6 +29,10 @@
    69.4   * @compile/fail/ref=WrongType.out -XDrawDiagnostics WrongType.java
    69.5   */
    69.6  
    69.7 +import java.lang.annotation.ElementType;
    69.8 +import java.lang.annotation.Target;
    69.9 +
   69.10 +@Target(ElementType.TYPE_USE)
   69.11  @interface A {}
   69.12  
   69.13  class WrongType {
    70.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Tue May 14 13:55:35 2013 -0700
    70.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Tue May 14 15:04:06 2013 -0700
    70.3 @@ -1,9 +1,9 @@
    70.4 -WrongType.java:51:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
    70.5 -WrongType.java:61:27: compiler.err.doesnt.exist: Outer
    70.6 -WrongType.java:62:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
    70.7 -WrongType.java:44:23: compiler.err.incorrect.receiver.type
    70.8 -WrongType.java:46:23: compiler.err.incorrect.receiver.type
    70.9 -WrongType.java:59:33: compiler.err.incorrect.receiver.type
   70.10 -WrongType.java:60:31: compiler.err.incorrect.receiver.type
   70.11 -WrongType.java:66:28: compiler.err.incorrect.receiver.type
   70.12 -8 errors
   70.13 \ No newline at end of file
   70.14 +WrongType.java:48:16: compiler.err.incorrect.receiver.type: WrongType, java.lang.Object
   70.15 +WrongType.java:50:16: compiler.err.incorrect.receiver.type: WrongType, java.lang.Object
   70.16 +WrongType.java:55:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
   70.17 +WrongType.java:63:23: compiler.err.incorrect.receiver.type: WrongType.Inner, WrongType
   70.18 +WrongType.java:64:24: compiler.err.incorrect.receiver.type: WrongType.Inner, java.lang.Object
   70.19 +WrongType.java:65:27: compiler.err.doesnt.exist: Outer
   70.20 +WrongType.java:66:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
   70.21 +WrongType.java:70:24: compiler.err.incorrect.receiver.type: WrongType.Generics<X>, WrongType.Generics<Y>
   70.22 +8 errors
    71.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Tue May 14 13:55:35 2013 -0700
    71.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Tue May 14 15:04:06 2013 -0700
    71.3 @@ -5,10 +5,15 @@
    71.4   * @author Mahmood Ali
    71.5   * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java
    71.6   */
    71.7 +
    71.8 +import java.lang.annotation.ElementType;
    71.9 +import java.lang.annotation.Target;
   71.10 +
   71.11  class MissingAnnotationValue {
   71.12    void test() {
   71.13      new @A String();
   71.14    }
   71.15  }
   71.16  
   71.17 +@Target(ElementType.TYPE_USE)
   71.18  @interface A { int field(); }
    72.1 --- a/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.out	Tue May 14 13:55:35 2013 -0700
    72.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.out	Tue May 14 15:04:06 2013 -0700
    72.3 @@ -1,2 +1,2 @@
    72.4 -MissingAnnotationValue.java:10:9: compiler.err.annotation.missing.default.value: A, field
    72.5 +MissingAnnotationValue.java:14:9: compiler.err.annotation.missing.default.value: A, field
    72.6  1 error
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.java	Tue May 14 15:04:06 2013 -0700
    73.3 @@ -0,0 +1,22 @@
    73.4 +/*
    73.5 + * @test /nodynamiccopyright/
    73.6 + * @bug 1234567
    73.7 + * @summary ensure that declaration annotations are not allowed on
    73.8 + *   wildcards
    73.9 + * @author Werner Dietl
   73.10 + * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
   73.11 + */
   73.12 +
   73.13 +import java.lang.annotation.ElementType;
   73.14 +import java.lang.annotation.Target;
   73.15 +import java.util.List;
   73.16 +
   73.17 +class DeclarationAnnotation {
   73.18 +    List<@DA ? extends Object> bad;
   73.19 +    List<@TA ? extends Object> good;
   73.20 +}
   73.21 +
   73.22 +@interface DA { }
   73.23 +
   73.24 +@Target(ElementType.TYPE_USE)
   73.25 +@interface TA { }
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.out	Tue May 14 15:04:06 2013 -0700
    74.3 @@ -0,0 +1,2 @@
    74.4 +DeclarationAnnotation.java:15:10: compiler.err.annotation.type.not.applicable
    74.5 +1 error
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/AnonymousClass.java	Tue May 14 15:04:06 2013 -0700
    75.3 @@ -0,0 +1,45 @@
    75.4 +/*
    75.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    75.7 + *
    75.8 + * This code is free software; you can redistribute it and/or modify it
    75.9 + * under the terms of the GNU General Public License version 2 only, as
   75.10 + * published by the Free Software Foundation.
   75.11 + *
   75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   75.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   75.15 + * version 2 for more details (a copy is included in the LICENSE file that
   75.16 + * accompanied this code).
   75.17 + *
   75.18 + * You should have received a copy of the GNU General Public License version
   75.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   75.21 + *
   75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   75.23 + * or visit www.oracle.com if you need additional information or have any
   75.24 + * questions.
   75.25 + */
   75.26 +
   75.27 +import java.lang.annotation.*;
   75.28 +
   75.29 +/*
   75.30 + * @test
   75.31 + * @bug 1234567
   75.32 + * @summary new type annotation location: anonymous class creation
   75.33 + * @author Werner Dietl
   75.34 + * @compile AnonymousClass.java
   75.35 + */
   75.36 +class AnonymousClass {
   75.37 +    Object o1 = new @TA Object() { };
   75.38 +    // Declaration annotations are also allowed.
   75.39 +    Object o2 = new @TA @DA Object() { };
   75.40 +}
   75.41 +
   75.42 +@interface DA { }
   75.43 +
   75.44 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   75.45 +@interface TA { }
   75.46 +
   75.47 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   75.48 +@interface TB { }
    76.1 --- a/test/tools/javac/annotations/typeAnnotations/newlocations/Lambda.java	Tue May 14 13:55:35 2013 -0700
    76.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/Lambda.java	Tue May 14 15:04:06 2013 -0700
    76.3 @@ -50,6 +50,13 @@
    76.4          return LambdaImpl::<@TA Object, @TB Object>new;
    76.5      }
    76.6  
    76.7 +    interface LambdaInt2 {
    76.8 +        void lambda(Object p1, Object p2);
    76.9 +    }
   76.10 +
   76.11 +    LambdaInt2 getLambda() {
   76.12 +        return (@TA Object x, @TB Object y) -> { @TA Object l = null; System.out.println("We have: " + (@TB Object) x); };
   76.13 +    }
   76.14  }
   76.15  
   76.16  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    77.1 --- a/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java	Tue May 14 13:55:35 2013 -0700
    77.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/MultiCatch.java	Tue May 14 15:04:06 2013 -0700
    77.3 @@ -25,7 +25,6 @@
    77.4  
    77.5  /*
    77.6   * @test
    77.7 - * @ignore 8013408: Need specification for type exceptions on multicatch
    77.8   * @bug 8006775
    77.9   * @summary new type annotation location: multicatch
   77.10   * @author Werner Dietl
   77.11 @@ -40,6 +39,8 @@
   77.12        e.toString();
   77.13      }
   77.14    }
   77.15 +  /* Disabled: there is no syntax to annotate all components
   77.16 +   * of the multicatch.
   77.17    void exception02() {
   77.18      try {
   77.19          System.out.println("Hello 2!");
   77.20 @@ -47,18 +48,24 @@
   77.21        e.toString();
   77.22      }
   77.23    }
   77.24 +  */
   77.25  }
   77.26  
   77.27  class ModifiedVars {
   77.28 -    /*
   77.29 -  void exception() {
   77.30 +  void exception01() {
   77.31      try {
   77.32 -      arrays();
   77.33 -    } catch (final @A Exception e) {
   77.34 +        System.out.println("Hello 1!");
   77.35 +    } catch (final @B NullPointerException | @C IllegalArgumentException e) {
   77.36        e.toString();
   77.37      }
   77.38    }
   77.39 -    */
   77.40 +  void exception02() {
   77.41 +    try {
   77.42 +        System.out.println("Hello 1!");
   77.43 +    } catch (@Decl @B NullPointerException | @C IllegalArgumentException e) {
   77.44 +      e.toString();
   77.45 +    }
   77.46 +  }
   77.47  }
   77.48  
   77.49  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   77.50 @@ -67,5 +74,5 @@
   77.51  @interface B { }
   77.52  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   77.53  @interface C { }
   77.54 -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
   77.55 -@interface D { }
   77.56 +
   77.57 +@interface Decl { }
    78.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java	Tue May 14 13:55:35 2013 -0700
    78.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Constructors.java	Tue May 14 15:04:06 2013 -0700
    78.3 @@ -1,5 +1,5 @@
    78.4  /*
    78.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
    78.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
    78.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    78.8   *
    78.9   * This code is free software; you can redistribute it and/or modify it
   78.10 @@ -54,7 +54,6 @@
   78.11                 " } }";
   78.12      }
   78.13  
   78.14 -    /* TODO: Outer.this annotation support.
   78.15      @TADescriptions({
   78.16          @TADescription(annotation = "TA", type = METHOD_RECEIVER),
   78.17          @TADescription(annotation = "TB", type = METHOD_RETURN),
   78.18 @@ -69,5 +68,21 @@
   78.19                 " @TD Inner(@TC Test Test.this, @TE int b) {}" +
   78.20                 " } }";
   78.21      }
   78.22 -    */
   78.23 +
   78.24 +    @TADescriptions({
   78.25 +        @TADescription(annotation = "TA", type = METHOD_RECEIVER),
   78.26 +        @TADescription(annotation = "TB", type = METHOD_RECEIVER, genericLocation = {1, 0}),
   78.27 +        @TADescription(annotation = "TC", type = METHOD_RETURN),
   78.28 +        @TADescription(annotation = "TD", type = METHOD_RECEIVER, genericLocation = {1, 0}),
   78.29 +        @TADescription(annotation = "TE", type = METHOD_RETURN),
   78.30 +        @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
   78.31 +    })
   78.32 +    @TestClass("Outer$Middle$Inner")
   78.33 +    public String innerClass3() {
   78.34 +        return "class Outer { class Middle { class Inner {" +
   78.35 +               " @TC Inner(@TA Outer. @TB Middle Middle.this) {}" +
   78.36 +               " @TE Inner(@TD Middle Outer.Middle.this, @TF int b) {}" +
   78.37 +               " } } }";
   78.38 +    }
   78.39 +
   78.40  }
    79.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java	Tue May 14 13:55:35 2013 -0700
    79.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java	Tue May 14 15:04:06 2013 -0700
    79.3 @@ -207,7 +207,7 @@
    79.4  
    79.5          if (isSnippet) {
    79.6              // Have a few common nested types for testing
    79.7 -            sb.append("class Outer { class Inner {} }");
    79.8 +            sb.append("class Outer { class Inner {} class Middle { class MInner {} } }");
    79.9              sb.append("class SOuter { static class SInner {} }");
   79.10              sb.append("class GOuter<X, Y> { class GInner<X, Y> {} }");
   79.11          }
    80.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java	Tue May 14 13:55:35 2013 -0700
    80.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java	Tue May 14 15:04:06 2013 -0700
    80.3 @@ -47,11 +47,43 @@
    80.4          @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1),
    80.5          @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2)
    80.6      })
    80.7 -    public String multipleExceptions() {
    80.8 +    public String multipleExceptions1() {
    80.9          return "void multipleExceptions() { " +
   80.10              "try { new Object(); } catch(@TA Exception e) { }" +
   80.11              "try { new Object(); } catch(@TB Exception e) { }" +
   80.12              "try { new Object(); } catch(@TC Exception e) { }" +
   80.13              " }";
   80.14      }
   80.15 +
   80.16 +    @TADescriptions({
   80.17 +        @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0),
   80.18 +        @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1),
   80.19 +        @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2)
   80.20 +    })
   80.21 +    public String multipleExceptions2() {
   80.22 +        return "void multipleExceptions() { " +
   80.23 +            "  try { new Object(); " +
   80.24 +            "    try { new Object(); " +
   80.25 +            "      try { new Object(); } catch(@TA Exception e) { }" +
   80.26 +            "    } catch(@TB Exception e) { }" +
   80.27 +            "  } catch(@TC Exception e) { }" +
   80.28 +            "}";
   80.29 +    }
   80.30 +
   80.31 +    @TADescriptions({
   80.32 +        @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 0),
   80.33 +        @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1),
   80.34 +        @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2)
   80.35 +    })
   80.36 +    public String multipleExceptions3() {
   80.37 +        return "void multipleExceptions() { " +
   80.38 +            "  try { new Object(); " +
   80.39 +            "  } catch(@TA Exception e1) { "+
   80.40 +            "    try { new Object(); " +
   80.41 +            "    } catch(@TB Exception e2) {" +
   80.42 +            "      try { new Object(); } catch(@TC Exception e3) { }" +
   80.43 +            "    }" +
   80.44 +            "  }" +
   80.45 +            "}";
   80.46 +    }
   80.47  }
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java	Tue May 14 15:04:06 2013 -0700
    81.3 @@ -0,0 +1,95 @@
    81.4 +/*
    81.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    81.7 + *
    81.8 + * This code is free software; you can redistribute it and/or modify it
    81.9 + * under the terms of the GNU General Public License version 2 only, as
   81.10 + * published by the Free Software Foundation.
   81.11 + *
   81.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   81.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   81.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   81.15 + * version 2 for more details (a copy is included in the LICENSE file that
   81.16 + * accompanied this code).
   81.17 + *
   81.18 + * You should have received a copy of the GNU General Public License version
   81.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   81.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   81.21 + *
   81.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   81.23 + * or visit www.oracle.com if you need additional information or have any
   81.24 + * questions.
   81.25 + */
   81.26 +
   81.27 +import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
   81.28 +
   81.29 +/*
   81.30 + * @test
   81.31 + * @bug 1234567
   81.32 + * @summary Test population of reference info for instance and class initializers
   81.33 + * @author Werner Dietl
   81.34 + * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java
   81.35 + * @run main Driver Initializers
   81.36 + */
   81.37 +public class Initializers {
   81.38 +
   81.39 +    @TADescriptions({
   81.40 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.41 +        @TADescription(annotation = "TB", type = NEW,
   81.42 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   81.43 +    })
   81.44 +    public String instanceInit1() {
   81.45 +        return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }";
   81.46 +    }
   81.47 +
   81.48 +    @TADescriptions({
   81.49 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.50 +        @TADescription(annotation = "TB", type = NEW,
   81.51 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.52 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.53 +        @TADescription(annotation = "TD", type = NEW,
   81.54 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   81.55 +    })
   81.56 +    public String instanceInit2() {
   81.57 +        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
   81.58 +                " { Object o = new @TC ArrayList<@TD String>(); } }";
   81.59 +    }
   81.60 +
   81.61 +    @TADescriptions({
   81.62 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.63 +        @TADescription(annotation = "TB", type = NEW,
   81.64 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   81.65 +    })
   81.66 +    public String staticInit1() {
   81.67 +        return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }";
   81.68 +    }
   81.69 +
   81.70 +    @TADescriptions({
   81.71 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.72 +        @TADescription(annotation = "TB", type = NEW,
   81.73 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.74 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.75 +        @TADescription(annotation = "TD", type = NEW,
   81.76 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.77 +        @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.78 +        @TADescription(annotation = "TF", type = NEW,
   81.79 +                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
   81.80 +    })
   81.81 +    public String staticInit2() {
   81.82 +        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
   81.83 +                " static Object g = new @TC ArrayList<@TD String>(); " +
   81.84 +                " static { Object o = new @TE ArrayList<@TF String>(); } }";
   81.85 +    }
   81.86 +
   81.87 +    // TODO: test interaction with several constructors, especially non-initial constuctors.
   81.88 +    // I don't think this kind of test is possible here.
   81.89 +
   81.90 +    @TADescriptions({
   81.91 +        @TADescription(annotation = "TA", type = CAST,
   81.92 +                typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE),
   81.93 +    })
   81.94 +    public String lazyConstantCast1() {
   81.95 +        return "class Test { public static final Object o = (@TA Object) null; }";
   81.96 +    }
   81.97 +
   81.98 +}
    82.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java	Tue May 14 13:55:35 2013 -0700
    82.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java	Tue May 14 15:04:06 2013 -0700
    82.3 @@ -259,4 +259,30 @@
    82.4                  "}";
    82.5      }
    82.6  
    82.7 +    @TADescriptions({
    82.8 +        @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
    82.9 +                paramIndex = 0),
   82.10 +        @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
   82.11 +                paramIndex = 1),
   82.12 +        @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
   82.13 +                paramIndex = 1, genericLocation = { 3, 0 }),
   82.14 +        @TADescription(annotation = "TD", type = LOCAL_VARIABLE,
   82.15 +                lvarOffset = ReferenceInfoUtil.IGNORE_VALUE,
   82.16 +                lvarLength = ReferenceInfoUtil.IGNORE_VALUE,
   82.17 +                lvarIndex = ReferenceInfoUtil.IGNORE_VALUE),
   82.18 +        @TADescription(annotation = "TE", type = CAST,
   82.19 +                offset = ReferenceInfoUtil.IGNORE_VALUE,
   82.20 +                typeIndex = 0)
   82.21 +    })
   82.22 +    public String returnLambdaExpr1() {
   82.23 +        return
   82.24 +                "interface LambdaInt {" +
   82.25 +                "  void lambda(Object p1, List<Object> p2);" +
   82.26 +                "}" +
   82.27 +                "class Test {" +
   82.28 +                "  LambdaInt getLambda() {" +
   82.29 +                "    return (@TA Object x, @TB List<@TC Object> y) -> { @TD Object l = null; System.out.println((@TE Object) l); };" +
   82.30 +                "  }" +
   82.31 +                "}";
   82.32 +    }
   82.33  }
    83.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java	Tue May 14 13:55:35 2013 -0700
    83.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MethodThrows.java	Tue May 14 15:04:06 2013 -0700
    83.3 @@ -1,5 +1,5 @@
    83.4  /*
    83.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    83.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    83.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.8   *
    83.9   * This code is free software; you can redistribute it and/or modify it
   83.10 @@ -54,4 +54,24 @@
   83.11      public String interfaceMethod() {
   83.12          return "interface Test { void test() throws @TA RuntimeException, IllegalArgumentException, @TB Exception; }";
   83.13      }
   83.14 +
   83.15 +    @TADescriptions({
   83.16 +        @TADescription(annotation = "TA", type = THROWS, typeIndex = 0,
   83.17 +                       genericLocation = {}),
   83.18 +        @TADescription(annotation = "TB", type = THROWS, typeIndex = 0,
   83.19 +                       genericLocation = {1, 0}),
   83.20 +        @TADescription(annotation = "TC", type = THROWS, typeIndex = 0,
   83.21 +                       genericLocation = {1, 0, 1, 0}),
   83.22 +        @TADescription(annotation = "TD", type = THROWS, typeIndex = 1,
   83.23 +                       genericLocation = {}),
   83.24 +        @TADescription(annotation = "TE", type = THROWS, typeIndex = 1,
   83.25 +                       genericLocation = {1, 0}),
   83.26 +        @TADescription(annotation = "TF", type = THROWS, typeIndex = 1,
   83.27 +                       genericLocation = {1, 0, 1, 0})
   83.28 +    })
   83.29 +    public String NestedTypes() {
   83.30 +        return "class Outer { class Middle { class Inner1 extends Exception {}" +
   83.31 +                "  class Inner2 extends Exception{} } }" +
   83.32 +                "class Test { void test() throws @TA Outer.@TB Middle.@TC Inner1, @TD Outer.@TE Middle.@TF Inner2 { } }";
   83.33 +    }
   83.34  }
    84.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Tue May 14 13:55:35 2013 -0700
    84.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Tue May 14 15:04:06 2013 -0700
    84.3 @@ -26,7 +26,6 @@
    84.4  /*
    84.5   * @test
    84.6   * @bug 8006732 8006775
    84.7 - * @ignore 8013408: Need specification for type exceptions on multicatch
    84.8   * @summary Test population of reference info for multicatch exception parameters
    84.9   * @author Werner Dietl
   84.10   * @compile -g Driver.java ReferenceInfoUtil.java MultiCatch.java
   84.11 @@ -53,4 +52,16 @@
   84.12              "try { new Object(); } catch (@TA NullPointerException | @TB IndexOutOfBoundsException | @TC IllegalArgumentException e) { e.toString(); } }";
   84.13      }
   84.14  
   84.15 +    @TADescriptions({
   84.16 +        @TADescription(annotation = "TA", type = EXCEPTION_PARAMETER, exceptionIndex = 1),
   84.17 +        @TADescription(annotation = "TB", type = EXCEPTION_PARAMETER, exceptionIndex = 1),
   84.18 +        @TADescription(annotation = "TC", type = EXCEPTION_PARAMETER, exceptionIndex = 2),
   84.19 +        @TADescription(annotation = "TD", type = EXCEPTION_PARAMETER, exceptionIndex = 2),
   84.20 +        @TADescription(annotation = "TE", type = EXCEPTION_PARAMETER, exceptionIndex = 3),
   84.21 +    })
   84.22 +    public String multiCatch3() {
   84.23 +        return "void multiCatch3() { " +
   84.24 +            "try { new Object(); } catch (NullPointerException e1) {}" +
   84.25 +            "try { new Object(); } catch (@TA @TB NullPointerException | @TC @TD IndexOutOfBoundsException | @TE IllegalArgumentException e2) { e2.toString(); } }";
   84.26 +    }
   84.27  }
    85.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java	Tue May 14 13:55:35 2013 -0700
    85.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java	Tue May 14 15:04:06 2013 -0700
    85.3 @@ -1,5 +1,5 @@
    85.4  /*
    85.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
    85.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
    85.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    85.8   *
    85.9   * This code is free software; you can redistribute it and/or modify it
   85.10 @@ -831,4 +831,48 @@
   85.11                  "  }\n" +
   85.12                  "}}\n";
   85.13      }
   85.14 +
   85.15 +    @TADescriptions({
   85.16 +        @TADescription(annotation = "TA", type = CLASS_EXTENDS,
   85.17 +                genericLocation = {}, typeIndex = -1),
   85.18 +        @TADescription(annotation = "TB", type = CLASS_EXTENDS,
   85.19 +                genericLocation = {3, 0}, typeIndex = -1),
   85.20 +        @TADescription(annotation = "TC", type = CLASS_EXTENDS,
   85.21 +                genericLocation = {3, 1}, typeIndex = -1),
   85.22 +        @TADescription(annotation = "TD", type = CLASS_EXTENDS,
   85.23 +                genericLocation = {1, 0}, typeIndex = -1),
   85.24 +        @TADescription(annotation = "TE", type = CLASS_EXTENDS,
   85.25 +                genericLocation = {1, 0, 3, 0}, typeIndex = -1),
   85.26 +        @TADescription(annotation = "TF", type = CLASS_EXTENDS,
   85.27 +                genericLocation = {1, 0, 3, 1}, typeIndex = -1)
   85.28 +    })
   85.29 +    @TestClass("GOuter$GInner$Test")
   85.30 +    public String testExtends1() {
   85.31 +        return "class GOuter<A, B> {\n" +
   85.32 +                "  class GInner<X, Y> {\n" +
   85.33 +                "    class Test extends @TA GOuter<@TB String, @TC String>.@TD GInner<@TE String, @TF String> {}" +
   85.34 +                "  }" +
   85.35 +                "}";
   85.36 +    }
   85.37 +
   85.38 +    @TADescriptions({
   85.39 +        @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER,
   85.40 +                genericLocation = {}, paramIndex = 0),
   85.41 +        @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND,
   85.42 +                genericLocation = {}, paramIndex = 0, boundIndex = 0),
   85.43 +        @TADescription(annotation = "TC", type = FIELD,
   85.44 +                genericLocation = {}),
   85.45 +        @TADescription(annotation = "TD", type = FIELD,
   85.46 +                genericLocation = {3, 0})
   85.47 +    })
   85.48 +    @TestClass("Test$1Nested")
   85.49 +    public String testNestedInMethod1() {
   85.50 +        return "class Test {\n" +
   85.51 +                "  void foobar() {\n" +
   85.52 +                "    class Nested<@TA X extends @TB Object> {\n" +
   85.53 +                "      @TC List<@TD Object> f;\n" +
   85.54 +                "    }\n" +
   85.55 +                "  }" +
   85.56 +                "}";
   85.57 +    }
   85.58  }
    86.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java	Tue May 14 13:55:35 2013 -0700
    86.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/NewObjects.java	Tue May 14 15:04:06 2013 -0700
    86.3 @@ -1,5 +1,5 @@
    86.4  /*
    86.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    86.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    86.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    86.8   *
    86.9   * This code is free software; you can redistribute it and/or modify it
   86.10 @@ -75,4 +75,81 @@
   86.11          return "void eqtestObjectGeneric() { if (null == new @TA ArrayList<@TB String >()); }";
   86.12      }
   86.13  
   86.14 +    @TADescriptions({
   86.15 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.16 +                genericLocation = {0, 0}),
   86.17 +        @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE)
   86.18 +    })
   86.19 +    public String returnNewArray1() {
   86.20 +        return "Object returnNewArray1() { return new @TA String @TB[1]; }";
   86.21 +    }
   86.22 +
   86.23 +    @TADescriptions({
   86.24 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.25 +                genericLocation = {0, 0, 0, 0}),
   86.26 +        @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   86.27 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.28 +                genericLocation = {0, 0}),
   86.29 +    })
   86.30 +    public String returnNewArray2() {
   86.31 +        return "Object returnNewArray2() { return new @TA String @TB [1] @TC [2]; }";
   86.32 +    }
   86.33 +
   86.34 +    @TADescriptions({
   86.35 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.36 +                genericLocation = {0, 0, 0, 0}),
   86.37 +        @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.38 +                genericLocation = {0, 0, 0, 0, 1, 0}),
   86.39 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   86.40 +        @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.41 +                genericLocation = {0, 0}),
   86.42 +    })
   86.43 +    public String returnNewArray3() {
   86.44 +        return "Object returnNewArray3() { return new @TA Outer. @TB Inner @TC [1] @TD [2]; }";
   86.45 +    }
   86.46 +
   86.47 +    @TADescriptions({
   86.48 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.49 +                genericLocation = {0, 0, 0, 0}),
   86.50 +        @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.51 +                genericLocation = {0, 0, 0, 0, 1, 0}),
   86.52 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.53 +                genericLocation = {0, 0, 0, 0, 1, 0, 1, 0}),
   86.54 +        @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   86.55 +        @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.56 +                genericLocation = {0, 0}),
   86.57 +    })
   86.58 +    public String returnNewArray4() {
   86.59 +        return "Object returnNewArray4() { return new @TA Outer. @TB Middle. @TC MInner @TD [1] @TE [2]; }";
   86.60 +    }
   86.61 +
   86.62 +    @TADescriptions({
   86.63 +        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
   86.64 +        @TADescription(annotation = "TB", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.65 +                genericLocation = {3, 0, 0, 0, 0, 0}),
   86.66 +        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.67 +                genericLocation = {3, 0, 0, 0, 0, 0, 1, 0}),
   86.68 +        @TADescription(annotation = "TD", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.69 +                genericLocation = {3, 0, 0, 0, 0, 0, 1, 0, 1, 0}),
   86.70 +        @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.71 +                genericLocation = {3, 0}),
   86.72 +        @TADescription(annotation = "TF", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.73 +                genericLocation = {3, 0, 0, 0}),
   86.74 +    })
   86.75 +    public String returnNewArray5() {
   86.76 +        return "Object returnNewArray5() { return new @TA ArrayList<@TB Outer. @TC Middle. @TD MInner @TE [] @TF []>(); }";
   86.77 +    }
   86.78 +
   86.79 +    @TADescriptions({
   86.80 +        @TADescription(annotation = "TA", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.81 +                genericLocation = {0, 0, 0, 0}),
   86.82 +        @TADescription(annotation = "TB", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.83 +                genericLocation = {0, 0, 0, 0, 1, 0}),
   86.84 +        @TADescription(annotation = "TC", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE),
   86.85 +        @TADescription(annotation = "TD", type = FIELD, offset = ReferenceInfoUtil.IGNORE_VALUE,
   86.86 +        genericLocation = {0, 0}),
   86.87 +    })
   86.88 +    public String arrayField() {
   86.89 +        return "@TA Outer. @TB Inner @TC [] @TD [] f;";
   86.90 +    }
   86.91  }
    87.1 --- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java	Tue May 14 13:55:35 2013 -0700
    87.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java	Tue May 14 15:04:06 2013 -0700
    87.3 @@ -1,5 +1,5 @@
    87.4  /*
    87.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
    87.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    87.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    87.8   *
    87.9   * This code is free software; you can redistribute it and/or modify it
   87.10 @@ -28,6 +28,7 @@
   87.11  
   87.12  import com.sun.tools.classfile.Attribute;
   87.13  import com.sun.tools.classfile.ClassFile;
   87.14 +import com.sun.tools.classfile.Code_attribute;
   87.15  import com.sun.tools.classfile.TypeAnnotation;
   87.16  import com.sun.tools.classfile.Field;
   87.17  import com.sun.tools.classfile.Method;
   87.18 @@ -90,6 +91,20 @@
   87.19              RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
   87.20              annos.addAll(Arrays.asList(tAttr.annotations));
   87.21          }
   87.22 +
   87.23 +        int cindex = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
   87.24 +        if (cindex != -1) {
   87.25 +            Attribute cattr = m.attributes.get(cindex);
   87.26 +            assert cattr instanceof Code_attribute;
   87.27 +            Code_attribute cAttr = (Code_attribute)cattr;
   87.28 +            index = cAttr.attributes.getIndex(cf.constant_pool, name);
   87.29 +            if (index != -1) {
   87.30 +                Attribute attr = cAttr.attributes.get(index);
   87.31 +                assert attr instanceof RuntimeTypeAnnotations_attribute;
   87.32 +                RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
   87.33 +                annos.addAll(Arrays.asList(tAttr.annotations));
   87.34 +            }
   87.35 +        }
   87.36      }
   87.37  
   87.38      // test the result of Attributes.getIndex according to expectations
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Test.java	Tue May 14 15:04:06 2013 -0700
    88.3 @@ -0,0 +1,33 @@
    88.4 +
    88.5 +import java.util.*;
    88.6 +import java.lang.annotation.*;
    88.7 +
    88.8 +class Test<K> { GOuter<@TC Object, String> entrySet() { return null; } }
    88.9 +
   88.10 +@interface A {}
   88.11 +@interface B {}
   88.12 +@interface C {}
   88.13 +@interface D {}
   88.14 +@interface E {}
   88.15 +@interface F {}
   88.16 +
   88.17 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA {}
   88.18 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TB {}
   88.19 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TC {}
   88.20 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TD {}
   88.21 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TE {}
   88.22 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TF {}
   88.23 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TG {}
   88.24 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TH {}
   88.25 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TI {}
   88.26 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TJ {}
   88.27 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TK {}
   88.28 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TL {}
   88.29 +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TM {}
   88.30 +
   88.31 +@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTA {}
   88.32 +@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTB {}
   88.33 +@ContainerFor(RTA.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTAs { RTA[] value(); }
   88.34 +@ContainerFor(RTB.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTBs { RTB[] value(); }
   88.35 +@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})
   88.36 +@interface Decl {}
    89.1 --- a/test/tools/javac/api/TestJavacTaskScanner.java	Tue May 14 13:55:35 2013 -0700
    89.2 +++ b/test/tools/javac/api/TestJavacTaskScanner.java	Tue May 14 15:04:06 2013 -0700
    89.3 @@ -111,7 +111,8 @@
    89.4          DeclaredType type = (DeclaredType)task.parseType("List<String>", clazz);
    89.5          for (Element member : elements.getAllMembers((TypeElement)type.asElement())) {
    89.6              TypeMirror mt = types.asMemberOf(type, member);
    89.7 -            System.out.format("%s : %s -> %s%n", member.getSimpleName(), member.asType(), mt);
    89.8 +            System.out.format("type#%d: %s : %s -> %s%n",
    89.9 +                numParseTypeElements, member.getSimpleName(), member.asType(), mt);
   89.10              numParseTypeElements++;
   89.11          }
   89.12      }
   89.13 @@ -123,7 +124,8 @@
   89.14  
   89.15      private void testGetAllMembers(TypeElement clazz) {
   89.16          for (Element member : elements.getAllMembers(clazz)) {
   89.17 -            System.out.format("%s : %s%n", member.getSimpleName(), member.asType());
   89.18 +            System.out.format("elem#%d: %s : %s%n",
   89.19 +                numAllMembers, member.getSimpleName(), member.asType());
   89.20              numAllMembers++;
   89.21          }
   89.22      }
    90.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    90.2 +++ b/test/tools/javac/diags/examples/ArrayAndReceiver.java	Tue May 14 15:04:06 2013 -0700
    90.3 @@ -0,0 +1,31 @@
    90.4 +/*
    90.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    90.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    90.7 + *
    90.8 + * This code is free software; you can redistribute it and/or modify it
    90.9 + * under the terms of the GNU General Public License version 2 only, as
   90.10 + * published by the Free Software Foundation.
   90.11 + *
   90.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   90.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   90.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   90.15 + * version 2 for more details (a copy is included in the LICENSE file that
   90.16 + * accompanied this code).
   90.17 + *
   90.18 + * You should have received a copy of the GNU General Public License version
   90.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   90.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   90.21 + *
   90.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   90.23 + * or visit www.oracle.com if you need additional information or have any
   90.24 + * questions.
   90.25 + */
   90.26 +
   90.27 +// key: compiler.err.array.and.receiver
   90.28 +// key: compiler.err.expected
   90.29 +// key: compiler.err.expected3
   90.30 +// key: compiler.err.illegal.start.of.type
   90.31 +
   90.32 +class ArrayAndReceiver {
   90.33 +    void m(ArrayAndReceiver this[]) { }
   90.34 +}
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/test/tools/javac/diags/examples/IncorrectConstructorReceiverName.java	Tue May 14 15:04:06 2013 -0700
    91.3 @@ -0,0 +1,30 @@
    91.4 +/*
    91.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    91.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    91.7 + *
    91.8 + * This code is free software; you can redistribute it and/or modify it
    91.9 + * under the terms of the GNU General Public License version 2 only, as
   91.10 + * published by the Free Software Foundation.
   91.11 + *
   91.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   91.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   91.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   91.15 + * version 2 for more details (a copy is included in the LICENSE file that
   91.16 + * accompanied this code).
   91.17 + *
   91.18 + * You should have received a copy of the GNU General Public License version
   91.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   91.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   91.21 + *
   91.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   91.23 + * or visit www.oracle.com if you need additional information or have any
   91.24 + * questions.
   91.25 + */
   91.26 +
   91.27 +// key: compiler.err.incorrect.constructor.receiver.name
   91.28 +
   91.29 +class IncorrectConstructorReceiverName {
   91.30 +    class Inner {
   91.31 +        Inner(IncorrectConstructorReceiverName this) { }
   91.32 +    }
   91.33 +}
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/test/tools/javac/diags/examples/IncorrectConstructorReceiverType.java	Tue May 14 15:04:06 2013 -0700
    92.3 @@ -0,0 +1,30 @@
    92.4 +/*
    92.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    92.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    92.7 + *
    92.8 + * This code is free software; you can redistribute it and/or modify it
    92.9 + * under the terms of the GNU General Public License version 2 only, as
   92.10 + * published by the Free Software Foundation.
   92.11 + *
   92.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   92.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   92.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   92.15 + * version 2 for more details (a copy is included in the LICENSE file that
   92.16 + * accompanied this code).
   92.17 + *
   92.18 + * You should have received a copy of the GNU General Public License version
   92.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   92.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   92.21 + *
   92.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   92.23 + * or visit www.oracle.com if you need additional information or have any
   92.24 + * questions.
   92.25 + */
   92.26 +
   92.27 +// key: compiler.err.incorrect.constructor.receiver.type
   92.28 +
   92.29 +class IncorrectConstructorReceiverType {
   92.30 +    class Inner {
   92.31 +        Inner(Object IncorrectConstructorReceiverType.this) { }
   92.32 +    }
   92.33 +}
    93.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    93.2 +++ b/test/tools/javac/diags/examples/IncorrectReceiverName.java	Tue May 14 15:04:06 2013 -0700
    93.3 @@ -0,0 +1,30 @@
    93.4 +/*
    93.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
    93.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    93.7 + *
    93.8 + * This code is free software; you can redistribute it and/or modify it
    93.9 + * under the terms of the GNU General Public License version 2 only, as
   93.10 + * published by the Free Software Foundation.
   93.11 + *
   93.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   93.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   93.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   93.15 + * version 2 for more details (a copy is included in the LICENSE file that
   93.16 + * accompanied this code).
   93.17 + *
   93.18 + * You should have received a copy of the GNU General Public License version
   93.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   93.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   93.21 + *
   93.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   93.23 + * or visit www.oracle.com if you need additional information or have any
   93.24 + * questions.
   93.25 + */
   93.26 +
   93.27 +// key: compiler.err.incorrect.receiver.name
   93.28 +
   93.29 +class IncorrectReceiverName {
   93.30 +    class Inner {
   93.31 +        void m(Inner IncorrectReceiverName.this) { }
   93.32 +    }
   93.33 +}
    94.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    94.2 +++ b/test/tools/javac/diags/examples/ReceiverParameterNotApplicableConstructor.java	Tue May 14 15:04:06 2013 -0700
    94.3 @@ -0,0 +1,28 @@
    94.4 +/*
    94.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    94.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    94.7 + *
    94.8 + * This code is free software; you can redistribute it and/or modify it
    94.9 + * under the terms of the GNU General Public License version 2 only, as
   94.10 + * published by the Free Software Foundation.
   94.11 + *
   94.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   94.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   94.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   94.15 + * version 2 for more details (a copy is included in the LICENSE file that
   94.16 + * accompanied this code).
   94.17 + *
   94.18 + * You should have received a copy of the GNU General Public License version
   94.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   94.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   94.21 + *
   94.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   94.23 + * or visit www.oracle.com if you need additional information or have any
   94.24 + * questions.
   94.25 + */
   94.26 +
   94.27 +// key: compiler.err.receiver.parameter.not.applicable.constructor.toplevel.class
   94.28 +
   94.29 +class ReceiverParameterNotApplicableConstructor {
   94.30 +    ReceiverParameterNotApplicableConstructor(ReceiverParameterNotApplicableConstructor this) { }
   94.31 +}
    95.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    95.2 +++ b/test/tools/javac/diags/examples/VarargsAndReceiver.java	Tue May 14 15:04:06 2013 -0700
    95.3 @@ -0,0 +1,28 @@
    95.4 +/*
    95.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    95.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    95.7 + *
    95.8 + * This code is free software; you can redistribute it and/or modify it
    95.9 + * under the terms of the GNU General Public License version 2 only, as
   95.10 + * published by the Free Software Foundation.
   95.11 + *
   95.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   95.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   95.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   95.15 + * version 2 for more details (a copy is included in the LICENSE file that
   95.16 + * accompanied this code).
   95.17 + *
   95.18 + * You should have received a copy of the GNU General Public License version
   95.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   95.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   95.21 + *
   95.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   95.23 + * or visit www.oracle.com if you need additional information or have any
   95.24 + * questions.
   95.25 + */
   95.26 +
   95.27 +// key: compiler.err.varargs.and.receiver
   95.28 +
   95.29 +class VarargsAndReceiver {
   95.30 +    void m(VarargsAndReceiver... this) { }
   95.31 +}
    96.1 --- a/test/tools/javac/lib/DPrinter.java	Tue May 14 13:55:35 2013 -0700
    96.2 +++ b/test/tools/javac/lib/DPrinter.java	Tue May 14 15:04:06 2013 -0700
    96.3 @@ -469,6 +469,7 @@
    96.4                      indent(+1);
    96.5                      printSymbol("tsym", type.tsym, Details.SUMMARY);
    96.6                      printObject("constValue", type.constValue(), Details.SUMMARY);
    96.7 +                    printObject("annotations", type.getAnnotationMirrors(), Details.SUMMARY);
    96.8                      type.accept(typeVisitor, null);
    96.9                      indent(-1);
   96.10              }
    97.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    97.2 +++ b/test/tools/javac/processing/model/type/BasicAnnoTests.java	Tue May 14 15:04:06 2013 -0700
    97.3 @@ -0,0 +1,287 @@
    97.4 +/*
    97.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    97.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    97.7 + *
    97.8 + * This code is free software; you can redistribute it and/or modify it
    97.9 + * under the terms of the GNU General Public License version 2 only, as
   97.10 + * published by the Free Software Foundation.
   97.11 + *
   97.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   97.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   97.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   97.15 + * version 2 for more details (a copy is included in the LICENSE file that
   97.16 + * accompanied this code).
   97.17 + *
   97.18 + * You should have received a copy of the GNU General Public License version
   97.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   97.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   97.21 + *
   97.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   97.23 + * or visit www.oracle.com if you need additional information or have any
   97.24 + * questions.
   97.25 + */
   97.26 +
   97.27 +/*
   97.28 + * @test
   97.29 + * @bug     1234567
   97.30 + * @summary Annotations on types
   97.31 + * @library /tools/javac/lib
   97.32 + * @build JavacTestingAbstractProcessor DPrinter BasicAnnoTests
   97.33 + * @compile/process -processor BasicAnnoTests -proc:only BasicAnnoTests.java
   97.34 + */
   97.35 +
   97.36 +import java.io.PrintWriter;
   97.37 +import java.lang.annotation.Annotation;
   97.38 +import java.lang.annotation.ElementType;
   97.39 +import java.lang.annotation.Target;
   97.40 +import java.util.Map;
   97.41 +import java.util.Set;
   97.42 +
   97.43 +import javax.annotation.processing.ProcessingEnvironment;
   97.44 +import javax.annotation.processing.RoundEnvironment;
   97.45 +import javax.lang.model.AnnotatedConstruct;
   97.46 +import javax.lang.model.element.AnnotationMirror;
   97.47 +import javax.lang.model.element.AnnotationValue;
   97.48 +import javax.lang.model.element.Element;
   97.49 +import javax.lang.model.element.ExecutableElement;
   97.50 +import javax.lang.model.element.TypeElement;
   97.51 +import javax.lang.model.type.ArrayType;
   97.52 +import javax.lang.model.type.ExecutableType;
   97.53 +import javax.lang.model.type.TypeMirror;
   97.54 +import javax.lang.model.type.TypeVariable;
   97.55 +import javax.lang.model.type.WildcardType;
   97.56 +import javax.tools.Diagnostic.Kind;
   97.57 +
   97.58 +import com.sun.tools.javac.code.Symbol;
   97.59 +import com.sun.tools.javac.code.Type;
   97.60 +import com.sun.tools.javac.processing.JavacProcessingEnvironment;
   97.61 +
   97.62 +/**
   97.63 + * The test scans this file looking for test cases annotated with @Test.
   97.64 + */
   97.65 +public class BasicAnnoTests extends JavacTestingAbstractProcessor {
   97.66 +    DPrinter dprinter;
   97.67 +    PrintWriter out;
   97.68 +    boolean verbose = true;
   97.69 +
   97.70 +    @Override
   97.71 +    public void init(ProcessingEnvironment pEnv) {
   97.72 +        super.init(pEnv);
   97.73 +        dprinter = new DPrinter(((JavacProcessingEnvironment) pEnv).getContext());
   97.74 +        out = dprinter.out;
   97.75 +    }
   97.76 +
   97.77 +    @Override
   97.78 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   97.79 +        TestElementScanner s = new TestElementScanner();
   97.80 +        for (Element e: roundEnv.getRootElements()) {
   97.81 +            s.scan(e);
   97.82 +        }
   97.83 +        return true;
   97.84 +    }
   97.85 +
   97.86 +    void error(Element e, String msg) {
   97.87 +        messager.printMessage(Kind.ERROR, msg, e);
   97.88 +        errors++;
   97.89 +    }
   97.90 +
   97.91 +    int errors;
   97.92 +
   97.93 +    /**
   97.94 +     * Scan an element looking for declarations annotated with @Test.
   97.95 +     * Run a TestTypeScanner on the annotations that are found.
   97.96 +     */
   97.97 +    class TestElementScanner extends ElementScanner<Void,Void> {
   97.98 +        public Void scan(Element elem, Void ignore) {
   97.99 +            AnnotationMirror test = getAnnotation(elem, Test.class.getName().replace('$', '.'));
  97.100 +            if (test != null) {
  97.101 +                out.println("Test: " + elem + " " + test);
  97.102 +                TestTypeScanner s = new TestTypeScanner(elem, test);
  97.103 +                s.scan(elem.asType(), null);
  97.104 +                if (getPosn(test) >= s.count)
  97.105 +                    error(elem, "position " + getPosn(test) + " not found");
  97.106 +                if (!s.found) {
  97.107 +                    dprinter.printSymbol("element", (Symbol) elem);
  97.108 +                    dprinter.printType("type", (Type) elem.asType());
  97.109 +                }
  97.110 +                out.println();
  97.111 +            }
  97.112 +            return super.scan(elem, ignore);
  97.113 +        }
  97.114 +    }
  97.115 +
  97.116 +    /**
  97.117 +     * Scan the type of an element, looking for an annotation
  97.118 +     * to match the expected annotation specified in the @Test annotation.
  97.119 +     */
  97.120 +    class TestTypeScanner extends TypeScanner<Void, Void> {
  97.121 +        Element elem;
  97.122 +        AnnotationMirror test;
  97.123 +        int count = 0;
  97.124 +        boolean found = false;
  97.125 +
  97.126 +        TestTypeScanner(Element elem, AnnotationMirror test) {
  97.127 +            this.elem = elem;
  97.128 +            this.test = test;
  97.129 +        }
  97.130 +
  97.131 +        @Override
  97.132 +        Void scan(TypeMirror t, Void ignore) {
  97.133 +            if (t == null)
  97.134 +                return DEFAULT_VALUE;
  97.135 +            if (verbose)
  97.136 +                out.println("scan " + count + ": " + t);
  97.137 +            if (count == getPosn(test)) {
  97.138 +                String annoType = getAnnoType(test);
  97.139 +                AnnotationMirror anno = getAnnotation(t, annoType);
  97.140 +                if (anno == null) {
  97.141 +                    error(elem, "annotation not found on " + count + ": " + t);
  97.142 +                } else {
  97.143 +                    String v = getValue(anno, "value").toString();
  97.144 +                    if (v.equals(getExpect(test))) {
  97.145 +                        out.println("found " + anno + " as expected");
  97.146 +                        found = true;
  97.147 +                    } else {
  97.148 +                        error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
  97.149 +                    }
  97.150 +                }
  97.151 +            }
  97.152 +            count++;
  97.153 +            return super.scan(t, ignore);
  97.154 +        }
  97.155 +    }
  97.156 +
  97.157 +    /** Get the position value from an @Test annotation mirror. */
  97.158 +    static int getPosn(AnnotationMirror test) {
  97.159 +        AnnotationValue v = getValue(test, "posn");
  97.160 +        return (Integer) v.getValue();
  97.161 +    }
  97.162 +
  97.163 +    /** Get the expect value from an @Test annotation mirror. */
  97.164 +    static String getExpect(AnnotationMirror test) {
  97.165 +        AnnotationValue v = getValue(test, "expect");
  97.166 +        return (String) v.getValue();
  97.167 +    }
  97.168 +
  97.169 +    /** Get the annoType value from an @Test annotation mirror. */
  97.170 +    static String getAnnoType(AnnotationMirror test) {
  97.171 +        AnnotationValue v = getValue(test, "annoType");
  97.172 +        TypeMirror m = (TypeMirror) v.getValue();
  97.173 +        return m.toString();
  97.174 +    }
  97.175 +
  97.176 +    /**
  97.177 +     * Get a specific annotation mirror from an annotated construct.
  97.178 +     */
  97.179 +    static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
  97.180 +        for (AnnotationMirror m: e.getAnnotationMirrors()) {
  97.181 +            TypeElement te = (TypeElement) m.getAnnotationType().asElement();
  97.182 +            if (te.getQualifiedName().contentEquals(name)) {
  97.183 +                return m;
  97.184 +            }
  97.185 +        }
  97.186 +        return null;
  97.187 +    }
  97.188 +
  97.189 +    /**
  97.190 +     * Get a specific value from an annotation mirror.
  97.191 +     */
  97.192 +    static AnnotationValue getValue(AnnotationMirror anno, String name) {
  97.193 +        Map<? extends ExecutableElement, ? extends AnnotationValue> map = anno.getElementValues();
  97.194 +        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e: map.entrySet()) {
  97.195 +            if (e.getKey().getSimpleName().contentEquals(name)) {
  97.196 +                return e.getValue();
  97.197 +            }
  97.198 +        }
  97.199 +        return null;
  97.200 +    }
  97.201 +
  97.202 +    /**
  97.203 +     * The Language Model API does not provide a type scanner, so provide
  97.204 +     * one sufficient for our needs.
  97.205 +     */
  97.206 +    static class TypeScanner<R, P> extends SimpleTypeVisitor<R, P> {
  97.207 +        @Override
  97.208 +        public R visitArray(ArrayType t, P p) {
  97.209 +            scan(t.getComponentType(), p);
  97.210 +            return super.visitArray(t, p);
  97.211 +        }
  97.212 +
  97.213 +        @Override
  97.214 +        public R visitExecutable(ExecutableType t, P p) {
  97.215 +            scan(t.getReceiverType());
  97.216 +            //out.println("  params: " + t.getParameterTypes());
  97.217 +            scan(t.getParameterTypes(), p);
  97.218 +            //out.println("  return: " + t.getReturnType());
  97.219 +            scan(t.getReturnType(), p);
  97.220 +            //out.println("  throws: " + t.getThrownTypes());
  97.221 +            scan(t.getThrownTypes(), p);
  97.222 +            return super.visitExecutable(t, p);
  97.223 +        }
  97.224 +
  97.225 +        @Override
  97.226 +        public R visitTypeVariable(TypeVariable t, P p) {
  97.227 +            scan(t.getLowerBound(), p);
  97.228 +            scan(t.getUpperBound(), p);
  97.229 +            return super.visitTypeVariable(t, p);
  97.230 +        }
  97.231 +
  97.232 +        @Override
  97.233 +        public R visitWildcard(WildcardType t, P p) {
  97.234 +            scan(t.getExtendsBound(), p);
  97.235 +            scan(t.getSuperBound(), p);
  97.236 +            return super.visitWildcard(t, p);
  97.237 +        }
  97.238 +
  97.239 +        R scan(TypeMirror t) {
  97.240 +            return scan(t, null);
  97.241 +        }
  97.242 +
  97.243 +        R scan(TypeMirror t, P p) {
  97.244 +            return (t == null) ? DEFAULT_VALUE : t.accept(this, p);
  97.245 +        }
  97.246 +
  97.247 +        R scan(Iterable<? extends TypeMirror> iter, P p) {
  97.248 +            if (iter == null)
  97.249 +                return DEFAULT_VALUE;
  97.250 +            R result = DEFAULT_VALUE;
  97.251 +            for (TypeMirror t: iter)
  97.252 +                result = scan(t, p);
  97.253 +            return result;
  97.254 +        }
  97.255 +    }
  97.256 +
  97.257 +    /** Annotation to identify test cases. */
  97.258 +    @interface Test {
  97.259 +        /** Where to look for the annotation, expressed as a scan index. */
  97.260 +        int posn();
  97.261 +        /** The annotation to look for. */
  97.262 +        Class<? extends Annotation> annoType();
  97.263 +        /** The string representation of the annotation's value. */
  97.264 +        String expect();
  97.265 +    }
  97.266 +
  97.267 +    /** Type annotation to use in test cases. */
  97.268 +    @Target(ElementType.TYPE_USE)
  97.269 +    public @interface TA {
  97.270 +        int value();
  97.271 +    }
  97.272 +
  97.273 +    @Test(posn=0, annoType=TA.class, expect="1")
  97.274 +    public @TA(1) int f1;
  97.275 +
  97.276 +    @Test(posn=0, annoType=TA.class, expect="2")
  97.277 +    public int @TA(2) [] f2;
  97.278 +
  97.279 +    @Test(posn=1, annoType=TA.class, expect="3")
  97.280 +    public @TA(3) int [] f3;
  97.281 +
  97.282 +    @Test(posn=1, annoType=TA.class, expect="4")
  97.283 +    public int m1(@TA(4) float a) throws Exception { return 0; }
  97.284 +
  97.285 +    @Test(posn=2, annoType=TA.class, expect="5")
  97.286 +    public @TA(5) int m2(float a) throws Exception { return 0; }
  97.287 +
  97.288 +    @Test(posn=3, annoType=TA.class, expect="6")
  97.289 +    public int m3(float a) throws @TA(6) Exception { return 0; }
  97.290 +}
    98.1 --- a/test/tools/javac/tree/SourceTreeScannerTest.java	Tue May 14 13:55:35 2013 -0700
    98.2 +++ b/test/tools/javac/tree/SourceTreeScannerTest.java	Tue May 14 15:04:06 2013 -0700
    98.3 @@ -1,5 +1,5 @@
    98.4  /*
    98.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    98.6 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    98.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    98.8   *
    98.9   * This code is free software; you can redistribute it and/or modify it
   98.10 @@ -36,6 +36,7 @@
   98.11  /*
   98.12   * @test
   98.13   * @bug 6923080
   98.14 + * @ignore 8014323: Add VariableTree.getNameExpression
   98.15   * @summary TreeScanner.visitNewClass should scan tree.typeargs
   98.16   * @build AbstractTreeScannerTest SourceTreeScannerTest
   98.17   * @run main SourceTreeScannerTest -q -r .
    99.1 --- a/test/tools/javap/output/RepeatingTypeAnnotations.java	Tue May 14 13:55:35 2013 -0700
    99.2 +++ b/test/tools/javap/output/RepeatingTypeAnnotations.java	Tue May 14 15:04:06 2013 -0700
    99.3 @@ -121,280 +121,307 @@
    99.4       */
    99.5  
    99.6      @TestCase
    99.7 -    @ignore // 8008082: missing type annotation for cast
    99.8      public static class TC1 extends RepeatingTypeAnnotations {
    99.9          public TC1() {
   99.10 -            setSrc("    static String so = \"hello world\";",
   99.11 +            setSrc(" /* TC1 */ ",
   99.12 +                   "    static String so = \"hello world\";",
   99.13                     "    public @A @A @A Object o = (@A @A @A String) Test.so;");
   99.14              verify("RuntimeInvisibleTypeAnnotations",
   99.15                     "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD",
   99.16 -                   "1: #25(#26=[@#27(),@#27(),@#27()]): CAST, offset=5");
   99.17 +                   "0: #25(#26=[@#27(),@#27(),@#27()]): CAST, offset=5, type_index=0");
   99.18          }
   99.19      }
   99.20  
   99.21      @TestCase
   99.22      public static class TC2 extends RepeatingTypeAnnotations {
   99.23          public TC2() {
   99.24 -            setSrc("    static String so = \"hello world\";",
   99.25 +            setSrc(" /* TC2 */ ",
   99.26 +                   "    static String so = \"hello world\";",
   99.27                     "    public @A @B @A Object o = (@B @A @B String) Test.so;");
   99.28              verify("RuntimeInvisibleTypeAnnotations",
   99.29                     "0: #25(#26=[@#27(),@#27()]): FIELD",
   99.30                     "1: #28(): FIELD",
   99.31 -                   "2: #29(#26=[@#28(),@#28()]): CAST, offset=5",
   99.32 -                   "3: #27(): CAST, offset=5");
   99.33 +                   "0: #36(#26=[@#28(),@#28()]): CAST, offset=5, type_index=0",
   99.34 +                   "1: #27(): CAST, offset=5, type_index=0");
   99.35          }
   99.36      }
   99.37  
   99.38      @TestCase
   99.39      public static class TC3 extends RepeatingTypeAnnotations {
   99.40          public TC3() {
   99.41 -            setSrc("    static String so = \"hello world\";",
   99.42 +            setSrc(" /* TC3 */ ",
   99.43 +                   "    static String so = \"hello world\";",
   99.44                     "    public @A @A @C Object o = (@B @C @B String) Test.so;");
   99.45 -            verify("RuntimeInvisibleTypeAnnotations",
   99.46 +            verify("RuntimeVisibleTypeAnnotations",
   99.47 +                   "RuntimeInvisibleTypeAnnotations",
   99.48                     "0: #25(): FIELD",
   99.49 -                   "1: #25(): CAST, offset=5",
   99.50 -                   "RuntimeVisibleTypeAnnotations",
   99.51                     "0: #27(#28=[@#29(),@#29()]): FIELD",
   99.52 -                   "1: #30(#28=[@#31(),@#31()]): CAST, offset=5");
   99.53 +                   "0: #25(): CAST, offset=5, type_index=0",
   99.54 +                   "0: #37(#28=[@#38(),@#38()]): CAST, offset=5, type_index=0");
   99.55          }
   99.56      }
   99.57  
   99.58      @TestCase
   99.59      public static class TC4 extends RepeatingTypeAnnotations {
   99.60          public TC4() {
   99.61 -            setSrc("    static String so = \"hello world\";",
   99.62 +            setSrc(" /* TC4 */ ",
   99.63 +                   "    static String so = \"hello world\";",
   99.64                     "    public @A @B @C Object o = (@C @B @A String) Test.so;");
   99.65              verify("RuntimeInvisibleTypeAnnotations",
   99.66                     "RuntimeVisibleTypeAnnotations",
   99.67                     "0: #25(): FIELD",
   99.68 -                   "1: #25(): CAST, offset=5",
   99.69                     "0: #27(): FIELD",
   99.70                     "1: #28(): FIELD",
   99.71 -                   "2: #28(): CAST, offset=5",
   99.72 -                   "3: #27(): CAST, offset=5");
   99.73 +                   "0: #25(): CAST, offset=5, type_index=0",
   99.74 +                   "0: #28(): CAST, offset=5, type_index=0",
   99.75 +                   "1: #27(): CAST, offset=5, type_index=0");
   99.76          }
   99.77      }
   99.78  
   99.79      @TestCase
   99.80 -    @ignore // 8008082: missing type annotation for cast
   99.81      public static class TC5 extends RepeatingTypeAnnotations {
   99.82          public TC5() {
   99.83 -            setSrc("    static String so = \"hello world\";",
   99.84 +            setSrc(" /* TC5 */ ",
   99.85 +                   "    static String so = \"hello world\";",
   99.86                     "    public static @A @A @A Object o = (@B @B @B String) Test.so;");
   99.87              verify("RuntimeInvisibleTypeAnnotations",
   99.88                     "0: #25(#26=[@#27(),@#27(),@#27()]): FIELD",
   99.89 -                   "1: #28(#26=[@#29(),@#29(),@#29()]): CAST, offset=5, type_index=0");
   99.90 +                   "0: #36(#26=[@#37(),@#37(),@#37()]): CAST, offset=5, type_index=0");
   99.91          }
   99.92      }
   99.93  
   99.94      @TestCase
   99.95      public static class TC6 extends RepeatingTypeAnnotations {
   99.96          public TC6() {
   99.97 -            setSrc("    static String so = \"hello world\";",
   99.98 +            setSrc(" /* TC6 */ ",
   99.99 +                   "    static String so = \"hello world\";",
  99.100                     "    public static @A @B @A Object o = (@B @A @B String) Test.so;");
  99.101              verify("RuntimeInvisibleTypeAnnotations",
  99.102                     "0: #25(#26=[@#27(),@#27()]): FIELD",
  99.103                     "1: #28(): FIELD",
  99.104 -                   "2: #29(#26=[@#28(),@#28()]): CAST, offset=5",
  99.105 -                   "3: #27(): CAST, offset=5");
  99.106 +                   "0: #37(#26=[@#28(),@#28()]): CAST, offset=5, type_index=0",
  99.107 +                   "1: #27(): CAST, offset=5, type_index=0");
  99.108          }
  99.109      }
  99.110  
  99.111      @TestCase
  99.112      public static class TC7 extends RepeatingTypeAnnotations {
  99.113          public TC7() {
  99.114 -            setSrc("    static String so = \"hello world\";",
  99.115 +            setSrc(" /* TC7 */ ",
  99.116 +                   "    static String so = \"hello world\";",
  99.117                     "    public static @A @A @C Object o = (@B @C @B String) Test.so;");
  99.118 -            verify("RuntimeInvisibleTypeAnnotations",
  99.119 -                   "RuntimeVisibleTypeAnnotations",
  99.120 +            verify("RuntimeVisibleTypeAnnotations",
  99.121 +                   "RuntimeInvisibleTypeAnnotations",
  99.122                     "0: #25(): FIELD",
  99.123 -                   "1: #25(): CAST, offset=5",
  99.124                     "0: #27(#28=[@#29(),@#29()]): FIELD",
  99.125 -                   "1: #30(#28=[@#31(),@#31()]): CAST, offset=5");
  99.126 +                   "0: #25(): CAST, offset=5, type_index=0",
  99.127 +                   "0: #38(#28=[@#39(),@#39()]): CAST, offset=5, type_index=0");
  99.128          }
  99.129      }
  99.130  
  99.131      @TestCase
  99.132      public static class TC8 extends RepeatingTypeAnnotations {
  99.133          public TC8() {
  99.134 -            setSrc("    static String so = \"hello world\";",
  99.135 +            setSrc(" /* TC8 */ ",
  99.136 +                   "    static String so = \"hello world\";",
  99.137                     "    public static @A @B @C Object o = (@C @B @A String) Test.so;");
  99.138 -            verify("RuntimeInvisibleTypeAnnotations",
  99.139 -                   "RuntimeVisibleTypeAnnotations",
  99.140 +
  99.141 +            verify("RuntimeVisibleTypeAnnotations",
  99.142 +                   "RuntimeInvisibleTypeAnnotations",
  99.143                     "0: #25(): FIELD",
  99.144 -                   "1: #25(): CAST, offset=5",
  99.145                     "0: #27(): FIELD",
  99.146                     "1: #28(): FIELD",
  99.147 -                   "2: #28(): CAST, offset=5",
  99.148 -                   "3: #27(): CAST, offset=5");
  99.149 +                   "0: #25(): CAST, offset=5, type_index=0",
  99.150 +                   "0: #28(): CAST, offset=5, type_index=0",
  99.151 +                   "1: #27(): CAST, offset=5, type_index=0");
  99.152          }
  99.153      }
  99.154  
  99.155      @TestCase
  99.156 -    @ignore // 8008082: missing type annotation for cast
  99.157      public static class TC9 extends RepeatingTypeAnnotations {
  99.158          public TC9() {
  99.159 -            setSrc("    public Test(@A @A @A Object o, @A int i, long l) {",
  99.160 +            setSrc(" /* TC9 */ ",
  99.161 +                   "    public Test(@A @A @A Object o, @A int i, long l) {",
  99.162                     "        @A @A @A String ls = (@B @B @B String) o;",
  99.163                     "    }");
  99.164              verify("RuntimeInvisibleTypeAnnotations",
  99.165 -                   "0: #34(#35=[@#36(),@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.166 -                   "1: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.167 -                   "2: #37(#35=[@#38(),@#38(),@#38()]): CAST, offset=4, type_index=0",
  99.168 -                   "3: #34(#35=[@#36(),@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
  99.169 +                   "0: #34(#35=[@#36(),@#36(),@#36()]): CAST, offset=4, type_index=0",
  99.170 +                   "1: #37(#35=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.171 +                   "RuntimeInvisibleTypeAnnotations",
  99.172 +                   "0: #37(#35=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.173 +                   "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1");
  99.174          }
  99.175      }
  99.176  
  99.177      @TestCase
  99.178      public static class TC10 extends RepeatingTypeAnnotations {
  99.179          public TC10() {
  99.180 -            setSrc("    public Test(@A @A @B Object o, @A @B int i, long l) {",
  99.181 +            setSrc(" /* TC10 */ ",
  99.182 +                   "    public Test(@A @A @B Object o, @A @B int i, long l) {",
  99.183                     "        @A @A @B String ls = (@B @A @B String) o;",
  99.184                     "    }");
  99.185 -            verify("RuntimeInvisibleTypeAnnotations:",
  99.186 -                   "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.187 -                   "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.188 -                   "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.189 -                   "3: #37(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.190 -                   "4: #38(#35=[@#37(),@#37()]): CAST, offset=4, type_index=0",
  99.191 -                   "5: #36(): CAST, offset=4, type_index=0",
  99.192 -                   "6: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.193 -                   "7: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
  99.194 +            verify("RuntimeInvisibleTypeAnnotations",
  99.195 +                   "0: #34(#35=[@#36(),@#36()]): CAST, offset=4, type_index=0",
  99.196 +                   "1: #37(): CAST, offset=4, type_index=0",
  99.197 +                   "2: #38(#35=[@#37(),@#37()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.198 +                   "3: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.199 +                   "RuntimeInvisibleTypeAnnotations",
  99.200 +                   "0: #38(#35=[@#37(),@#37()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.201 +                   "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.202 +                   "2: #37(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.203 +                   "3: #36(): METHOD_FORMAL_PARAMETER, param_index=1");
  99.204          }
  99.205      }
  99.206  
  99.207      @TestCase
  99.208      public static class TC11 extends RepeatingTypeAnnotations {
  99.209          public TC11() {
  99.210 -            setSrc("    public Test(@C @C @A Object o, @A @B int i, long l) {",
  99.211 +            setSrc(" /* TC11 */ ",
  99.212 +                   "    public Test(@C @C @A Object o, @A @B int i, long l) {",
  99.213                     "        @C @C @A String ls = (@A @A @C String) o;",
  99.214                     "    }");
  99.215 -            verify("RuntimeInvisibleTypeAnnotations",
  99.216 -                   "RuntimeVisibleTypeAnnotations",
  99.217 -                   "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.218 -                   "1: #36(): CAST, offset=4",
  99.219 -                   "2: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.220 -                   "0: #38(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.221 -                   "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.222 -                   "2: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.223 -                   "3: #40(#35=[@#38(),@#38()]): CAST, offset=4",
  99.224 -                   "4: #38(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
  99.225 +            verify("RuntimeVisibleTypeAnnotations",
  99.226 +                   "RuntimeInvisibleTypeAnnotations",
  99.227 +                   "0: #34(): CAST, offset=4, type_index=0",
  99.228 +                   "1: #35(#36=[@#34(),@#34()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.229 +                   "0: #38(#36=[@#39(),@#39()]): CAST, offset=4, type_index=0",
  99.230 +                   "1: #39(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.231 +                   "0: #35(#36=[@#34(),@#34()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.232 +                   "0: #39(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.233 +                   "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.234 +                   "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1");
  99.235          }
  99.236      }
  99.237  
  99.238      @TestCase
  99.239      public static class TC12 extends RepeatingTypeAnnotations {
  99.240          public TC12() {
  99.241 -            setSrc("    public Test(@A @B @C Object o, @A @C int i, long l) {",
  99.242 +            setSrc(" /* TC12 */ ",
  99.243 +                   "    public Test(@A @B @C Object o, @A @C int i, long l) {",
  99.244                     "        @A @B @C String ls = (@C @A @B String) o;",
  99.245                     "    }");
  99.246 -            verify("RuntimeInvisibleTypeAnnotations",
  99.247 -                   "RuntimeVisibleTypeAnnotations",
  99.248 +            verify("RuntimeVisibleTypeAnnotations",
  99.249 +                   "0: #34(): CAST, offset=4, type_index=0",
  99.250 +                   "1: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.251 +                   "RuntimeInvisibleTypeAnnotations",
  99.252 +                   "0: #36(): CAST, offset=4, type_index=0",
  99.253 +                   "1: #37(): CAST, offset=4, type_index=0",
  99.254 +                   "2: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.255 +                   "3: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.256                     "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.257                     "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.258 -                   "2: #34(): CAST, offset=4",
  99.259 -                   "3: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.260                     "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.261                     "1: #37(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.262 -                   "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.263 -                   "3: #36(): CAST, offset=4",
  99.264 -                   "4: #37(): CAST, offset=4",
  99.265 -                   "5: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}",
  99.266 -                   "6: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}");
  99.267 +                   "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1");
  99.268          }
  99.269      }
  99.270  
  99.271      @TestCase
  99.272 -    @ignore // 8008082: missing type annotation for cast
  99.273      public static class TC13 extends RepeatingTypeAnnotations {
  99.274          public TC13() {
  99.275 -            setSrc("    public @A @A @A String foo(@A @A @A Object o, @A int i, long l) {",
  99.276 +            setSrc(" /* TC13 */ ",
  99.277 +                   "    public @A @A @A String foo(@A @A @A Object o, @A int i, long l) {",
  99.278                     "        @A @A @A String ls = (@B @B @B String) o;",
  99.279                     "        return (@A @A @A String) o;",
  99.280                     "    }");
  99.281              verify("RuntimeInvisibleTypeAnnotations",
  99.282 -                   "0: #36(#37=[@#38(),@#38(),@#38()]): METHOD_RETURN",
  99.283 -                   "1: #36(#37=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.284 -                   "2: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.285 -                   "3: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=0, type_index=0",
  99.286 -                   "4: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=6, type_index=0",
  99.287 -                   "5: #36(#37=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
  99.288 +                   "0: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=0, type_index=0",
  99.289 +                   "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=6, type_index=0",
  99.290 +                   "2: #39(#37=[@#40(),@#40(),@#40()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.291 +                    "RuntimeInvisibleTypeAnnotations",
  99.292 +                   "0: #39(#37=[@#40(),@#40(),@#40()]): METHOD_RETURN",
  99.293 +                   "1: #39(#37=[@#40(),@#40(),@#40()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.294 +                   "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1");
  99.295          }
  99.296      }
  99.297  
  99.298      @TestCase
  99.299      public static class TC14 extends RepeatingTypeAnnotations {
  99.300          public TC14() {
  99.301 -            setSrc("    public @A @B @B String foo(@A @A @B Object o, @A @B int i, long l) {",
  99.302 +            setSrc(" /* TC14 */ ",
  99.303 +                   "    public @A @B @B String foo(@A @A @B Object o, @A @B int i, long l) {",
  99.304                     "        @A @A @B String ls = (@B @A @B String) o;",
  99.305                     "        return (@A @B @B String) o;",
  99.306                     "    }");
  99.307 -            verify("RuntimeInvisibleTypeAnnotations",
  99.308 -                    "0: #36(): METHOD_RETURN",
  99.309 -                    "1: #37(#38=[@#39(),@#39()]): METHOD_RETURN",
  99.310 -                    "2: #40(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.311 -                    "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.312 -                    "4: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.313 -                    "5: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.314 -                    "6: #37(#38=[@#39(),@#39()]): CAST, offset=0",
  99.315 -                    "7: #36(): CAST, offset=0",
  99.316 -                    "8: #36(): CAST, offset=6",
  99.317 -                    "9: #37(#38=[@#39(),@#39()]): CAST, offset=6",
  99.318 -                    "10: #40(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.319 -                    "11: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
  99.320 +           verify(
  99.321 +                    "RuntimeInvisibleTypeAnnotations:",
  99.322 +                    "0: #36(#37=[@#38(),@#38()]): CAST, offset=0, type_index=0",
  99.323 +                    "1: #39(): CAST, offset=0, type_index=0",
  99.324 +                  "2: #39(): CAST, offset=6, type_index=0",
  99.325 +                  "3: #36(#37=[@#38(),@#38()]): CAST, offset=6, type_index=0",
  99.326 +                  "4: #40(#37=[@#39(),@#39()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.327 +                  "5: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.328 +                    "RuntimeInvisibleTypeAnnotations:",
  99.329 +                  "0: #39(): METHOD_RETURN",
  99.330 +                  "1: #36(#37=[@#38(),@#38()]): METHOD_RETURN",
  99.331 +                  "2: #40(#37=[@#39(),@#39()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.332 +                  "3: #38(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.333 +                  "4: #39(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.334 +                    "5: #38(): METHOD_FORMAL_PARAMETER, param_index=1"
  99.335 +                 );
  99.336          }
  99.337      }
  99.338  
  99.339      @TestCase
  99.340      public static class TC15 extends RepeatingTypeAnnotations {
  99.341          public TC15() {
  99.342 -            setSrc("    public @A @A @C String foo(@C @C @A Object o, @A @B int i, long l) {",
  99.343 +            setSrc(" /* TC15 */ ",
  99.344 +                   "    public @A @A @C String foo(@C @C @A Object o, @A @B int i, long l) {",
  99.345                     "        @C @C @A String ls = (@A @A @C String) o;",
  99.346                     "        return (@C @B @B String) o;",
  99.347                     "    }");
  99.348 -            verify("RuntimeInvisibleTypeAnnotations",
  99.349 -                    "RuntimeVisibleTypeAnnotations",
  99.350 -                    "0: #36(): METHOD_RETURN",
  99.351 -                    "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.352 -                    "2: #36(): CAST, offset=0",
  99.353 -                    "3: #36(): CAST, offset=6",
  99.354 -                    "4: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.355 -                    "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN",
  99.356 -                    "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.357 -                    "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.358 -                    "3: #42(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.359 -                    "4: #40(#38=[@#41(),@#41()]): CAST, offset=0",
  99.360 -                    "5: #43(#38=[@#42(),@#42()]): CAST, offset=6",
  99.361 -                    "6: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
  99.362 +            verify(
  99.363 +                    "RuntimeVisibleTypeAnnotations:",
  99.364 +                    "0: #36(): CAST, offset=0, type_index=0",
  99.365 +                   "1: #36(): CAST, offset=6, type_index=0",
  99.366 +                   "2: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.367 +                    "RuntimeInvisibleTypeAnnotations:",
  99.368 +                    "0: #40(#38=[@#41(),@#41()]): CAST, offset=0, type_index=0",
  99.369 +                   "1: #42(#38=[@#43(),@#43()]): CAST, offset=6, type_index=0",
  99.370 +                   "2: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.371 +                    "RuntimeVisibleTypeAnnotations:",
  99.372 +                   "0: #36(): METHOD_RETURN",
  99.373 +                   "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0",
  99.374 +                    "RuntimeInvisibleTypeAnnotations:",
  99.375 +                   "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN",
  99.376 +                   "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.377 +                   "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.378 +                    "3: #43(): METHOD_FORMAL_PARAMETER, param_index=1"
  99.379 +                    );
  99.380          }
  99.381      }
  99.382  
  99.383      @TestCase
  99.384      public static class TC16 extends RepeatingTypeAnnotations {
  99.385          public TC16() {
  99.386 -            setSrc("    public @A @B @C String foo(@A @B @C Object o, @A @C int i, long l) {",
  99.387 +            setSrc(" /* TC16 */ ",
  99.388 +                   "    public @A @B @C String foo(@A @B @C Object o, @A @C int i, long l) {",
  99.389                     "        @A @B @C String ls = (@C @A @B String) o;",
  99.390                     "        return (@B @A @C String) o;",
  99.391                     "    }");
  99.392 -            verify("RuntimeInvisibleTypeAnnotations",
  99.393 -                   "RuntimeVisibleTypeAnnotations",
  99.394 +            verify(
  99.395 +                    "RuntimeVisibleTypeAnnotations:",
  99.396 +                    "0: #36(): CAST, offset=0, type_index=0",
  99.397 +                   "1: #36(): CAST, offset=6, type_index=0",
  99.398 +                   "2: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.399 +                    "RuntimeInvisibleTypeAnnotations:",
  99.400 +                    "0: #38(): CAST, offset=0, type_index=0",
  99.401 +                    "1: #39(): CAST, offset=0, type_index=0",
  99.402 +                   "2: #39(): CAST, offset=6, type_index=0",
  99.403 +                   "3: #38(): CAST, offset=6, type_index=0",
  99.404 +                   "4: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.405 +                   "5: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.406 +                    "RuntimeVisibleTypeAnnotations:",
  99.407                     "0: #36(): METHOD_RETURN",
  99.408                     "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.409                     "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.410 -                   "3: #36(): CAST, offset=0",
  99.411 -                   "4: #36(): CAST, offset=6",
  99.412 -                   "5: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.413 +                    "RuntimeInvisibleTypeAnnotations:",
  99.414                     "0: #38(): METHOD_RETURN",
  99.415                     "1: #39(): METHOD_RETURN",
  99.416                     "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.417                     "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0",
  99.418 -                   "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1",
  99.419 -                   "5: #38(): CAST, offset=0",
  99.420 -                   "6: #39(): CAST, offset=0",
  99.421 -                   "7: #39(): CAST, offset=6",
  99.422 -                   "8: #38(): CAST, offset=6",
  99.423 -                   "9: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}",
  99.424 -                   "10: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}");
  99.425 +                    "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1"
  99.426 +                  );
  99.427          }
  99.428      }
  99.429  }
   100.1 --- a/test/tools/javap/typeAnnotations/NewArray.java	Tue May 14 13:55:35 2013 -0700
   100.2 +++ b/test/tools/javap/typeAnnotations/NewArray.java	Tue May 14 15:04:06 2013 -0700
   100.3 @@ -27,10 +27,11 @@
   100.4  /*
   100.5   * @test NewArray
   100.6   * @bug 6843077
   100.7 - * @summary test that all type annotations are present in the classfile
   100.8 + * @summary Test type annotations on local array are in method's code attribute.
   100.9   */
  100.10  
  100.11  public class NewArray {
  100.12 +
  100.13      public static void main(String[] args) throws Exception {
  100.14          new NewArray().run();
  100.15      }
  100.16 @@ -40,10 +41,6 @@
  100.17          File classFile = compileTestFile(javaFile);
  100.18  
  100.19          ClassFile cf = ClassFile.read(classFile);
  100.20 -        test(cf);
  100.21 -        for (Field f : cf.fields) {
  100.22 -            test(cf, f);
  100.23 -        }
  100.24          for (Method m: cf.methods) {
  100.25              test(cf, m);
  100.26          }
  100.27 @@ -55,66 +52,34 @@
  100.28          System.out.println("PASSED");
  100.29      }
  100.30  
  100.31 -    void test(ClassFile cf) {
  100.32 -        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  100.33 -        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  100.34 -    }
  100.35 -
  100.36      void test(ClassFile cf, Method m) {
  100.37          test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  100.38          test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  100.39      }
  100.40  
  100.41 -    void test(ClassFile cf, Field m) {
  100.42 -        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  100.43 -        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  100.44 -    }
  100.45 -
  100.46      // test the result of Attributes.getIndex according to expectations
  100.47      // encoded in the method's name
  100.48 -    void test(ClassFile cf, String name, boolean visible) {
  100.49 -        int index = cf.attributes.getIndex(cf.constant_pool, name);
  100.50 -        if (index != -1) {
  100.51 -            Attribute attr = cf.attributes.get(index);
  100.52 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  100.53 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  100.54 -            all += tAttr.annotations.length;
  100.55 -            if (visible)
  100.56 -                visibles += tAttr.annotations.length;
  100.57 -            else
  100.58 -                invisibles += tAttr.annotations.length;
  100.59 -        }
  100.60 -    }
  100.61 +    void test(ClassFile cf, Method m, String name, boolean visible) {
  100.62 +        Attribute attr = null;
  100.63 +        Code_attribute cAttr = null;
  100.64 +        RuntimeTypeAnnotations_attribute tAttr = null;
  100.65  
  100.66 -    // test the result of Attributes.getIndex according to expectations
  100.67 -    // encoded in the method's name
  100.68 -    void test(ClassFile cf, Method m, String name, boolean visible) {
  100.69 -        int index = m.attributes.getIndex(cf.constant_pool, name);
  100.70 -        if (index != -1) {
  100.71 -            Attribute attr = m.attributes.get(index);
  100.72 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  100.73 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  100.74 -            all += tAttr.annotations.length;
  100.75 -            if (visible)
  100.76 -                visibles += tAttr.annotations.length;
  100.77 -            else
  100.78 -                invisibles += tAttr.annotations.length;
  100.79 -        }
  100.80 -    }
  100.81 -
  100.82 -    // test the result of Attributes.getIndex according to expectations
  100.83 -    // encoded in the method's name
  100.84 -    void test(ClassFile cf, Field m, String name, boolean visible) {
  100.85 -        int index = m.attributes.getIndex(cf.constant_pool, name);
  100.86 -        if (index != -1) {
  100.87 -            Attribute attr = m.attributes.get(index);
  100.88 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  100.89 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  100.90 -            all += tAttr.annotations.length;
  100.91 -            if (visible)
  100.92 -                visibles += tAttr.annotations.length;
  100.93 -            else
  100.94 -                invisibles += tAttr.annotations.length;
  100.95 +        int index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
  100.96 +        if(index!= -1) {
  100.97 +            attr = m.attributes.get(index);
  100.98 +            assert attr instanceof Code_attribute;
  100.99 +            cAttr = (Code_attribute)attr;
 100.100 +            index = cAttr.attributes.getIndex(cf.constant_pool, name);
 100.101 +            if(index!= -1) {
 100.102 +                attr = cAttr.attributes.get(index);
 100.103 +                assert attr instanceof RuntimeTypeAnnotations_attribute;
 100.104 +                tAttr = (RuntimeTypeAnnotations_attribute)attr;
 100.105 +                all += tAttr.annotations.length;
 100.106 +                if (visible)
 100.107 +                    visibles += tAttr.annotations.length;
 100.108 +                else
 100.109 +                    invisibles += tAttr.annotations.length;
 100.110 +               }
 100.111          }
 100.112      }
 100.113  
 100.114 @@ -124,14 +89,12 @@
 100.115          out.println("import java.lang.annotation.*;");
 100.116          out.println("import java.util.*;");
 100.117          out.println("class Test { ");
 100.118 -        out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
 100.119 -        out.println("  @interface A { }");
 100.120 -
 100.121 -        out.println(" void test() {");
 100.122 -        out.println("  Object a = new @A String @A [5] @A  [];");
 100.123 -        out.println("  Object b = new @A String @A [5] @A [3];");
 100.124 -        out.println("  Object c = new @A String @A [] @A [] {};");
 100.125 -        out.println(" }");
 100.126 +        out.println("  @Target(ElementType.TYPE_USE) @interface A { }");
 100.127 +        out.println("  void test() {");
 100.128 +        out.println("    Object a = new @A String @A [5] @A  [];");
 100.129 +        out.println("    Object b = new @A String @A [5] @A [3];");
 100.130 +        out.println("    Object c = new @A String @A [] @A [] {};");
 100.131 +        out.println("  }");
 100.132          out.println("}");
 100.133  
 100.134          out.close();
   101.1 --- a/test/tools/javap/typeAnnotations/Presence.java	Tue May 14 13:55:35 2013 -0700
   101.2 +++ b/test/tools/javap/typeAnnotations/Presence.java	Tue May 14 15:04:06 2013 -0700
   101.3 @@ -91,17 +91,40 @@
   101.4      // test the result of Attributes.getIndex according to expectations
   101.5      // encoded in the method's name
   101.6      void test(ClassFile cf, Method m, String name, boolean visible) {
   101.7 +        Attribute attr = null;
   101.8 +        Code_attribute cAttr = null;
   101.9 +        RuntimeTypeAnnotations_attribute tAttr = null;
  101.10 +
  101.11 +        // collect annotations attributes on method
  101.12          int index = m.attributes.getIndex(cf.constant_pool, name);
  101.13          if (index != -1) {
  101.14 -            Attribute attr = m.attributes.get(index);
  101.15 +            attr = m.attributes.get(index);
  101.16              assert attr instanceof RuntimeTypeAnnotations_attribute;
  101.17 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  101.18 +            tAttr = (RuntimeTypeAnnotations_attribute)attr;
  101.19              all += tAttr.annotations.length;
  101.20              if (visible)
  101.21                  visibles += tAttr.annotations.length;
  101.22              else
  101.23                  invisibles += tAttr.annotations.length;
  101.24          }
  101.25 +        // collect annotations from method's code attribute
  101.26 +        index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
  101.27 +        if(index!= -1) {
  101.28 +            attr = m.attributes.get(index);
  101.29 +            assert attr instanceof Code_attribute;
  101.30 +            cAttr = (Code_attribute)attr;
  101.31 +            index = cAttr.attributes.getIndex(cf.constant_pool, name);
  101.32 +            if(index!= -1) {
  101.33 +                attr = cAttr.attributes.get(index);
  101.34 +                assert attr instanceof RuntimeTypeAnnotations_attribute;
  101.35 +                tAttr = (RuntimeTypeAnnotations_attribute)attr;
  101.36 +                all += tAttr.annotations.length;
  101.37 +                if (visible)
  101.38 +                    visibles += tAttr.annotations.length;
  101.39 +                else
  101.40 +                    invisibles += tAttr.annotations.length;
  101.41 +               }
  101.42 +        }
  101.43      }
  101.44  
  101.45      // test the result of Attributes.getIndex according to expectations
  101.46 @@ -121,12 +144,12 @@
  101.47      }
  101.48  
  101.49      File writeTestFile() throws IOException {
  101.50 -        File f = new File("Test.java");
  101.51 +        File f = new File("TestPresence.java");
  101.52          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
  101.53          out.println("import java.util.*;");
  101.54          out.println("import java.lang.annotation.*;");
  101.55  
  101.56 -        out.println("class Test<@Test.A T extends @Test.A List<@Test.A String>> { ");
  101.57 +        out.println("class TestPresence<@TestPresence.A T extends @TestPresence.A List<@TestPresence.A String>> { ");
  101.58          out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
  101.59          out.println("  @interface A { }");
  101.60  
  101.61 @@ -134,7 +157,7 @@
  101.62  
  101.63          out.println("  <@A TM extends @A List<@A String>>");
  101.64          out.println("  Map<@A String, @A List<@A String>>");
  101.65 -        out.println("  method(@A Test<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
  101.66 +        out.println("  method(@A TestPresence<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
  101.67          out.println("  throws @A Exception {");
  101.68          out.println("    @A String lc1 = null;");
  101.69          out.println("    @A List<@A String> lc2 = null;");
   102.1 --- a/test/tools/javap/typeAnnotations/TypeCasts.java	Tue May 14 13:55:35 2013 -0700
   102.2 +++ b/test/tools/javap/typeAnnotations/TypeCasts.java	Tue May 14 15:04:06 2013 -0700
   102.3 @@ -41,10 +41,6 @@
   102.4          File classFile = compileTestFile(javaFile);
   102.5  
   102.6          ClassFile cf = ClassFile.read(classFile);
   102.7 -        test(cf);
   102.8 -        for (Field f : cf.fields) {
   102.9 -            test(cf, f);
  102.10 -        }
  102.11          for (Method m: cf.methods) {
  102.12              test(cf, m);
  102.13          }
  102.14 @@ -56,68 +52,37 @@
  102.15          System.out.println("PASSED");
  102.16      }
  102.17  
  102.18 -    void test(ClassFile cf) {
  102.19 -        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
  102.20 -        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
  102.21 -    }
  102.22 -
  102.23      void test(ClassFile cf, Method m) {
  102.24          test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  102.25          test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  102.26      }
  102.27  
  102.28 -    void test(ClassFile cf, Field m) {
  102.29 -        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
  102.30 -        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
  102.31 -    }
  102.32 -
  102.33 -    // test the result of Attributes.getIndex according to expectations
  102.34 -    // encoded in the method's name
  102.35 -    void test(ClassFile cf, String name, boolean visible) {
  102.36 -        int index = cf.attributes.getIndex(cf.constant_pool, name);
  102.37 -        if (index != -1) {
  102.38 -            Attribute attr = cf.attributes.get(index);
  102.39 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  102.40 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  102.41 -            all += tAttr.annotations.length;
  102.42 -            if (visible)
  102.43 -                visibles += tAttr.annotations.length;
  102.44 -            else
  102.45 -                invisibles += tAttr.annotations.length;
  102.46 -        }
  102.47 -    }
  102.48  
  102.49      // test the result of Attributes.getIndex according to expectations
  102.50      // encoded in the method's name
  102.51      void test(ClassFile cf, Method m, String name, boolean visible) {
  102.52 -        int index = m.attributes.getIndex(cf.constant_pool, name);
  102.53 -        if (index != -1) {
  102.54 -            Attribute attr = m.attributes.get(index);
  102.55 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  102.56 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  102.57 -            all += tAttr.annotations.length;
  102.58 -            if (visible)
  102.59 -                visibles += tAttr.annotations.length;
  102.60 -            else
  102.61 -                invisibles += tAttr.annotations.length;
  102.62 +        Attribute attr = null;
  102.63 +        Code_attribute cAttr = null;
  102.64 +
  102.65 +        int index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
  102.66 +        if(index!= -1) {
  102.67 +            attr = m.attributes.get(index);
  102.68 +            assert attr instanceof Code_attribute;
  102.69 +            cAttr = (Code_attribute)attr;
  102.70 +            index = cAttr.attributes.getIndex(cf.constant_pool, name);
  102.71 +            if(index!= -1) {
  102.72 +                attr = cAttr.attributes.get(index);
  102.73 +                assert attr instanceof RuntimeTypeAnnotations_attribute;
  102.74 +                RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  102.75 +                all += tAttr.annotations.length;
  102.76 +                if (visible)
  102.77 +                    visibles += tAttr.annotations.length;
  102.78 +                else
  102.79 +                    invisibles += tAttr.annotations.length;
  102.80 +               }
  102.81          }
  102.82      }
  102.83  
  102.84 -    // test the result of Attributes.getIndex according to expectations
  102.85 -    // encoded in the method's name
  102.86 -    void test(ClassFile cf, Field m, String name, boolean visible) {
  102.87 -        int index = m.attributes.getIndex(cf.constant_pool, name);
  102.88 -        if (index != -1) {
  102.89 -            Attribute attr = m.attributes.get(index);
  102.90 -            assert attr instanceof RuntimeTypeAnnotations_attribute;
  102.91 -            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
  102.92 -            all += tAttr.annotations.length;
  102.93 -            if (visible)
  102.94 -                visibles += tAttr.annotations.length;
  102.95 -            else
  102.96 -                invisibles += tAttr.annotations.length;
  102.97 -        }
  102.98 -    }
  102.99  
 102.100  
 102.101      File writeTestFile() throws IOException {
 102.102 @@ -125,8 +90,7 @@
 102.103          PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
 102.104          out.println("import java.lang.annotation.*;");
 102.105          out.println("class Test { ");
 102.106 -        out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
 102.107 -        out.println("  @interface A { }");
 102.108 +        out.println("  @Target(ElementType.TYPE_USE) @interface A { }");
 102.109  
 102.110          out.println("  void emit() {");
 102.111          out.println("    Object o = null;");

mercurial