annotation: add arg_as_id
authorJean Privat <jean@pryen.org>
Mon, 21 Jul 2014 15:55:54 +0000 (11:55 -0400)
committerJean Privat <jean@pryen.org>
Mon, 21 Jul 2014 16:11:18 +0000 (12:11 -0400)
I do not know why is was forgot

Signed-off-by: Jean Privat <jean@pryen.org>

src/annotation.nit

index d4a13ac..a0d397e 100644 (file)
@@ -84,6 +84,20 @@ redef class AAnnotation
                modelbuilder.error(self, "Annotation error: \"{name}\" expects a single Int as argument.")
                return null
        end
+
+       # Get the single argument of `self` as an identifier.
+       # Raise error and return null on any inconsistency.
+       fun arg_as_id(modelbuilder: ModelBuilder): nullable String
+       do
+               var args = n_args
+               if args.length == 1 then
+                       var arg = args.first.as_id
+                       if arg != null then return arg
+               end
+
+               modelbuilder.error(self, "Annotation error: \"{name}\" expects a single identifier as argument.")
+               return null
+       end
 end
 
 redef class AAtArg