@@ -788,7 +788,7 @@ trait Parsers extends NewScanners with MarkupParsers {
788788 }
789789 }
790790
791- /** AnnotType ::= SimpleType Annotations
791+ /** AnnotType ::= SimpleType {Annotation}
792792 * SimpleType ::= SimpleType TypeArgs
793793 * | SimpleType `#' Id
794794 * | StableId
@@ -797,13 +797,6 @@ trait Parsers extends NewScanners with MarkupParsers {
797797 * | WildcardType
798798 */
799799 def annotType (isPattern : Boolean ): Tree = placeholderTypeBoundary {
800- val annots1 = annotations()
801- if (! annots1.isEmpty)
802- deprecationWarning(
803- annots1.head.pos,
804- " Type annotations should now follow the type" )
805- // deprecated on August 13, 2007
806-
807800 val pos = inCurrentPos
808801
809802 val t : Tree = annotTypeRest(pos, isPattern,
@@ -821,10 +814,7 @@ trait Parsers extends NewScanners with MarkupParsers {
821814 case _ => convertToTypeId(r)
822815 }
823816 })
824-
825- val annots2 = annotations()
826- val annots = annots1 ::: annots2
827- (t /: annots) (makeAnnotated)
817+ (t /: annotations(false )) (makeAnnotated)
828818 }
829819
830820 def annotTypeRest (pos : Int , isPattern : Boolean , t : Tree ): Tree =
@@ -1038,8 +1028,8 @@ trait Parsers extends NewScanners with MarkupParsers {
10381028 } else if (inToken == COLON ) {
10391029 t = stripParens(t)
10401030 val pos = inSkipToken
1041- val annots = annotations()
10421031 if (inToken == USCORE ) {
1032+ // todo: need to handle case where USCORE is a wildcard in a type
10431033 val pos1 = inSkipToken
10441034 if (isIdent && inName == nme.STAR ) {
10451035 inNextToken
@@ -1049,7 +1039,9 @@ trait Parsers extends NewScanners with MarkupParsers {
10491039 } else {
10501040 syntaxErrorOrIncomplete(" `*' expected" , true )
10511041 }
1052- } else if (annots.isEmpty || isTypeIntro) {
1042+ } else if (in.token == AT ) {
1043+ t = (t /: annotations(false )) (makeAnnotated)
1044+ } else {
10531045 t = atPos(pos) {
10541046 val tpt = if (location != Local ) compoundType(false ) else typ()
10551047 if (isWildcard(t))
@@ -1059,10 +1051,8 @@ trait Parsers extends NewScanners with MarkupParsers {
10591051 }
10601052 // this does not correspond to syntax, but is necessary to
10611053 // accept closures. We might restrict closures to be between {...} only!
1062- Typed (t, ( tpt /: annots) (makeAnnotated) )
1054+ Typed (t, tpt)
10631055 }
1064- } else {
1065- t = (t /: annots) (makeAnnotated)
10661056 }
10671057 } else if (inToken == MATCH ) {
10681058 t = atPos(inSkipToken) {
@@ -1280,6 +1270,8 @@ trait Parsers extends NewScanners with MarkupParsers {
12801270 */
12811271 def enumerators (): List [Enumerator ] = {
12821272 val newStyle = inToken != VAL // todo: deprecate old style
1273+ // if (!newStyle)
1274+ // deprecationWarning(inCurrentPos, "for (val x <- ... ) has been deprecated; use for (x <- ... ) instead")
12831275 val enums = new ListBuffer [Enumerator ]
12841276 generator(enums, false )
12851277 while (isStatSep) {
@@ -1576,29 +1568,15 @@ trait Parsers extends NewScanners with MarkupParsers {
15761568 loop(NoMods )
15771569 }
15781570
1579- /** Annotations ::= {Annotation}
1580- * Annotation ::= `@' AnnotationExpr [nl]
1571+ /** Annotations ::= {Annotation [nl] }
1572+ * Annotation ::= `@' AnnotationExpr
15811573 */
1582- def annotations (): List [Annotation ] = {
1574+ def annotations (skipNewLines : Boolean ): List [Annotation ] = {
15831575 var annots = new ListBuffer [Annotation ]
1584- if (inToken == LBRACKET ) {
1585- deprecationWarning(in.currentPos, " The [attribute] syntax has been deprecated; use @annotation instead" )
1586- while (inToken == LBRACKET ) {
1587- inNextToken
1588- annots += annotation()
1589- while (inToken == COMMA ) {
1590- inNextToken
1591- annots += annotation()
1592- }
1593- accept(RBRACKET )
1594- newLineOpt()
1595- }
1596- } else {
1597- while (inToken == AT ) {
1598- inNextToken
1599- annots += annotation()
1600- newLineOpt()
1601- }
1576+ while (inToken == AT ) {
1577+ inNextToken
1578+ annots += annotationExpr()
1579+ if (skipNewLines) newLineOpt()
16021580 }
16031581 annots.toList
16041582 }
@@ -1617,10 +1595,10 @@ trait Parsers extends NewScanners with MarkupParsers {
16171595 exps.toList
16181596 }
16191597
1620- /** Annotation ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}']
1598+ /** AnnotationExpr ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}']
16211599 * NameValuePair ::= val id `=' PrefixExpr
16221600 */
1623- def annotation (): Annotation = {
1601+ def annotationExpr (): Annotation = {
16241602 def nameValuePair (): Tree = {
16251603 var pos = inCurrentPos
16261604 accept(VAL )
@@ -1654,11 +1632,11 @@ trait Parsers extends NewScanners with MarkupParsers {
16541632 /** ParamClauses ::= {ParamClause} [[nl] `(' implicit Params `)']
16551633 * ParamClause ::= [nl] `(' [Params] ')'
16561634 * Params ::= Param {`,' Param}
1657- * Param ::= Annotations Id [`:' ParamType]
1635+ * Param ::= {Annotation} Id [`:' ParamType]
16581636 * ClassParamClauses ::= {ClassParamClause} [[nl] `(' implicit ClassParams `)']
16591637 * ClassParamClause ::= [nl] `(' [ClassParams] ')'
16601638 * ClassParams ::= ClassParam {`,' ClassParam}
1661- * ClassParam ::= Annotations [{Modifier} (`val' | `var')] Id [`:' ParamType]
1639+ * ClassParam ::= {Annotation} [{Modifier} (`val' | `var')] Id [`:' ParamType]
16621640 */
16631641 def paramClauses (owner : Name , implicitViews : List [Tree ], ofCaseClass : Boolean ): List [List [ValDef ]] = {
16641642 var implicitmod = 0
@@ -1667,7 +1645,7 @@ trait Parsers extends NewScanners with MarkupParsers {
16671645 var pos = inCurrentPos
16681646
16691647 {
1670- val annots = annotations()
1648+ val annots = annotations(false )
16711649 var mods = Modifiers (Flags .PARAM )
16721650 if (owner.isTypeName) {
16731651 mods = modifiers() | Flags .PARAMACCESSOR
@@ -1945,7 +1923,7 @@ trait Parsers extends NewScanners with MarkupParsers {
19451923 }
19461924 /** IDE hook: for non-local defs or dcls with modifiers and annotations */
19471925 def nonLocalDefOrDcl : List [Tree ] = {
1948- val annots = annotations()
1926+ val annots = annotations(true )
19491927 defOrDcl(modifiers() withAnnotations annots)
19501928 }
19511929
@@ -2142,7 +2120,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21422120
21432121 /** Hook for IDE, for top-level classes/objects */
21442122 def topLevelTmplDef : Tree = {
2145- val annots = annotations()
2123+ val annots = annotations(true )
21462124 val mods = modifiers() withAnnotations annots
21472125 tmplDef(mods)
21482126 }
@@ -2170,7 +2148,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21702148 }
21712149 }
21722150
2173- /** ClassDef ::= Id [TypeParamClause] Annotations
2151+ /** ClassDef ::= Id [TypeParamClause] {Annotation}
21742152 [AccessModifier] ClassParamClauses RequiresTypeOpt ClassTemplateOpt
21752153 * TraitDef ::= Id [TypeParamClause] RequiresTypeOpt TraitTemplateOpt
21762154 */
@@ -2188,7 +2166,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21882166 syntaxError(" traits cannot have type parameters with <% bounds" , false )
21892167 implicitClassViews = List ()
21902168 }
2191- val constrAnnots = annotations()
2169+ val constrAnnots = annotations(false )
21922170 val (constrMods, vparamss) =
21932171 if (mods.hasFlag(Flags .TRAIT )) (Modifiers (Flags .TRAIT ), List ())
21942172 else (accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags .CASE )))
@@ -2444,7 +2422,7 @@ trait Parsers extends NewScanners with MarkupParsers {
24442422
24452423 /** overridable IDE hook for local definitions of blockStatSeq */
24462424 def localDef : List [Tree ] = {
2447- val annots = annotations()
2425+ val annots = annotations(true )
24482426 val mods = localModifiers() withAnnotations annots
24492427 if (! (mods hasFlag ~ (Flags .IMPLICIT | Flags .LAZY ))) defOrDcl(mods)
24502428 else List (tmplDef(mods))
0 commit comments