1 ###############################################################################
3 # Package: NaturalDocs::Parser::ParsedTopic
5 ###############################################################################
7 # A class for parsed topics of source files. Also encompasses some of the <TopicType>-specific behavior.
9 ###############################################################################
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
18 package NaturalDocs::Parser::ParsedTopic;
21 ###############################################################################
22 # Group: Implementation
27 # The object is a blessed arrayref with the following indexes.
29 # TYPE - The <TopicType>.
30 # TITLE - The title of the topic.
31 # PACKAGE - The package <SymbolString> the topic appears in, or undef if none.
32 # USING - An arrayref of additional package <SymbolStrings> available to the topic via "using" statements, or undef if
34 # PROTOTYPE - The prototype, if it exists and is applicable.
35 # SUMMARY - The summary, if it exists.
36 # BODY - The body of the topic, formatted in <NDMarkup>. Some topics may not have bodies, and if not, this
38 # LINE_NUMBER - The line number the topic appears at in the file.
39 # IS_LIST - Whether the topic is a list.
41 use NaturalDocs::DefineMembers 'TYPE', 'TITLE', 'PACKAGE', 'USING', 'PROTOTYPE', 'SUMMARY', 'BODY',
42 'LINE_NUMBER', 'IS_LIST';
43 # DEPENDENCY: New() depends on the order of these constants, and that this class is not inheriting any members.
47 # Architecture: Title, Package, and Symbol Behavior
49 # Title, package, and symbol behavior is a little awkward so it deserves some explanation. Basically you set them according to
50 # certain rules, but you get computed values that try to hide all the different scoping situations.
54 # Set them to the title and package as they appear. "Function" and "PkgA.PkgB" will return "Function" for the title,
55 # "PkgA.PkgB" for the package, and "PkgA.PkgB.Function" for the symbol.
57 # In the rare case that a title has a separator symbol it's treated as inadvertant, so "A vs. B" in "PkgA.PkgB" still returns just
58 # "PkgA.PkgB" for the package even though if you got it from the symbol it can be seen as "PkgA.PkgB.A vs".
62 # Set the title normally and leave the package undef. So "PkgA.PkgB" and undef will return "PkgA.PkgB" for the title as well
63 # as for the package and symbol.
65 # The only time you should set the package is when you have full language support and they only documented the class with
66 # a partial title. So if you documented "PkgA.PkgB" with just "PkgB", you want to set the package to "PkgA". This
67 # will return "PkgB" as the title for presentation and will return "PkgA.PkgB" for the package and symbol, which is correct.
69 # Always Global Topics:
71 # Set the title and package normally, do not set the package to undef. So "Global" and "PkgA.PkgB" will return "Global" as
72 # the title, "PkgA.PkgB" as the package, and "Global" as the symbol.
76 # So does this suck? Yes, yes it does. But the suckiness is centralized here instead of having to be handled everywhere these
77 # issues come into play. Just realize there are a certain set of rules to follow when you *set* these variables, and the results
78 # you see when you *get* them are computed rather than literal.
82 ###############################################################################
88 # Creates a new object.
92 # type - The <TopicType>.
93 # title - The title of the topic.
94 # package - The package <SymbolString> the topic appears in, or undef if none.
95 # using - An arrayref of additional package <SymbolStrings> available to the topic via "using" statements, or undef if
97 # prototype - The prototype, if it exists and is applicable. Otherwise set to undef.
98 # summary - The summary of the topic, if any.
99 # body - The body of the topic, formatted in <NDMarkup>. May be undef, as some topics may not have bodies.
100 # lineNumber - The line number the topic appears at in the file.
101 # isList - Whether the topic is a list topic or not.
107 sub New #(type, title, package, using, prototype, summary, body, lineNumber, isList)
109 # DEPENDENCY: This depends on the order of the parameter list being the same as the constants, and that there are no
110 # members inherited from a base class.
115 bless $object, $package;
117 if (defined $object->[USING])
118 { $object->[USING] = [ @{$object->[USING]} ]; };
125 # Returns the <TopicType>.
127 { return $_[0]->[TYPE]; };
130 # Replaces the <TopicType>.
132 { $_[0]->[TYPE] = $_[1]; };
135 # Returns whether the topic is a list.
137 { return $_[0]->[IS_LIST]; };
139 # Function: SetIsList
140 # Sets whether the topic is a list.
142 { $_[0]->[IS_LIST] = $_[1]; };
145 # Returns the title of the topic.
147 { return $_[0]->[TITLE]; };
150 # Replaces the topic title.
151 sub SetTitle #(title)
152 { $_[0]->[TITLE] = $_[1]; };
157 # Returns the <SymbolString> defined by the topic. It is fully resolved and does _not_ need to be joined with <Package()>.
159 # Type-Specific Behavior:
161 # - If the <TopicType> is always global, the symbol will be generated from the title only.
162 # - Everything else's symbols will be generated from the title and the package passed to <New()>.
168 my $titleSymbol = NaturalDocs::SymbolString->FromText($self->[TITLE]);
170 if (NaturalDocs::Topics->TypeInfo($self->Type())->Scope() == ::SCOPE_ALWAYS_GLOBAL())
171 { return $titleSymbol; }
174 return NaturalDocs::SymbolString->Join( $self->[PACKAGE], $titleSymbol );
182 # Returns the package <SymbolString> that the topic appears in.
184 # Type-Specific Behavior:
186 # - If the <TopicType> has scope, the package will be generated from both the title and the package passed to <New()>, not
188 # - If the <TopicType> is always global, the package will be the one passed to <New()>, even though it isn't part of it's
190 # - Everything else's package will be what was passed to <New()>, even if the title has separator symbols in it.
196 # Headerless topics may not have a type yet.
197 if ($self->Type() && NaturalDocs::Topics->TypeInfo($self->Type())->Scope() == ::SCOPE_START())
198 { return $self->Symbol(); }
200 { return $self->[PACKAGE]; };
204 # Function: SetPackage
205 # Replaces the package the topic appears in. This will behave the same way as the package parameter in <New()>. Later calls
206 # to <Package()> will still be generated according to its type-specific behavior.
207 sub SetPackage #(package)
208 { $_[0]->[PACKAGE] = $_[1]; };
211 # Returns an arrayref of additional scope <SymbolStrings> available to the topic via "using" statements, or undef if none.
213 { return $_[0]->[USING]; };
216 # Replaces the using arrayref of sope <SymbolStrings>.
217 sub SetUsing #(using)
218 { $_[0]->[USING] = $_[1]; };
220 # Function: Prototype
221 # Returns the prototype if one is defined. Will be undef otherwise.
223 { return $_[0]->[PROTOTYPE]; };
225 # Function: SetPrototype
226 # Replaces the function or variable prototype.
227 sub SetPrototype #(prototype)
228 { $_[0]->[PROTOTYPE] = $_[1]; };
231 # Returns the topic summary, if it exists, formatted in <NDMarkup>.
233 { return $_[0]->[SUMMARY]; };
236 # Returns the topic's body, formatted in <NDMarkup>. May be undef.
238 { return $_[0]->[BODY]; };
241 # Replaces the topic's body, formatted in <NDMarkup>. May be undef.
244 my ($self, $body) = @_;
245 $self->[BODY] = $body;
248 # Function: LineNumber
249 # Returns the line the topic appears at in the file.
251 { return $_[0]->[LINE_NUMBER]; };