@@ -16,8 +16,19 @@ class JavadocParent extends @javadocParent, Top {
16
16
/** Gets the number of documentation elements attached to this parent. */
17
17
int getNumChild ( ) { result = count ( getAChild ( ) ) }
18
18
19
- /** Gets a documentation element with the specified Javadoc tag name. */
20
- JavadocTag getATag ( string name ) { result = this .getAChild ( ) and result .getTagName ( ) = name }
19
+ /**
20
+ * DEPRECATED: Only `Javadoc` can have tag elements; `JavadocTag` (which also extends
21
+ * `JavadocParent`) cannot have nested tag elements. Therefore this predicate has been
22
+ * moved to `Javadoc`.
23
+ *
24
+ * Gets a documentation element with the specified Javadoc tag name.
25
+ */
26
+ deprecated JavadocTag getATag ( string name ) {
27
+ result = this .getAChild ( ) and result .getTagName ( ) = name
28
+ }
29
+
30
+ /** Gets a text documentation element which is a direct child of this. */
31
+ JavadocText getATextElement ( ) { result = this .getAChild ( ) }
21
32
22
33
/*abstract*/ override string toString ( ) { result = "Javadoc" }
23
34
}
@@ -27,11 +38,19 @@ class Javadoc extends JavadocParent, @javadoc {
27
38
/** Gets the number of lines in this Javadoc comment. */
28
39
int getNumberOfLines ( ) { result = this .getLocation ( ) .getNumberOfCommentLines ( ) }
29
40
41
+ /** Gets a documentation element with the specified Javadoc tag name. */
42
+ override JavadocTag getATag ( string name ) {
43
+ result = this .getATag ( ) and result .getTagName ( ) = name
44
+ }
45
+
46
+ /** Gets a Javadoc tag documentation element. */
47
+ JavadocTag getATag ( ) { result = getAChild ( ) }
48
+
30
49
/** Gets the value of the `@version` tag, if any. */
31
- string getVersion ( ) { result = this . getATag ( "@version" ) . getChild ( 0 ) . toString ( ) }
50
+ string getVersion ( ) { result = getATag ( ) . ( VersionTag ) . getVersion ( ) }
32
51
33
52
/** Gets the value of the `@author` tag, if any. */
34
- string getAuthor ( ) { result = this . getATag ( "@author" ) . getChild ( 0 ) . toString ( ) }
53
+ string getAuthor ( ) { result = getATag ( ) . ( AuthorTag ) . getAuthorName ( ) }
35
54
36
55
override string toString ( ) { result = toStringPrefix ( ) + getChild ( 0 ) + toStringPostfix ( ) }
37
56
@@ -90,7 +109,7 @@ class JavadocTag extends JavadocElement, JavadocParent, @javadocTag {
90
109
override string toString ( ) { result = this .getTagName ( ) }
91
110
92
111
/** Gets the text associated with this Javadoc tag. */
93
- override string getText ( ) { result = this .getChild ( 0 ) .toString ( ) }
112
+ override string getText ( ) { result = this .getChild ( 0 ) .( JavadocText ) . getText ( ) }
94
113
95
114
override string getAPrimaryQlClass ( ) { result = "JavadocTag" }
96
115
}
@@ -100,37 +119,55 @@ class ParamTag extends JavadocTag {
100
119
ParamTag ( ) { this .getTagName ( ) = "@param" }
101
120
102
121
/** Gets the name of the parameter. */
103
- string getParamName ( ) { result = this .getChild ( 0 ) .toString ( ) }
122
+ string getParamName ( ) { result = this .getChild ( 0 ) .( JavadocText ) . getText ( ) }
104
123
105
124
/** Gets the documentation for the parameter. */
106
- override string getText ( ) { result = this .getChild ( 1 ) .toString ( ) }
125
+ override string getText ( ) { result = this .getChild ( 1 ) .( JavadocText ) .getText ( ) }
126
+ }
127
+
128
+ /** A Javadoc `@return` tag. */
129
+ class ReturnTag extends JavadocTag {
130
+ ReturnTag ( ) { this .getTagName ( ) = "@return" }
107
131
}
108
132
109
133
/** A Javadoc `@throws` or `@exception` tag. */
110
134
class ThrowsTag extends JavadocTag {
111
- ThrowsTag ( ) { this .getTagName ( ) = "@throws" or this . getTagName ( ) = "@exception" }
135
+ ThrowsTag ( ) { this .getTagName ( ) = [ "@throws" , "@exception" ] }
112
136
113
137
/** Gets the name of the exception. */
114
- string getExceptionName ( ) { result = this .getChild ( 0 ) .toString ( ) }
138
+ string getExceptionName ( ) { result = this .getChild ( 0 ) .( JavadocText ) . getText ( ) }
115
139
116
140
/** Gets the documentation for the exception. */
117
- override string getText ( ) { result = this .getChild ( 1 ) .toString ( ) }
141
+ override string getText ( ) { result = this .getChild ( 1 ) .( JavadocText ) . getText ( ) }
118
142
}
119
143
120
144
/** A Javadoc `@see` tag. */
121
145
class SeeTag extends JavadocTag {
122
146
SeeTag ( ) { getTagName ( ) = "@see" }
123
147
124
148
/** Gets the name of the entity referred to. */
125
- string getReference ( ) { result = getChild ( 0 ) .toString ( ) }
149
+ string getReference ( ) { result = getText ( ) }
150
+ }
151
+
152
+ /** A Javadoc `@deprecated` tag. */
153
+ class DeprecatedTag extends JavadocTag {
154
+ DeprecatedTag ( ) { this .getTagName ( ) = "@deprecated" }
126
155
}
127
156
128
157
/** A Javadoc `@author` tag. */
129
158
class AuthorTag extends JavadocTag {
130
159
AuthorTag ( ) { this .getTagName ( ) = "@author" }
131
160
132
161
/** Gets the name of the author. */
133
- string getAuthorName ( ) { result = this .getChild ( 0 ) .toString ( ) }
162
+ string getAuthorName ( ) { result = getText ( ) }
163
+ }
164
+
165
+ /** A Javadoc `@version` tag. */
166
+ class VersionTag extends JavadocTag {
167
+ VersionTag ( ) { this .getTagName ( ) = "@version" }
168
+
169
+ /** Gets the version specified by this tag. */
170
+ string getVersion ( ) { result = getText ( ) }
134
171
}
135
172
136
173
/** A piece of Javadoc text. */
0 commit comments