parser_nodes: promote `get_annotation` and `AAnnotation::name` from `annotation`
authorJean Privat <jean@pryen.org>
Thu, 18 Dec 2014 20:01:43 +0000 (15:01 -0500)
committerJean Privat <jean@pryen.org>
Thu, 18 Dec 2014 21:28:11 +0000 (16:28 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/annotation.nit
src/parser/parser_nodes.nit

index f5d2447..19653a3 100644 (file)
@@ -34,29 +34,9 @@ redef class Prod
                end
                return res.first
        end
-
-       # Return all its annotations of a given name in the order of their declaration
-       # Retun an empty array if no such an annotation.
-       fun get_annotations(name: String): Array[AAnnotation]
-       do
-               var res = new Array[AAnnotation]
-               var nas = n_annotations
-               if nas == null then return res
-               for na in nas.n_items do
-                       if na.name != name then continue
-                       res.add(na)
-               end
-               return res
-       end
 end
 
 redef class AAnnotation
-       # The name of the annotation
-       fun name: String
-       do
-               return n_atid.n_id.text
-       end
-
        # Get the single argument of `self` as a `String`.
        # Raise error and return null on any inconsistency.
        fun arg_as_string(modelbuilder: ModelBuilder): nullable String
index a7f8071..1cc8a31 100644 (file)
@@ -269,6 +269,20 @@ abstract class Prod
        # All the annotations attached directly to the node
        var n_annotations: nullable AAnnotations = null is writable
 
+       # Return all its annotations of a given name in the order of their declaration
+       # Retun an empty array if no such an annotation.
+       fun get_annotations(name: String): Array[AAnnotation]
+       do
+               var res = new Array[AAnnotation]
+               var nas = n_annotations
+               if nas == null then return res
+               for na in nas.n_items do
+                       if na.name != name then continue
+                       res.add(na)
+               end
+               return res
+       end
+
        redef fun replace_with(n: ANode)
        do
                super
@@ -2038,6 +2052,12 @@ class AAnnotation
        var n_opar: nullable TOpar = null is writable
        var n_args = new ANodes[AExpr](self)
        var n_cpar: nullable TCpar = null is writable
+
+       # The name of the annotation
+       fun name: String
+       do
+               return n_atid.n_id.text
+       end
 end
 
 # An annotation name