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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a property declaration in the source code.
28 public class Vala
.Property
: Member
, Lockable
{
32 public string! name
{ get; set construct; }
37 public TypeReference
! type_reference
{ get; set construct; }
40 * The get accessor of this property if available.
42 public PropertyAccessor get_accessor
{ get; set; }
45 * The set/construct accessor of this property if available.
47 public PropertyAccessor set_accessor
{ get; set; }
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
55 public MemberAccessibility access
{ get; set; }
58 * Represents the generated ´this' parameter in this property.
60 public FormalParameter this_parameter
{ get; set; }
63 * Specifies whether the implementation of this property does not
64 * provide getter/setter methods.
66 public bool no_accessor_method
{ get; set; }
69 * Specifies whether automatic accessor code generation should be
72 public bool interface_only
{ get; set; }
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; }
82 * Specifies whether this property is virtual. Virtual properties may be
83 * overridden by derived classes.
85 public bool is_virtual
{ get; set; }
88 * Specifies whether this property overrides a virtual or abstract
89 * property of a base type.
91 public bool overrides
{ get; set; }
94 * Specifies the virtual or abstract property this property overrides.
95 * Reference must be weak as virtual properties set base_property to
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
) {
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 ("\"");
163 while (i
.len () > 0) {
164 unichar c
= i
.get_char ();
168 str
.append_unichar (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 () {
194 public void set_lock_used (bool 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
206 public bool equals (Property
! prop2
) {
207 if (!prop2
.type_reference
.equals (type_reference
)) {
211 if ((get_accessor
== null && prop2
.get_accessor
!= null) ||
212 (get_accessor
!= null && prop2
.get_accessor
== null)) {
216 if ((set_accessor
== null && prop2
.set_accessor
!= null) ||
217 (set_accessor
!= null && prop2
.set_accessor
== null)) {
221 if (set_accessor
!= null) {
222 if (set_accessor
.writable
!= prop2
.set_accessor
.writable
) {
225 if (set_accessor
.construction
!= prop2
.set_accessor
.construction
) {