3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Represents an attribute specified in the source code.
28 public class Vala
.Attribute
: CodeNode
{
30 * The name of the attribute type.
32 public string name
{ get; set; }
35 * Contains all specified attribute arguments.
37 public Vala
.Map
<string,Expression
> args
= new HashMap
<string,Expression
> (str_hash
, str_equal
);
40 * Creates a new attribute.
42 * @param name attribute type name
43 * @param source_reference reference to source code
44 * @return newly created attribute
46 public Attribute (string name
, SourceReference? source_reference
= null) {
48 this
.source_reference
= source_reference
;
52 * Adds an attribute argument.
54 * @param arg named argument
56 public void add_argument (string key
, Expression value
) {
57 args
.set (key
, value
);
61 * Returns whether this attribute has the specified named argument.
63 * @param name argument name
64 * @return true if the argument has been found, false otherwise
66 public bool has_argument (string name
) {
67 return args
.contains (name
);
71 * Returns the string value of the specified named argument.
73 * @param name argument name
74 * @return string value
76 public string?
get_string (string name
) {
77 var lit
= args
.get (name
) as StringLiteral
;
86 * Returns the integer value of the specified named argument.
88 * @param name argument name
89 * @return integer value
91 public int get_integer (string name
) {
92 var lit
= args
.get (name
) as IntegerLiteral
;
94 return lit
.value
.to_int ();
101 * Returns the double value of the specified named argument.
103 * @param name argument name
104 * @return double value
106 public double get_double (string name
) {
107 var arg
= args
.get (name
);
108 if (arg is RealLiteral
) {
109 var lit
= (RealLiteral
) arg
;
110 return lit
.value
.to_double ();
111 } else if (arg is IntegerLiteral
) {
112 var lit
= (IntegerLiteral
) arg
;
113 return lit
.value
.to_int ();
114 } else if (arg is UnaryExpression
) {
115 var unary
= (UnaryExpression
) arg
;
116 if (unary
.operator
== UnaryOperator
.MINUS
) {
117 if (unary
.inner is RealLiteral
) {
118 var lit
= (RealLiteral
) unary
.inner
;
119 return -lit
.value
.to_double ();
120 } else if (unary
.inner is IntegerLiteral
) {
121 var lit
= (IntegerLiteral
) unary
.inner
;
122 return -lit
.value
.to_int ();
131 * Returns the boolean value of the specified named argument.
133 * @param name argument name
134 * @return boolean value
136 public bool get_bool (string name
) {
137 var lit
= args
.get (name
) as BooleanLiteral
;