44
44
import javax .lang .model .element .VariableElement ;
45
45
import javax .lang .model .type .TypeMirror ;
46
46
import javax .lang .model .util .Elements ;
47
+ import javax .lang .model .util .Types ;
47
48
import javax .tools .FileObject ;
48
49
import javax .tools .JavaFileManager .Location ;
49
50
@@ -94,110 +95,36 @@ public class WorkArounds {
94
95
public final BaseConfiguration configuration ;
95
96
public final ToolEnvironment toolEnv ;
96
97
public final Utils utils ;
97
-
98
- private DocLint doclint ;
98
+ public final Elements elementUtils ;
99
+ public final Types typeUtils ;
100
+ public final com .sun .tools .javac .code .Types javacTypes ;
99
101
100
102
public WorkArounds (BaseConfiguration configuration ) {
101
103
this .configuration = configuration ;
102
104
this .utils = this .configuration .utils ;
103
- this .toolEnv = ((DocEnvImpl )this .configuration .docEnv ).toolEnv ;
104
- }
105
-
106
- Map <CompilationUnitTree , Boolean > shouldCheck = new HashMap <>();
107
- // TODO: fix this up correctly
108
- public void runDocLint (TreePath path ) {
109
- CompilationUnitTree unit = path .getCompilationUnit ();
110
- if (doclint != null && shouldCheck .computeIfAbsent (unit , doclint ::shouldCheck )) {
111
- doclint .scan (path );
112
- }
113
- }
114
-
115
- /**
116
- * Initializes doclint, if appropriate, depending on options derived
117
- * from the doclet command-line options, and the set of custom tags
118
- * that should be ignored by doclint.
119
- *
120
- * DocLint is not enabled if the option {@code -Xmsgs:none} is given,
121
- * and it is not followed by any options to enable any groups.
122
- * Note that arguments for {@code -Xmsgs:} can be given individually
123
- * in separate {@code -Xmsgs:} options, or in a comma-separated list
124
- * for a single option. For example, the following are equivalent:
125
- * <ul>
126
- * <li>{@code -Xmsgs:all} {@code -Xmsgs:-html}
127
- * <li>{@code -Xmsgs:all,-html}
128
- * </ul>
129
- *
130
- * @param opts options for doclint, derived from the corresponding doclet
131
- * command-line options
132
- * @param customTagNames the names of custom tags, to be ignored by doclint
133
- */
134
- public void initDocLint (List <String > opts , Set <String > customTagNames ) {
135
- List <String > doclintOpts = new ArrayList <>();
136
-
137
- // basic analysis of -Xmsgs and -Xmsgs: options to see if doclint is enabled
138
- Set <String > groups = new HashSet <>();
139
- boolean seenXmsgs = false ;
140
- for (String opt : opts ) {
141
- if (opt .equals (DocLint .XMSGS_OPTION )) {
142
- groups .add ("all" );
143
- seenXmsgs = true ;
144
- } else if (opt .startsWith (DocLint .XMSGS_CUSTOM_PREFIX )) {
145
- String [] args = opt .substring (DocLint .XMSGS_CUSTOM_PREFIX .length ())
146
- .split (DocLint .SEPARATOR );
147
- for (String a : args ) {
148
- if (a .equals ("none" )) {
149
- groups .clear ();
150
- } else if (a .startsWith ("-" )) {
151
- groups .remove (a .substring (1 ));
152
- } else {
153
- groups .add (a );
154
- }
155
- }
156
- seenXmsgs = true ;
157
- }
158
- doclintOpts .add (opt );
159
- }
160
-
161
- if (seenXmsgs ) {
162
- if (groups .isEmpty ()) {
163
- // no groups enabled; do not init doclint
164
- return ;
165
- }
166
- } else {
167
- // no -Xmsgs options of any kind, use default
168
- doclintOpts .add (DocLint .XMSGS_OPTION );
169
- }
170
-
171
- if (!customTagNames .isEmpty ()) {
172
- String customTags = String .join (DocLint .SEPARATOR , customTagNames );
173
- doclintOpts .add (DocLint .XCUSTOM_TAGS_PREFIX + customTags );
174
- }
175
-
176
- doclintOpts .add (DocLint .XHTML_VERSION_PREFIX + "html5" );
177
105
178
- JavacTask t = BasicJavacTask .instance (toolEnv .context );
179
- doclint = new DocLint ();
180
- doclint .init (t , doclintOpts .toArray (new String [0 ]), false );
181
- }
106
+ elementUtils = configuration .docEnv .getElementUtils ();
107
+ typeUtils = configuration .docEnv .getTypeUtils ();
182
108
183
- // TODO: fix this up correctly
184
- public boolean haveDocLint () {
185
- return (doclint == null );
109
+ // Note: this one use of DocEnvImpl is what prevents us tunnelling extra
110
+ // info from a doclet to its taglets via a doclet-specific subtype of
111
+ // DocletEnvironment.
112
+ toolEnv = ((DocEnvImpl )this .configuration .docEnv ).toolEnv ;
113
+ javacTypes = toolEnv .getTypes ();
186
114
}
187
115
188
116
/*
189
117
* TODO: This method exists because of a bug in javac which does not
190
- * handle "@deprecated tag in package-info.java", when this issue
191
- * is fixed this method and its uses must be jettisoned.
118
+ * handle "@deprecated tag in package-info.java", when this issue
119
+ * is fixed this method and its uses must be jettisoned.
192
120
*/
193
121
public boolean isDeprecated0 (Element e ) {
194
122
if (!utils .getDeprecatedTrees (e ).isEmpty ()) {
195
123
return true ;
196
124
}
197
- JavacTypes jctypes = ((DocEnvImpl )configuration .docEnv ).toolEnv .typeutils ;
198
125
TypeMirror deprecatedType = utils .getDeprecatedType ();
199
126
for (AnnotationMirror anno : e .getAnnotationMirrors ()) {
200
- if (jctypes .isSameType (anno .getAnnotationType ().asElement ().asType (), deprecatedType ))
127
+ if (typeUtils .isSameType (anno .getAnnotationType ().asElement ().asType (), deprecatedType ))
201
128
return true ;
202
129
}
203
130
return false ;
@@ -208,24 +135,11 @@ public boolean isSynthesized(AnnotationMirror aDesc) {
208
135
return ((Attribute )aDesc ).isSynthesized ();
209
136
}
210
137
211
- // TODO: fix the caller
212
- public Object getConstValue (VariableElement ve ) {
213
- return ((VarSymbol )ve ).getConstValue ();
214
- }
215
-
216
138
// TODO: DocTrees: Trees.getPath(Element e) is slow a factor 4-5 times.
217
139
public Map <Element , TreePath > getElementToTreePath () {
218
140
return toolEnv .elementToTreePath ;
219
141
}
220
142
221
- // TODO: we need ElementUtils.getPackage to cope with input strings
222
- // to return the proper unnamedPackage for all supported releases.
223
- PackageElement getUnnamedPackage () {
224
- return (Feature .MODULES .allowedInSource (toolEnv .source ))
225
- ? toolEnv .syms .unnamedModule .unnamedPackage
226
- : toolEnv .syms .noModule .unnamedPackage ;
227
- }
228
-
229
143
// TODO: implement in either jx.l.m API (preferred) or DocletEnvironment.
230
144
FileObject getJavaFileObject (PackageElement packageElement ) {
231
145
return ((PackageSymbol )packageElement ).sourcefile ;
@@ -238,7 +152,7 @@ public TypeElement searchClass(TypeElement klass, String className) {
238
152
// search by qualified name in current module first
239
153
ModuleElement me = utils .containingModule (klass );
240
154
if (me != null ) {
241
- te = configuration . docEnv . getElementUtils () .getTypeElement (me , className );
155
+ te = elementUtils .getTypeElement (me , className );
242
156
if (te != null ) {
243
157
return te ;
244
158
}
@@ -290,17 +204,12 @@ public TypeElement searchClass(TypeElement klass, String className) {
290
204
}
291
205
292
206
// finally, search by qualified name in all modules
293
- te = configuration .docEnv .getElementUtils ().getTypeElement (className );
294
- if (te != null ) {
295
- return te ;
296
- }
297
-
298
- return null ; // not found
207
+ return elementUtils .getTypeElement (className );
299
208
}
300
209
301
210
// TODO: need to re-implement this using j.l.m. correctly!, this has
302
- // implications on testInterface, the note here is that javac's supertype
303
- // does the right thing returning Parameters in scope.
211
+ // implications on testInterface, the note here is that javac's supertype
212
+ // does the right thing returning Parameters in scope.
304
213
/**
305
214
* Return the type containing the method that this method overrides.
306
215
* It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>.
@@ -311,14 +220,14 @@ public TypeMirror overriddenType(ExecutableElement method) {
311
220
if (utils .isStatic (method )) {
312
221
return null ;
313
222
}
314
- MethodSymbol sym = (MethodSymbol )method ;
223
+ MethodSymbol sym = (MethodSymbol ) method ;
315
224
ClassSymbol origin = (ClassSymbol ) sym .owner ;
316
- for (com .sun .tools .javac .code .Type t = toolEnv . getTypes () .supertype (origin .type );
225
+ for (com .sun .tools .javac .code .Type t = javacTypes .supertype (origin .type );
317
226
t .hasTag (TypeTag .CLASS );
318
- t = toolEnv . getTypes () .supertype (t )) {
227
+ t = javacTypes .supertype (t )) {
319
228
ClassSymbol c = (ClassSymbol ) t .tsym ;
320
229
for (com .sun .tools .javac .code .Symbol sym2 : c .members ().getSymbolsByName (sym .name )) {
321
- if (sym .overrides (sym2 , origin , toolEnv . getTypes () , true )) {
230
+ if (sym .overrides (sym2 , origin , javacTypes , true )) {
322
231
// Ignore those methods that may be a simple override
323
232
// and allow the real API method to be found.
324
233
if (sym2 .type .hasTag (TypeTag .METHOD ) &&
@@ -353,10 +262,10 @@ public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement
353
262
!rider .isStatic () &&
354
263
355
264
// Symbol.overrides assumes the following
356
- ridee .isMemberOf (origin , toolEnv . getTypes () ) &&
265
+ ridee .isMemberOf (origin , javacTypes ) &&
357
266
358
267
// check access, signatures and check return types
359
- rider .overrides (ridee , origin , toolEnv . getTypes () , true );
268
+ rider .overrides (ridee , origin , javacTypes , true );
360
269
}
361
270
362
271
// TODO: jx.l.m ?
0 commit comments