changeset 354:e4d42305296e

permit annotations on wildcards
author mali
date Fri, 20 Feb 2009 21:40:55 -0500
parents 67c75844461f
children f7d2ff026493
files src/share/classes/com/sun/tools/javac/parser/JavacParser.java test/tools/javac/typeAnnotations/newlocations/Wildcards.java
diffstat 2 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Feb 20 15:10:19 2009 -0500
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Feb 20 21:40:55 2009 -0500
@@ -591,13 +591,20 @@
      * parsing annotations.
      */
     public JCExpression parseType() {
+        return parseType(List.<JCAnnotation>nil());
+    }
+
+    public JCExpression parseType(List<JCAnnotation> annotations) {
         int prevmode = mode;
         mode = TYPE;
 
         // JSR 308: Parse type annotations, and push the (possibly empty)
         // annotation list to typeAnnotations, where it may be consumed during
         // parsing of array types
-        final List<JCAnnotation> typeAnnos = typeAnnotationsOpt();
+        List<JCAnnotation> typeAnnos = typeAnnotationsOpt();
+        if (annotations != null)
+            typeAnnos = typeAnnos.prependList(annotations);
+
         typeAnnotations.prepend(typeAnnos);
 
         JCExpression result = unannotatedType();
@@ -1391,17 +1398,19 @@
      *               | "?" SUPER Type
      */
     JCExpression typeArgument() {
-        if (S.token() != QUES) return parseType();
+        List<JCAnnotation> annotations = typeAnnotationsOpt();
+        if (S.token() != QUES) return parseType(annotations);
         int pos = S.pos();
         S.nextToken();
+        JCExpression result;
         if (S.token() == EXTENDS) {
             TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.EXTENDS));
             S.nextToken();
-            return F.at(pos).Wildcard(t, parseType());
+            result = F.at(pos).Wildcard(t, parseType());
         } else if (S.token() == SUPER) {
             TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.SUPER));
             S.nextToken();
-            return F.at(pos).Wildcard(t, parseType());
+            result = F.at(pos).Wildcard(t, parseType());
         } else if (S.token() == IDENTIFIER) {
             //error recovery
             reportSyntaxError(S.prevEndPos(), "expected3",
@@ -1409,11 +1418,14 @@
             TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
             JCExpression wc = toP(F.at(pos).Wildcard(t, null));
             JCIdent id = toP(F.at(S.pos()).Ident(ident()));
-            return F.at(pos).Erroneous(List.<JCTree>of(wc, id));
+            result = F.at(pos).Erroneous(List.<JCTree>of(wc, id));
         } else {
             TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
-            return toP(F.at(pos).Wildcard(t, null));
+            result = toP(F.at(pos).Wildcard(t, null));
         }
+        if (!annotations.isEmpty())
+            result = toP(F.at(annotations.head.pos).AnnotatedType(annotations,result));
+        return result;
     }
 
     JCTypeApply typeArguments(JCExpression t) {
--- a/test/tools/javac/typeAnnotations/newlocations/Wildcards.java	Fri Feb 20 15:10:19 2009 -0500
+++ b/test/tools/javac/typeAnnotations/newlocations/Wildcards.java	Fri Feb 20 21:40:55 2009 -0500
@@ -27,7 +27,7 @@
  * @author Mahmood Ali
  * @compile Wildcards.java
  */
-class Test {
+class BoundTest {
   void wcExtends(MyList<? extends @A String> l) { }
   void wcSuper(MyList<? super @A String> l) { }
 
@@ -36,7 +36,7 @@
   MyList<? extends @A MyList<? super @B("m") String>> complex() { return null; }
 }
 
-class WithValue {
+class BoundWithValue {
   void wcExtends(MyList<? extends @B("m") String> l) { }
   void wcSuper(MyList<? super @B(value="m") String> l) { }
 
@@ -45,6 +45,24 @@
   MyList<? extends @B("m") MyList<? super @B("m") String>> complex() { return null; }
 }
 
+class SelfTest {
+  void wcExtends(MyList<@A ?> l) { }
+  void wcSuper(MyList<@A ?> l) { }
+
+  MyList<@A ?> returnWcExtends() { return null; }
+  MyList<@A ?> returnWcSuper() { return null; }
+  MyList<@A ? extends @A MyList<@B("m") ?>> complex() { return null; }
+}
+
+class SelfWithValue {
+  void wcExtends(MyList<@B("m") ?> l) { }
+  void wcSuper(MyList<@B(value="m") ?> l) { }
+
+  MyList<@B("m") ?> returnWcExtends() { return null; }
+  MyList<@B(value="m") ?> returnWcSuper() { return null; }
+  MyList<@B("m") ? extends MyList<@B("m") ? super String>> complex() { return null; }
+}
+
 class MyList<K> { }
 
 @interface A { }