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,string> args
{ get; private set; }
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
;
49 this
.args
= new HashMap
<string,string> (str_hash
, str_equal
);
51 if (!CodeContext
.get ().deprecated
) {
52 if (name
== "Deprecated") {
53 Report
.deprecated (source_reference
, "[Deprecated] is deprecated. Use [Version (deprecated = true, deprecated_since = \"\", replacement = \"\")]");
54 } else if (name
== "Experimental") {
55 Report
.deprecated (source_reference
, "[Experimental] is deprecated. Use [Version (experimental = true, experimental_until = \"\")]");
61 * Adds an attribute argument.
63 * @param key argument name
64 * @param value argument value
66 public void add_argument (string key
, string value
) {
67 args
.set (key
, value
);
71 * Returns whether this attribute has the specified named argument.
73 * @param name argument name
74 * @return true if the argument has been found, false otherwise
76 public bool has_argument (string name
) {
77 return args
.contains (name
);
81 * Returns the string value of the specified named argument.
83 * @param name argument name
84 * @return string value
86 public string?
get_string (string name
, string? default_value
= null) {
87 string value
= args
.get (name
);
94 var noquotes
= value
.substring (1, (uint) (value
.length
- 2));
96 return noquotes
.compress ();
100 * Returns the integer value of the specified named argument.
102 * @param name argument name
103 * @return integer value
105 public int get_integer (string name
, int default_value
= 0) {
106 string value
= args
.get (name
);
109 return default_value
;
112 return int.parse (value
);
116 * Returns the double value of the specified named argument.
118 * @param name argument name
119 * @return double value
121 public double get_double (string name
, double default_value
= 0) {
122 string value
= args
.get (name
);
125 return default_value
;
128 return double.parse (value
);
132 * Returns the boolean value of the specified named argument.
134 * @param name argument name
135 * @return boolean value
137 public bool get_bool (string name
, bool default_value
= false) {
138 string value
= args
.get (name
);
141 return default_value
;
144 return bool.parse (value
);