35
35
import com .sun .source .doctree .DocTree ;
36
36
import com .sun .source .doctree .LiteralTree ;
37
37
import com .sun .source .doctree .UnknownBlockTagTree ;
38
+ import com .sun .source .doctree .UnknownInlineTagTree ;
38
39
import com .sun .source .util .SimpleDocTreeVisitor ;
39
40
import jdk .javadoc .doclet .Taglet ;
40
41
@@ -96,16 +97,14 @@ public JVMS() {
96
97
private String baseURL ;
97
98
private String idPrefix ;
98
99
99
- protected JSpec (String tagName , String specTitle , String baseURL , String idPrefix ) {
100
+ JSpec (String tagName , String specTitle , String baseURL , String idPrefix ) {
100
101
this .tagName = tagName ;
101
102
this .specTitle = specTitle ;
102
103
this .baseURL = baseURL ;
103
104
this .idPrefix = idPrefix ;
104
105
}
105
106
106
-
107
- static final Pattern TAG_PATTERN = Pattern .compile ("(?s)(.+ )?(?<chapter>[1-9][0-9]*)(?<section>[0-9.]*)( .*)?$" );
108
-
107
+ private static final Pattern TAG_PATTERN = Pattern .compile ("(?s)(.+ )?(?<chapter>[1-9][0-9]*)(?<section>[0-9.]*)( .*)?$" );
109
108
110
109
/**
111
110
* Returns the set of locations in which the tag may be used.
@@ -115,9 +114,14 @@ public Set<Location> getAllowedLocations() {
115
114
return EnumSet .allOf (jdk .javadoc .doclet .Taglet .Location .class );
116
115
}
117
116
117
+ //@Override // uncomment when JDK 15 is the boot JDK
118
+ public boolean isBlockTag () {
119
+ return true ;
120
+ }
121
+
118
122
@ Override
119
123
public boolean isInlineTag () {
120
- return false ;
124
+ return true ;
121
125
}
122
126
123
127
@ Override
@@ -132,17 +136,28 @@ public String toString(List<? extends DocTree> tags, Element elem) {
132
136
return "" ;
133
137
134
138
StringBuilder sb = new StringBuilder ();
135
- sb .append ("<dt>See <i>" + specTitle + "</i>:</dt>\n " )
136
- .append ("<dd>\n " );
139
+ boolean in_dd = false ;
137
140
138
141
for (DocTree tag : tags ) {
142
+ if (sb .length () == 0 && tag .getKind () == DocTree .Kind .UNKNOWN_BLOCK_TAG ) {
143
+ sb .append ("<dt>See <i>" ).append (specTitle ).append ("</i>:</dt>\n " )
144
+ .append ("<dd>\n " );
145
+ in_dd = true ;
146
+ }
139
147
140
- if (tag .getKind () != UNKNOWN_BLOCK_TAG ) {
141
- continue ;
148
+ List <? extends DocTree > contents ;
149
+ switch (tag .getKind ()) {
150
+ case UNKNOWN_BLOCK_TAG :
151
+ contents = ((UnknownBlockTagTree ) tag ).getContent ();
152
+ break ;
153
+ case UNKNOWN_INLINE_TAG :
154
+ contents = ((UnknownInlineTagTree ) tag ).getContent ();
155
+ break ;
156
+ default :
157
+ continue ;
142
158
}
143
159
144
- UnknownBlockTagTree blockTag = (UnknownBlockTagTree )tag ;
145
- String tagText = blockTag .getContent ().toString ().trim ();
160
+ String tagText = contents .toString ().trim ();
146
161
Matcher m = TAG_PATTERN .matcher (tagText );
147
162
if (m .find ()) {
148
163
String chapter = m .group ("chapter" );
@@ -151,23 +166,27 @@ public String toString(List<? extends DocTree> tags, Element elem) {
151
166
String url = String .format ("%1$s/%2$s-%3$s.html#jls-%3$s%4$s" ,
152
167
baseURL , idPrefix , chapter , section );
153
168
154
-
155
169
sb .append ("<a href=\" " )
156
170
.append (url )
157
171
.append ("\" >" )
158
- .append (expand (blockTag ))
159
- .append ("</a><br>" );
160
- }
172
+ .append (expand (contents ))
173
+ .append ("</a>" );
161
174
175
+ if (tag .getKind () == DocTree .Kind .UNKNOWN_BLOCK_TAG ) {
176
+ sb .append ("<br>" );
177
+ }
178
+ }
162
179
}
163
180
164
- sb .append ("</dd>" );
181
+ if (in_dd ) {
182
+ sb .append ("</dd>" );
183
+ }
165
184
166
185
return sb .toString ();
167
186
}
168
187
169
- private String expand ( UnknownBlockTagTree tree ) {
170
- StringBuilder sb = new StringBuilder ();
188
+
189
+ private String expand ( List <? extends DocTree > trees ) {
171
190
return (new SimpleDocTreeVisitor <StringBuilder , StringBuilder >() {
172
191
public StringBuilder defaultAction (DocTree tree , StringBuilder sb ) {
173
192
return sb .append (tree .toString ());
@@ -185,8 +204,10 @@ public StringBuilder visitLiteral(LiteralTree tree, StringBuilder sb) {
185
204
}
186
205
187
206
private String escape (String s ) {
188
- return s .replace ("&" , "&" ).replace ("<" , "<" ).replace (">" , ">" );
207
+ return s .replace ("&" , "&" )
208
+ .replace ("<" , "<" )
209
+ .replace (">" , ">" );
189
210
}
190
- }).visit (tree . getContent () , new StringBuilder ()).toString ();
211
+ }).visit (trees , new StringBuilder ()).toString ();
191
212
}
192
213
}
0 commit comments