changeset 2366:0826f546fbdd

Simplify handling of anonymous class - preventing an assertion violation and still passing previous tests. Expand test case to not depend on repeating annotations.
author wmdietl
date Sun, 31 Mar 2013 11:33:19 -0700
parents 0830284d56fb
children a41491fd7864
files src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java test/tools/javac/annotations/typeAnnotations/failures/T8009360.java
diffstat 2 files changed, 6 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Tue Mar 26 18:32:11 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Mar 31 11:33:19 2013 -0700
@@ -287,11 +287,6 @@
                 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);
 
@@ -317,33 +312,6 @@
             }
         }
 
-        // 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,
@@ -977,15 +945,11 @@
         // 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 = !isAnonClass;
+
             if (sigOnly) {
                 scan(tree.mods);
                 scan(tree.typarams);
@@ -1206,12 +1170,6 @@
             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);
         }
 
--- a/test/tools/javac/annotations/typeAnnotations/failures/T8009360.java	Tue Mar 26 18:32:11 2013 +0100
+++ b/test/tools/javac/annotations/typeAnnotations/failures/T8009360.java	Sun Mar 31 11:33:19 2013 -0700
@@ -35,9 +35,10 @@
     Object mtest( Test1<T> t){ return null; }
     public void test() {
         mtest( new Test1<T>() {
-                @A String data1 = "test";    //ok
-                @A @A String data2 = "test"; //ok
-                @A @B String data3 = "test"; //AssertionError
+                @A String data1 = "test";    // ok
+                @A @A String data2 = "test"; // ok
+                @A @B String data3 = "test"; // was AssertionError
+                @B @C String data4 = "test"; // was AssertionError
            });
    }
 }
@@ -45,3 +46,4 @@
 @Target({TYPE_USE,FIELD}) @Repeatable( AC.class) @interface A { }
 @Target({TYPE_USE,FIELD}) @interface AC { A[] value(); }
 @Target({TYPE_USE}) @interface B { }
+@Target({TYPE_USE, FIELD}) @interface C { }