changeset 2281:a9ea02b425ff

Automated merge with http://hg.openjdk.java.net/jdk8/tl/langtools
author wmdietl
date Fri, 01 Mar 2013 11:10:14 -0800
parents 08782b8b03ce cc7184b9aa57
children b6aaac6d09b4
files src/share/classes/com/sun/tools/javac/code/Symbol.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Check.java src/share/classes/com/sun/tools/javac/comp/Infer.java src/share/classes/com/sun/tools/javac/comp/Resolve.java src/share/classes/com/sun/tools/javac/resources/compiler.properties src/share/classes/javax/lang/model/type/AnnotatedType.java
diffstat 69 files changed, 2223 insertions(+), 1121 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Thu Feb 28 14:05:52 2013 +0000
+++ b/.hgtags	Fri Mar 01 11:10:14 2013 -0800
@@ -140,6 +140,7 @@
 1cbe86c11ba69521875c0b0357d7540781eb334d jdk8-b17
 ec2c0973cc31e143cffc05ceb63d98fae76f97d4 jdk8-b16
 ab1b1cc7857716914f2bb20b3128e5a8978290f7 jdk8-b18
+2a2d6ac056cfde7326f309ab73b8cddf518cc729 308-jdk8-sync
 77b2c066084cbc75150efc6603a713c558329813 jdk8-b19
 ffd294128a48cbb90ce8f0569f82b61f1f164a18 jdk8-b20
 bcb21abf1c4177baf4574f99709513dcd4474727 jdk8-b21
--- a/src/share/classes/com/sun/tools/javac/code/Printer.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Printer.java	Fri Mar 01 11:10:14 2013 -0800
@@ -311,9 +311,9 @@
             }
             if (args.head.unannotatedType().getKind() == TypeKind.ARRAY) {
                 buf.append(visit(((ArrayType) args.head.unannotatedType()).elemtype, locale));
-                if (args.head.getAnnotations().nonEmpty()) {
+                if (args.head.getAnnotationMirrors().nonEmpty()) {
                     buf.append(' ');
-                    buf.append(args.head.getAnnotations());
+                    buf.append(args.head.getAnnotationMirrors());
                     buf.append(' ');
                 }
                 buf.append("...");
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Mar 01 11:10:14 2013 -0800
@@ -483,12 +483,12 @@
      */
     @Deprecated
     public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
-        return JavacElements.getAnnotation(this, annoType);
+        return JavacAnnoConstructs.getAnnotation(this, annoType);
     }
 
     // This method is part of the javax.lang.model API, do not use this in javac code.
     public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(Class<A> annoType) {
-        return JavacElements.getAnnotations(this, annoType);
+        return JavacAnnoConstructs.getAnnotations(this, annoType);
     }
 
     // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
@@ -782,6 +782,14 @@
          */
         public Pool pool;
 
+        /** The type attributes of initializers in this class.
+         */
+        public List<Attribute.TypeCompound> init_type_annotations = List.<Attribute.TypeCompound>nil();
+
+        /** The type attributes of class initializers in this class.
+         */
+        public List<Attribute.TypeCompound> clinit_type_annotations = List.<Attribute.TypeCompound>nil();
+
         public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
             super(flags, name, type, owner);
             this.members_field = null;
@@ -935,11 +943,12 @@
         }
 
         /**
-         * @deprecated this method should never be used by javac internally.
+         * Since this method works in terms of the runtime representation
+         * of annotations, it should never be used by javac internally.
          */
-        @Override @Deprecated
+        @Override
         public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
-            return JavacElements.getAnnotation(this, annoType);
+            return JavacAnnoConstructs.getAnnotation(this, annoType);
         }
 
         public <R, P> R accept(ElementVisitor<R, P> v, P p) {
@@ -1443,6 +1452,10 @@
         public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
             return v.visitMethodSymbol(this, p);
         }
+        
+        public Type getReceiverType() {
+            return asType().getReceiverType();
+        }
 
         public Type getReturnType() {
             return asType().getReturnType();
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Fri Mar 01 11:10:14 2013 -0800
@@ -25,13 +25,14 @@
 
 package com.sun.tools.javac.code;
 
+import com.sun.tools.javac.model.JavacAnnoConstructs;
+import java.lang.annotation.Annotation;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.Map;
 import java.util.Set;
 
-import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.type.*;
 
 import com.sun.tools.javac.code.Symbol.*;
@@ -246,6 +247,10 @@
         return this;
     }
 
+    public boolean isAnnotated() {
+        return false;
+    }
+
     /**
      * If this is an annotated type, return the underlying type.
      * Otherwise, return the type itself.
@@ -254,6 +259,23 @@
         return this;
     }
 
+    @Override
+    public List<? extends Attribute.TypeCompound> getAnnotationMirrors() {
+        return List.nil();
+    }
+
+    @Override
+    public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
+        return null;
+    }
+
+    @Override
+    public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
+        @SuppressWarnings("unchecked")
+        A[] tmp = (A[]) java.lang.reflect.Array.newInstance(annotationType, 0);
+        return tmp;
+    } 
+
     /** Return the base types of a list of types.
      */
     public static List<Type> baseTypes(List<Type> ts) {
@@ -350,8 +372,8 @@
         }
         if (args.head.unannotatedType().tag == ARRAY) {
             buf.append(((ArrayType)args.head.unannotatedType()).elemtype);
-            if (args.head.getAnnotations().nonEmpty()) {
-                buf.append(args.head.getAnnotations());
+            if (args.head.getAnnotationMirrors().nonEmpty()) {
+                buf.append(args.head.getAnnotationMirrors());
             }
             buf.append("...");
         } else {
@@ -362,7 +384,6 @@
 
     /** Access methods.
      */
-    public List<? extends AnnotationMirror> getAnnotations() { return List.nil(); }
     public List<Type>        getTypeArguments()  { return List.nil(); }
     public Type              getEnclosingType()  { return null; }
     public List<Type>        getParameterTypes() { return List.nil(); }
@@ -706,7 +727,7 @@
                     return s.toString();
                 } else if (sym.name.isEmpty()) {
                     String s;
-                    ClassType norm = (ClassType) tsym.type;
+                    ClassType norm = (ClassType) tsym.type.unannotatedType();
                     if (norm == null) {
                         s = Log.getLocalizedString("anonymous.class", (Object)null);
                     } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
@@ -758,7 +779,7 @@
             return
                 getEnclosingType().isErroneous() ||
                 isErroneous(getTypeArguments()) ||
-                this != tsym.type && tsym.type.isErroneous();
+                this != tsym.type.unannotatedType() && tsym.type.isErroneous();
         }
 
         public boolean isParameterized() {
@@ -1539,7 +1560,12 @@
     }
 
     public static class AnnotatedType extends Type
-            implements javax.lang.model.type.AnnotatedType {
+            implements 
+                javax.lang.model.type.ArrayType,
+                javax.lang.model.type.DeclaredType,
+                javax.lang.model.type.PrimitiveType, 
+                javax.lang.model.type.TypeVariable, 
+                javax.lang.model.type.WildcardType {
         /** The type annotations on this type.
          */
         public List<Attribute.TypeCompound> typeAnnotations;
@@ -1552,7 +1578,7 @@
             super(underlyingType.tag, underlyingType.tsym);
             this.typeAnnotations = List.nil();
             this.underlyingType = underlyingType;
-            Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED,
+            Assert.check(!underlyingType.isAnnotated(),
                     "Can't annotate already annotated type: " + underlyingType);
         }
 
@@ -1561,24 +1587,34 @@
             super(underlyingType.tag, underlyingType.tsym);
             this.typeAnnotations = typeAnnotations;
             this.underlyingType = underlyingType;
-            Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED,
+            Assert.check(!underlyingType.isAnnotated(),
                     "Can't annotate already annotated type: " + underlyingType +
                     "; adding: " + typeAnnotations);
         }
 
-        @Override
-        public TypeKind getKind() {
-            return TypeKind.ANNOTATED;
+        @Override 
+        public boolean isAnnotated() {
+            return true;
         }
 
         @Override
-        public List<? extends AnnotationMirror> getAnnotations() {
+        public List<? extends Attribute.TypeCompound> getAnnotationMirrors() {
             return typeAnnotations;
         }
 
         @Override
-        public TypeMirror getUnderlyingType() {
-            return underlyingType;
+        public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
+            return JavacAnnoConstructs.getAnnotation(this, annotationType);
+        }
+
+        @Override
+        public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
+            return JavacAnnoConstructs.getAnnotationsByType(this, annotationType);
+        } 
+
+        @Override
+        public TypeKind getKind() {
+            return underlyingType.getKind();
         }
 
         @Override
@@ -1593,7 +1629,7 @@
 
         @Override
         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
-            return v.visitAnnotated(this, p);
+            return underlyingType.accept(v, p);
         }
 
         @Override
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Fri Mar 01 11:10:14 2013 -0800
@@ -49,12 +49,14 @@
 import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
 import com.sun.tools.javac.code.TypeTag;
 import com.sun.tools.javac.code.Symbol.VarSymbol;
+import com.sun.tools.javac.comp.Annotate;
 import com.sun.tools.javac.comp.Annotate.Annotator;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.JCBlock;
 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.JCTree.JCExpression;
 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCNewClass;
 import com.sun.tools.javac.tree.JCTree.JCTypeApply;
 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
 import com.sun.tools.javac.tree.TreeScanner;
@@ -81,17 +83,18 @@
      * determine the correct positions for type annotations.
      * This version only visits types in signatures and should be
      * called from MemberEnter.
-     * The method returns the Annotator object that should be added
-     * to the correct Annotate queue for later processing.
+     * The method takes the Annotate object as parameter and
+     * adds an Annotator to the correct Annotate queue for
+     * later processing.
      */
-    public static Annotator organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
-            final Log log, final JCClassDecl tree) {
-        return new Annotator() {
+    public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
+            final Log log, final JCClassDecl tree, Annotate annotate) {
+        annotate.afterRepeated( new Annotator() {
             @Override
             public void enterAnnotation() {
                 new TypeAnnotationPositions(syms, names, log, true).scan(tree);
             }
-        };
+        } );
     }
 
     /**
@@ -102,10 +105,104 @@
         new TypeAnnotationPositions(syms, names, log, false).scan(tree);
     }
 
+    public enum AnnotationType { DECLARATION, TYPE, BOTH };
+
+    /**
+     * Determine whether an annotation is a declaration annotation,
+     * a type annotation, or both.
+     */
+    public static AnnotationType annotationType(Symtab syms, Names names,
+            Attribute.Compound a, Symbol s) {
+        Attribute.Compound atTarget =
+            a.type.tsym.attribute(syms.annotationTargetType.tsym);
+        if (atTarget == null) {
+            return inferTargetMetaInfo(a, s);
+        }
+        Attribute atValue = atTarget.member(names.value);
+        if (!(atValue instanceof Attribute.Array)) {
+            Assert.error("annotationType(): bad @Target argument " + atValue +
+                    " (" + atValue.getClass() + ")");
+            return AnnotationType.DECLARATION; // error recovery
+        }
+        Attribute.Array arr = (Attribute.Array) atValue;
+        boolean isDecl = false, isType = false;
+        for (Attribute app : arr.values) {
+            if (!(app instanceof Attribute.Enum)) {
+                Assert.error("annotationType(): unrecognized Attribute kind " + app +
+                        " (" + app.getClass() + ")");
+                isDecl = true;
+                continue;
+            }
+            Attribute.Enum e = (Attribute.Enum) app;
+            if (e.value.name == names.TYPE) {
+                if (s.kind == Kinds.TYP)
+                    isDecl = true;
+            } else if (e.value.name == names.FIELD) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind != Kinds.MTH)
+                    isDecl = true;
+            } else if (e.value.name == names.METHOD) {
+                if (s.kind == Kinds.MTH &&
+                        !s.isConstructor())
+                    isDecl = true;
+            } else if (e.value.name == names.PARAMETER) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind == Kinds.MTH &&
+                        (s.flags() & Flags.PARAMETER) != 0)
+                    isDecl = true;
+            } else if (e.value.name == names.CONSTRUCTOR) {
+                if (s.kind == Kinds.MTH &&
+                        s.isConstructor())
+                    isDecl = true;
+            } else if (e.value.name == names.LOCAL_VARIABLE) {
+                if (s.kind == Kinds.VAR &&
+                        s.owner.kind == Kinds.MTH &&
+                        (s.flags() & Flags.PARAMETER) == 0)
+                    isDecl = true;
+            } else if (e.value.name == names.ANNOTATION_TYPE) {
+                if (s.kind == Kinds.TYP &&
+                        (s.flags() & Flags.ANNOTATION) != 0)
+                    isDecl = true;
+            } else if (e.value.name == names.PACKAGE) {
+                if (s.kind == Kinds.PCK)
+                    isDecl = true;
+            } else if (e.value.name == names.TYPE_USE) {
+                if (s.kind == Kinds.TYP ||
+                        s.kind == Kinds.VAR ||
+                        (s.kind == Kinds.MTH && !s.isConstructor() &&
+                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
+                        (s.kind == Kinds.MTH && s.isConstructor()))
+                    isType = true;
+            } else if (e.value.name == names.TYPE_PARAMETER) {
+                /* Irrelevant in this case */
+                // TYPE_PARAMETER doesn't aid in distinguishing between
+                // Type annotations and declaration annotations on an
+                // Element
+            } else {
+                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
+                        " (" + e.value.name.getClass() + ")");
+                isDecl = true;
+            }
+        }
+        if (isDecl && isType) {
+            return AnnotationType.BOTH;
+        } else if (isType) {
+            return AnnotationType.TYPE;
+        } else {
+            return AnnotationType.DECLARATION;
+        }
+    }
+
+    /** Infer the target annotation kind, if none is give.
+     * We only infer declaration annotations.
+     */
+    private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
+        return AnnotationType.DECLARATION;
+    }
+
+
     private static class TypeAnnotationPositions extends TreeScanner {
 
-        private enum AnnotationType { DECLARATION, TYPE, BOTH };
-
         private final Symtab syms;
         private final Names names;
         private final Log log;
@@ -154,7 +251,7 @@
             ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>();
 
             for (Attribute.Compound a : annotations) {
-                switch (annotationType(a, sym)) {
+                switch (annotationType(syms, names, a, sym)) {
                 case DECLARATION:
                     declAnnos.append(a);
                     break;
@@ -175,6 +272,10 @@
             sym.annotations.reset();
             sym.annotations.setDeclarationAttributes(declAnnos.toList());
 
+            if (typeAnnos.isEmpty()) {
+                return;
+            }
+
             List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
 
             if (type == null) {
@@ -185,6 +286,11 @@
                 return;
             }
 
+            if (leftmostTypeAnnotationsEqual(type, typeAnnotations)) {
+                // TODO: hackish - see comment with called method.
+                return;
+            }
+
             // type is non-null and annotations are added to that type
             type = typeWithAnnotations(typetree, type, typeAnnotations, log);
 
@@ -210,6 +316,33 @@
             }
         }
 
+        // For a class declarations within an anonymous class
+        // declaration the body has been visited before.
+        // Don't try to annotate the type again, which would crash.
+        // This happens for type annotations that are also declaration
+        // annotations - they will appear in sym.getRawAttributes()
+        // and then because they are kind BOTH will be type and
+        // declaration annotations.
+        // TODO: find a nicer solution - not visiting the declaration twice.
+        // However, I didn't manage without breaking other test cases.
+        private static boolean leftmostTypeAnnotationsEqual(Type type, List<Attribute.TypeCompound> typeAnnotations) {
+            Type leftmost = type;
+            while (true) {
+                if (leftmost.getKind() == TypeKind.ARRAY) {
+                    leftmost = leftmost.unannotatedType();
+                    leftmost = ((ArrayType)leftmost).getComponentType();
+                } else if (leftmost.getKind() == TypeKind.DECLARED &&
+                        leftmost.getEnclosingType() != null &&
+                        leftmost.getEnclosingType().getKind() == TypeKind.DECLARED) {
+                    leftmost = leftmost.getEnclosingType();
+                } else {
+                    break;
+                }
+            }
+            // Comparing the length is enough to notice duplicate calls.
+            return leftmost.getAnnotationMirrors().length() == typeAnnotations.length();
+        }
+
         // This method has a similar purpose as
         // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
         // We found a type annotation in a declaration annotation position,
@@ -233,7 +366,7 @@
                 Type.ArrayType arType;
                 {
                     Type touse = type;
-                    if (type.getKind() == TypeKind.ANNOTATED) {
+                    if (type.isAnnotated()) {
                         Type.AnnotatedType atype = (Type.AnnotatedType)type;
                         toreturn = new Type.AnnotatedType(atype.underlyingType);
                         ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
@@ -252,7 +385,7 @@
                 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
                 depth = depth.append(TypePathEntry.ARRAY);
                 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
-                    if (arType.elemtype.getKind() == TypeKind.ANNOTATED) {
+                    if (arType.elemtype.isAnnotated()) {
                         Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
                         Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
                         tomodify.elemtype = newAT;
@@ -480,94 +613,6 @@
             return new Attribute.TypeCompound(a, p);
         }
 
-        private AnnotationType annotationType(Attribute.Compound a, Symbol s) {
-            Attribute.Compound atTarget =
-                a.type.tsym.attribute(syms.annotationTargetType.tsym);
-            if (atTarget == null) {
-                return inferTargetMetaInfo(a, s);
-            }
-            Attribute atValue = atTarget.member(names.value);
-            if (!(atValue instanceof Attribute.Array)) {
-                Assert.error("annotationType(): bad @Target argument " + atValue +
-                        " (" + atValue.getClass() + ")");
-                return AnnotationType.DECLARATION; // error recovery
-            }
-            Attribute.Array arr = (Attribute.Array) atValue;
-            boolean isDecl = false, isType = false;
-            for (Attribute app : arr.values) {
-                if (!(app instanceof Attribute.Enum)) {
-                    Assert.error("annotationType(): unrecognized Attribute kind " + app +
-                            " (" + app.getClass() + ")");
-                    isDecl = true;
-                    continue;
-                }
-                Attribute.Enum e = (Attribute.Enum) app;
-                if (e.value.name == names.TYPE) {
-                    if (s.kind == Kinds.TYP)
-                        isDecl = true;
-                } else if (e.value.name == names.FIELD) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind != Kinds.MTH)
-                        isDecl = true;
-                } else if (e.value.name == names.METHOD) {
-                    if (s.kind == Kinds.MTH &&
-                            !s.isConstructor())
-                        isDecl = true;
-                } else if (e.value.name == names.PARAMETER) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind == Kinds.MTH &&
-                            (s.flags() & Flags.PARAMETER) != 0)
-                        isDecl = true;
-                } else if (e.value.name == names.CONSTRUCTOR) {
-                    if (s.kind == Kinds.MTH &&
-                            s.isConstructor())
-                        isDecl = true;
-                } else if (e.value.name == names.LOCAL_VARIABLE) {
-                    if (s.kind == Kinds.VAR &&
-                            s.owner.kind == Kinds.MTH &&
-                            (s.flags() & Flags.PARAMETER) == 0)
-                        isDecl = true;
-                } else if (e.value.name == names.ANNOTATION_TYPE) {
-                    if (s.kind == Kinds.TYP &&
-                            (s.flags() & Flags.ANNOTATION) != 0)
-                        isDecl = true;
-                } else if (e.value.name == names.PACKAGE) {
-                    if (s.kind == Kinds.PCK)
-                        isDecl = true;
-                } else if (e.value.name == names.TYPE_USE) {
-                    if (s.kind == Kinds.TYP ||
-                            s.kind == Kinds.VAR ||
-                            (s.kind == Kinds.MTH && !s.isConstructor() &&
-                            !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
-                            (s.kind == Kinds.MTH && s.isConstructor()))
-                        isType = true;
-                } else if (e.value.name == names.TYPE_PARAMETER) {
-                    /* Irrelevant in this case */
-                    // TYPE_PARAMETER doesn't aid in distinguishing between
-                    // Type annotations and declaration annotations on an
-                    // Element
-                } else {
-                    Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
-                            " (" + e.value.name.getClass() + ")");
-                    isDecl = true;
-                }
-            }
-            if (isDecl && isType) {
-                return AnnotationType.BOTH;
-            } else if (isType) {
-                return AnnotationType.TYPE;
-            } else {
-                return AnnotationType.DECLARATION;
-            }
-        }
-
-        /** Infer the target annotation kind, if none is give.
-         * We only infer declaration annotations.
-         */
-        private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
-            return AnnotationType.DECLARATION;
-        }
-
 
         /* This is the beginning of the second part of organizing
          * type annotations: determine the type annotation positions.
@@ -585,7 +630,13 @@
 
             switch (frame.getKind()) {
                 case TYPE_CAST:
+                    JCTypeCast frameTC = (JCTypeCast) frame;
                     p.type = TargetType.CAST;
+                    if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
+                        // This case was already handled by INTERSECTION_TYPE
+                    } else {
+                        p.type_index = 0;
+                    }
                     p.pos = frame.pos;
                     return;
 
@@ -595,8 +646,22 @@
                     return;
 
                 case NEW_CLASS:
-                    JCNewClass frameNewClass = (JCNewClass)frame;
-                    if (frameNewClass.typeargs.contains(tree)) {
+                    JCNewClass frameNewClass = (JCNewClass) frame;
+                    if (frameNewClass.def != null) {
+                        // Special handling for anonymous class instantiations
+                        JCClassDecl frameClassDecl = frameNewClass.def;
+                        if (frameClassDecl.extending == tree) {
+                            p.type = TargetType.CLASS_EXTENDS;
+                            p.type_index = -1;
+                        } else if (frameClassDecl.implementing.contains(tree)) {
+                            p.type = TargetType.CLASS_EXTENDS;
+                            p.type_index = frameClassDecl.implementing.indexOf(tree);
+                        } else {
+                            // In contrast to CLASS below, typarams cannot occur here.
+                            Assert.error("Could not determine position of tree " + tree +
+                                    " within frame " + frame);
+                        }
+                    } else if (frameNewClass.typeargs.contains(tree)) {
                         p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
                         p.type_index = frameNewClass.typeargs.indexOf(tree);
                     } else {
@@ -649,6 +714,8 @@
                 }
 
                 case PARAMETERIZED_TYPE: {
+                    List<JCTree> newPath = path.tail;
+
                     if (((JCTypeApply)frame).clazz == tree) {
                         // generic: RAW; noop
                     } else if (((JCTypeApply)frame).arguments.contains(tree)) {
@@ -656,13 +723,21 @@
                         int arg = taframe.arguments.indexOf(tree);
                         p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
 
-                        locateNestedTypes(taframe.type, p);
+                        Type typeToUse;
+                        if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
+                            // If we are within an anonymous class instantiation, use its type,
+                            // because it contains a correctly nested type. 
+                            typeToUse = newPath.tail.head.type;
+                        } else {
+                            typeToUse = taframe.type;
+                        }
+
+                        locateNestedTypes(typeToUse, p);
                     } else {
                         Assert.error("Could not determine type argument position of tree " + tree +
                                 " within frame " + frame);
                     }
 
-                    List<JCTree> newPath = path.tail;
                     resolveFrame(newPath.head, newPath.tail.head, newPath, p);
                     return;
                 }
@@ -780,6 +855,9 @@
                         default:
                             Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
                     }
+                    if (v.getKind() != ElementKind.FIELD) {
+                        v.owner.annotations.appendUniqueTypes(v.getTypeAnnotationMirrors());
+                    }
                     return;
 
                 case ANNOTATED_TYPE: {
@@ -789,6 +867,11 @@
                         // not care about inner types.
                         JCAnnotatedType atypetree = (JCAnnotatedType) frame;
                         final Type utype = atypetree.underlyingType.type;
+                        if (utype == null) {
+                            // This might happen during DeferredAttr;
+                            // we will be back later.
+                            return;
+                        }
                         Symbol tsym = utype.tsym;
                         if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) ||
                                 utype.getKind().equals(TypeKind.WILDCARD) ||
@@ -884,11 +967,15 @@
         // This flag is used to prevent from visiting inner classes.
         private boolean isInClass = false;
 
+        // If we are visiting an anonymous class, we need to visit enclosed
+        // class declarations, as they are not visited otherwise.
+        private boolean isAnonClass = false;
+
         @Override
         public void visitClassDef(JCClassDecl tree) {
             if (isInClass)
                 return;
-            isInClass = true;
+            isInClass = !isAnonClass;
             if (sigOnly) {
                 scan(tree.mods);
                 scan(tree.typarams);
@@ -910,7 +997,9 @@
                 return;
             }
             if (sigOnly) {
-                {
+                if (!tree.mods.annotations.isEmpty()) {
+                    // Nothing to do for separateAnnotationsKinds if
+                    // there are no annotations of either kind.
                     TypeAnnotationPosition pos = new TypeAnnotationPosition();
                     pos.type = TargetType.METHOD_RETURN;
                     if (tree.sym.isConstructor()) {
@@ -923,7 +1012,10 @@
                                 tree.sym, pos);
                     }
                 }
-                if (tree.recvparam != null && tree.recvparam.sym != null) {
+                if (tree.recvparam != null && tree.recvparam.sym != null &&
+                        !tree.recvparam.mods.annotations.isEmpty()) {
+                    // Nothing to do for separateAnnotationsKinds if
+                    // there are no annotations of either kind.
                     // TODO: make sure there are no declaration annotations.
                     TypeAnnotationPosition pos = new TypeAnnotationPosition();
                     pos.type = TargetType.METHOD_RECEIVER;
@@ -933,11 +1025,15 @@
                 }
                 int i = 0;
                 for (JCVariableDecl param : tree.params) {
-                    TypeAnnotationPosition pos = new TypeAnnotationPosition();
-                    pos.type = TargetType.METHOD_FORMAL_PARAMETER;
-                    pos.parameter_index = i;
-                    pos.pos = param.vartype.pos;
-                    separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
+                    if (!param.mods.annotations.isEmpty()) {
+                        // Nothing to do for separateAnnotationsKinds if
+                        // there are no annotations of either kind.
+                        TypeAnnotationPosition pos = new TypeAnnotationPosition();
+                        pos.type = TargetType.METHOD_FORMAL_PARAMETER;
+                        pos.parameter_index = i;
+                        pos.pos = param.vartype.pos;
+                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
+                    }
                     ++i;
                 }
             }
@@ -964,7 +1060,10 @@
          */
         @Override
         public void visitVarDef(final JCVariableDecl tree) {
-            if (tree.sym == null) {
+            if (tree.mods.annotations.isEmpty()) {
+                // Nothing to do for separateAnnotationsKinds if
+                // there are no annotations of either kind.
+            } else if (tree.sym == null) {
                 // Something is wrong already. Quietly ignore.
             } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
                 // Parameters are handled in visitMethodDef above.
@@ -1031,6 +1130,45 @@
         }
 
         @Override
+        public void visitNewClass(JCNewClass tree) {
+            if (tree.def != null &&
+                    !tree.def.mods.annotations.isEmpty()) {
+                JCClassDecl classdecl = tree.def;
+                TypeAnnotationPosition pos = new TypeAnnotationPosition();
+                pos.type = TargetType.CLASS_EXTENDS;
+                pos.pos = tree.pos;
+                if (classdecl.extending == tree.clazz) {
+                    pos.type_index = -1;
+                } else if (classdecl.implementing.contains(tree.clazz)) {
+                    pos.type_index = classdecl.implementing.indexOf(tree.clazz);
+                } else {
+                    // In contrast to CLASS elsewhere, typarams cannot occur here.
+                    Assert.error("Could not determine position of tree " + tree);
+                }
+                Type before = classdecl.sym.type;
+                separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
+
+                // classdecl.sym.type now contains an annotated type, which
+                // is not what we want there.
+                // TODO: should we put this type somewhere in the superclass/interface?
+                classdecl.sym.type = before;
+            }
+
+            scan(tree.encl);
+            scan(tree.typeargs);
+            scan(tree.clazz);
+            scan(tree.args);
+
+            // Visit the class decl once with sigOnly true...
+            TypeAnnotationPositions tap = new TypeAnnotationPositions(syms, names, log, true);
+            // and noting that we are in an anonymous class.
+            tap.isAnonClass = true;
+            tap.scan(tree.def);
+            // Also visit the class decl with sigOnly false.
+            scan(tree.def);
+        }
+
+        @Override
         public void visitNewArray(JCNewArray tree) {
             findPosition(tree, tree, tree.annotations);
             int dimAnnosCount = tree.dimAnnotations.size();
@@ -1076,8 +1214,8 @@
             if (!annotations.isEmpty()) {
                 /*
                 System.out.println("Finding pos for: " + annotations);
-                System.out.println("    tree: " + tree);
-                System.out.println("    frame: " + frame);
+                System.out.println("    tree: " + tree + " kind: " + tree.getKind());
+                System.out.println("    frame: " + frame + " kind: " + frame.getKind());
                 */
                 TypeAnnotationPosition p = new TypeAnnotationPosition();
                 resolveFrame(tree, frame, frames.toList(), p);
@@ -1088,7 +1226,11 @@
         private static void setTypeAnnotationPos(List<JCAnnotation> annotations,
                 TypeAnnotationPosition position) {
             for (JCAnnotation anno : annotations) {
-                ((Attribute.TypeCompound) anno.attribute).position = position;
+                // attribute might be null during DeferredAttr;
+                // we will be back later.
+                if (anno.attribute != null) {
+                    ((Attribute.TypeCompound) anno.attribute).position = position;
+                }
             }
         }
     }
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Mar 01 11:10:14 2013 -0800
@@ -26,7 +26,6 @@
 package com.sun.tools.javac.code;
 
 import java.lang.ref.SoftReference;
-import java.util.Comparator;
 import java.util.HashSet;
 import java.util.HashMap;
 import java.util.Locale;
@@ -34,8 +33,6 @@
 import java.util.Set;
 import java.util.WeakHashMap;
 
-import javax.lang.model.type.TypeKind;
-
 import com.sun.tools.javac.code.Attribute.RetentionPolicy;
 import com.sun.tools.javac.code.Lint.LintCategory;
 import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
@@ -2091,7 +2088,7 @@
             @Override
             public Type visitAnnotatedType(AnnotatedType t, Boolean recurse) {
                 Type erased = erasure(t.underlyingType, recurse);
-                if (erased.getKind() == TypeKind.ANNOTATED) {
+                if (erased.isAnnotated()) {
                     // This can only happen when the underlying type is a
                     // type variable and the upper bound of it is annotated.
                     // The annotation on the type variable overrides the one
--- a/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Annotate.java	Fri Mar 01 11:10:14 2013 -0800
@@ -216,18 +216,42 @@
     Attribute.Compound enterAnnotation(JCAnnotation a,
                                        Type expected,
                                        Env<AttrContext> env) {
+        return enterAnnotation(a, expected, env, false);
+    }
+
+    Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
+            Type expected,
+            Env<AttrContext> env) {
+        return (Attribute.TypeCompound) enterAnnotation(a, expected, env, true);
+    }
+
+    // boolean typeAnnotation determines whether the method returns
+    // a Compound (false) or TypeCompound (true).
+    Attribute.Compound enterAnnotation(JCAnnotation a,
+            Type expected,
+            Env<AttrContext> env,
+            boolean typeAnnotation) {
         // The annotation might have had its type attributed (but not checked)
         // by attr.attribAnnotationTypes during MemberEnter, in which case we do not
         // need to do it again.
         Type at = (a.annotationType.type != null ? a.annotationType.type
                   : attr.attribType(a.annotationType, env));
         a.type = chk.checkType(a.annotationType.pos(), at, expected);
-        if (a.type.isErroneous())
-            return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
+        if (a.type.isErroneous()) {
+            if (typeAnnotation) {
+                return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
+            } else {
+                return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
+            }
+        }
         if ((a.type.tsym.flags() & Flags.ANNOTATION) == 0) {
             log.error(a.annotationType.pos(),
                       "not.annotation.type", a.type.toString());
-            return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
+            if (typeAnnotation) {
+                return new Attribute.TypeCompound(a.type, List.<Pair<MethodSymbol,Attribute>>nil(), null);
+            } else {
+                return new Attribute.Compound(a.type, List.<Pair<MethodSymbol,Attribute>>nil());
+            }
         }
         List<JCExpression> args = a.args;
         if (args.length() == 1 && !args.head.hasTag(ASSIGN)) {
@@ -266,12 +290,21 @@
                            ((MethodSymbol)method, value));
             t.type = result;
         }
-        // TODO: this should be a TypeCompound if "a" is a JCTypeAnnotation.
-        // However, how do we find the correct position?
-        Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList());
-        // TODO: is this something we want? Who would use it?
-        // a.attribute = ac;
-        return ac;
+        if (typeAnnotation) {
+            if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) {
+                // Create a new TypeCompound
+                Attribute.TypeCompound tc = new Attribute.TypeCompound(a.type, buf.toList(), new TypeAnnotationPosition());
+                a.attribute = tc;
+                return tc;
+            } else {
+                // Use an existing TypeCompound
+                return a.attribute;
+            }
+        } else {
+            Attribute.Compound ac = new Attribute.Compound(a.type, buf.toList());
+            a.attribute = ac;
+            return ac;
+        }
     }
 
     Attribute enterAttributeValue(Type expected,
@@ -354,15 +387,6 @@
         return new Attribute.Error(attr.attribExpr(tree, env, expected));
     }
 
-    Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a,
-            Type expected,
-            Env<AttrContext> env) {
-        Attribute.Compound c = enterAnnotation(a, expected, env);
-        Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, new TypeAnnotationPosition());
-        a.attribute = tc;
-        return tc;
-    }
-
     /* *********************************
      * Support for repeating annotations
      ***********************************/
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Mar 01 11:10:14 2013 -0800
@@ -766,7 +766,12 @@
         JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
 
         try {
-            memberEnter.typeAnnotate(initializer, env, env.info.enclVar);
+            // Use null as symbol to not attach the type annotation to any symbol.
+            // The initializer will later also be visited and then we'll attach
+            // to the symbol.
+            // This prevents having multiple type annotations, just because of
+            // lazy constant value evaluation.
+            memberEnter.typeAnnotate(initializer, env, null);
             annotate.flush();
             Type itype = attribExpr(initializer, env, type);
             if (itype.constValue() != null)
@@ -1110,6 +1115,18 @@
             memberEnter.typeAnnotate(tree, localEnv, localEnv.info.scope.owner);
             annotate.flush();
 
+            {
+                // Store init and clinit type annotations with the ClassSymbol
+                // to allow output in Gen.normalizeDefs.
+                ClassSymbol cs = (ClassSymbol)env.info.scope.owner;
+                List<Attribute.TypeCompound> tas = localEnv.info.scope.owner.getRawTypeAttributes();
+                if ((tree.flags & STATIC) != 0) {
+                    cs.clinit_type_annotations = cs.clinit_type_annotations.appendList(tas);
+                } else {
+                    cs.init_type_annotations = cs.init_type_annotations.appendList(tas);
+                }
+            }
+
             attribStats(tree.stats, localEnv);
         } else {
             // Create a new local environment with a local scope.
@@ -2129,6 +2146,11 @@
                     tree.constructor,
                     localEnv,
                     new ResultInfo(VAL, newMethodTemplate(syms.voidType, argtypes, typeargtypes)));
+            } else {
+                if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
+                    checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
+                            tree.clazz.type.tsym);
+                }
             }
 
             if (tree.constructor != null && tree.constructor.kind == MTH)
@@ -2190,6 +2212,20 @@
                 }
             }
 
+    private void checkForDeclarationAnnotations(List<? extends JCAnnotation> annotations,
+            Symbol sym) {
+        // Ensure that no declaration annotations are present.
+        // Note that a tree type might be an AnnotatedType with
+        // empty annotations, if only declaration annotations were given.
+        // This method will raise an error for such a type.
+        for (JCAnnotation ai : annotations) {
+            if (TypeAnnotations.annotationType(syms, names, ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) {
+                log.error(ai.pos(), "annotation.type.not.applicable");
+            }
+        }
+    }
+
+
     /** Make an attributed null check tree.
      */
     public JCExpression makeNullCheck(JCExpression arg) {
@@ -2216,6 +2252,10 @@
                 attribExpr(l.head, localEnv, syms.intType);
                 owntype = new ArrayType(owntype, syms.arrayClass);
             }
+            if (tree.elemtype.hasTag(ANNOTATED_TYPE)) {
+                checkForDeclarationAnnotations(((JCAnnotatedType) tree.elemtype).annotations,
+                        tree.elemtype.type.tsym);
+            }
         } else {
             // we are seeing an untyped aggregate { ... }
             // this is allowed only if the prototype is an array
@@ -3358,7 +3398,7 @@
                         Type normOuter = site;
                         if (normOuter.hasTag(CLASS)) {
                             normOuter = types.asEnclosingSuper(site, ownOuter.tsym);
-                            if (site.getKind() == TypeKind.ANNOTATED) {
+                            if (site.isAnnotated()) {
                                 // Propagate any type annotations.
                                 // TODO: should asEnclosingSuper do this?
                                 // Note that the type annotations in site will be updated
@@ -3893,7 +3933,14 @@
 
         ListBuffer<Attribute.TypeCompound> buf = ListBuffer.lb();
         for (JCAnnotation anno : annotations) {
-            buf.append((Attribute.TypeCompound) anno.attribute);
+            if (anno.attribute != null) {
+                // TODO: this null-check is only needed for an obscure
+                // ordering issue, where annotate.flush is called when
+                // the attribute is not set yet. For an example failure
+                // try the referenceinfos/NestedTypes.java test.
+                // Any better solutions?
+                buf.append((Attribute.TypeCompound) anno.attribute);
+            }
         }
         return buf.toList();
     }
@@ -4199,15 +4246,12 @@
         tree.accept(typeAnnotationsValidator);
     }
     //where
-    private final JCTree.Visitor typeAnnotationsValidator =
-        new TreeScanner() {
+    private final JCTree.Visitor typeAnnotationsValidator = new TreeScanner() {
+
+        private boolean checkAllAnnotations = false;
+
         public void visitAnnotation(JCAnnotation tree) {
-            if (tree.hasTag(TYPE_ANNOTATION)) {
-                // TODO: It seems to WMD as if the annotation in
-                // parameters, in particular also the recvparam, are never
-                // of type JCTypeAnnotation and therefore never checked!
-                // Luckily this check doesn't really do anything that isn't
-                // also done elsewhere.
+            if (tree.hasTag(TYPE_ANNOTATION) || checkAllAnnotations) {
                 chk.validateTypeAnnotation(tree, false);
             }
             super.visitAnnotation(tree);
@@ -4227,10 +4271,14 @@
             // I would say it's safe to skip.
             if (tree.sym != null && (tree.sym.flags() & Flags.STATIC) != 0) {
                 if (tree.recvparam != null) {
-                    // TODO: better error message. Is the pos good?
-                    log.error(tree.recvparam.pos(), "annotation.type.not.applicable");
+                    log.error(tree.recvparam.pos(), "receiver.parameter.not.applicable");
                 }
             }
+            if (tree.recvparam != null &&
+                    tree.recvparam.vartype.type.getKind() != TypeKind.ERROR) {
+                checkForDeclarationAnnotations(tree.recvparam.mods.annotations,
+                        tree.recvparam.vartype.type.tsym);
+            }
             if (tree.restype != null && tree.restype.type != null) {
                 validateAnnotatedType(tree.restype, tree.restype.type);
             }
@@ -4251,9 +4299,30 @@
                 validateAnnotatedType(tree.clazz, tree.clazz.type);
             super.visitTypeTest(tree);
         }
-        // TODO: what else do we need?
-        // public void visitNewClass(JCNewClass tree) {
-        // public void visitNewArray(JCNewArray tree) {
+        public void visitNewClass(JCNewClass tree) {
+            if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
+                boolean prevCheck = this.checkAllAnnotations;
+                try {
+                    this.checkAllAnnotations = true;
+                    scan(((JCAnnotatedType)tree.clazz).annotations);
+                } finally {
+                    this.checkAllAnnotations = prevCheck;
+                }
+            }
+            super.visitNewClass(tree);
+        }
+        public void visitNewArray(JCNewArray tree) {
+            if (tree.elemtype != null && tree.elemtype.hasTag(ANNOTATED_TYPE)) {
+                boolean prevCheck = this.checkAllAnnotations;
+                try {
+                    this.checkAllAnnotations = true;
+                    scan(((JCAnnotatedType)tree.elemtype).annotations);
+                } finally {
+                    this.checkAllAnnotations = prevCheck;
+                }
+            }
+            super.visitNewArray(tree);
+        }
 
         /* I would want to model this after
          * com.sun.tools.javac.comp.Check.Validator.visitSelectInternal(JCFieldAccess)
@@ -4276,7 +4345,7 @@
             validateAnnotatedType(errtree, type);
             if (type.tsym != null &&
                     type.tsym.isStatic() &&
-                    type.getAnnotations().nonEmpty()) {
+                    type.getAnnotationMirrors().nonEmpty()) {
                     // Enclosing static classes cannot have type annotations.
                 log.error(errtree.pos(), "cant.annotate.static.class");
             }
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Mar 01 11:10:14 2013 -0800
@@ -1205,7 +1205,7 @@
 
     /** Validate a type expression. That is,
      *  check that all type arguments of a parametric type are within
-     *  their bounds. This must be done in a second phase after type attributon
+     *  their bounds. This must be done in a second phase after type attribution
      *  since a class might have a subclass as type parameter bound. E.g:
      *
      *  <pre>{@code
--- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Mar 01 11:10:14 2013 -0800
@@ -31,7 +31,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import javax.lang.model.type.TypeKind;
 import javax.tools.JavaFileObject;
 
 import com.sun.tools.javac.code.*;
@@ -1088,9 +1087,12 @@
                 isFirst = true;
             }
         }
-        annotate.afterRepeated(TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree));
+        TypeAnnotations.organizeTypeAnnotationsSignatures(syms, names, log, tree, annotate);
     }
 
+    /*
+     * If the symbol is non-null, attach the type annotation to it.
+     */
     private void actualEnterTypeAnnotations(final List<JCAnnotation> annotations,
             final Env<AttrContext> env,
             final Symbol s) {
@@ -1123,8 +1125,10 @@
             }
         }
 
-        s.annotations.appendTypeAttributesWithCompletion(
-                annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
+        if (s != null) {
+            s.annotations.appendTypeAttributesWithCompletion(
+                    annotate.new AnnotateRepeatedContext<Attribute.TypeCompound>(env, annotated, pos, log, true));
+        }
     }
 
     public void typeAnnotate(final JCTree tree, final Env<AttrContext> env, final Symbol sym) {
@@ -1198,6 +1202,33 @@
             // Do not annotate the body, just the signature.
             // scan(tree.body);
         }
+
+        @Override
+        public void visitVarDef(final JCVariableDecl tree) {
+            if (sym.kind == Kinds.VAR) {
+                // Don't visit a parameter once when the sym is the method
+                // and once when the sym is the parameter.
+                scan(tree.mods);
+                scan(tree.vartype);
+            }
+            scan(tree.init);
+        }
+
+        @Override
+        public void visitClassDef(JCClassDecl tree) {
+            // We can only hit a classdef if it is declared within
+            // a method. Ignore it - the class will be visited
+            // separately later.
+        }
+
+        @Override
+        public void visitNewClass(JCNewClass tree) {
+            if (tree.def == null) {
+                // For an anonymous class instantiation the class
+                // will be visited separately.
+                super.visitNewClass(tree);
+            }
+        }
     }
 
 
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java	Fri Mar 01 11:10:14 2013 -0800
@@ -632,7 +632,7 @@
             acount++;
         }
         acount += writeJavaAnnotations(sym.getRawAttributes());
-        acount += writeTypeAnnotations(sym.getRawTypeAttributes());
+        acount += writeTypeAnnotations(sym.getRawTypeAttributes(), false);
         return acount;
     }
 
@@ -759,7 +759,7 @@
         return attrCount;
     }
 
-    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) {
+    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos, boolean inCode) {
         if (typeAnnos.isEmpty()) return 0;
 
         ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
@@ -793,10 +793,13 @@
                     // For method parameters we get the annotation twice! Once with
                     // a valid position, once unknown.
                     // TODO: find a cleaner solution.
-                    // System.err.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
+                    PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
+                    pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
                     continue;
                 }
             }
+            if (tc.position.type.isLocal() != inCode)
+                continue;
             if (!tc.position.emitToClassfile())
                 continue;
             switch (types.getRetention(tc)) {
@@ -1240,6 +1243,9 @@
             endAttr(alenIdx);
             acount++;
         }
+
+        acount += writeTypeAnnotations(code.meth.getRawTypeAttributes(), true);
+
         endAttrs(acountIdx, acount);
     }
     //where
@@ -1626,7 +1632,7 @@
             out = null;
         } finally {
             if (out != null) {
-                // if we are propogating an exception, delete the file
+                // if we are propagating an exception, delete the file
                 out.close();
                 outFile.delete();
                 outFile = null;
@@ -1740,7 +1746,7 @@
 
         acount += writeFlagAttrs(c.flags());
         acount += writeJavaAnnotations(c.getRawAttributes());
-        acount += writeTypeAnnotations(c.getRawTypeAttributes());
+        acount += writeTypeAnnotations(c.getRawTypeAttributes(), false);
         acount += writeEnclosingMethodAttribute(c);
         acount += writeExtraClassAttributes(c);
 
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Fri Mar 01 11:10:14 2013 -0800
@@ -30,6 +30,8 @@
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.code.Attribute.TypeCompound;
+import com.sun.tools.javac.code.Symbol.VarSymbol;
 import com.sun.tools.javac.comp.*;
 import com.sun.tools.javac.tree.*;
 
@@ -47,7 +49,6 @@
 import static com.sun.tools.javac.jvm.CRTFlags.*;
 import static com.sun.tools.javac.main.Option.*;
 import static com.sun.tools.javac.tree.JCTree.Tag.*;
-import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
 
 /** This pass maps flat Java (i.e. without inner classes) to bytecodes.
  *
@@ -456,7 +457,9 @@
      */
     List<JCTree> normalizeDefs(List<JCTree> defs, ClassSymbol c) {
         ListBuffer<JCStatement> initCode = new ListBuffer<JCStatement>();
+        ListBuffer<Attribute.TypeCompound> initTAs = new ListBuffer<Attribute.TypeCompound>();
         ListBuffer<JCStatement> clinitCode = new ListBuffer<JCStatement>();
+        ListBuffer<Attribute.TypeCompound> clinitTAs = new ListBuffer<Attribute.TypeCompound>();
         ListBuffer<JCTree> methodDefs = new ListBuffer<JCTree>();
         // Sort definitions into three listbuffers:
         //  - initCode for instance initializers
@@ -486,6 +489,7 @@
                             Assignment(sym, vdef.init);
                         initCode.append(init);
                         endPosTable.replaceTree(vdef, init);
+                        initTAs.addAll(getAndRemoveNonFieldTAs(sym));
                     } else if (sym.getConstValue() == null) {
                         // Initialize class (static) variables only if
                         // they are not compile-time constants.
@@ -493,6 +497,7 @@
                             Assignment(sym, vdef.init);
                         clinitCode.append(init);
                         endPosTable.replaceTree(vdef, init);
+                        clinitTAs.addAll(getAndRemoveNonFieldTAs(sym));
                     } else {
                         checkStringConstant(vdef.init.pos(), sym.getConstValue());
                     }
@@ -505,8 +510,10 @@
         // Insert any instance initializers into all constructors.
         if (initCode.length() != 0) {
             List<JCStatement> inits = initCode.toList();
+            initTAs.addAll(c.init_type_annotations);
+            List<Attribute.TypeCompound> initTAlist = initTAs.toList();
             for (JCTree t : methodDefs) {
-                normalizeMethod((JCMethodDecl)t, inits);
+                normalizeMethod((JCMethodDecl)t, inits, initTAlist);
             }
         }
         // If there are class initializers, create a <clinit> method
@@ -524,11 +531,28 @@
             JCBlock block = make.at(clinitStats.head.pos()).Block(0, clinitStats);
             block.endpos = TreeInfo.endPos(clinitStats.last());
             methodDefs.append(make.MethodDef(clinit, block));
+            clinit.annotations.appendUniqueTypes(clinitTAs.toList());
+            clinit.annotations.appendUniqueTypes(c.clinit_type_annotations);
         }
         // Return all method definitions.
         return methodDefs.toList();
     }
 
+    private List<Attribute.TypeCompound> getAndRemoveNonFieldTAs(VarSymbol sym) {
+        List<TypeCompound> tas = sym.getRawTypeAttributes();
+        ListBuffer<Attribute.TypeCompound> fieldTAs = new ListBuffer<Attribute.TypeCompound>();
+        ListBuffer<Attribute.TypeCompound> nonfieldTAs = new ListBuffer<Attribute.TypeCompound>();
+        for (TypeCompound ta : tas) {
+            if (ta.position.type == TargetType.FIELD) {
+                fieldTAs.add(ta);
+            } else {
+                nonfieldTAs.add(ta);
+            }
+        }
+        sym.annotations.setTypeAttributes(fieldTAs.toList());
+        return nonfieldTAs.toList();
+    }
+
     /** Check a constant value and report if it is a string that is
      *  too large.
      */
@@ -546,8 +570,9 @@
      *  @param md        The tree potentially representing a
      *                   constructor's definition.
      *  @param initCode  The list of instance initializer statements.
+     *  @param initTAs  Type annotations from the initializer expression.
      */
-    void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode) {
+    void normalizeMethod(JCMethodDecl md, List<JCStatement> initCode, List<TypeCompound> initTAs) {
         if (md.name == names.init && TreeInfo.isInitialConstructor(md)) {
             // We are seeing a constructor that does not call another
             // constructor of the same class.
@@ -581,6 +606,8 @@
             md.body.stats = newstats.toList();
             if (md.body.endpos == Position.NOPOS)
                 md.body.endpos = TreeInfo.endPos(md.body.stats.last());
+
+            md.sym.annotations.appendUniqueTypes(initTAs);
         }
     }
 
--- a/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java	Fri Mar 01 11:10:14 2013 -0800
@@ -273,7 +273,7 @@
 
     /**
      * ExceptionProxy for MirroredTypeException.
-     * The toString, hashCode, and equals methods foward to the underlying
+     * The toString, hashCode, and equals methods forward to the underlying
      * type.
      */
     private static final class MirroredTypeExceptionProxy extends ExceptionProxy {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,412 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.tools.javac.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Inherited;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import com.sun.tools.javac.code.Attribute;
+import com.sun.tools.javac.code.Kinds;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.AnnotatedType;
+import com.sun.tools.javac.util.ListBuffer;
+import static com.sun.tools.javac.code.TypeTag.CLASS;
+
+/**
+ * Utility methods for operating on annotated constructs.
+ *
+ * <p><b>This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own
+ * risk.  This code and its internal interfaces are subject to change
+ * or deletion without notice.</b></p>
+ */
+public class JavacAnnoConstructs {
+
+    // <editor-fold defaultstate="collapsed" desc="Symbols">
+    
+    /**
+     * An internal-use utility that creates a runtime view of an
+     * annotation. This is the implementation of
+     * Element.getAnnotation(Class).
+     */
+    public static <A extends Annotation> A getAnnotation(Symbol annotated,
+                                                         Class<A> annoType) {
+        if (!annoType.isAnnotation())
+            throw new IllegalArgumentException("Not an annotation type: "
+                                               + annoType);
+        Attribute.Compound c;
+        if (annotated.kind == Kinds.TYP && annotated instanceof ClassSymbol) {
+            c = getAttributeOnClass((ClassSymbol)annotated, annoType);
+        } else {
+            c = getAttribute(annotated, annoType);
+        }
+        return c == null ? null : AnnotationProxyMaker.generateAnnotation(c, annoType);
+    }
+
+    // Helper to getAnnotation[s]
+    private static <A extends Annotation> Attribute.Compound getAttribute(Symbol annotated,
+                                                                          Class<A> annoType) {
+        String name = annoType.getName();
+
+        for (Attribute.Compound anno : annotated.getRawAttributes()) {
+            if (name.equals(anno.type.tsym.flatName().toString()))
+                return anno;
+        }
+
+        return null;
+    }
+    
+    // Helper to getAnnotation[s]
+    private static <A extends Annotation> Attribute.Compound getAttributeOnClass(ClassSymbol annotated,
+                                                                Class<A> annoType) {
+        boolean inherited = annoType.isAnnotationPresent(Inherited.class);
+        Attribute.Compound result = null;
+        while (annotated.name != annotated.name.table.names.java_lang_Object) {
+            result = getAttribute(annotated, annoType);
+            if (result != null || !inherited)
+                break;
+            Type sup = annotated.getSuperclass();
+            if (!sup.hasTag(CLASS) || sup.isErroneous())
+                break;
+            annotated = (ClassSymbol) sup.tsym;
+        }
+        return result;
+    }
+
+    /**
+     * An internal-use utility that creates a runtime view of
+     * annotations. This is the implementation of
+     * Element.getAnnotations(Class).
+     */
+    public static <A extends Annotation> A[] getAnnotations(Symbol annotated,
+                                                            Class<A> annoType) {
+        if (!annoType.isAnnotation())
+            throw new IllegalArgumentException("Not an annotation type: "
+                                               + annoType);
+        // If annoType does not declare a container this is equivalent to wrapping
+        // getAnnotation(...) in an array.
+        Class <? extends Annotation> containerType = getContainer(annoType);
+        if (containerType == null) {
+            A res = getAnnotation(annotated, annoType);
+            int size;
+            if (res == null) {
+                size = 0;
+            } else {
+                size = 1;
+            }
+            @SuppressWarnings("unchecked") // annoType is the Class for A
+            A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
+            if (res != null)
+                arr[0] = res;
+            return arr;
+        }
+
+        // So we have a containing type
+        String name = annoType.getName();
+        String annoTypeName = annoType.getSimpleName();
+        String containerTypeName = containerType.getSimpleName();
+        int directIndex = -1, containerIndex = -1;
+        Attribute.Compound direct = null, container = null;
+        Attribute.Compound[] rawAttributes = annotated.getRawAttributes().toArray(new Attribute.Compound[0]);
+
+        // Find directly present annotations
+        for (int i = 0; i < rawAttributes.length; i++) {
+            if (annoTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
+                directIndex = i;
+                direct = rawAttributes[i];
+            } else if(containerTypeName != null &&
+                      containerTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
+                containerIndex = i;
+                container = rawAttributes[i];
+            }
+        }
+        
+        // Deal with inherited annotations
+        if (annotated.kind == Kinds.TYP &&
+                (annotated instanceof ClassSymbol)) {
+            ClassSymbol s = (ClassSymbol)annotated;
+            if (direct == null && container == null) {
+                direct = getAttributeOnClass(s, annoType);
+                container = getAttributeOnClass(s, containerType);
+
+                // both are inherited and found, put container last
+                if (direct != null && container != null) {
+                    directIndex = 0;
+                    containerIndex = 1;
+                } else if (direct != null) {
+                    directIndex = 0;
+                } else {
+                    containerIndex = 0;
+                }
+            } else if (direct == null) {
+                direct = getAttributeOnClass(s, annoType);
+                if (direct != null)
+                    directIndex = containerIndex + 1;
+            } else if (container == null) {
+                container = getAttributeOnClass(s, containerType);
+                if (container != null)
+                    containerIndex = directIndex + 1;
+            }
+        }
+
+        // Pack them in an array
+        Attribute[] contained0 = new Attribute[0];
+        if (container != null)
+            contained0 = unpackAttributes(container);
+        ListBuffer<Attribute.Compound> compounds = ListBuffer.lb();
+        for (Attribute a : contained0)
+            if (a instanceof Attribute.Compound)
+                compounds = compounds.append((Attribute.Compound)a);
+        Attribute.Compound[] contained = compounds.toArray(new Attribute.Compound[0]);
+
+        int size = (direct == null ? 0 : 1) + contained.length;
+        @SuppressWarnings("unchecked") // annoType is the Class for A
+        A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
+
+        // if direct && container, which is first?
+        int insert = -1;
+        int length = arr.length;
+        if (directIndex >= 0 && containerIndex >= 0) {
+            if (directIndex < containerIndex) {
+                arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+                insert = 1;
+            } else {
+                arr[arr.length - 1] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+                insert = 0;
+                length--;
+            }
+        } else if (directIndex >= 0) {
+            arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+            return arr;
+        } else {
+            // Only container
+            insert = 0;
+        }
+
+        for (int i = 0; i + insert < length; i++)
+            arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);
+
+        return arr;
+    }
+    
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="Types">
+    
+    /**
+     * An internal-use utility that creates a runtime view of an
+     * annotation. This is the implementation of
+     * TypeMirror.getAnnotation(Class).
+     */
+    public static <A extends Annotation> A getAnnotation(AnnotatedType annotated, Class<A> annoType) {
+        if (!annoType.isAnnotation())
+            throw new IllegalArgumentException("Not an annotation type: "
+                                               + annoType);
+        Attribute.Compound c = getAttribute(annotated, annoType);
+        return c == null ? null : AnnotationProxyMaker.generateAnnotation(c, annoType);
+    }
+    
+    // Helper to getAnnotation[s]
+    private static <A extends Annotation> Attribute.Compound getAttribute(Type annotated,
+                                                                          Class<A> annoType) {
+        String name = annoType.getName();
+
+        for (Attribute.Compound anno : annotated.getAnnotationMirrors()) {
+            if (name.equals(anno.type.tsym.flatName().toString()))
+                return anno;
+        }
+
+        return null;
+    }
+
+    /**
+     * An internal-use utility that creates a runtime view of
+     * annotations. This is the implementation of
+     * TypeMirror.getAnnotationsByType(Class).
+     */
+    public static <A extends Annotation> A[] getAnnotationsByType(AnnotatedType annotated, Class<A> annoType) {
+        if (!annoType.isAnnotation())
+            throw new IllegalArgumentException("Not an annotation type: "
+                                               + annoType);
+        // If annoType does not declare a container this is equivalent to wrapping
+        // getAnnotation(...) in an array.
+        Class <? extends Annotation> containerType = getContainer(annoType);
+        if (containerType == null) {
+            A res = getAnnotation(annotated, annoType);
+            int size;
+            if (res == null) {
+                size = 0;
+            } else {
+                size = 1;
+            }
+            @SuppressWarnings("unchecked") // annoType is the Class for A
+            A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
+            if (res != null)
+                arr[0] = res;
+            return arr;
+        }
+
+        // So we have a containing type
+        String name = annoType.getName();
+        String annoTypeName = annoType.getSimpleName();
+        String containerTypeName = containerType.getSimpleName();
+        int directIndex = -1, containerIndex = -1;
+        Attribute.Compound direct = null, container = null;
+        Attribute.Compound[] rawAttributes = annotated.getAnnotationMirrors().toArray(new Attribute.Compound[0]);
+
+        // Find directly present annotations
+        for (int i = 0; i < rawAttributes.length; i++) {
+            if (annoTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
+                directIndex = i;
+                direct = rawAttributes[i];
+            } else if(containerTypeName != null &&
+                      containerTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
+                containerIndex = i;
+                container = rawAttributes[i];
+            }
+        }
+
+        // Pack them in an array
+        Attribute[] contained0 = new Attribute[0];
+        if (container != null)
+            contained0 = unpackAttributes(container);
+        ListBuffer<Attribute.Compound> compounds = ListBuffer.lb();
+        for (Attribute a : contained0) {
+            if (a instanceof Attribute.Compound)
+                compounds = compounds.append((Attribute.Compound)a);
+        }
+        Attribute.Compound[] contained = compounds.toArray(new Attribute.Compound[0]);
+
+        int size = (direct == null ? 0 : 1) + contained.length;
+        @SuppressWarnings("unchecked") // annoType is the Class for A
+        A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
+
+        // if direct && container, which is first?
+        int insert = -1;
+        int length = arr.length;
+        if (directIndex >= 0 && containerIndex >= 0) {
+            if (directIndex < containerIndex) {
+                arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+                insert = 1;
+            } else {
+                arr[arr.length - 1] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+                insert = 0;
+                length--;
+            }
+        } else if (directIndex >= 0) {
+            arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
+            return arr;
+        } else {
+            // Only container
+            insert = 0;
+        }
+
+        for (int i = 0; i + insert < length; i++)
+            arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);
+
+        return arr;
+    } 
+    
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="Container support">
+
+    // Needed to unpack the runtime view of containing annotations
+    private static final Class<? extends Annotation> REPEATABLE_CLASS = initRepeatable();
+    private static final Method VALUE_ELEMENT_METHOD = initValueElementMethod();
+
+    private static Class<? extends Annotation> initRepeatable() {
+        try {
+            // Repeatable will not be available when bootstrapping on
+            // JDK 7 so use a reflective lookup instead of a class
+            // literal for Repeatable.class.
+            return Class.forName("java.lang.annotation.Repeatable").asSubclass(Annotation.class);
+        } catch (ClassNotFoundException e) {
+            return null;
+        } catch (SecurityException e) {
+            return null;
+        }
+    }
+    
+    private static Method initValueElementMethod() {
+        if (REPEATABLE_CLASS == null)
+            return null;
+
+        Method m = null;
+        try {
+            m = REPEATABLE_CLASS.getMethod("value");
+            if (m != null)
+                m.setAccessible(true);
+            return m;
+        } catch (NoSuchMethodException e) {
+            return null;
+        }
+    }
+
+    // Helper to getAnnotations
+    private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
+        // Since we can not refer to java.lang.annotation.Repeatable until we are
+        // bootstrapping with java 8 we need to get the Repeatable annotation using
+        // reflective invocations instead of just using its type and element method.
+        if (REPEATABLE_CLASS != null &&
+            VALUE_ELEMENT_METHOD != null) {
+            // Get the Repeatable instance on the annotations declaration
+            Annotation repeatable = (Annotation)annoType.getAnnotation(REPEATABLE_CLASS);
+            if (repeatable != null) {
+                try {
+                    // Get the value element, it should be a class
+                    // indicating the containing annotation type
+                    @SuppressWarnings("unchecked")
+                    Class<? extends Annotation> containerType = (Class)VALUE_ELEMENT_METHOD.invoke(repeatable);
+                    if (containerType == null)
+                        return null;
+
+                    return containerType;
+                } catch (ClassCastException e) {
+                    return null;
+                } catch (IllegalAccessException e) {
+                    return null;
+                } catch (InvocationTargetException e ) {
+                    return null;
+                }
+            }
+        }
+        return null;
+    }
+    
+    // Helper to getAnnotations
+    private static Attribute[] unpackAttributes(Attribute.Compound container) {
+        // We now have an instance of the container,
+        // unpack it returning an instance of the
+        // contained type or null
+        return ((Attribute.Array)container.member(container.type.tsym.name.table.names.value)).values;
+    }
+    
+    // </editor-fold>
+}
--- a/src/share/classes/com/sun/tools/javac/model/JavacElements.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/model/JavacElements.java	Fri Mar 01 11:10:14 2013 -0800
@@ -25,10 +25,6 @@
 
 package com.sun.tools.javac.model;
 
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Inherited;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.Map;
 
 import javax.lang.model.SourceVersion;
@@ -40,7 +36,6 @@
 
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.code.TypeTag;
 import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Enter;
 import com.sun.tools.javac.comp.Env;
@@ -98,237 +93,6 @@
         enter = Enter.instance(context);
     }
 
-    /**
-     * An internal-use utility that creates a runtime view of an
-     * annotation. This is the implementation of
-     * Element.getAnnotation(Class).
-     */
-    public static <A extends Annotation> A getAnnotation(Symbol annotated,
-                                                         Class<A> annoType) {
-        if (!annoType.isAnnotation())
-            throw new IllegalArgumentException("Not an annotation type: "
-                                               + annoType);
-        Attribute.Compound c;
-        if (annotated.kind == Kinds.TYP && annotated instanceof ClassSymbol) {
-            c = getAttributeOnClass((ClassSymbol)annotated, annoType);
-        } else {
-            c = getAttribute(annotated, annoType);
-        }
-        return c == null ? null : AnnotationProxyMaker.generateAnnotation(c, annoType);
-    }
-
-    // Helper to getAnnotation[s]
-    private static <A extends Annotation> Attribute.Compound getAttribute(Symbol annotated,
-                                                                          Class<A> annoType) {
-        String name = annoType.getName();
-
-        for (Attribute.Compound anno : annotated.getRawAttributes())
-            if (name.equals(anno.type.tsym.flatName().toString()))
-                return anno;
-
-        return null;
-    }
-    // Helper to getAnnotation[s]
-    private static <A extends Annotation> Attribute.Compound getAttributeOnClass(ClassSymbol annotated,
-                                                                Class<A> annoType) {
-        boolean inherited = annoType.isAnnotationPresent(Inherited.class);
-        Attribute.Compound result = null;
-        while (annotated.name != annotated.name.table.names.java_lang_Object) {
-            result = getAttribute(annotated, annoType);
-            if (result != null || !inherited)
-                break;
-            Type sup = annotated.getSuperclass();
-            if (!sup.hasTag(CLASS) || sup.isErroneous())
-                break;
-            annotated = (ClassSymbol) sup.tsym;
-        }
-        return result;
-    }
-
-    /**
-     * An internal-use utility that creates a runtime view of
-     * annotations. This is the implementation of
-     * Element.getAnnotations(Class).
-     */
-    public static <A extends Annotation> A[] getAnnotations(Symbol annotated,
-                                                            Class<A> annoType) {
-        if (!annoType.isAnnotation())
-            throw new IllegalArgumentException("Not an annotation type: "
-                                               + annoType);
-        // If annoType does not declare a container this is equivalent to wrapping
-        // getAnnotation(...) in an array.
-        Class <? extends Annotation> containerType = getContainer(annoType);
-        if (containerType == null) {
-            A res = getAnnotation(annotated, annoType);
-            int size;
-            if (res == null) {
-                size = 0;
-            } else {
-                size = 1;
-            }
-            @SuppressWarnings("unchecked") // annoType is the Class for A
-            A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
-            if (res != null)
-                arr[0] = res;
-            return arr;
-        }
-
-        // So we have a containing type
-        String name = annoType.getName();
-        String annoTypeName = annoType.getSimpleName();
-        String containerTypeName = containerType.getSimpleName();
-        int directIndex = -1, containerIndex = -1;
-        Attribute.Compound direct = null, container = null;
-        Attribute.Compound[] rawAttributes = annotated.getRawAttributes().toArray(new Attribute.Compound[0]);
-
-        // Find directly present annotations
-        for (int i = 0; i < rawAttributes.length; i++) {
-            if (annoTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
-                directIndex = i;
-                direct = rawAttributes[i];
-            } else if(containerTypeName != null &&
-                      containerTypeName.equals(rawAttributes[i].type.tsym.flatName().toString())) {
-                containerIndex = i;
-                container = rawAttributes[i];
-            }
-        }
-        // Deal with inherited annotations
-        if (annotated.kind == Kinds.TYP &&
-                (annotated instanceof ClassSymbol)) {
-            ClassSymbol s = (ClassSymbol)annotated;
-            if (direct == null && container == null) {
-                direct = getAttributeOnClass(s, annoType);
-                container = getAttributeOnClass(s, containerType);
-
-                // both are inherited and found, put container last
-                if (direct != null && container != null) {
-                    directIndex = 0;
-                    containerIndex = 1;
-                } else if (direct != null) {
-                    directIndex = 0;
-                } else {
-                    containerIndex = 0;
-                }
-            } else if (direct == null) {
-                direct = getAttributeOnClass(s, annoType);
-                if (direct != null)
-                    directIndex = containerIndex + 1;
-            } else if (container == null) {
-                container = getAttributeOnClass(s, containerType);
-                if (container != null)
-                    containerIndex = directIndex + 1;
-            }
-        }
-
-        // Pack them in an array
-        Attribute[] contained0 = new Attribute[0];
-        if (container != null)
-            contained0 = unpackAttributes(container);
-        ListBuffer<Attribute.Compound> compounds = ListBuffer.lb();
-        for (Attribute a : contained0)
-            if (a instanceof Attribute.Compound)
-                compounds = compounds.append((Attribute.Compound)a);
-        Attribute.Compound[] contained = compounds.toArray(new Attribute.Compound[0]);
-
-        int size = (direct == null ? 0 : 1) + contained.length;
-        @SuppressWarnings("unchecked") // annoType is the Class for A
-        A[] arr = (A[])java.lang.reflect.Array.newInstance(annoType, size);
-
-        // if direct && container, which is first?
-        int insert = -1;
-        int length = arr.length;
-        if (directIndex >= 0 && containerIndex >= 0) {
-            if (directIndex < containerIndex) {
-                arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
-                insert = 1;
-            } else {
-                arr[arr.length - 1] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
-                insert = 0;
-                length--;
-            }
-        } else if (directIndex >= 0) {
-            arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
-            return arr;
-        } else {
-            // Only container
-            insert = 0;
-        }
-
-        for (int i = 0; i + insert < length; i++)
-            arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);
-
-        return arr;
-    }
-
-    // Needed to unpack the runtime view of containing annotations
-    private static final Class<? extends Annotation> REPEATABLE_CLASS = initRepeatable();
-    private static final Method VALUE_ELEMENT_METHOD = initValueElementMethod();
-
-    private static Class<? extends Annotation> initRepeatable() {
-        try {
-            // Repeatable will not be available when bootstrapping on
-            // JDK 7 so use a reflective lookup instead of a class
-            // literal for Repeatable.class.
-            return Class.forName("java.lang.annotation.Repeatable").asSubclass(Annotation.class);
-        } catch (ClassNotFoundException e) {
-            return null;
-        } catch (SecurityException e) {
-            return null;
-        }
-    }
-    private static Method initValueElementMethod() {
-        if (REPEATABLE_CLASS == null)
-            return null;
-
-        Method m = null;
-        try {
-            m = REPEATABLE_CLASS.getMethod("value");
-            if (m != null)
-                m.setAccessible(true);
-            return m;
-        } catch (NoSuchMethodException e) {
-            return null;
-        }
-    }
-
-    // Helper to getAnnotations
-    private static Class<? extends Annotation> getContainer(Class<? extends Annotation> annoType) {
-        // Since we can not refer to java.lang.annotation.Repeatable until we are
-        // bootstrapping with java 8 we need to get the Repeatable annotation using
-        // reflective invocations instead of just using its type and element method.
-        if (REPEATABLE_CLASS != null &&
-            VALUE_ELEMENT_METHOD != null) {
-            // Get the Repeatable instance on the annotations declaration
-            Annotation repeatable = (Annotation)annoType.getAnnotation(REPEATABLE_CLASS);
-            if (repeatable != null) {
-                try {
-                    // Get the value element, it should be a class
-                    // indicating the containing annotation type
-                    @SuppressWarnings("unchecked")
-                    Class<? extends Annotation> containerType = (Class)VALUE_ELEMENT_METHOD.invoke(repeatable);
-                    if (containerType == null)
-                        return null;
-
-                    return containerType;
-                } catch (ClassCastException e) {
-                    return null;
-                } catch (IllegalAccessException e) {
-                    return null;
-                } catch (InvocationTargetException e ) {
-                    return null;
-                }
-            }
-        }
-        return null;
-    }
-    // Helper to getAnnotations
-    private static Attribute[] unpackAttributes(Attribute.Compound container) {
-        // We now have an instance of the container,
-        // unpack it returning an instance of the
-        // contained type or null
-        return ((Attribute.Array)container.member(container.type.tsym.name.table.names.value)).values;
-    }
-
     public PackageSymbol getPackageElement(CharSequence name) {
         String strName = name.toString();
         if (strName.equals(""))
--- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Fri Mar 01 11:10:14 2013 -0800
@@ -25,7 +25,6 @@
 
 package com.sun.tools.javac.model;
 
-import java.lang.annotation.Annotation;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.LinkedHashSet;
@@ -333,28 +332,4 @@
 
         return results;
     }
-
-    public List<? extends AnnotationMirror> typeAnnotationsOf(TypeMirror type) {
-        // TODO: these methods can be removed.
-        return null; // ((Type)type).typeAnnotations;
-    }
-
-    public <A extends Annotation> A typeAnnotationOf(TypeMirror type,
-            Class<A> annotationType) {
-        // TODO: these methods can be removed.
-        return null; // JavacElements.getAnnotation(((Type)type).typeAnnotations, annotationType);
-    }
-
-    public TypeMirror receiverTypeOf(ExecutableType type) {
-        return ((Type)type).asMethodType().recvtype;
-    }
-
-    /*
-    public <A extends Annotation> A receiverTypeAnnotationOf(
-            ExecutableType type, Class<A> annotationType) {
-        return JavacElements.getAnnotation(
-                ((Type)type).asMethodType().receiverTypeAnnotations,
-                annotationType);
-    }*/
-
 }
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Mar 01 11:10:14 2013 -0800
@@ -2013,7 +2013,7 @@
     /** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
      */
     JCExpression creator(int newpos, List<JCExpression> typeArgs) {
-        List<JCAnnotation> newAnnotations = typeAnnotationsOpt();
+        List<JCAnnotation> newAnnotations = annotationsOpt(Tag.ANNOTATION);
 
         switch (token.kind) {
         case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
@@ -2030,11 +2030,6 @@
         }
         JCExpression t = qualident(true);
 
-        // handle type annotations for non primitive arrays
-        if (newAnnotations.nonEmpty()) {
-            t = insertAnnotationsToMostInner(t, newAnnotations, false);
-        }
-
         int oldmode = mode;
         mode = TYPE;
         boolean diamondFound = false;
@@ -2068,6 +2063,11 @@
         }
         mode = oldmode;
         if (token.kind == LBRACKET || token.kind == MONKEYS_AT) {
+            // handle type annotations for non primitive arrays
+            if (newAnnotations.nonEmpty()) {
+                t = insertAnnotationsToMostInner(t, newAnnotations, false);
+            }
+
             JCExpression e = arrayCreatorRest(newpos, t);
             if (diamondFound) {
                 reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond");
@@ -2092,8 +2092,18 @@
             if (newClass.def != null) {
                 assert newClass.def.mods.annotations.isEmpty();
                 if (newAnnotations.nonEmpty()) {
+                    // Add type and declaration annotations to the new class;
+                    // com.sun.tools.javac.code.TypeAnnotations.TypeAnnotationPositions.visitNewClass(JCNewClass)
+                    // will later remove all type annotations and only leave the
+                    // declaration annotations.
                     newClass.def.mods.pos = earlier(newClass.def.mods.pos, newAnnotations.head.pos);
-                    newClass.def.mods.annotations = List.convert(JCAnnotation.class, newAnnotations);
+                    newClass.def.mods.annotations = newAnnotations;
+                }
+            } else {
+                // handle type annotations for instantiations
+                if (newAnnotations.nonEmpty()) {
+                    t = insertAnnotationsToMostInner(t, newAnnotations, false);
+                    newClass.clazz = t;
                 }
             }
             return newClass;
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Mar 01 11:10:14 2013 -0800
@@ -2172,6 +2172,10 @@
     as of release 8, ''this'' is allowed as the parameter name for the receiver type only, which has to be the first parameter
 
 # TODO 308: make a better error message
+compiler.err.receiver.parameter.not.applicable=\
+    receiver parameter not applicable
+
+# TODO 308: make a better error message
 compiler.err.cant.annotate.static.class=\
     enclosing static nested class cannot be annotated
 # TODO 308: make a better error message
--- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Fri Mar 01 11:10:14 2013 -0800
@@ -918,6 +918,9 @@
                 printExprs(tree.typeargs);
                 print(">");
             }
+            if (tree.def != null && tree.def.mods.annotations.nonEmpty()) {
+                printTypeAnnotations(tree.def.mods.annotations);
+            }
             printExpr(tree.clazz);
             print("(");
             printExprs(tree.args);
--- a/src/share/classes/com/sun/tools/javac/util/List.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/List.java	Fri Mar 01 11:10:14 2013 -0800
@@ -37,7 +37,7 @@
 /** A class for generic linked lists. Links are supposed to be
  *  immutable, the only exception being the incremental construction of
  *  lists via ListBuffers.  List is the main container class in
- *  GJC. Most data structures and algorthms in GJC use lists rather
+ *  GJC. Most data structures and algorithms in GJC use lists rather
  *  than arrays.
  *
  *  <p>Lists are always trailed by a sentinel element, whose head and tail
--- a/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Fri Mar 01 11:10:14 2013 -0800
@@ -205,7 +205,7 @@
         if (recvtype == null) {
             return new AnnotationDesc[0];
         }
-        if (recvtype.getKind() != TypeKind.ANNOTATED) {
+        if (!recvtype.isAnnotated()) {
             return new AnnotationDesc[0];
         }
         List<? extends Compound> typeAnnos = ((com.sun.tools.javac.code.Type.AnnotatedType)recvtype).typeAnnotations;
--- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java	Fri Mar 01 11:10:14 2013 -0800
@@ -65,11 +65,11 @@
             t = env.types.erasure(t);
         }
         if (considerAnnotations
-                && t.getKind() == TypeKind.ANNOTATED) {
+                && t.isAnnotated()) {
             return new AnnotatedTypeImpl(env, (com.sun.tools.javac.code.Type.AnnotatedType) t);
         }
 
-        if (t.getKind() == TypeKind.ANNOTATED) {
+        if (t.isAnnotated()) {
             Type.AnnotatedType at = (Type.AnnotatedType) t;
             return new AnnotatedTypeImpl(env, at);
         }
@@ -147,7 +147,7 @@
      */
     static String getTypeString(DocEnv env, Type t, boolean full) {
         // TODO: should annotations be included here?
-        if (t.getKind() == TypeKind.ANNOTATED) {
+        if (t.isAnnotated()) {
             Type.AnnotatedType at = (Type.AnnotatedType)t;
             t = at.underlyingType;
         }
--- a/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java	Fri Mar 01 11:10:14 2013 -0800
@@ -127,7 +127,7 @@
         final Type upperBound = v.getUpperBound();
         Name boundname = upperBound.tsym.getQualifiedName();
         if (boundname == boundname.table.names.java_lang_Object
-            && upperBound.getKind() != TypeKind.ANNOTATED) {
+            && !upperBound.isAnnotated()) {
             return List.nil();
         } else {
             return env.types.getBounds(v);
@@ -139,7 +139,7 @@
      * Return an empty array if there are none.
      */
     public AnnotationDesc[] annotations() {
-        if (type.getKind() != TypeKind.ANNOTATED) {
+        if (!type.isAnnotated()) {
             return new AnnotationDesc[0];
         }
         List<TypeCompound> tas = ((com.sun.tools.javac.code.Type.AnnotatedType) type).typeAnnotations;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/javax/lang/model/AnnotatedConstruct.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.lang.model;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+import javax.lang.model.element.*;
+
+/**
+ * Represent a construct that can have annotations.
+ *
+ * When annotations are on an {@linkplain element.Element element},
+ * the are on a <em>declaration</em>.  When annotations are on a {@linkplain
+ * type.TypeMirror type}, they are on a <em>use</em> of a type.
+ *
+ * @since 1.8
+ */
+public interface AnnotatedConstruct {
+    /**
+     * Returns the annotations that are directly present on this
+     * element or type use.
+     *
+     * @return the annotations directly present on this element or type;
+     *          an empty list if there are none
+     */
+    List<? extends AnnotationMirror> getAnnotationMirrors();
+
+    /**
+     * Returns this element's or type use's annotation for the
+     * specified type if such an annotation is present, else {@code
+     * null}.  The annotation may be either inherited or directly
+     * present on this element.
+     *
+     * <p> The annotation returned by this method could contain an element
+     * whose value is of type {@code Class}.
+     * This value cannot be returned directly:  information necessary to
+     * locate and load a class (such as the class loader to use) is
+     * not available, and the class might not be loadable at all.
+     * Attempting to read a {@code Class} object by invoking the relevant
+     * method on the returned annotation
+     * will result in a {@link MirroredTypeException},
+     * from which the corresponding {@link TypeMirror} may be extracted.
+     * Similarly, attempting to read a {@code Class[]}-valued element
+     * will result in a {@link MirroredTypesException}.
+     *
+     * <blockquote>
+     * <i>Note:</i> This method is unlike others in this and related
+     * interfaces.  It operates on runtime reflective information &mdash;
+     * representations of annotation types currently loaded into the
+     * VM &mdash; rather than on the representations defined by and used
+     * throughout these interfaces.  Consequently, calling methods on
+     * the returned annotation object can throw many of the exceptions
+     * that can be thrown when calling methods on an annotation object
+     * returned by core reflection.  This method is intended for
+     * callers that are written to operate on a known, fixed set of
+     * annotation types.
+     * </blockquote>
+     *
+     * @param <A>  the annotation type
+     * @param annotationType  the {@code Class} object corresponding to
+     *          the annotation type
+     * @return this element's or type use's annotation for the
+     * specified annotation type if present on this element, else
+     * {@code null}
+     *
+     * @see #getAnnotationMirrors()
+     * @see java.lang.reflect.AnnotatedElement#getAnnotation
+     * @see EnumConstantNotPresentException
+     * @see AnnotationTypeMismatchException
+     * @see IncompleteAnnotationException
+     * @see MirroredTypeException
+     * @see MirroredTypesException
+     */
+    <A extends Annotation> A getAnnotation(Class<A> annotationType);
+
+    /**
+     * Returns annotations that are <em>present</em> on this element.
+     *
+     * If there are no annotations <em>present</em> on this element, the return
+     * value is an array of length 0.
+     *
+     * The difference between this method and {@link #getAnnotation(Class)}
+     * is that this method detects if its argument is a <em>repeatable
+     * annotation type</em> (JLS 9.6), and if so, attempts to find one or more
+     * annotations of that type by "looking through" a container annotation.
+     *
+     * <p> The annotations returned by this method could contain an element
+     * whose value is of type {@code Class}.
+     * This value cannot be returned directly:  information necessary to
+     * locate and load a class (such as the class loader to use) is
+     * not available, and the class might not be loadable at all.
+     * Attempting to read a {@code Class} object by invoking the relevant
+     * method on the returned annotation
+     * will result in a {@link MirroredTypeException},
+     * from which the corresponding {@link TypeMirror} may be extracted.
+     * Similarly, attempting to read a {@code Class[]}-valued element
+     * will result in a {@link MirroredTypesException}.
+     *
+     * <blockquote>
+     * <i>Note:</i> This method is unlike others in this and related
+     * interfaces.  It operates on runtime reflective information &mdash;
+     * representations of annotation types currently loaded into the
+     * VM &mdash; rather than on the representations defined by and used
+     * throughout these interfaces.  Consequently, calling methods on
+     * the returned annotation object can throw many of the exceptions
+     * that can be thrown when calling methods on an annotation object
+     * returned by core reflection.  This method is intended for
+     * callers that are written to operate on a known, fixed set of
+     * annotation types.
+     * </blockquote>
+     *
+     * @param <A>  the annotation type
+     * @param annotationType  the {@code Class} object corresponding to
+     *          the annotation type
+     * @return this element's annotations for the specified annotation
+     *         type if present on this element, else an empty array
+     *
+     * @see #getAnnotationMirrors()
+     * @see #getAnnotation(java.lang.Class)
+     * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType
+     * @see EnumConstantNotPresentException
+     * @see AnnotationTypeMismatchException
+     * @see IncompleteAnnotationException
+     * @see MirroredTypeException
+     * @see MirroredTypesException
+     */
+    <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
+}
--- a/src/share/classes/javax/lang/model/element/Element.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/element/Element.java	Fri Mar 01 11:10:14 2013 -0800
@@ -60,8 +60,7 @@
  * @see TypeMirror
  * @since 1.6
  */
-public interface Element {
-
+public interface Element extends javax.lang.model.AnnotatedConstruct {
     /**
      * Returns the type defined by this element.
      *
@@ -89,119 +88,6 @@
     ElementKind getKind();
 
     /**
-     * Returns the annotations that are directly present on this element.
-     *
-     * <p> To get inherited annotations as well, use
-     * {@link Elements#getAllAnnotationMirrors(Element) getAllAnnotationMirrors}.
-     *
-     * @see ElementFilter
-     *
-     * @return the annotations directly present on this element;
-     *          an empty list if there are none
-     */
-    List<? extends AnnotationMirror> getAnnotationMirrors();
-
-    /**
-     * Returns this element's annotation for the specified type if
-     * such an annotation is present, else {@code null}.  The
-     * annotation may be either inherited or directly present on this
-     * element.
-     *
-     * <p> The annotation returned by this method could contain an element
-     * whose value is of type {@code Class}.
-     * This value cannot be returned directly:  information necessary to
-     * locate and load a class (such as the class loader to use) is
-     * not available, and the class might not be loadable at all.
-     * Attempting to read a {@code Class} object by invoking the relevant
-     * method on the returned annotation
-     * will result in a {@link MirroredTypeException},
-     * from which the corresponding {@link TypeMirror} may be extracted.
-     * Similarly, attempting to read a {@code Class[]}-valued element
-     * will result in a {@link MirroredTypesException}.
-     *
-     * <blockquote>
-     * <i>Note:</i> This method is unlike others in this and related
-     * interfaces.  It operates on runtime reflective information &mdash;
-     * representations of annotation types currently loaded into the
-     * VM &mdash; rather than on the representations defined by and used
-     * throughout these interfaces.  Consequently, calling methods on
-     * the returned annotation object can throw many of the exceptions
-     * that can be thrown when calling methods on an annotation object
-     * returned by core reflection.  This method is intended for
-     * callers that are written to operate on a known, fixed set of
-     * annotation types.
-     * </blockquote>
-     *
-     * @param <A>  the annotation type
-     * @param annotationType  the {@code Class} object corresponding to
-     *          the annotation type
-     * @return this element's annotation for the specified annotation
-     *         type if present on this element, else {@code null}
-     *
-     * @see #getAnnotationMirrors()
-     * @see java.lang.reflect.AnnotatedElement#getAnnotation
-     * @see EnumConstantNotPresentException
-     * @see AnnotationTypeMismatchException
-     * @see IncompleteAnnotationException
-     * @see MirroredTypeException
-     * @see MirroredTypesException
-     */
-    <A extends Annotation> A getAnnotation(Class<A> annotationType);
-
-    /**
-     * Returns annotations that are <em>present</em> on this element.
-     *
-     * If there are no annotations <em>present</em> on this element, the return
-     * value is an array of length 0.
-     *
-     * The difference between this method and {@link #getAnnotation(Class)}
-     * is that this method detects if its argument is a <em>repeatable
-     * annotation type</em> (JLS 9.6), and if so, attempts to find one or more
-     * annotations of that type by "looking through" a container annotation.
-     *
-     * <p> The annotations returned by this method could contain an element
-     * whose value is of type {@code Class}.
-     * This value cannot be returned directly:  information necessary to
-     * locate and load a class (such as the class loader to use) is
-     * not available, and the class might not be loadable at all.
-     * Attempting to read a {@code Class} object by invoking the relevant
-     * method on the returned annotation
-     * will result in a {@link MirroredTypeException},
-     * from which the corresponding {@link TypeMirror} may be extracted.
-     * Similarly, attempting to read a {@code Class[]}-valued element
-     * will result in a {@link MirroredTypesException}.
-     *
-     * <blockquote>
-     * <i>Note:</i> This method is unlike others in this and related
-     * interfaces.  It operates on runtime reflective information &mdash;
-     * representations of annotation types currently loaded into the
-     * VM &mdash; rather than on the representations defined by and used
-     * throughout these interfaces.  Consequently, calling methods on
-     * the returned annotation object can throw many of the exceptions
-     * that can be thrown when calling methods on an annotation object
-     * returned by core reflection.  This method is intended for
-     * callers that are written to operate on a known, fixed set of
-     * annotation types.
-     * </blockquote>
-     *
-     * @param <A>  the annotation type
-     * @param annotationType  the {@code Class} object corresponding to
-     *          the annotation type
-     * @return this element's annotations for the specified annotation
-     *         type if present on this element, else an empty array
-     *
-     * @see #getAnnotationMirrors()
-     * @see #getAnnotation(java.lang.Class)
-     * @see java.lang.reflect.AnnotatedElement#getAnnotationsByType
-     * @see EnumConstantNotPresentException
-     * @see AnnotationTypeMismatchException
-     * @see IncompleteAnnotationException
-     * @see MirroredTypeException
-     * @see MirroredTypesException
-     */
-    <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);
-
-    /**
      * Returns the modifiers of this element, excluding annotations.
      * Implicit modifiers, such as the {@code public} and {@code static}
      * modifiers of interface members, are included.
@@ -325,6 +211,19 @@
      */
     int hashCode();
 
+
+    /**
+     * {@inheritDoc}
+     *
+     * <p> To get inherited annotations as well, use {@link
+     * Elements#getAllAnnotationMirrors(Element)
+     * getAllAnnotationMirrors}.
+     *
+     * @see ElementFilter
+     * @since 1.6
+     */
+    @Override
+    List<? extends AnnotationMirror> getAnnotationMirrors();
     /**
      * Applies a visitor to this element.
      *
--- a/src/share/classes/javax/lang/model/element/ExecutableElement.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/element/ExecutableElement.java	Fri Mar 01 11:10:14 2013 -0800
@@ -69,6 +69,17 @@
     List<? extends VariableElement> getParameters();
 
     /**
+     * Returns the type of this executable's receiver parameter,
+     * or {@link javax.lang.model.type.NoType NoType} 
+     * (kind {@link javax.lang.model.type.TypeKind#NONE NONE}) 
+     * if the ExecutableType represents the type of an executable 
+     * which is a static method or an initializer (static or instance)
+     * 
+     * @return the type of this executable's receiver parameter
+     */
+    TypeMirror getReceiverType();
+
+    /**
      * Returns {@code true} if this method or constructor accepts a variable
      * number of arguments and returns {@code false} otherwise.
      *
--- a/src/share/classes/javax/lang/model/type/AnnotatedType.java	Thu Feb 28 14:05:52 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package javax.lang.model.type;
-
-import java.util.List;
-
-import javax.lang.model.element.AnnotationMirror;
-
-/**
- * Represents an annotated type.
- *
- * As of the {@link javax.lang.model.SourceVersion#RELEASE_8
- * RELEASE_8} source version, annotated types can appear for all
- * type uses.
- *
- * @author Werner Dietl
- * @since 1.8
- */
-public interface AnnotatedType extends TypeMirror,
-    DeclaredType, TypeVariable, WildcardType,
-    PrimitiveType, ArrayType {
-
-    List<? extends AnnotationMirror> getAnnotations();
-    TypeMirror getUnderlyingType();
-}
--- a/src/share/classes/javax/lang/model/type/ExecutableType.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/type/ExecutableType.java	Fri Mar 01 11:10:14 2013 -0800
@@ -78,10 +78,13 @@
     List<? extends TypeMirror> getParameterTypes();
 
     /**
-     * Returns the type of this executable's receiver parameter.
-     *
+     * Returns the type of this executable's receiver parameter,
+     * or {@link javax.lang.model.type.NoType NoType} 
+     * (kind {@link javax.lang.model.type.TypeKind#NONE NONE}) 
+     * if the ExecutableType represents the type of an executable 
+     * which is a static method or an initializer (static or instance)
+     * 
      * @return the type of this executable's receiver parameter
-     * TODO: null if none specified or always a valid value?
      */
     TypeMirror getReceiverType();
 
--- a/src/share/classes/javax/lang/model/type/TypeKind.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/type/TypeKind.java	Fri Mar 01 11:10:14 2013 -0800
@@ -151,14 +151,7 @@
       *
       * @since 1.8
       */
-    INTERSECTION,
-
-    /**
-     * An annotated type.
-     *
-     * @since 1.8
-     */
-    ANNOTATED;
+    INTERSECTION;
 
     /**
      * Returns {@code true} if this kind corresponds to a primitive
--- a/src/share/classes/javax/lang/model/type/TypeMirror.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/type/TypeMirror.java	Fri Mar 01 11:10:14 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
 
 package javax.lang.model.type;
 
+import java.lang.annotation.Annotation;
+import java.util.List;
 import javax.lang.model.element.*;
 import javax.lang.model.util.Types;
 
@@ -55,7 +57,7 @@
  * @see Types
  * @since 1.6
  */
-public interface TypeMirror {
+public interface TypeMirror extends javax.lang.model.AnnotatedConstruct {
 
     /**
      * Returns the {@code kind} of this type.
--- a/src/share/classes/javax/lang/model/type/TypeVisitor.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/type/TypeVisitor.java	Fri Mar 01 11:10:14 2013 -0800
@@ -194,14 +194,4 @@
      * @since 1.8
      */
     R visitIntersection(IntersectionType t, P p);
-
-    /**
-     * Visits an annotated type.
-     *
-     * @param t the type to visit
-     * @param p a visitor-specified parameter
-     * @return  a visitor-specified result
-     * @since 1.8
-     */
-    R visitAnnotated(AnnotatedType t, P p);
 }
--- a/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/util/AbstractTypeVisitor6.java	Fri Mar 01 11:10:14 2013 -0800
@@ -134,23 +134,6 @@
     }
 
     /**
-     * Visits an {@code AnnotatedType} element by calling {@code
-     * visit} on the underlying type.
-
-     * @param t  {@inheritDoc}
-     * @param p  {@inheritDoc}
-     * @return the result of calling {@code visit} on the underlying type
-     *
-     * @since 1.8
-     *
-     * TODO: should xxxVisitor8 subclasses override this and call
-     *   the defaultAction?
-     */
-    public R visitAnnotated(AnnotatedType t, P p) {
-        return visit(t.getUnderlyingType(), p);
-    }
-
-    /**
      * {@inheritDoc}
      *
      * <p> The default implementation of this method in {@code
--- a/src/share/classes/javax/lang/model/util/Types.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/src/share/classes/javax/lang/model/util/Types.java	Fri Mar 01 11:10:14 2013 -0800
@@ -59,6 +59,13 @@
     /**
      * Tests whether two {@code TypeMirror} objects represent the same type.
      *
+     * <p>Since annotations are only meta-data associated with a type,
+     * the set of annotations on either argument is <em>not</em> taken
+     * into account when computing whether or not two {@code
+     * TypeMirror} objects are the same type. In particular, two
+     * {@code TypeMirror} objects can have different annotations and
+     * still be considered the same.
+     *
      * <p>Caveat: if either of the arguments to this method represents a
      * wildcard, this method will return false.  As a consequence, a wildcard
      * is not the same type as itself.  This might be surprising at first,
@@ -301,116 +308,4 @@
      *          for the given type
      */
     TypeMirror asMemberOf(DeclaredType containing, Element element);
-
-    /**
-     * Returns the annotations targeting the type.
-     *
-     * @param type the targeted type
-     * @return the type annotations targeting the type
-     */
-    List<? extends AnnotationMirror> typeAnnotationsOf(TypeMirror type);
-
-    /**
-     * Returns the type's annotation for the specified type if
-     * such an annotation is present, else {@code null}.  The
-     * annotation has to be directly present on this
-     * element.
-     *
-     * <p> The annotation returned by this method could contain an element
-     * whose value is of type {@code Class}.
-     * This value cannot be returned directly:  information necessary to
-     * locate and load a class (such as the class loader to use) is
-     * not available, and the class might not be loadable at all.
-     * Attempting to read a {@code Class} object by invoking the relevant
-     * method on the returned annotation
-     * will result in a {@link MirroredTypeException},
-     * from which the corresponding {@link TypeMirror} may be extracted.
-     * Similarly, attempting to read a {@code Class[]}-valued element
-     * will result in a {@link MirroredTypesException}.
-     *
-     * <blockquote>
-     * <i>Note:</i> This method is unlike others in this and related
-     * interfaces.  It operates on runtime reflective information &mdash;
-     * representations of annotation types currently loaded into the
-     * VM &mdash; rather than on the representations defined by and used
-     * throughout these interfaces.  Consequently, calling methods on
-     * the returned annotation object can throw many of the exceptions
-     * that can be thrown when calling methods on an annotation object
-     * returned by core reflection.  This method is intended for
-     * callers that are written to operate on a known, fixed set of
-     * annotation types.
-     * </blockquote>
-     *
-     * @param <A>   the annotation type
-     * @param type  the targeted type
-     * @param annotationType  the {@code Class} object corresponding to
-     *          the annotation type
-     * @return the type's annotation for the specified annotation
-     *         type if present on the type, else {@code null}
-     *
-     * @see Element#getAnnotationMirrors()
-     * @see EnumConstantNotPresentException
-     * @see AnnotationTypeMismatchException
-     * @see IncompleteAnnotationException
-     * @see MirroredTypeException
-     * @see MirroredTypesException
-     */
-    <A extends Annotation> A typeAnnotationOf(TypeMirror type, Class<A> annotationType);
-
-    /**
-     * Returns the annotations targeting the method receiver type.
-     *
-     * @param type the targeted type
-     * @return the receiver type of the executable type
-     */
-    TypeMirror receiverTypeOf(ExecutableType type);
-
-    /**
-     * Returns the type's annotation for the specified executable type
-     * receiver if such an annotation is present, else {@code null}.  The
-     * annotation has to be directly present on this
-     * element.
-     *
-     * <p> The annotation returned by this method could contain an element
-     * whose value is of type {@code Class}.
-     * This value cannot be returned directly:  information necessary to
-     * locate and load a class (such as the class loader to use) is
-     * not available, and the class might not be loadable at all.
-     * Attempting to read a {@code Class} object by invoking the relevant
-     * method on the returned annotation
-     * will result in a {@link MirroredTypeException},
-     * from which the corresponding {@link TypeMirror} may be extracted.
-     * Similarly, attempting to read a {@code Class[]}-valued element
-     * will result in a {@link MirroredTypesException}.
-     *
-     * <blockquote>
-     * <i>Note:</i> This method is unlike others in this and related
-     * interfaces.  It operates on runtime reflective information &mdash;
-     * representations of annotation types currently loaded into the
-     * VM &mdash; rather than on the representations defined by and used
-     * throughout these interfaces.  Consequently, calling methods on
-     * the returned annotation object can throw many of the exceptions
-     * that can be thrown when calling methods on an annotation object
-     * returned by core reflection.  This method is intended for
-     * callers that are written to operate on a known, fixed set of
-     * annotation types.
-     * </blockquote>
-     *
-     * @param <A>   the annotation type
-     * @param type  the method type
-     * @param annotationType  the {@code Class} object corresponding to
-     *          the annotation type
-     * @return the type's annotation for the specified annotation
-     *         type if present on the type, else {@code null}
-     *
-     * @see Element#getAnnotationMirrors()
-     * @see EnumConstantNotPresentException
-     * @see AnnotationTypeMismatchException
-     * @see IncompleteAnnotationException
-     * @see MirroredTypeException
-     * @see MirroredTypesException
-     */
-    // TODO: no longer needed?
-    // <A extends Annotation> A receiverTypeAnnotationOf(ExecutableType type, Class<A> annotationType);
-
 }
--- a/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java	Fri Mar 01 11:10:14 2013 -0800
@@ -24,7 +24,6 @@
 /*
  * @test
  * @bug 8006735
- * @ignore
  * @summary  Smoke test for ensuring that annotations are emited to javadoc
  *
  * @author   Mahmood Ali <mali>
--- a/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/attribution/Scopes.java	Fri Mar 01 11:10:14 2013 -0800
@@ -28,11 +28,17 @@
  * @author Mahmood Ali
  * @compile Scopes.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
 class Scopes {
 
   void test(@A(VALUE) Scopes this) { }
   void test1(@A(value=VALUE) Scopes this) { }
 
   private static final int VALUE = 1;
+
+  @Target(ElementType.TYPE_USE)
   @interface A { int value(); }
 }
--- a/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java	Fri Mar 01 11:10:14 2013 -0800
@@ -83,20 +83,43 @@
         test("CLASS",cf, null, null, Attribute.RuntimeInvisibleAnnotations, false);
     }
 
-    void test(ClassFile cf, Method m) {
-        test("METHOD",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test("METHOD",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
-        test("METHOD",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
-        test("METHOD",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
+    void test(ClassFile cf, Field f, Boolean local) {
+        if (!local) {
+            test("FIELD",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
+            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
+            test("FIELD",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
+            test("FIELD",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
+        } else {
+            test("CODE",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
+            test("CODE",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
+            test("CODE",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
+            test("CODE",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
+        }
+    }
+    
+    void test(ClassFile cf, Field f) {
+        test(cf, f, false);
     }
 
-    void test(ClassFile cf, Field f) {
-        test("FIELD",cf, f, null, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test("FIELD",cf, f, null, Attribute.RuntimeInvisibleTypeAnnotations, false);
-        test("FIELD",cf, f, null, Attribute.RuntimeVisibleAnnotations, true);
-        test("FIELD",cf, f, null, Attribute.RuntimeInvisibleAnnotations, false);
+    // 'local' determines whether to look for annotations in code attribute or not.
+    void test(ClassFile cf, Method m, Boolean local) {
+        if (!local) {
+            test("METHOD",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
+            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
+            test("METHOD",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
+            test("METHOD",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
+        } else  {
+            test("MCODE",cf, null, m, Attribute.RuntimeVisibleTypeAnnotations, true);
+            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
+            test("MCODE",cf, null, m, Attribute.RuntimeVisibleAnnotations, true);
+            test("MCODE",cf, null, m, Attribute.RuntimeInvisibleAnnotations, false);
+        }
     }
-
+    
+    // default to not looking in code attribute
+    void test(ClassFile cf, Method m ) {
+        test(cf, m, false);
+    }
 
     // Test the result of Attributes.getIndex according to expectations
     // encoded in the class/field/method name; increment annotations counts.
@@ -105,18 +128,47 @@
         String name = null;
         int index = -1;
         Attribute attr = null;
+        Code_attribute cAttr = null;
         boolean isTAattr = annName.contains("TypeAnnotations");
         try {
             switch(testtype) {
                 case "FIELD":
                     name = f.getName(cf.constant_pool);
                     index = f.attributes.getIndex(cf.constant_pool, annName);
-                    if(index!= -1) attr = f.attributes.get(index);
+                    if(index!= -1) 
+                        attr = f.attributes.get(index);
+                    break;
+                case "CODE":
+                    name = f.getName(cf.constant_pool);
+                    //fetch index of and code attribute and annotations from code attribute.
+                    index = cf.attributes.getIndex(cf.constant_pool, Attribute.Code);
+                    if(index!= -1) {
+                        attr = cf.attributes.get(index);
+                        assert attr instanceof Code_attribute;
+                        cAttr = (Code_attribute)attr;
+                        index = cAttr.attributes.getIndex(cf.constant_pool, annName); 
+                        if(index!= -1) 
+                            attr = cAttr.attributes.get(index);
+                    }
                     break;
                 case "METHOD":
                     name = m.getName(cf.constant_pool);
                     index = m.attributes.getIndex(cf.constant_pool, annName);
-                    if(index!= -1) attr = m.attributes.get(index);
+                    if(index!= -1) 
+                        attr = m.attributes.get(index);
+                    break;
+                case "MCODE":
+                    name = m.getName(cf.constant_pool);
+                    //fetch index of and code attribute and annotations from code attribute.
+                    index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
+                    if(index!= -1) {
+                        attr = m.attributes.get(index);
+                        assert attr instanceof Code_attribute;
+                        cAttr = (Code_attribute)attr;
+                        index = cAttr.attributes.getIndex(cf.constant_pool, annName); 
+                        if(index!= -1) 
+                            attr = cAttr.attributes.get(index);
+                    }
                     break;
                 default:
                     name = cf.getName();
@@ -126,7 +178,6 @@
         } catch(ConstantPoolException cpe) { cpe.printStackTrace(); }
 
         if (index != -1) {
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
             if(isTAattr) { //count RuntimeTypeAnnotations
                 RuntimeTypeAnnotations_attribute tAttr =
                         (RuntimeTypeAnnotations_attribute)attr;
--- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest1.java	Fri Mar 01 11:10:14 2013 -0800
@@ -24,7 +24,6 @@
 /*
  * @test
  * @bug 8005085 8005877 8004829 8005681 8006734 8006775
- * @ignore
  * @summary Combinations of Target ElementTypes on (repeated)type annotations.
  */
 
@@ -32,10 +31,25 @@
 import java.io.File;
 
 public class CombinationsTargetTest1 extends ClassfileTestHelper {
-    // Helps identify test case in event of failure.
+
+    // Test count helps identify test case in event of failure.
     int testcount = 0;
-    int src1 = 1, src2 = 2, src4 = 4,
-        src5 = 5, src6 = 6, src7 = 7;
+
+    // Base test case template descriptions
+    enum srce  {
+        src1("(repeating) type annotations at class level"),
+        src2("(repeating) type annotations on method"),
+        src3("(repeating) type annotations on wildcard, type arguments in anonymous class"),
+        src4("(repeating) type annotations on type parameters, bounds and  type arguments on class decl"),
+        src5("(repeating) type annotations on type parameters, bounds and  type arguments on method"),
+        src6("(repeating) type annotations on type parameters, bounds and  type arguments in method");
+
+        String description;
+
+        srce(String desc) {
+            this.description = this + ": " +desc;
+        }
+    }
 
     String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
                      "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
@@ -52,7 +66,6 @@
         // Determines which repeat and order in source(ABMix).
         Boolean As= false, BDs=true, ABMix=false;
         int testrun=0;
-        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
         Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
                                                {true,false,false}, //repeat @A
                                                {false,true,false}, //repeat @B
@@ -64,29 +77,29 @@
             for(String et : ETypes) {
                switch(et) {
                    case "METHOD":
-                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
-                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src2);
-                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src4);
-                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src6);
-                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
-                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src2);
-                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src4);
-                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src6);
+                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
+                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
+                       test( 6,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
+                       test(10,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
+                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
+                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
+                       test( 0,  6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
+                       test( 0, 10, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
                        break;
                    case "CONSTRUCTOR":
                    case "FIELD":
-                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
-                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
-                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src7);
-                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
-                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
-                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src7);
+                       test( 8,  0, 4, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
+                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
+                       test( 9,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src6);
+                       test( 0,  8, 0, 4, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
+                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
+                       test( 0,  9, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src6);
                        break;
                    default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
-                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src1);
-                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src5);
-                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, src1);
-                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, src5);
+                       test( 8,  0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
+                       test( 6,  0, 3, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
+                       test( 0,  8, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
+                       test( 0,  6, 0, 3, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
                }
             }
         }
@@ -94,7 +107,7 @@
 
     public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
                      Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
-                     Integer N, int source) throws Exception {
+                     Integer N, srce source) throws Exception {
         ++testcount;
         expected_tvisibles = tvis;
         expected_tinvisibles = tinv;
@@ -125,7 +138,8 @@
         //if sourcString() set hasInnerClass it also set innerClassname.
         if(hasInnerClass) {
             StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
-            classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
+            classFile=new File(sb.insert(sb.lastIndexOf(".class"),
+                                         innerClassname).toString());
         }
         ClassFile cf = ClassFile.read(classFile);
 
@@ -152,7 +166,7 @@
     //
     String sourceString(String testname, String retentn, String annot2,
                         Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
-                        int src) {
+                        srce src) {
 
         String As = "@A", Bs = "@B", Ds = "@D";
         if(Arepeats) As = "@A @A";
@@ -201,11 +215,11 @@
 
             "@Retention("+retentn+")\n" +
             "@Target({TYPE_USE,TYPE_PARAMETER,_OTHER_})\n" +
-            "@interface DC { D[] value(); }\n\n");
+            "@interface DC { D[] value(); }\n");
 
         // Test case sources with sample generated source.
         switch(src) {
-            case 1: // repeating type annotations at class level
+            case src1: // repeating type annotations at class level
                     /*
                      * @A @B class Test1 {
                      * @A @B Test1(){}
@@ -218,21 +232,21 @@
                      * }}
                      */
                 source = new String(
-                "// (repeating) type annotations at class level. \n" +
-                "_As_ _Bs_ class " + testname + " {\n" +
-                "_As_ _Bs_ " + testname +"(){} \n" +
-                "_As_ _Bs_ Integer i1 = 0; \n" +
-                "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
-                "// type usage in method body \n" +
-                "String test("+testname+" this, " +
-                   "String param, String ... vararg) { \n" +
-                "    Object o = new  String  [3]; \n" +
-                "    return (String) null; \n" +
-                "} \n" +
-                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
-                "\n\n";
+                    "// " + src.description + "\n" +
+                    "_As_ _Bs_ class " + testname + " {\n" +
+                    "_As_ _Bs_ " + testname +"(){} \n" +
+                    "_As_ _Bs_ Integer i1 = 0; \n" +
+                    "String _As_ _Bs_ [] _As_ _Bs_ [] sa = null; \n" +
+                    "// type usage in method body \n" +
+                    "String test("+testname+" this, " +
+                       "String param, String ... vararg) { \n" +
+                    "    Object o = new  String  [3]; \n" +
+                    "    return (String) null; \n" +
+                    "}\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n";
                 break;
-            case 2: // (repeating) type annotations on method.
+            case src2: // (repeating) type annotations on method.
                     /*
                      * class Test12 {
                      * Test12(){}
@@ -243,26 +257,26 @@
                      * }}
                      */
                 source = new String(
-                "// (repeating) type annotations on method. \n" +
-                "class " + testname + " {\n" +
-                testname +"(){} \n" +
-                "// type usage on method \n" +
-                "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
-                   "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
-                "    Object o = new String [3]; \n" +
-                "    return (String) null; \n" +
-                "} \n" +
-                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
-                "\n\n";
+                    "// " + src.description + "\n" +
+                    "class " + testname + " {\n" +
+                    testname +"(){} \n" +
+                    "// type usage on method \n" +
+                    "_As_ _Bs_ String test(_As_ _Bs_  "+testname+" this, " +
+                       "_As_ _Bs_  String param, _As_ _Bs_  String _As_ _Bs_  ... vararg) { \n" +
+                    "    Object o = new String [3]; \n" +
+                    "    return (String) null; \n" +
+                    "}\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n";
                 break;
-            case 4: //(repeating) annotations on wildcard, type arguments in anonymous class.
+            case src3: //(repeating) annotations on wildcard, type arguments in anonymous class.
                     /*
                      * class Test13<T extends Object> {
                      *     public T data = null;
                      *     T getData() { return data;}
                      *     String mtest( Test13<String> t){ return t.getData(); }
                      *     public void test() {
-                     *         mtest( new Test13<@A @B String>() {
+                     *         mtest( new Test13<String>() {
                      *                  void m1(List<@A @B ? extends @A @B  Object> lst) {}
                      *                  void m2() throws@A @B Exception { }
                      *                });
@@ -270,22 +284,23 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating) annotations on wildcard, type arguments in anonymous class. \n" +
-                "class " + testname + "<T extends Object> {\n" +
-                "    public T data = null;\n" +
-                "    T getData() { return data;}\n" +
-                "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
-                "    public void test() {\n" +
-                "        mtest( new " + testname + "<_As_ _Bs_ String>() {\n" +
-                "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
-                "                 void m2() throws_As_ _Bs_ Exception { }\n" +
-                "               });\n" +
-                "    }\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) + "\n\n";
-                hasInnerClass=true;
-                innerClassname="$1";
+                    "// " + src.description + "\n" +
+                    "class " + testname + "<T extends Object> {\n" +
+                    "    public T data = null;\n" +
+                    "    T getData() { return data;}\n" +
+                    "    String mtest( " + testname + "<String> t){ return t.getData(); }\n" +
+                    "    public void test() {\n" +
+                    "        mtest( new " + testname + "<String>() {\n" +
+                    "                 void m1(List<_As_ _Bs_ ? extends _As_ _Bs_  Object> lst) {}\n" +
+                    "                 void m2() throws_As_ _Bs_ Exception { }\n" +
+                    "               });\n" +
+                    "    }\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n";
+                    hasInnerClass=true;
+                    innerClassname="$1";
             break;
-            case 5: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
+            case src4: // (repeating)annotations on type parameters, bounds and  type arguments on class decl.
                     /*
                      * @A @B @D
                      * class Test2<@A @B @C @D T extends @A @B Object> {
@@ -297,18 +312,18 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating)annotations on type parameters, bounds and  type arguments on class decl. \n" +
-                "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
-                "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
-                "    Map<List<String>, Integer> map =\n" +
-                "        new HashMap<List< String>, Integer>();\n" +
-                "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
-                "    String test(" + testname + "<T> this) { return null;}\n" +
-                "    <T> String genericMethod(T t) { return null; }\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
-                "\n\n";
-            break;
-            case 6: // (repeating) annotations on type parameters, bounds and  type arguments on method.
+                    "// " + src.description + "\n" +
+                    "_As_ _Bs_ _Ds_\n" +  //8004829: A and B on type parameter below.
+                    "class " + testname + "<_As_ _Bs_ @C _Ds_ T extends _As_ _Bs_ Object> {\n" +
+                    "    Map<List<String>, Integer> map =\n" +
+                    "        new HashMap<List< String>, Integer>();\n" +
+                    "    Map<List<String>,Integer> map2 = new HashMap<>();\n" +
+                    "    String test(" + testname + "<T> this) { return null;}\n" +
+                    "    <T> String genericMethod(T t) { return null; }\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
+                    "\n";
+                break;
+            case src5: // (repeating) annotations on type parameters, bounds and  type arguments on method.
                     /*
                      * class Test14<T extends Object> {
                      *     Map<List<String>, Integer> map =
@@ -319,17 +334,17 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating) annotations on type parameters, bounds and  type arguments on method. \n" +
-                "class " + testname + "<T extends Object> {\n" +
-                "    Map<List<String>, Integer> map =\n" +
-                "        new HashMap<List<String>, Integer>();\n" +
-                "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
-                "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
-                "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
-                "\n\n";
-            break;
-            case 7: // repeating annotations on type parameters, bounds and  type arguments in method.
+                    "// " + src.description + "\n" +
+                    "class " + testname + "<T extends Object> {\n" +
+                    "    Map<List<String>, Integer> map =\n" +
+                    "        new HashMap<List<String>, Integer>();\n" +
+                    "    Map<List<String>, Integer> map2 = new HashMap<>();\n" +
+                    "    String test(_As_ _Bs_ " + testname + "<_Ds_ T> this) { return null;}\n" +
+                    "    <@C _Ds_ T> _As_ _Bs_ String genericMethod(_As_ _Bs_ _Ds_ T t) { return null; }\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
+                    "\n";
+                break;
+            case src6: // repeating annotations on type parameters, bounds and  type arguments in method.
                     /*
                      * class Test7{
                      *     <E extends Comparable> Map<List<E>, E > foo(E e) {
@@ -344,22 +359,22 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating)annotations on type parameters of class, method return value in method. \n" +
-                "class "+ testname + "{\n" +
-                "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
-                "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
-                "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
-                "                return new HashMap<List<E>,E>();\n" +
-                "            }\n" +
-                "        }\n" +
-                "        return new maptest<E>().getMap();\n" +
-                "   }\n" +
-                "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
-                "\n\n";
-                hasInnerClass=true;
-                innerClassname="$1maptest";
-            break;
+                    "// " + src.description + "\n" +
+                    "class "+ testname + "{\n" +
+                    "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
+                    "        class maptest <_As_ _Bs_ _Ds_ E> {\n" +                  // inner class $1maptest
+                    "            Map<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E> getMap() { \n" +
+                    "                return new HashMap<List<E>,E>();\n" +
+                    "            }\n" +
+                    "        }\n" +
+                    "        return new maptest<E>().getMap();\n" +
+                    "   }\n" +
+                    "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
+                    "}\n\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
+                    "\n";
+                    hasInnerClass=true;
+                    innerClassname="$1maptest";
+                break;
         }
         return imports + source;
     }
--- a/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/CombinationsTargetTest2.java	Fri Mar 01 11:10:14 2013 -0800
@@ -23,8 +23,7 @@
 
 /*
  * @test
- * @bug 8005085 8005877 8004829 8005681 8006734 8006775
- * @ignore
+ * @bug 8005085 8005877 8004829 8005681 8006734 8006775 8006507
  * @summary Combinations of Target ElementTypes on (repeated)type annotations.
  */
 
@@ -32,9 +31,27 @@
 import java.io.File;
 
 public class CombinationsTargetTest2 extends ClassfileTestHelper {
-    // Helps identify test case in event of failure.
+
+    // Test count helps identify test case in event of failure.
     int testcount = 0;
-    int src3 = 3, src8 = 8, src9 = 9;
+
+    // Base test case template descriptions
+    enum srce  {
+        src1("(repeating) type annotations on on field in method body",true),
+        src2("(repeating) type annotations on type parameters, bounds and  type arguments", true),
+        src3("(repeating) type annotations on type parameters of class, method return value in method", true),
+        src4("(repeating) type annotations on field in anonymous class", false),
+        src5("(repeating) type annotations on field in anonymous class", false);
+
+        String description;
+        Boolean local;
+
+        srce(String desc, Boolean b) {
+            this.description = this + ": " +desc;
+            this.local = b;
+        }
+    }
+
 
     String[] ETypes={"TYPE", "FIELD", "METHOD", "PARAMETER", "CONSTRUCTOR",
                      "LOCAL_VARIABLE", "ANNOTATION_TYPE", "PACKAGE"};
@@ -51,31 +68,36 @@
         // Determines which repeat and order in source(ABMix).
         Boolean As= false, BDs=true, ABMix=false;
         int testrun=0;
-        // A repeats and/or B/D repeats, ABMix for order of As and Bs.
         Boolean [][] bRepeat = new Boolean[][]{{false,false,false},//no repeats
                                                {true,false,false}, //repeat @A
                                                {false,true,false}, //repeat @B
                                                {true,true,false},  //repeat both
                                                {false,false,true}  //repeat mix
         };
+
         for(Boolean[] bCombo : bRepeat) {
             As=bCombo[0]; BDs=bCombo[1]; ABMix=bCombo[2];
             for(String et : ETypes) {
                switch(et) {
                    case "METHOD":
-                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src3);
-                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3);
+                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
+                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
+                       test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src5);
+                       test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
                        break;
-                   case "CONSTRUCTOR":
                    case "FIELD":
-                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src3);
-                       test( 8,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src8);
-                       test( 6,  0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, src9);
-                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src3);
-                       test( 0,  8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src8);
-                       test( 0,  6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, src9);
+                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src1);
+                       test( 8, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src2);
+                       test( 6, 0, 0, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src3);
+                       test( 2, 0, 2, 0, As, BDs, ABMix, "CLASS",   et, ++testrun, srce.src4);
+                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src1);
+                       test( 0, 8, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src2);
+                       test( 0, 6, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src3);
+                       test( 0, 2, 0, 2, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
                        break;
                    default:/*TYPE,PARAMETER,LOCAL_VARIABLE,ANNOTATION_TYPE,PACKAGE*/
+                       test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src4);
+                       test( 0, 2, 0, 0, As, BDs, ABMix, "RUNTIME", et, ++testrun, srce.src5);
                        break;
                }
             }
@@ -84,7 +106,7 @@
 
     public void test(int tinv, int tvis, int inv, int vis, Boolean Arepeats,
                      Boolean BDrepeats, Boolean ABmix, String rtn, String et2,
-                     Integer N, int source) throws Exception {
+                     Integer N, srce source) throws Exception {
         ++testcount;
         expected_tvisibles = tvis;
         expected_tinvisibles = tinv;
@@ -97,14 +119,19 @@
                 ", tvis=" + tvis + ", inv=" + inv + ", vis=" + vis +
                 ", Arepeats=" + Arepeats + ", BDrepeats=" + BDrepeats +
                 ", ABmix=" + ABmix + ", retention: " + rtn + ", anno2: " +
-                et2 + ", src=" + source;
+                et2 + ", src=" + source + "\n    " + source.description;
 
-// Uncomment this block to run the tests but skip failing scenarios.
-//        // 8005681 - skip cases with repeated annotations on new, array, cast.
-//        if((source==3 || source==8 || source==9) && (ABmix || (Arepeats && BDrepeats))) {
-//            System.out.println(testDef+"\n8005681-skip repeated annotations on new,array,cast");
-//            return;
-//        }
+        if(
+// 8005681 - src1,2,3 - skip cases with repeated annotations on new, array, cast.
+            (( source.equals(srce.src1) || source.equals(srce.src2) ||
+              source.equals(srce.src3)) && (ABmix || (Arepeats && BDrepeats)))
+ // 8008928 - src4,5 - this change cause crash with t-a on anon class)
+            || (source.equals(srce.src4) || source.equals(srce.src5))
+          ) {
+            System.out.println(testDef + 
+                       "\n    8005681-skip repeated annotations on new,array,cast");
+            return;
+        }
 
         println(testDef);
         // Create test source and File.
@@ -123,6 +150,7 @@
         if(hasInnerClass) {
             StringBuffer sb = new StringBuffer(classFile.getAbsolutePath());
             classFile=new File(sb.insert(sb.lastIndexOf(".class"),innerClassname).toString());
+            println("classfile: " + classFile.getAbsolutePath());
         }
         ClassFile cf = ClassFile.read(classFile);
 
@@ -130,10 +158,16 @@
         test(cf);
 
         for (Field f : cf.fields) {
-            test(cf, f);
+            if(source.local)
+                test(cf, f, true);
+            else
+                test(cf,f);
         }
         for (Method m: cf.methods) {
-            test(cf, m);
+            if(source.local)
+                test(cf, m, true);
+            else
+                test(cf, m);
         }
         countAnnotations();
         if (errors > 0) {
@@ -149,7 +183,7 @@
     //
     String sourceString(String testname, String retentn, String annot2,
                         Boolean Arepeats, Boolean BDrepeats, Boolean ABmix,
-                        int src) {
+                        srce src) {
 
         String As = "@A", Bs = "@B", Ds = "@D";
         if(Arepeats) As = "@A @A";
@@ -198,7 +232,7 @@
 
         // Test case sources with sample generated source
         switch(src) {
-            case 3: // (repeating) type annotations on field in method body
+            case src1: // (repeating) type annotations on field in method body
                     /*
                      * class Test1 {
                      * Test1(){}
@@ -210,18 +244,19 @@
                      * }}
                       */
                 source = new String(
-                "class " + testname + " {\n" +
-                "" + testname +"(){} \n" +
-                "// type usage in method body \n" +
-                "String test("+testname+" this, " +
-                   "String param, String ... vararg) { \n" +
-                "    _As_ _Bs_\n    Object o = new _As_ _Bs_  String _As_ _Bs_  [3]; \n" +
-                "        return (_As_ _Bs_  String) null; \n" +
-                "} \n" +
-                "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
-                "\n\n";
-                break;
-            case 8: // (repeating) annotations on type parameters, bounds and  type arguments in new statement.
+                    "// " + src.description + "\n" +
+                    "class " + testname + " {\n" +
+                    "" + testname +"(){} \n" +
+                    "// type usage in method body \n" +
+                    "String test("+testname+" this, " +
+                       "String param, String ... vararg) { \n" +
+                    "    _As_ _Bs_\n    Object o = new _As_ _Bs_  String _As_ _Bs_  [3]; \n" +
+                    "        return (_As_ _Bs_  String) null; \n" +
+                    "} \n" +
+                    "} \n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n\n";
+                    break;
+            case src2: // (repeating) annotations on type parameters, bounds and  type arguments in new statement.
                     /*
                      * class Test2<T extends Object> {
                      *     Map<List<String>, Integer> map =
@@ -232,17 +267,17 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating) annotations on type parameters, bounds and  type arguments. \n" +
-                "class " + testname + "<T extends Object> {\n" +
-                "    Map<List<String>, Integer> map =\n" +
-                "        new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" +
-                "    Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" +
-                "    String test(" + testname + "<T> this) { return null;}\n" +
-                "    <T> String genericMethod(T t) { return null; }\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
-                "\n\n";
-            break;
-            case 9: // (repeating)annotations on type parameters of class, method return value in method.
+                    "// " + src.description + "\n" +
+                    "class " + testname + "<T extends Object> {\n" +
+                    "    Map<List<String>, Integer> map =\n" +
+                    "        new HashMap<_As_ _Bs_ List<_As_ _Bs_ String>, _As_ _Bs_ Integer>();\n" +
+                    "    Map<List<String>, Integer> map2 = new _As_ _Bs_ HashMap<>();\n" +
+                    "    String test(" + testname + "<T> this) { return null;}\n" +
+                    "    <T> String genericMethod(T t) { return null; }\n" +
+                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n\n";
+                break;
+            case src3: // (repeating)annotations on type parameters of class, method return value in method.
                     /*
                      * class Test3{
                      *     <E extends Comparable> Map<List<E>, E > foo(E e) {
@@ -258,24 +293,72 @@
                      * }
                      */
                 source = new String( source +
-                "// (repeating)annotations on type parameters of class, method return value in method. \n" +
-                "class "+ testname + "{\n" +
-                "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
-                "        class maptest <E> {\n" +                  // inner class $1maptest
-                "            Map<List<E>,E> getMap() { \n" +
-                "                Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" +
-                "                return Em;\n" +
-                "            }\n" +
-                "        }\n" +
-                "        return new maptest<E>().getMap();\n" +
-                "   }\n" +
-                "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
-                "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
-                "\n\n";
-                hasInnerClass=true;
-                innerClassname="$1maptest";
-            break;
-
+                    "// " + src.description + "\n" +
+                    "class "+ testname + "{\n" +
+                    "    <E extends Comparable> Map<List<E>, E > foo(E e) {\n" +
+                    "        class maptest <E> {\n" +                  // inner class $1maptest
+                    "            Map<List<E>,E> getMap() { \n" +
+                    "                Map<List<E>,E> Em = new HashMap<List<_As_ _Bs_ _Ds_ E>,_As_ _Bs_ _Ds_ E>();\n" +
+                    "                return Em;\n" +
+                    "            }\n" +
+                    "        }\n" +
+                    "        return new maptest<E>().getMap();\n" +
+                    "   }\n" +
+                    "   Map<List<String>,String> shm = foo(new String(\"hello\"));\n" +
+                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs).replace("_Ds_",Ds) +
+                    "\n\n";
+                    hasInnerClass=true;
+                    innerClassname="$1maptest";
+                break;
+            case src4: // (repeating)annotations on field in anonymous class
+                    /*
+                     * class Test95{
+                     *     void mtest( Test95 t){  }
+                     *     public void test() {
+                     *         mtest( new Test95() {
+                     *             @A @A @B @B String data2 = "test";
+                     *         });
+                     *     }
+                     * }
+                     */
+                source = new String( source +
+                    "// " + src.description + "\n" +
+                    "class "+ testname + "{\n" +
+                    "    void mtest( "+ testname + " t){  }\n" +
+                    "    public void test() {\n" +
+                    "        mtest( new "+ testname + "() {\n" +
+                    "            _As_ _Bs_ String data2 = \"test\";\n" +
+                    "        });\n" +
+                    "    }\n" +
+                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n\n";
+                    hasInnerClass=true;
+                    innerClassname="$1";
+                break;
+            case src5: // (repeating)annotations on method in anonymous class
+                    /*
+                     * class Test120{
+                     *     void mtest( Test120 t){  }
+                     *     public void test() {
+                     *         mtest( new Test120() {
+                     *             @A @B @A @B String m2(){return null;};
+                     *         });
+                     *     }
+                     */
+                source = new String( source +
+                    "// " + src.description + "\n" +
+                    "class "+ testname + "{\n" +
+                    "    void mtest( "+ testname + " t){  }\n" +
+                    "    public void test() {\n" +
+                    "        mtest( new "+ testname + "() {\n" +
+                    "            _As_ _Bs_ String m2(){return null;};\n" +
+                    "        });\n" +
+                    "    }\n" +
+                    "}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
+                    "\n\n";
+                    hasInnerClass=true;
+                    innerClassname="$1";
+                break;
         }
         return imports + source;
     }
--- a/test/tools/javac/annotations/typeAnnotations/classfile/DeadCode.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/DeadCode.java	Fri Mar 01 11:10:14 2013 -0800
@@ -49,7 +49,7 @@
             test(cf, f);
         }
         for (Method m: cf.methods) {
-            test(cf, m);
+            test(cf, m, true);
         }
 
         countAnnotations();
--- a/test/tools/javac/annotations/typeAnnotations/classfile/NewTypeArguments.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/NewTypeArguments.java	Fri Mar 01 11:10:14 2013 -0800
@@ -48,7 +48,7 @@
             test(cf, f);
         }
         for (Method m: cf.methods) {
-            test(cf, m);
+            test(cf, m, true);
         }
 
         countAnnotations();
--- a/test/tools/javac/annotations/typeAnnotations/classfile/TypeCasts.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/TypeCasts.java	Fri Mar 01 11:10:14 2013 -0800
@@ -50,7 +50,7 @@
             test(cf, f);
         }
         for (Method m: cf.methods) {
-            test(cf, m);
+            test(cf, m, true);
         }
 
         countAnnotations();
--- a/test/tools/javac/annotations/typeAnnotations/classfile/Wildcards.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/classfile/Wildcards.java	Fri Mar 01 11:10:14 2013 -0800
@@ -48,7 +48,7 @@
             test(cf, f);
         }
         for (Method m: cf.methods) {
-            test(cf, m);
+            test(cf, m,false);
         }
 
         countAnnotations();
--- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java	Fri Mar 01 11:10:14 2013 -0800
@@ -1,7 +1,6 @@
 /*
  * @test /nodynamiccopyright/
  * @bug 8006733 8006775
- * @ignore
  * @summary A static outer class cannot be annotated.
  * @author Werner Dietl
  * @compile/fail/ref=CantAnnotateStaticClass.out -XDrawDiagnostics CantAnnotateStaticClass.java
--- a/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/LazyConstantValue.java	Fri Mar 01 11:10:14 2013 -0800
@@ -27,7 +27,7 @@
  * @summary Type annotations in a lazy constant need to be attributed
  *   in the correct order.
  * @author Werner Dietl
- * @compile LazyConstantValue.java
+ * @compile/ref=LazyConstantValue.out LazyConstantValue.java
  */
 
 import java.lang.annotation.*;
@@ -40,5 +40,9 @@
     static final String[] lcv = new @TA String[0];
 }
 
+class ClassC {
+    static final Object o = (@TA Object) null;
+}
+
 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
 @interface TA {}
--- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.java	Fri Mar 01 11:10:14 2013 -0800
@@ -6,7 +6,7 @@
  * @compile/fail/ref=StaticMethods.out -XDrawDiagnostics StaticMethods.java
  */
 class StaticMethods {
-  static void main(@A StaticMethods this) { }
+  static void main(StaticMethods this) { }
 }
 
 @interface A { }
--- a/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/StaticMethods.out	Fri Mar 01 11:10:14 2013 -0800
@@ -1,2 +1,2 @@
-StaticMethods.java:9:37: compiler.err.annotation.type.not.applicable
-1 error
+StaticMethods.java:9:34: compiler.err.receiver.parameter.not.applicable
+1 error
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,19 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 1234567
+ * @summary ensure that declaration annotations are not allowed on
+ *   new array expressions
+ * @author Werner Dietl
+ * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
+ */
+class DeclarationAnnotation {
+    Object e1 = new @DA int[5];
+    Object e2 = new @DA String[42];
+    Object e3 = new @DA Object();
+
+    // The declaration annotation is only allowed for
+    // an anonymous class creation.
+    Object ok = new @DA Object() { };
+}
+
+@interface DA { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,4 @@
+DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable
+DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable
+DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable
+3 errors
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 1234567
+ * @summary ensure that declaration annotations are not allowed on
+ *   method receiver types
+ * @author Werner Dietl
+ * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+class DeclarationAnnotation {
+    void bad(@DA DeclarationAnnotation this) {}
+    void good(@TA DeclarationAnnotation this) {}
+}
+
+@interface DA { }
+
+@Target(ElementType.TYPE_USE)
+@interface TA { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/DeclarationAnnotation.out	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,2 @@
+DeclarationAnnotation.java:14:14: compiler.err.annotation.type.not.applicable
+1 error
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/Nesting.java	Fri Mar 01 11:10:14 2013 -0800
@@ -28,6 +28,11 @@
  * @author Werner Dietl
  * @compile Nesting.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE_USE)
 @interface A { }
 
 class Nesting {
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/StaticThings.out	Fri Mar 01 11:10:14 2013 -0800
@@ -1,5 +1,5 @@
-StaticThings.java:52:32: compiler.err.annotation.type.not.applicable
-StaticThings.java:54:37: compiler.err.annotation.type.not.applicable
-StaticThings.java:33:26: compiler.err.annotation.type.not.applicable
-StaticThings.java:36:28: compiler.err.annotation.type.not.applicable
+StaticThings.java:52:32: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:54:37: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:33:26: compiler.err.receiver.parameter.not.applicable
+StaticThings.java:36:28: compiler.err.receiver.parameter.not.applicable
 4 errors
\ No newline at end of file
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.java	Fri Mar 01 11:10:14 2013 -0800
@@ -29,6 +29,10 @@
  * @compile/fail/ref=WrongType.out -XDrawDiagnostics WrongType.java
  */
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE_USE)
 @interface A {}
 
 class WrongType {
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/WrongType.out	Fri Mar 01 11:10:14 2013 -0800
@@ -1,9 +1,9 @@
-WrongType.java:51:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
-WrongType.java:61:27: compiler.err.doesnt.exist: Outer
-WrongType.java:62:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
-WrongType.java:44:23: compiler.err.incorrect.receiver.type
-WrongType.java:46:23: compiler.err.incorrect.receiver.type
-WrongType.java:59:33: compiler.err.incorrect.receiver.type
-WrongType.java:60:31: compiler.err.incorrect.receiver.type
-WrongType.java:66:28: compiler.err.incorrect.receiver.type
+WrongType.java:55:15: compiler.err.cant.resolve.location: kindname.class, XYZ, , , (compiler.misc.location: kindname.class, WrongType, null)
+WrongType.java:65:27: compiler.err.doesnt.exist: Outer
+WrongType.java:66:31: compiler.err.cant.resolve.location: kindname.class, XY, , , (compiler.misc.location: kindname.class, WrongType, null)
+WrongType.java:48:23: compiler.err.incorrect.receiver.type
+WrongType.java:50:23: compiler.err.incorrect.receiver.type
+WrongType.java:63:33: compiler.err.incorrect.receiver.type
+WrongType.java:64:31: compiler.err.incorrect.receiver.type
+WrongType.java:70:28: compiler.err.incorrect.receiver.type
 8 errors
\ No newline at end of file
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.java	Fri Mar 01 11:10:14 2013 -0800
@@ -5,10 +5,15 @@
  * @author Mahmood Ali
  * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java
  */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
 class MissingAnnotationValue {
   void test() {
     new @A String();
   }
 }
 
+@Target(ElementType.TYPE_USE)
 @interface A { int field(); }
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.out	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/rest/MissingAnnotationValue.out	Fri Mar 01 11:10:14 2013 -0800
@@ -1,2 +1,2 @@
-MissingAnnotationValue.java:10:9: compiler.err.annotation.missing.default.value: A, field
+MissingAnnotationValue.java:14:9: compiler.err.annotation.missing.default.value: A, field
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,22 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 1234567
+ * @summary ensure that declaration annotations are not allowed on
+ *   wildcards
+ * @author Werner Dietl
+ * @compile/fail/ref=DeclarationAnnotation.out -XDrawDiagnostics DeclarationAnnotation.java
+ */
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+
+class DeclarationAnnotation {
+    List<@DA ? extends Object> bad;
+    List<@TA ? extends Object> good;
+}
+
+@interface DA { }
+
+@Target(ElementType.TYPE_USE)
+@interface TA { }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/failures/common/wildcards/DeclarationAnnotation.out	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,2 @@
+DeclarationAnnotation.java:15:10: compiler.err.annotation.type.not.applicable
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/newlocations/AnonymousClass.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.annotation.*;
+
+/*
+ * @test
+ * @bug 1234567
+ * @summary new type annotation location: anonymous class creation
+ * @author Werner Dietl
+ * @compile AnonymousClass.java
+ */
+class AnonymousClass {
+    Object o1 = new @TA Object() { };
+    // Declaration annotations are also allowed.
+    Object o2 = new @TA @DA Object() { };
+}
+
+@interface DA { }
+
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
+@interface TA { }
+
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
+@interface TB { }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Initializers.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
+
+/*
+ * @test
+ * @bug 1234567
+ * @summary Test population of reference info for instance and class initializers
+ * @author Werner Dietl
+ * @compile -g Driver.java ReferenceInfoUtil.java Initializers.java
+ * @run main Driver Initializers
+ */
+public class Initializers {
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TB", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
+    })
+    public String instanceInit1() {
+        return "class Test { { Object o = new @TA ArrayList<@TB String>(); } }";
+    }
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TB", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TD", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
+    })
+    public String instanceInit2() {
+        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
+                " { Object o = new @TC ArrayList<@TD String>(); } }";
+    }
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TB", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
+    })
+    public String staticInit1() {
+        return "class Test { static { Object o = new @TA ArrayList<@TB String>(); } }";
+    }
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TB", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TC", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TD", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TE", type = NEW, offset = ReferenceInfoUtil.IGNORE_VALUE),
+        @TADescription(annotation = "TF", type = NEW,
+                genericLocation = { 3, 0 }, offset = ReferenceInfoUtil.IGNORE_VALUE)
+    })
+    public String staticInit2() {
+        return "class Test { Object f = new @TA ArrayList<@TB String>(); " +
+                " static Object g = new @TC ArrayList<@TD String>(); " +
+                " static { Object o = new @TE ArrayList<@TF String>(); } }";
+    }
+
+    // TODO: test interaction with several constructors, especially non-initial constuctors.
+    // I don't think this kind of test is possible here.
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = CAST,
+                typeIndex = 0, offset = ReferenceInfoUtil.IGNORE_VALUE),
+    })
+    public String lazyConstantCast1() {
+        return "class Test { public static final Object o = (@TA Object) null; }";
+    }
+
+}
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/MultiCatch.java	Fri Mar 01 11:10:14 2013 -0800
@@ -26,7 +26,6 @@
 /*
  * @test
  * @bug 8006732 8006775
- * @ignore
  * @summary Test population of reference info for multicatch exception parameters
  * @author Werner Dietl
  * @compile -g Driver.java ReferenceInfoUtil.java MultiCatch.java
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java	Fri Mar 01 11:10:14 2013 -0800
@@ -831,4 +831,48 @@
                 "  }\n" +
                 "}}\n";
     }
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = CLASS_EXTENDS,
+                genericLocation = {}, typeIndex = -1),
+        @TADescription(annotation = "TB", type = CLASS_EXTENDS,
+                genericLocation = {3, 0}, typeIndex = -1),
+        @TADescription(annotation = "TC", type = CLASS_EXTENDS,
+                genericLocation = {3, 1}, typeIndex = -1),
+        @TADescription(annotation = "TD", type = CLASS_EXTENDS,
+                genericLocation = {1, 0}, typeIndex = -1),
+        @TADescription(annotation = "TE", type = CLASS_EXTENDS,
+                genericLocation = {1, 0, 3, 0}, typeIndex = -1),
+        @TADescription(annotation = "TF", type = CLASS_EXTENDS,
+                genericLocation = {1, 0, 3, 1}, typeIndex = -1)
+    })
+    @TestClass("GOuter$GInner$Test")
+    public String testExtends1() {
+        return "class GOuter<A, B> {\n" +
+                "  class GInner<X, Y> {\n" +
+                "    class Test extends @TA GOuter<@TB String, @TC String>.@TD GInner<@TE String, @TF String> {}" +
+                "  }" +
+                "}";
+    }
+
+    @TADescriptions({
+        @TADescription(annotation = "TA", type = CLASS_TYPE_PARAMETER,
+                genericLocation = {}, paramIndex = 0),
+        @TADescription(annotation = "TB", type = CLASS_TYPE_PARAMETER_BOUND,
+                genericLocation = {}, paramIndex = 0, boundIndex = 0),
+        @TADescription(annotation = "TC", type = FIELD,
+                genericLocation = {}),
+        @TADescription(annotation = "TD", type = FIELD,
+                genericLocation = {3, 0})
+    })
+    @TestClass("Test$1Nested")
+    public String testNestedInMethod1() {
+        return "class Test {\n" + 
+                "  void foobar() {\n" +
+                "    class Nested<@TA X extends @TB Object> {\n" +
+                "      @TC List<@TD Object> f;\n" +
+                "    }\n" +
+                "  }" +
+                "}";
+    }
 }
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/ReferenceInfoUtil.java	Fri Mar 01 11:10:14 2013 -0800
@@ -28,6 +28,7 @@
 
 import com.sun.tools.classfile.Attribute;
 import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.Code_attribute;
 import com.sun.tools.classfile.TypeAnnotation;
 import com.sun.tools.classfile.Field;
 import com.sun.tools.classfile.Method;
@@ -90,6 +91,20 @@
             RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
             annos.addAll(Arrays.asList(tAttr.annotations));
         }
+
+        int cindex = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
+        if (cindex != -1) {
+            Attribute cattr = m.attributes.get(cindex);
+            assert cattr instanceof Code_attribute;
+            Code_attribute cAttr = (Code_attribute)cattr;
+            index = cAttr.attributes.getIndex(cf.constant_pool, name);
+            if (index != -1) {
+                Attribute attr = cAttr.attributes.get(index);
+                assert attr instanceof RuntimeTypeAnnotations_attribute;
+                RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
+                annos.addAll(Arrays.asList(tAttr.annotations));
+            }
+        }
     }
 
     // test the result of Attributes.getIndex according to expectations
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Test.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,33 @@
+
+import java.util.*;
+import java.lang.annotation.*;
+
+class Test<K> { GOuter<@TC Object, String> entrySet() { return null; } }
+
+@interface A {}
+@interface B {}
+@interface C {}
+@interface D {}
+@interface E {}
+@interface F {}
+
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TA {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TB {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TC {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TD {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TE {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TF {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TG {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TH {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TI {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TJ {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TK {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TL {}
+@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface TM {}
+
+@Repeatable(RTAs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTA {}
+@Repeatable(RTBs.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTB {}
+@ContainerFor(RTA.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTAs { RTA[] value(); }
+@ContainerFor(RTB.class) @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface RTBs { RTB[] value(); }
+@Target(value={ElementType.TYPE,ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER,ElementType.CONSTRUCTOR,ElementType.LOCAL_VARIABLE})
+@interface Decl {}
--- a/test/tools/javac/lib/DPrinter.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javac/lib/DPrinter.java	Fri Mar 01 11:10:14 2013 -0800
@@ -469,6 +469,7 @@
                     indent(+1);
                     printSymbol("tsym", type.tsym, Details.SUMMARY);
                     printObject("constValue", type.constValue(), Details.SUMMARY);
+                    printObject("annotations", type.getAnnotationMirrors(), Details.SUMMARY);
                     type.accept(typeVisitor, null);
                     indent(-1);
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/processing/model/type/BasicAnnoTests.java	Fri Mar 01 11:10:14 2013 -0800
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug     1234567
+ * @summary Annotations on types
+ * @library /tools/javac/lib
+ * @build JavacTestingAbstractProcessor DPrinter BasicAnnoTests
+ * @compile/process -processor BasicAnnoTests -proc:only BasicAnnoTests.java 
+ */
+
+import java.io.PrintWriter;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.AnnotatedConstruct;
+import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.ExecutableType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.type.WildcardType;
+import javax.tools.Diagnostic.Kind;
+
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+
+/**
+ * The test scans this file looking for test cases annotated with @Test.
+ */
+public class BasicAnnoTests extends JavacTestingAbstractProcessor {
+    DPrinter dprinter;
+    PrintWriter out;
+    boolean verbose = true;
+    
+    @Override
+    public void init(ProcessingEnvironment pEnv) {
+        super.init(pEnv);
+        dprinter = new DPrinter(((JavacProcessingEnvironment) pEnv).getContext());
+        out = dprinter.out;
+    }
+
+    @Override
+    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+        TestElementScanner s = new TestElementScanner();
+        for (Element e: roundEnv.getRootElements()) {
+            s.scan(e);
+        }
+        return true;
+    }
+    
+    void error(Element e, String msg) {
+        messager.printMessage(Kind.ERROR, msg, e);
+        errors++;
+    }
+
+    int errors;
+    
+    /** 
+     * Scan an element looking for declarations annotated with @Test. 
+     * Run a TestTypeScanner on the annotations that are found.
+     */
+    class TestElementScanner extends ElementScanner<Void,Void> {
+        public Void scan(Element elem, Void ignore) {
+            AnnotationMirror test = getAnnotation(elem, Test.class.getName().replace('$', '.'));
+            if (test != null) {
+                out.println("Test: " + elem + " " + test);
+                TestTypeScanner s = new TestTypeScanner(elem, test);
+                s.scan(elem.asType(), null);
+                if (getPosn(test) >= s.count)
+                    error(elem, "position " + getPosn(test) + " not found");
+                if (!s.found) {
+                    dprinter.printSymbol("element", (Symbol) elem);
+                    dprinter.printType("type", (Type) elem.asType());
+                }
+                out.println();
+            }
+            return super.scan(elem, ignore);
+        }
+    }
+    
+    /**
+     * Scan the type of an element, looking for an annotation
+     * to match the expected annotation specified in the @Test annotation.
+     */
+    class TestTypeScanner extends TypeScanner<Void, Void> {
+        Element elem;
+        AnnotationMirror test;
+        int count = 0;
+        boolean found = false;
+        
+        TestTypeScanner(Element elem, AnnotationMirror test) {
+            this.elem = elem;
+            this.test = test;
+        }
+        
+        @Override
+        Void scan(TypeMirror t, Void ignore) {
+            if (t == null)
+                return DEFAULT_VALUE;
+            if (verbose)
+                out.println("scan " + count + ": " + t);
+            if (count == getPosn(test)) {
+                String annoType = getAnnoType(test);
+                AnnotationMirror anno = getAnnotation(t, annoType);
+                if (anno == null)
+                    error(elem, "annotation not found on " + count + ": " + t);
+                else {
+                    String v = getValue(anno, "value").toString();
+                    if (v.equals(getExpect(test))) {
+                        out.println("found " + anno + " as expected");
+                        found = true;
+                    } else
+                        error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
+                }
+            }
+            count++;
+            return super.scan(t, ignore);
+        }
+    }
+        
+    /** Get the position value from an @Test annotation mirror. */
+    static int getPosn(AnnotationMirror test) {
+        AnnotationValue v = getValue(test, "posn");
+        return (Integer) v.getValue();
+    }
+
+    /** Get the expect value from an @Test annotation mirror. */
+    static String getExpect(AnnotationMirror test) {
+        AnnotationValue v = getValue(test, "expect");
+        return (String) v.getValue();
+    }
+
+    /** Get the annoType value from an @Test annotation mirror. */
+    static String getAnnoType(AnnotationMirror test) {
+        AnnotationValue v = getValue(test, "annoType");
+        TypeMirror m = (TypeMirror) v.getValue();
+        return m.toString();
+    }
+    
+    /**
+     * Get a specific annotation mirror from an annotated construct.
+     */
+    static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
+        for (AnnotationMirror m: e.getAnnotationMirrors()) {
+            TypeElement te = (TypeElement) m.getAnnotationType().asElement();
+            if (te.getQualifiedName().contentEquals(name)) {
+                return m;
+            }
+        }
+        return null;
+    }
+
+    /** 
+     * Get a specific value from an annotation mirror. 
+     */
+    static AnnotationValue getValue(AnnotationMirror anno, String name) {
+        Map<? extends ExecutableElement, ? extends AnnotationValue> map = anno.getElementValues();
+        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e: map.entrySet()) {
+            if (e.getKey().getSimpleName().contentEquals(name)) {
+                return e.getValue();
+            }
+        } 
+        return null;
+    }
+    
+    /**
+     * The Language Model API does not provide a type scanner, so provide
+     * one sufficient for our needs.
+     */
+    static class TypeScanner<R, P> extends SimpleTypeVisitor<R, P> {
+        @Override 
+        public R visitArray(ArrayType t, P p) {
+            scan(t.getComponentType(), p);
+            return super.visitArray(t, p);
+        }
+        
+        @Override 
+        public R visitExecutable(ExecutableType t, P p) {
+            scan(t.getReceiverType());
+            //out.println("  params: " + t.getParameterTypes());
+            scan(t.getParameterTypes(), p);
+            //out.println("  return: " + t.getReturnType());
+            scan(t.getReturnType(), p);
+            //out.println("  throws: " + t.getThrownTypes());
+            scan(t.getThrownTypes(), p);
+            return super.visitExecutable(t, p);
+        }
+        
+        @Override 
+        public R visitTypeVariable(TypeVariable t, P p) {
+            scan(t.getLowerBound(), p);
+            scan(t.getUpperBound(), p);
+            return super.visitTypeVariable(t, p);
+        }
+        
+        @Override 
+        public R visitWildcard(WildcardType t, P p) {
+            scan(t.getExtendsBound(), p);
+            scan(t.getSuperBound(), p);
+            return super.visitWildcard(t, p);
+        }
+        
+        R scan(TypeMirror t) {
+            return scan(t, null);
+        }
+        
+        R scan(TypeMirror t, P p) {
+            return (t == null) ? DEFAULT_VALUE : t.accept(this, p);
+        }
+        
+        R scan(Iterable<? extends TypeMirror> iter, P p) {
+            if (iter == null)
+                return DEFAULT_VALUE;
+            R result = DEFAULT_VALUE;
+            for (TypeMirror t: iter) 
+                result = scan(t, p);
+            return result;
+        }
+    }
+
+    /** Annotation to identify test cases. */
+    @interface Test {
+        /** Where to look for the annotation, expressed as a scan index. */
+        int posn();
+        /** The annotation to look for. */
+        Class<? extends Annotation> annoType();
+        /** The string representation of the annotation's value. */
+        String expect();
+    }
+
+    /** Type annotation to use in test cases. */
+    @Target(ElementType.TYPE_USE)
+    public @interface TA {
+	int value();
+    }
+
+    @Test(posn=0, annoType=TA.class, expect="1")  
+    public @TA(1) int f1;
+    
+    @Test(posn=0, annoType=TA.class, expect="2")  
+    public int @TA(2) [] f2;
+    
+    @Test(posn=1, annoType=TA.class, expect="3")  
+    public @TA(3) int [] f3;
+    
+    @Test(posn=1, annoType=TA.class, expect="4")  
+    public int m1(@TA(4) float a) throws Exception { return 0; }
+    
+    @Test(posn=2, annoType=TA.class, expect="5")  
+    public @TA(5) int m2(float a) throws Exception { return 0; }
+    
+    @Test(posn=3, annoType=TA.class, expect="6")  
+    public int m3(float a) throws @TA(6) Exception { return 0; }
+}
--- a/test/tools/javap/typeAnnotations/NewArray.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javap/typeAnnotations/NewArray.java	Fri Mar 01 11:10:14 2013 -0800
@@ -27,10 +27,11 @@
 /*
  * @test NewArray
  * @bug 6843077
- * @summary test that all type annotations are present in the classfile
+ * @summary Test type annotations on local array are in method's code attribute.
  */
 
 public class NewArray {
+
     public static void main(String[] args) throws Exception {
         new NewArray().run();
     }
@@ -40,10 +41,6 @@
         File classFile = compileTestFile(javaFile);
 
         ClassFile cf = ClassFile.read(classFile);
-        test(cf);
-        for (Field f : cf.fields) {
-            test(cf, f);
-        }
         for (Method m: cf.methods) {
             test(cf, m);
         }
@@ -55,66 +52,34 @@
         System.out.println("PASSED");
     }
 
-    void test(ClassFile cf) {
-        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
-    }
-
     void test(ClassFile cf, Method m) {
         test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
         test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
     }
 
-    void test(ClassFile cf, Field m) {
-        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
-    }
-
     // test the result of Attributes.getIndex according to expectations
     // encoded in the method's name
-    void test(ClassFile cf, String name, boolean visible) {
-        int index = cf.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = cf.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
-        }
-    }
+    void test(ClassFile cf, Method m, String name, boolean visible) {
+        Attribute attr = null;
+        Code_attribute cAttr = null;
+        RuntimeTypeAnnotations_attribute tAttr = null;
 
-    // test the result of Attributes.getIndex according to expectations
-    // encoded in the method's name
-    void test(ClassFile cf, Method m, String name, boolean visible) {
-        int index = m.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = m.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
-        }
-    }
-
-    // test the result of Attributes.getIndex according to expectations
-    // encoded in the method's name
-    void test(ClassFile cf, Field m, String name, boolean visible) {
-        int index = m.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = m.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
+        int index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
+        if(index!= -1) {
+            attr = m.attributes.get(index);
+            assert attr instanceof Code_attribute;
+            cAttr = (Code_attribute)attr;
+            index = cAttr.attributes.getIndex(cf.constant_pool, name); 
+            if(index!= -1) {
+                attr = cAttr.attributes.get(index);
+                assert attr instanceof RuntimeTypeAnnotations_attribute;
+                tAttr = (RuntimeTypeAnnotations_attribute)attr;
+                all += tAttr.annotations.length;
+                if (visible)
+                    visibles += tAttr.annotations.length;
+                else
+                    invisibles += tAttr.annotations.length;
+               }
         }
     }
 
@@ -124,14 +89,12 @@
         out.println("import java.lang.annotation.*;");
         out.println("import java.util.*;");
         out.println("class Test { ");
-        out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
-        out.println("  @interface A { }");
-
-        out.println(" void test() {");
-        out.println("  Object a = new @A String @A [5] @A  [];");
-        out.println("  Object b = new @A String @A [5] @A [3];");
-        out.println("  Object c = new @A String @A [] @A [] {};");
-        out.println(" }");
+        out.println("  @Target(ElementType.TYPE_USE) @interface A { }");
+        out.println("  void test() {");
+        out.println("    Object a = new @A String @A [5] @A  [];");
+        out.println("    Object b = new @A String @A [5] @A [3];");
+        out.println("    Object c = new @A String @A [] @A [] {};");
+        out.println("  }");
         out.println("}");
 
         out.close();
--- a/test/tools/javap/typeAnnotations/Presence.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javap/typeAnnotations/Presence.java	Fri Mar 01 11:10:14 2013 -0800
@@ -91,17 +91,40 @@
     // test the result of Attributes.getIndex according to expectations
     // encoded in the method's name
     void test(ClassFile cf, Method m, String name, boolean visible) {
+        Attribute attr = null;
+        Code_attribute cAttr = null;
+        RuntimeTypeAnnotations_attribute tAttr = null;
+
+        // collect annotations attributes on method
         int index = m.attributes.getIndex(cf.constant_pool, name);
         if (index != -1) {
-            Attribute attr = m.attributes.get(index);
+            attr = m.attributes.get(index);
             assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
+            tAttr = (RuntimeTypeAnnotations_attribute)attr;
             all += tAttr.annotations.length;
             if (visible)
                 visibles += tAttr.annotations.length;
             else
                 invisibles += tAttr.annotations.length;
         }
+        // collect annotations from method's code attribute
+        index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
+        if(index!= -1) {
+            attr = m.attributes.get(index);
+            assert attr instanceof Code_attribute;
+            cAttr = (Code_attribute)attr;
+            index = cAttr.attributes.getIndex(cf.constant_pool, name); 
+            if(index!= -1) {
+                attr = cAttr.attributes.get(index);
+                assert attr instanceof RuntimeTypeAnnotations_attribute;
+                tAttr = (RuntimeTypeAnnotations_attribute)attr;
+                all += tAttr.annotations.length;
+                if (visible)
+                    visibles += tAttr.annotations.length;
+                else
+                    invisibles += tAttr.annotations.length;
+               }
+        }        
     }
 
     // test the result of Attributes.getIndex according to expectations
@@ -121,12 +144,12 @@
     }
 
     File writeTestFile() throws IOException {
-        File f = new File("Test.java");
+        File f = new File("TestPresence.java");
         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
         out.println("import java.util.*;");
         out.println("import java.lang.annotation.*;");
 
-        out.println("class Test<@Test.A T extends @Test.A List<@Test.A String>> { ");
+        out.println("class TestPresence<@TestPresence.A T extends @TestPresence.A List<@TestPresence.A String>> { ");
         out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
         out.println("  @interface A { }");
 
@@ -134,7 +157,7 @@
 
         out.println("  <@A TM extends @A List<@A String>>");
         out.println("  Map<@A String, @A List<@A String>>");
-        out.println("  method(@A Test<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
+        out.println("  method(@A TestPresence<T> this, List<@A String> @A [] param1, String @A [] @A ... param2)");
         out.println("  throws @A Exception {");
         out.println("    @A String lc1 = null;");
         out.println("    @A List<@A String> lc2 = null;");
--- a/test/tools/javap/typeAnnotations/TypeCasts.java	Thu Feb 28 14:05:52 2013 +0000
+++ b/test/tools/javap/typeAnnotations/TypeCasts.java	Fri Mar 01 11:10:14 2013 -0800
@@ -41,10 +41,6 @@
         File classFile = compileTestFile(javaFile);
 
         ClassFile cf = ClassFile.read(classFile);
-        test(cf);
-        for (Field f : cf.fields) {
-            test(cf, f);
-        }
         for (Method m: cf.methods) {
             test(cf, m);
         }
@@ -56,68 +52,37 @@
         System.out.println("PASSED");
     }
 
-    void test(ClassFile cf) {
-        test(cf, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test(cf, Attribute.RuntimeInvisibleTypeAnnotations, false);
-    }
-
     void test(ClassFile cf, Method m) {
         test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
         test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
     }
 
-    void test(ClassFile cf, Field m) {
-        test(cf, m, Attribute.RuntimeVisibleTypeAnnotations, true);
-        test(cf, m, Attribute.RuntimeInvisibleTypeAnnotations, false);
-    }
-
-    // test the result of Attributes.getIndex according to expectations
-    // encoded in the method's name
-    void test(ClassFile cf, String name, boolean visible) {
-        int index = cf.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = cf.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
-        }
-    }
 
     // test the result of Attributes.getIndex according to expectations
     // encoded in the method's name
     void test(ClassFile cf, Method m, String name, boolean visible) {
-        int index = m.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = m.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
+        Attribute attr = null;
+        Code_attribute cAttr = null;
+
+        int index = m.attributes.getIndex(cf.constant_pool, Attribute.Code);
+        if(index!= -1) {
+            attr = m.attributes.get(index);
+            assert attr instanceof Code_attribute;
+            cAttr = (Code_attribute)attr;
+            index = cAttr.attributes.getIndex(cf.constant_pool, name); 
+            if(index!= -1) {
+                attr = cAttr.attributes.get(index);
+                assert attr instanceof RuntimeTypeAnnotations_attribute;
+                RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
+                all += tAttr.annotations.length;
+                if (visible)
+                    visibles += tAttr.annotations.length;
+                else
+                    invisibles += tAttr.annotations.length;
+               }
         }
     }
 
-    // test the result of Attributes.getIndex according to expectations
-    // encoded in the method's name
-    void test(ClassFile cf, Field m, String name, boolean visible) {
-        int index = m.attributes.getIndex(cf.constant_pool, name);
-        if (index != -1) {
-            Attribute attr = m.attributes.get(index);
-            assert attr instanceof RuntimeTypeAnnotations_attribute;
-            RuntimeTypeAnnotations_attribute tAttr = (RuntimeTypeAnnotations_attribute)attr;
-            all += tAttr.annotations.length;
-            if (visible)
-                visibles += tAttr.annotations.length;
-            else
-                invisibles += tAttr.annotations.length;
-        }
-    }
 
 
     File writeTestFile() throws IOException {
@@ -125,8 +90,7 @@
         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
         out.println("import java.lang.annotation.*;");
         out.println("class Test { ");
-        out.println("  @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})");
-        out.println("  @interface A { }");
+        out.println("  @Target(ElementType.TYPE_USE) @interface A { }");
 
         out.println("  void emit() {");
         out.println("    Object o = null;");