langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 23800 f7ffcfe938f2
parent 23133 a58476887b3d
child 23803 98c4ebaddefc
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sat Mar 29 11:06:33 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Mar 31 21:27:25 2014 +0200
@@ -161,6 +161,7 @@
         this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods();
         this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
         this.allowTypeAnnotations = source.allowTypeAnnotations();
+        this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams();
         this.keepDocComments = keepDocComments;
         docComments = newDocCommentTable(keepDocComments, fac);
         this.keepLineMap = keepLineMap;
@@ -254,6 +255,10 @@
      */
     boolean allowTypeAnnotations;
 
+    /** Switch: should we allow annotations after the method type parameters?
+     */
+    boolean allowAnnotationsAfterTypeParams;
+
     /** Switch: is "this" allowed as an identifier?
      * This is needed to parse receiver types.
      */
@@ -2026,7 +2031,7 @@
     /** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
      */
     JCExpression creator(int newpos, List<JCExpression> typeArgs) {
-        List<JCAnnotation> newAnnotations = annotationsOpt(Tag.ANNOTATION);
+        List<JCAnnotation> newAnnotations = typeAnnotationsOpt();
 
         switch (token.kind) {
         case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
@@ -3464,6 +3469,7 @@
                     nextToken();
                 } else {
                     if (annosAfterParams.nonEmpty()) {
+                        checkAnnotationsAfterTypeParams(annosAfterParams.head.pos);
                         mods.annotations = mods.annotations.appendList(annosAfterParams);
                         if (mods.pos == Position.NOPOS)
                             mods.pos = mods.annotations.head.pos;
@@ -4063,6 +4069,12 @@
             allowTypeAnnotations = true;
         }
     }
+    void checkAnnotationsAfterTypeParams(int pos) {
+        if (!allowAnnotationsAfterTypeParams) {
+            log.error(pos, "annotations.after.type.params.not.supported.in.source", source.name);
+            allowAnnotationsAfterTypeParams = true;
+        }
+    }
 
     /*
      * a functional source tree and end position mappings