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 *
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.
22 */
23
24 package pkg;
25
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.Set;
29 import javax.lang.model.SourceVersion;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.util.ElementScanner9;
32 import javax.tools.Diagnostic;
33
34 import jdk.javadoc.doclet.Doclet;
35 import jdk.javadoc.doclet.DocletEnvironment;
36 import jdk.javadoc.doclet.Reporter;
37
38 public class MyDoclet implements Doclet {
39 private static final boolean OK = true;
40 private boolean verbose;
41 private Reporter reporter;
42
43 Set<Option> options = Set.of(
44 new Option("--alpha -a", false, "an example no-arg option") {
45 @Override
46 public boolean process(String option, List<String> arguments) {
47 System.out.println("received option " + option + " " + arguments);
48 return OK;
49 }
50 },
51 new Option("--beta -b", true, "an example 1-arg option") {
77 @Override
78 public Set<? extends Option> getSupportedOptions() {
79 return options;
80 }
81
82 @Override
83 public SourceVersion getSupportedSourceVersion() {
84 return SourceVersion.latest();
85 }
86
87 @Override
88 public boolean run(DocletEnvironment environment) {
89 MyScanner myScanner = new MyScanner();
90 for (Element e : environment.getSpecifiedElements()) {
91 myScanner.scan(e, 0);
92 }
93
94 return OK;
95 }
96
97 class MyScanner extends ElementScanner9<Void, Integer> {
98 @Override
99 public Void scan(Element e, Integer depth) {
100 String msg = e.getKind() + " " + e;
101 reporter.print(Diagnostic.Kind.NOTE, e, msg);
102 return super.scan(e, depth + 1);
103 }
104 }
105
106
107 abstract class Option implements Doclet.Option {
108 final List<String> names;
109 final boolean hasArg;
110 final String description;
111
112 Option(String names, boolean hasArg, String description) {
113 this.names = List.of(names.split("\\s+"));
114 this.hasArg = hasArg;
115 this.description = description;
116 }
117
|
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 *
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.
22 */
23
24 package pkg;
25
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.Set;
29 import javax.lang.model.SourceVersion;
30 import javax.lang.model.element.Element;
31 import javax.lang.model.util.ElementScanner14;
32 import javax.tools.Diagnostic;
33
34 import jdk.javadoc.doclet.Doclet;
35 import jdk.javadoc.doclet.DocletEnvironment;
36 import jdk.javadoc.doclet.Reporter;
37
38 public class MyDoclet implements Doclet {
39 private static final boolean OK = true;
40 private boolean verbose;
41 private Reporter reporter;
42
43 Set<Option> options = Set.of(
44 new Option("--alpha -a", false, "an example no-arg option") {
45 @Override
46 public boolean process(String option, List<String> arguments) {
47 System.out.println("received option " + option + " " + arguments);
48 return OK;
49 }
50 },
51 new Option("--beta -b", true, "an example 1-arg option") {
77 @Override
78 public Set<? extends Option> getSupportedOptions() {
79 return options;
80 }
81
82 @Override
83 public SourceVersion getSupportedSourceVersion() {
84 return SourceVersion.latest();
85 }
86
87 @Override
88 public boolean run(DocletEnvironment environment) {
89 MyScanner myScanner = new MyScanner();
90 for (Element e : environment.getSpecifiedElements()) {
91 myScanner.scan(e, 0);
92 }
93
94 return OK;
95 }
96
97 class MyScanner extends ElementScanner14<Void, Integer> {
98 @Override
99 public Void scan(Element e, Integer depth) {
100 String msg = e.getKind() + " " + e;
101 reporter.print(Diagnostic.Kind.NOTE, e, msg);
102 return super.scan(e, depth + 1);
103 }
104 }
105
106
107 abstract class Option implements Doclet.Option {
108 final List<String> names;
109 final boolean hasArg;
110 final String description;
111
112 Option(String names, boolean hasArg, String description) {
113 this.names = List.of(names.split("\\s+"));
114 this.hasArg = hasArg;
115 this.description = description;
116 }
117
|