author | aph |
Mon, 04 Nov 2019 13:13:34 -0500 | |
changeset 58917 | 33f9271b3167 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27991
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
4 |
* |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
8 |
* |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
14 |
* |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
18 |
* |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
21 |
* questions. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
22 |
*/ |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
23 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
24 |
/* |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
25 |
* @test |
6717 | 26 |
* @bug 6985205 6986246 |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
27 |
* @summary access to tree positions and doc comments may be lost across annotation processing rounds |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27991
diff
changeset
|
28 |
* @modules jdk.compiler |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
29 |
* @build TreePosRoundsTest |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
30 |
* @compile -proc:only -processor TreePosRoundsTest TreePosRoundsTest.java |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
31 |
* @run main TreePosRoundsTest |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
32 |
*/ |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
33 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
34 |
import java.io.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
35 |
import java.util.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
36 |
import javax.annotation.processing.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
37 |
import javax.lang.model.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
38 |
import javax.lang.model.element.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
39 |
import javax.tools.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
40 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
41 |
import com.sun.source.tree.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
42 |
import com.sun.source.util.*; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
43 |
import javax.tools.JavaCompiler.CompilationTask; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
44 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
45 |
// This test is an annotation processor that performs multiple rounds of |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
46 |
// processing, and on each round, it checks that source positions are |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
47 |
// available and correct. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
48 |
// |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
49 |
// The test can be run directly as a processor from the javac command line |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
50 |
// or via JSR 199 by invoking the main program. |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
51 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
52 |
@SupportedAnnotationTypes("*") |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
53 |
public class TreePosRoundsTest extends AbstractProcessor { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
54 |
public static void main(String... args) throws Exception { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
55 |
String testSrc = System.getProperty("test.src"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
56 |
String testClasses = System.getProperty("test.classes"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
57 |
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
58 |
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
59 |
String thisName = TreePosRoundsTest.class.getName(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
60 |
File thisFile = new File(testSrc, thisName + ".java"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
61 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
62 |
List<String> options = Arrays.asList( |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
63 |
"-proc:only", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
64 |
"-processor", thisName, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
65 |
"-processorpath", testClasses); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
66 |
CompilationTask t = c.getTask(null, fm, null, options, null, files); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
67 |
boolean ok = t.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
68 |
if (!ok) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
69 |
throw new Exception("processing failed"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
70 |
} |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
71 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
72 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
73 |
Filer filer; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
74 |
Messager messager; |
6717 | 75 |
Trees trees; |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
76 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
77 |
@Override |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
78 |
public SourceVersion getSupportedSourceVersion() { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
79 |
return SourceVersion.latest(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
80 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
81 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
82 |
@Override |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
83 |
public void init(ProcessingEnvironment pEnv) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
84 |
super.init(pEnv); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
85 |
filer = pEnv.getFiler(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
86 |
messager = pEnv.getMessager(); |
6717 | 87 |
trees = Trees.instance(pEnv); |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
88 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
89 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
90 |
int round = 0; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
91 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
92 |
@Override |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
93 |
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
94 |
round++; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
95 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
96 |
// Scan trees for elements, verifying source tree positions |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
97 |
for (Element e: roundEnv.getRootElements()) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
98 |
try { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
99 |
TreePath p = trees.getPath(e); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
100 |
new TestTreeScanner(p.getCompilationUnit(), trees).scan(trees.getPath(e), null); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
101 |
} catch (IOException ex) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
102 |
messager.printMessage(Diagnostic.Kind.ERROR, |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
103 |
"Cannot get source: " + ex, e); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
104 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
105 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
106 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
107 |
final int MAXROUNDS = 3; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
108 |
if (round < MAXROUNDS) |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
109 |
generateSource("Gen" + round); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
110 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
111 |
return true; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
112 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
113 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
114 |
void generateSource(String name) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
115 |
StringBuilder text = new StringBuilder(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
116 |
text.append("class ").append(name).append("{\n"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
117 |
text.append(" int one = 1;\n"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
118 |
text.append(" int two = 2;\n"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
119 |
text.append(" int three = one + two;\n"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
120 |
text.append("}\n"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
121 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
122 |
try { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
123 |
JavaFileObject fo = filer.createSourceFile(name); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
124 |
Writer out = fo.openWriter(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
125 |
try { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
126 |
out.write(text.toString()); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
127 |
} finally { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
128 |
out.close(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
129 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
130 |
} catch (IOException e) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
131 |
throw new Error(e); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
132 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
133 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
134 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
135 |
class TestTreeScanner extends TreePathScanner<Void,Void> { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
136 |
TestTreeScanner(CompilationUnitTree unit, Trees trees) throws IOException { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
137 |
this.unit = unit; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
138 |
JavaFileObject sf = unit.getSourceFile(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
139 |
source = sf.getCharContent(true).toString(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
140 |
sourcePositions = trees.getSourcePositions(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
141 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
142 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
143 |
@Override |
27991
8f4b68523da3
8061549: Disallow _ as a one-character identifier
jlahoda
parents:
27319
diff
changeset
|
144 |
public Void visitVariable(VariableTree tree, Void p) { |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
145 |
check(getCurrentPath()); |
27991
8f4b68523da3
8061549: Disallow _ as a one-character identifier
jlahoda
parents:
27319
diff
changeset
|
146 |
return super.visitVariable(tree, p); |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
147 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
148 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
149 |
void check(TreePath tp) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
150 |
Tree tree = tp.getLeaf(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
151 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
152 |
String expect = tree.toString(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
153 |
if (tree.getKind() == Tree.Kind.VARIABLE) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
154 |
// tree.toString() does not know enough context to add ";", |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
155 |
// so deal with that manually... |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
156 |
Tree.Kind enclKind = tp.getParentPath().getLeaf().getKind(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
157 |
//System.err.println(" encl: " +enclKind); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
158 |
if (enclKind == Tree.Kind.CLASS || enclKind == Tree.Kind.BLOCK) |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
159 |
expect += ";"; |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
160 |
// t-w-r- adds implicit final: remove it |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
161 |
if (enclKind == Tree.Kind.TRY && expect.startsWith("final ")) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
6717
diff
changeset
|
162 |
expect = expect.substring(6); |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
163 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
164 |
//System.err.println("expect: " + expect); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
165 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
166 |
int start = (int)sourcePositions.getStartPosition(unit, tree); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
167 |
if (start == Diagnostic.NOPOS) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
168 |
messager.printMessage(Diagnostic.Kind.ERROR, "start pos not set for " + trim(tree)); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
169 |
return; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
170 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
171 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
172 |
int end = (int)sourcePositions.getEndPosition(unit, tree); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
173 |
if (end == Diagnostic.NOPOS) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
174 |
messager.printMessage(Diagnostic.Kind.ERROR, "end pos not set for " + trim(tree)); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
175 |
return; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
176 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
177 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
178 |
String found = source.substring(start, end); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
179 |
//System.err.println(" found: " + found); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
180 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
181 |
// allow for long lines, in which case just compare beginning and |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
182 |
// end of the strings |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
183 |
boolean equal; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
184 |
if (found.contains("\n")) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
185 |
String head = found.substring(0, found.indexOf("\n")); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
186 |
String tail = found.substring(found.lastIndexOf("\n")).trim(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
187 |
equal = expect.startsWith(head) && expect.endsWith(tail); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
188 |
} else { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
189 |
equal = expect.equals(found); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
190 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
191 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
192 |
if (!equal) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
193 |
messager.printMessage(Diagnostic.Kind.ERROR, |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
194 |
"unexpected value found: '" + found + "'; expected: '" + expect + "'"); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
195 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
196 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
197 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
198 |
String trim(Tree tree) { |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
199 |
final int MAXLEN = 32; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
200 |
String s = tree.toString().replaceAll("\\s+", " ").trim(); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
201 |
return (s.length() < MAXLEN) ? s : s.substring(0, MAXLEN); |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
202 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
203 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
204 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
205 |
CompilationUnitTree unit; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
206 |
SourcePositions sourcePositions; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
207 |
String source; |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
208 |
} |
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
209 |
|
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
diff
changeset
|
210 |
} |