remove obsolete ref modifier and callback keyword
[vala-lang.git] / vala / valaproperty.vala
blob0de75331f0a9a2b95e80495224fb9ab9a71b44ec
1 /* valaproperty.vala
3 * Copyright (C) 2006-2007 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 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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a property declaration in the source code.
28 public class Vala.Property : Member, Lockable {
29 /**
30 * The property name.
32 public string! name { get; set construct; }
34 /**
35 * The property type.
37 public TypeReference! type_reference { get; set construct; }
39 /**
40 * The get accessor of this property if available.
42 public PropertyAccessor get_accessor { get; set; }
44 /**
45 * The set/construct accessor of this property if available.
47 public PropertyAccessor set_accessor { get; set; }
49 /**
50 * Specifies the accessibility of this property. Public accessibility
51 * doesn't limit access. Default accessibility limits access to this
52 * program or library. Private accessibility limits access to the parent
53 * class.
55 public MemberAccessibility access { get; set; }
57 /**
58 * Represents the generated ´this' parameter in this property.
60 public FormalParameter this_parameter { get; set; }
62 /**
63 * Specifies whether the implementation of this property does not
64 * provide getter/setter methods.
66 public bool no_accessor_method { get; set; }
68 /**
69 * Specifies whether automatic accessor code generation should be
70 * disabled.
72 public bool interface_only { get; set; }
74 /**
75 * Specifies whether this property is abstract. Abstract properties have
76 * no accessor bodies, may only be specified within abstract classes and
77 * interfaces, and must be overriden by derived non-abstract classes.
79 public bool is_abstract { get; set; }
81 /**
82 * Specifies whether this property is virtual. Virtual properties may be
83 * overridden by derived classes.
85 public bool is_virtual { get; set; }
87 /**
88 * Specifies whether this property overrides a virtual or abstract
89 * property of a base type.
91 public bool overrides { get; set; }
93 /**
94 * Specifies the virtual or abstract property this property overrides.
95 * Reference must be weak as virtual properties set base_property to
96 * themselves.
98 public weak Property base_property { get; set; }
101 * Specifies the abstract interface property this property implements.
103 public Property base_interface_property { get; set; }
105 private bool lock_used = false;
108 * Creates a new property.
110 * @param name property name
111 * @param type property type
112 * @param get_accessor get accessor
113 * @param set_accessor set/construct accessor
114 * @param source reference to source code
115 * @return newly created property
117 public Property (string! _name, TypeReference! type, PropertyAccessor _get_accessor, PropertyAccessor _set_accessor, SourceReference source) {
118 name = _name;
119 type_reference = type;
120 get_accessor = _get_accessor;
121 set_accessor = _set_accessor;
122 source_reference = source;
125 public override void accept (CodeVisitor! visitor) {
126 visitor.visit_member (this);
128 visitor.visit_property (this);
131 public override void accept_children (CodeVisitor! visitor) {
132 type_reference.accept (visitor);
134 if (get_accessor != null) {
135 get_accessor.accept (visitor);
137 if (set_accessor != null) {
138 set_accessor.accept (visitor);
143 * Returns the C name of this property in upper case. Words are
144 * separated by underscores. The upper case C name of the class is
145 * prefix of the result.
147 * @return the upper case name to be used in C code
149 public string! get_upper_case_cname () {
150 return "%s_%s".printf (((DataType) symbol.parent_symbol.node).get_lower_case_cname (null), Namespace.camel_case_to_lower_case (name)).up ();
154 * Returns the string literal of this property to be used in C code.
156 * @return string literal to be used in C code
158 public CCodeConstant! get_canonical_cconstant () {
159 var str = new String ("\"");
161 string i = name;
163 while (i.len () > 0) {
164 unichar c = i.get_char ();
165 if (c == '_') {
166 str.append_c ('-');
167 } else {
168 str.append_unichar (c);
171 i = i.next_char ();
174 str.append_c ('"');
176 return new CCodeConstant (str.str);
180 * Process all associated attributes.
182 public void process_attributes () {
183 foreach (Attribute a in attributes) {
184 if (a.name == "NoAccessorMethod") {
185 no_accessor_method = true;
190 public bool get_lock_used () {
191 return lock_used;
194 public void set_lock_used (bool used) {
195 lock_used = used;
199 * Checks whether the accessors and type of the specified property
200 * matches this property.
202 * @param prop a property
203 * @return true if the specified property is compatible to this
204 * property
206 public bool equals (Property! prop2) {
207 if (!prop2.type_reference.equals (type_reference)) {
208 return false;
211 if ((get_accessor == null && prop2.get_accessor != null) ||
212 (get_accessor != null && prop2.get_accessor == null)) {
213 return false;
216 if ((set_accessor == null && prop2.set_accessor != null) ||
217 (set_accessor != null && prop2.set_accessor == null)) {
218 return false;
221 if (set_accessor != null) {
222 if (set_accessor.writable != prop2.set_accessor.writable) {
223 return false;
225 if (set_accessor.construction != prop2.set_accessor.construction) {
226 return false;
230 return true;