Skip to content

Commit a1d396c

Browse files
committedDec 17, 2019
8235926: Update @jls @JVMS taglets to allow inline usage
Reviewed-by: hannesw
1 parent df75426 commit a1d396c

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed
 

‎make/jdk/src/classes/build/tools/taglet/JSpec.java

+41-20
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.sun.source.doctree.DocTree;
3636
import com.sun.source.doctree.LiteralTree;
3737
import com.sun.source.doctree.UnknownBlockTagTree;
38+
import com.sun.source.doctree.UnknownInlineTagTree;
3839
import com.sun.source.util.SimpleDocTreeVisitor;
3940
import jdk.javadoc.doclet.Taglet;
4041

@@ -96,16 +97,14 @@ public JVMS() {
9697
private String baseURL;
9798
private String idPrefix;
9899

99-
protected JSpec(String tagName, String specTitle, String baseURL, String idPrefix) {
100+
JSpec(String tagName, String specTitle, String baseURL, String idPrefix) {
100101
this.tagName = tagName;
101102
this.specTitle = specTitle;
102103
this.baseURL = baseURL;
103104
this.idPrefix = idPrefix;
104105
}
105106

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.]*)( .*)?$");
109108

110109
/**
111110
* Returns the set of locations in which the tag may be used.
@@ -115,9 +114,14 @@ public Set<Location> getAllowedLocations() {
115114
return EnumSet.allOf(jdk.javadoc.doclet.Taglet.Location.class);
116115
}
117116

117+
//@Override // uncomment when JDK 15 is the boot JDK
118+
public boolean isBlockTag() {
119+
return true;
120+
}
121+
118122
@Override
119123
public boolean isInlineTag() {
120-
return false;
124+
return true;
121125
}
122126

123127
@Override
@@ -132,17 +136,28 @@ public String toString(List<? extends DocTree> tags, Element elem) {
132136
return "";
133137

134138
StringBuilder sb = new StringBuilder();
135-
sb.append("<dt>See <i>" + specTitle + "</i>:</dt>\n")
136-
.append("<dd>\n");
139+
boolean in_dd = false;
137140

138141
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+
}
139147

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;
142158
}
143159

144-
UnknownBlockTagTree blockTag = (UnknownBlockTagTree)tag;
145-
String tagText = blockTag.getContent().toString().trim();
160+
String tagText = contents.toString().trim();
146161
Matcher m = TAG_PATTERN.matcher(tagText);
147162
if (m.find()) {
148163
String chapter = m.group("chapter");
@@ -151,23 +166,27 @@ public String toString(List<? extends DocTree> tags, Element elem) {
151166
String url = String.format("%1$s/%2$s-%3$s.html#jls-%3$s%4$s",
152167
baseURL, idPrefix, chapter, section);
153168

154-
155169
sb.append("<a href=\"")
156170
.append(url)
157171
.append("\">")
158-
.append(expand(blockTag))
159-
.append("</a><br>");
160-
}
172+
.append(expand(contents))
173+
.append("</a>");
161174

175+
if (tag.getKind() == DocTree.Kind.UNKNOWN_BLOCK_TAG) {
176+
sb.append("<br>");
177+
}
178+
}
162179
}
163180

164-
sb.append("</dd>");
181+
if (in_dd) {
182+
sb.append("</dd>");
183+
}
165184

166185
return sb.toString();
167186
}
168187

169-
private String expand(UnknownBlockTagTree tree) {
170-
StringBuilder sb = new StringBuilder();
188+
189+
private String expand(List<? extends DocTree> trees) {
171190
return (new SimpleDocTreeVisitor<StringBuilder, StringBuilder>() {
172191
public StringBuilder defaultAction(DocTree tree, StringBuilder sb) {
173192
return sb.append(tree.toString());
@@ -185,8 +204,10 @@ public StringBuilder visitLiteral(LiteralTree tree, StringBuilder sb) {
185204
}
186205

187206
private String escape(String s) {
188-
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt");
207+
return s.replace("&", "&amp;")
208+
.replace("<", "&lt;")
209+
.replace(">", "&gt");
189210
}
190-
}).visit(tree.getContent(), new StringBuilder()).toString();
211+
}).visit(trees, new StringBuilder()).toString();
191212
}
192213
}

0 commit comments

Comments
 (0)
Please sign in to comment.