changeset 2264:de1519daf492

8008762: Type annotation on inner class in anonymous class show up as regular annotations. Fixed by visiting classes that are nested within anonymous classes, once just the signature and once the whole class.
author wmdietl
date Sun, 24 Feb 2013 13:06:56 -0800
parents 4e9f487137b9
children d92cbf4c1699
files src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sat Feb 23 23:09:34 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java	Sun Feb 24 13:06:56 2013 -0800
@@ -925,11 +925,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);
@@ -1098,6 +1102,13 @@
             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);
         }