summaryrefslogtreecommitdiff
path: root/libvaladoc/api/symbol.vala
blob: 020c28ab1cc801941a1294d3d7fe0e6bcc5889aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* symbol.vala
 *
 * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
 * Copyright (C) 2011      Florian Brosch
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Didier 'Ptitjes Villevalois <ptitjes@free.fr>
 */


/**
 * Represents a node in the symbol tree.
 */
public abstract class Valadoc.Api.Symbol : Node {
	private Vala.ArrayList<Attribute> attributes;

	public bool is_deprecated {
		default = false;
		private set;
		get;
	}

	public Symbol (Node parent, SourceFile file, string? name, SymbolAccessibility accessibility,
				   void* data)
	{
		base (parent, file, name, data);

		this.accessibility = accessibility;
	}

	public void add_attribute (Attribute att) {
		if (attributes == null) {
			attributes = new Vala.ArrayList<Attribute> ();
		}

		// register deprecated symbols:
		if (att.name == "Version") {
			AttributeArgument? deprecated = att.get_argument ("deprecated");
			AttributeArgument? version = att.get_argument ("deprecated_since");
			if ((deprecated != null && deprecated.get_value_as_boolean ()) || version != null) {
				string? version_str = (version != null) ? version.get_value_as_string () : null;

				package.register_deprecated_symbol (this, version_str);
				is_deprecated = true;
			}
		} else if (att.name == "Deprecated") {
			AttributeArgument? version = att.get_argument ("version");
			string? version_str = (version != null) ? version.get_value_as_string () : null;

			package.register_deprecated_symbol (this, version_str);
			is_deprecated = true;
		}

		attributes.add (att);
	}

	public Vala.Collection<Attribute> get_attributes () {
		if (attributes == null) {
			return new Vala.ArrayList<Attribute> ();
		} else {
			return attributes;
		}
	}

	public Attribute? get_attribute (string name) {
		if (attributes != null) {
			foreach (Attribute att in attributes) {
				if (att.name == name) {
					return att;
				}
			}
		}

		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	public override bool is_browsable (Settings settings) {
		if (!settings._private && this.is_private) {
			return false;
		}
		if (!settings._internal && this.is_internal) {
			return false;
		}
		if (!settings._protected && this.is_protected) {
			return false;
		}

		Item? pos = parent;
		while (pos != null && pos is Symbol && pos is Namespace == false) {
			if (((Symbol) pos).is_browsable (settings) == false) {
				return false;
			}
			pos = pos.parent;
		}

		return true;
	}

	public SymbolAccessibility accessibility {
		private set;
		get;
	}

	/**
	 * Specifies whether this symbol is public.
	 */
	public bool is_public {
		get {
			return accessibility == SymbolAccessibility.PUBLIC;
		}
	}

	/**
	 * Specifies whether this symbol is protected.
	 */
	public bool is_protected {
		get {
			return accessibility == SymbolAccessibility.PROTECTED;
		}
	}

	/**
	 * Specifies whether this symbol is internal.
	 */
	public bool is_internal {
		get {
			return accessibility == SymbolAccessibility.INTERNAL;
		}
	}

	/**
	 * Specifies whether this symbol is private.
	 */
	public bool is_private {
		get {
			return accessibility == SymbolAccessibility.PRIVATE;
		}
	}
}