equal
deleted
inserted
replaced
66 DocEnv docenv; |
66 DocEnv docenv; |
67 |
67 |
68 final Messager messager; |
68 final Messager messager; |
69 final JavadocClassReader javadocReader; |
69 final JavadocClassReader javadocReader; |
70 final JavadocEnter javadocEnter; |
70 final JavadocEnter javadocEnter; |
|
71 final Set<JavaFileObject> uniquefiles; |
71 |
72 |
72 /** |
73 /** |
73 * Construct a new JavaCompiler processor, using appropriately |
74 * Construct a new JavaCompiler processor, using appropriately |
74 * extended phases of the underlying compiler. |
75 * extended phases of the underlying compiler. |
75 */ |
76 */ |
76 protected JavadocTool(Context context) { |
77 protected JavadocTool(Context context) { |
77 super(context); |
78 super(context); |
78 messager = Messager.instance0(context); |
79 messager = Messager.instance0(context); |
79 javadocReader = JavadocClassReader.instance0(context); |
80 javadocReader = JavadocClassReader.instance0(context); |
80 javadocEnter = JavadocEnter.instance0(context); |
81 javadocEnter = JavadocEnter.instance0(context); |
|
82 uniquefiles = new HashSet<>(); |
81 } |
83 } |
82 |
84 |
83 /** |
85 /** |
84 * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler. |
86 * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler. |
85 */ |
87 */ |
146 ? (StandardJavaFileManager) docenv.fileManager : null; |
148 ? (StandardJavaFileManager) docenv.fileManager : null; |
147 for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) { |
149 for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) { |
148 String name = it.head; |
150 String name = it.head; |
149 if (!docClasses && fm != null && name.endsWith(".java") && new File(name).exists()) { |
151 if (!docClasses && fm != null && name.endsWith(".java") && new File(name).exists()) { |
150 JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next(); |
152 JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next(); |
151 docenv.notice("main.Loading_source_file", name); |
153 parse(fo, classTrees, true); |
152 JCCompilationUnit tree = parse(fo); |
|
153 classTrees.append(tree); |
|
154 } else if (isValidPackageName(name)) { |
154 } else if (isValidPackageName(name)) { |
155 names = names.append(name); |
155 names = names.append(name); |
156 } else if (name.endsWith(".java")) { |
156 } else if (name.endsWith(".java")) { |
157 if (fm == null) |
157 if (fm == null) |
158 throw new IllegalArgumentException(); |
158 throw new IllegalArgumentException(); |
161 } else { |
161 } else { |
162 docenv.error(null, "main.illegal_package_name", name); |
162 docenv.error(null, "main.illegal_package_name", name); |
163 } |
163 } |
164 } |
164 } |
165 for (JavaFileObject fo: fileObjects) { |
165 for (JavaFileObject fo: fileObjects) { |
166 docenv.notice("main.Loading_source_file", fo.getName()); |
166 parse(fo, classTrees, true); |
167 JCCompilationUnit tree = parse(fo); |
|
168 classTrees.append(tree); |
|
169 } |
167 } |
170 |
168 |
171 if (!docClasses) { |
169 if (!docClasses) { |
172 // Recursively search given subpackages. If any packages |
170 // Recursively search given subpackages. If any packages |
173 //are found, add them to the list. |
171 //are found, add them to the list. |
211 /** |
209 /** |
212 * search all directories in path for subdirectory name. Add all |
210 * search all directories in path for subdirectory name. Add all |
213 * .java files found in such a directory to args. |
211 * .java files found in such a directory to args. |
214 */ |
212 */ |
215 private void parsePackageClasses(String name, |
213 private void parsePackageClasses(String name, |
216 Iterable<JavaFileObject> files, |
214 List<JavaFileObject> files, |
217 ListBuffer<JCCompilationUnit> trees, |
215 ListBuffer<JCCompilationUnit> trees, |
218 List<String> excludedPackages) |
216 List<String> excludedPackages) |
219 throws IOException { |
217 throws IOException { |
220 if (excludedPackages.contains(name)) { |
218 if (excludedPackages.contains(name)) { |
221 return; |
219 return; |
222 } |
220 } |
223 |
221 |
224 boolean hasFiles = false; |
|
225 docenv.notice("main.Loading_source_files_for_package", name); |
222 docenv.notice("main.Loading_source_files_for_package", name); |
226 |
223 |
227 if (files == null) { |
224 if (files == null) { |
228 Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
225 Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
229 ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
226 ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
236 lb.append(fo); |
233 lb.append(fo); |
237 } |
234 } |
238 } |
235 } |
239 files = lb.toList(); |
236 files = lb.toList(); |
240 } |
237 } |
241 |
238 if (files.nonEmpty()) { |
242 Set<JavaFileObject> ufiles = new HashSet<>(); |
239 for (JavaFileObject fo : files) { |
243 for (JavaFileObject fo : files) { |
240 parse(fo, trees, false); |
244 if (ufiles.add(fo)) { // ignore duplicates |
241 } |
245 // messager.notice("main.Loading_source_file", fn); |
242 } else { |
246 trees.append(parse(fo)); |
|
247 hasFiles = true; |
|
248 } |
|
249 } |
|
250 |
|
251 if (!hasFiles) { |
|
252 messager.warning(Messager.NOPOS, "main.no_source_files_for_package", |
243 messager.warning(Messager.NOPOS, "main.no_source_files_for_package", |
253 name.replace(File.separatorChar, '.')); |
244 name.replace(File.separatorChar, '.')); |
|
245 } |
|
246 } |
|
247 |
|
248 private void parse(JavaFileObject fo, ListBuffer<JCCompilationUnit> trees, |
|
249 boolean trace) { |
|
250 if (uniquefiles.add(fo)) { // ignore duplicates |
|
251 if (trace) |
|
252 docenv.notice("main.Loading_source_file", fo.getName()); |
|
253 trees.append(parse(fo)); |
254 } |
254 } |
255 } |
255 } |
256 |
256 |
257 /** |
257 /** |
258 * Recursively search all directories in path for subdirectory name. |
258 * Recursively search all directories in path for subdirectory name. |