langtools/test/tools/javac/processing/model/util/elements/doccomments/TestDocComments.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 6877202 6986246 |
26 * @bug 6877202 6986246 |
27 * @summary Elements.getDocComment() is not getting JavaDocComments |
27 * @summary Elements.getDocComment() is not getting JavaDocComments |
|
28 * @library /tools/javac/lib |
|
29 * @build JavacTestingAbstractProcessor TestDocComments |
|
30 * @run main TestDocComments |
28 */ |
31 */ |
29 |
32 |
30 import com.sun.source.tree.*; |
33 import com.sun.source.tree.*; |
31 import com.sun.source.util.*; |
34 import com.sun.source.util.*; |
32 import java.io.*; |
35 import java.io.*; |
47 * command line and JSR 199 invocation, the test covers both ways of invoking the |
50 * command line and JSR 199 invocation, the test covers both ways of invoking the |
48 * compiler. |
51 * compiler. |
49 */ |
52 */ |
50 |
53 |
51 @SupportedOptions("scan") |
54 @SupportedOptions("scan") |
52 @SupportedAnnotationTypes("*") |
55 public class TestDocComments extends JavacTestingAbstractProcessor { |
53 public class TestDocComments extends AbstractProcessor { |
|
54 enum CompileKind { API, CMD }; |
56 enum CompileKind { API, CMD }; |
55 enum ScanKind { TREE, ELEMENT }; |
57 enum ScanKind { TREE, ELEMENT }; |
56 |
58 |
57 // ----- Main test driver: invoke compiler for the various test cases ------ |
59 // ----- Main test driver: invoke compiler for the various test cases ------ |
58 |
60 |
70 if (errors > 0) |
72 if (errors > 0) |
71 throw new Exception(errors + " errors occurred"); |
73 throw new Exception(errors + " errors occurred"); |
72 } |
74 } |
73 |
75 |
74 static void test(CompileKind ck, ScanKind sk) throws IOException { |
76 static void test(CompileKind ck, ScanKind sk) throws IOException { |
75 String testClasses = System.getProperty("test.classes"); |
77 String testClasses = System.getProperty("test.class.path"); |
76 String testSrc = System.getProperty("test.src"); |
78 String testSrc = System.getProperty("test.src"); |
77 File testDir = new File("test." + ck + "." + sk); |
79 File testDir = new File("test." + ck + "." + sk); |
78 testDir.mkdirs(); |
80 testDir.mkdirs(); |
79 String[] opts = { |
81 String[] opts = { |
80 "-d", testDir.getPath(), |
82 "-d", testDir.getPath(), |
134 static int errors; |
136 static int errors; |
135 |
137 |
136 // ----- Annotation processor: scan for elements and check doc comments ---- |
138 // ----- Annotation processor: scan for elements and check doc comments ---- |
137 |
139 |
138 Map<String,String> options; |
140 Map<String,String> options; |
139 Filer filer; |
|
140 Messager messager; |
|
141 Elements elements; |
|
142 Trees trees; |
141 Trees trees; |
143 ScanKind skind; |
142 ScanKind skind; |
144 |
143 |
145 int round = 0; |
144 int round = 0; |
146 |
|
147 @Override |
|
148 public SourceVersion getSupportedSourceVersion() { |
|
149 return SourceVersion.latest(); |
|
150 } |
|
151 |
145 |
152 @Override |
146 @Override |
153 public void init(ProcessingEnvironment pEnv) { |
147 public void init(ProcessingEnvironment pEnv) { |
154 super.init(pEnv); |
148 super.init(pEnv); |
155 options = pEnv.getOptions(); |
149 options = pEnv.getOptions(); |
156 filer = pEnv.getFiler(); |
|
157 messager = pEnv.getMessager(); |
|
158 elements = pEnv.getElementUtils(); |
|
159 trees = Trees.instance(processingEnv); |
150 trees = Trees.instance(processingEnv); |
160 skind = ScanKind.valueOf(options.get("scan")); |
151 skind = ScanKind.valueOf(options.get("scan")); |
161 } |
152 } |
162 |
153 |
163 @Override |
154 @Override |
269 } |
260 } |
270 } |
261 } |
271 |
262 |
272 // ----- Scanners to find elements ----------------------------------------- |
263 // ----- Scanners to find elements ----------------------------------------- |
273 |
264 |
274 class TestElementScanner extends ElementScanner7<Void, Void> { |
265 class TestElementScanner extends ElementScanner<Void, Void> { |
275 @Override |
266 @Override |
276 public Void visitExecutable(ExecutableElement e, Void _) { |
267 public Void visitExecutable(ExecutableElement e, Void _) { |
277 check(e); |
268 check(e); |
278 return super.visitExecutable(e, _); |
269 return super.visitExecutable(e, _); |
279 } |
270 } |
304 public Void visitVariable(VariableTree tree, Trees trees) { |
295 public Void visitVariable(VariableTree tree, Trees trees) { |
305 check(trees.getElement(getCurrentPath())); |
296 check(trees.getElement(getCurrentPath())); |
306 return super.visitVariable(tree, trees); |
297 return super.visitVariable(tree, trees); |
307 } |
298 } |
308 } |
299 } |
309 |
|
310 } |
300 } |