author | jjg |
Thu, 23 Mar 2017 10:58:16 -0700 | |
changeset 44388 | 4d0903f1f311 |
parent 44189 | dd311cfb920b |
permissions | -rw-r--r-- |
10 | 1 |
/* |
44180 | 2 |
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
24 |
import java.util.EnumSet; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
25 |
import java.util.List; |
10 | 26 |
import java.util.Map; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
27 |
import java.util.Set; |
44388 | 28 |
import javax.lang.model.element.Element; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
29 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
30 |
import com.sun.source.doctree.DocTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
31 |
import com.sun.source.doctree.TextTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
32 |
import com.sun.source.doctree.UnknownBlockTagTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
33 |
import com.sun.source.doctree.UnknownInlineTagTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
34 |
import com.sun.source.util.SimpleDocTreeVisitor; |
44189 | 35 |
import jdk.javadoc.doclet.Taglet; |
36 |
import jdk.javadoc.doclet.Taglet.Location; |
|
37 |
import static jdk.javadoc.doclet.Taglet.Location.*; |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
38 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
39 |
|
10 | 40 |
/** |
41 |
* A sample Taglet representing @todo. This tag can be used in any kind of |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
42 |
* {@link javax.lang.model.Element}. It is not an inline tag. The text is displayed |
10 | 43 |
* in yellow to remind the developer to perform a task. For |
44 |
* example, "@todo Fix this!" would be shown as: |
|
45 |
* <DL> |
|
46 |
* <DT> |
|
47 |
* <B>To Do:</B> |
|
25295
bb0339807d3c
8048168: update 2 javadoc tests to add summary attribute for table tag
sogoel
parents:
5520
diff
changeset
|
48 |
* <DD><table summary="Summary" cellpadding=2 cellspacing=0><tr><td bgcolor="yellow">Fix this! |
10 | 49 |
* </td></tr></table></DD> |
50 |
* </DL> |
|
51 |
* |
|
52 |
* @author Jamie Ho |
|
53 |
* @since 1.4 |
|
54 |
*/ |
|
55 |
||
56 |
public class ToDoTaglet implements Taglet { |
|
57 |
||
58 |
private static final String NAME = "todo"; |
|
59 |
private static final String HEADER = "To Do:"; |
|
60 |
||
61 |
/** |
|
62 |
* Return the name of this custom tag. |
|
63 |
*/ |
|
64 |
public String getName() { |
|
65 |
return NAME; |
|
66 |
} |
|
67 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
68 |
private final EnumSet<Location> allowedSet = EnumSet.allOf(Location.class); |
10 | 69 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
70 |
@Override |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
71 |
public Set<Taglet.Location> getAllowedLocations() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
72 |
return allowedSet; |
10 | 73 |
} |
74 |
||
75 |
/** |
|
76 |
* Will return false since <code>@todo</code> |
|
77 |
* is not an inline tag. |
|
78 |
* @return false since <code>@todo</code> |
|
79 |
* is not an inline tag. |
|
80 |
*/ |
|
81 |
||
82 |
public boolean isInlineTag() { |
|
83 |
return false; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Given an array of <code>Tag</code>s representing this custom |
|
88 |
* tag, return its string representation. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
89 |
* @param tags the array of <code>DocTree</code>s representing this custom tag. |
44388 | 90 |
* @param element the declaration to which the enclosing comment belongs |
10 | 91 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
92 |
@Override |
44388 | 93 |
public String toString(List<? extends DocTree> tags, Element element) { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
94 |
if (tags.isEmpty()) { |
44180 | 95 |
return ""; |
10 | 96 |
} |
97 |
String result = "\n<DT><B>" + HEADER + "</B><DD>"; |
|
25295
bb0339807d3c
8048168: update 2 javadoc tests to add summary attribute for table tag
sogoel
parents:
5520
diff
changeset
|
98 |
result += "<table summary=\"Summary\" cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">"; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
99 |
for (int i = 0; i < tags.size(); i++) { |
10 | 100 |
if (i > 0) { |
101 |
result += ", "; |
|
102 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
103 |
result += getText(tags.get(i)); |
10 | 104 |
} |
105 |
return result + "</td></tr></table></DD>\n"; |
|
106 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
107 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
108 |
static String getText(DocTree dt) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
109 |
return new SimpleDocTreeVisitor<String, Void>() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
110 |
@Override |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
111 |
public String visitUnknownBlockTag(UnknownBlockTagTree node, Void p) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
112 |
for (DocTree dt : node.getContent()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
113 |
return dt.accept(this, null); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
114 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
115 |
return ""; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
116 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
117 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
118 |
@Override |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
119 |
public String visitUnknownInlineTag(UnknownInlineTagTree node, Void p) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
120 |
for (DocTree dt : node.getContent()) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
121 |
return dt.accept(this, null); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
122 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
123 |
return ""; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
124 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
125 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
126 |
@Override |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
127 |
public String visitText(TextTree node, Void p) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
128 |
return node.getBody(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
129 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
130 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
131 |
@Override |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
132 |
protected String defaultAction(DocTree node, Void p) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
133 |
return ""; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
134 |
} |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
135 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
136 |
}.visit(dt, null); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25295
diff
changeset
|
137 |
} |
10 | 138 |
} |