28 import java.io.File; |
28 import java.io.File; |
29 import java.io.IOException; |
29 import java.io.IOException; |
30 import java.io.PrintWriter; |
30 import java.io.PrintWriter; |
31 import java.util.ArrayList; |
31 import java.util.ArrayList; |
32 import java.util.List; |
32 import java.util.List; |
33 import java.util.regex.Pattern; |
|
34 |
33 |
35 import javax.lang.model.element.Name; |
34 import javax.lang.model.element.Name; |
|
35 import javax.tools.Diagnostic; |
|
36 import javax.tools.JavaFileObject; |
36 import javax.tools.StandardLocation; |
37 import javax.tools.StandardLocation; |
37 |
38 |
38 import com.sun.source.doctree.DocCommentTree; |
39 import com.sun.source.doctree.DocCommentTree; |
39 import com.sun.source.tree.ClassTree; |
40 import com.sun.source.tree.ClassTree; |
40 import com.sun.source.tree.CompilationUnitTree; |
41 import com.sun.source.tree.CompilationUnitTree; |
149 @Override |
150 @Override |
150 void visitDecl(Tree tree, Name name) { |
151 void visitDecl(Tree tree, Name name) { |
151 TreePath p = getCurrentPath(); |
152 TreePath p = getCurrentPath(); |
152 DocCommentTree dc = env.trees.getDocCommentTree(p); |
153 DocCommentTree dc = env.trees.getDocCommentTree(p); |
153 |
154 |
|
155 if (p.getLeaf() == p.getCompilationUnit()) { |
|
156 JavaFileObject fo = p.getCompilationUnit().getSourceFile(); |
|
157 boolean pkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); |
|
158 if (!pkgInfo) { |
|
159 if (dc == null) |
|
160 return; |
|
161 env.setCurrent(p, dc); |
|
162 env.messages.report(Messages.Group.REFERENCE, Diagnostic.Kind.WARNING, p.getLeaf(), |
|
163 "dc.unexpected.comment"); |
|
164 } |
|
165 } |
|
166 |
154 checker.scan(dc, p); |
167 checker.scan(dc, p); |
155 } |
168 } |
156 }; |
169 }; |
157 |
170 |
158 ds.scan(units, null); |
171 ds.scan(units, null); |
164 c.printCount("error", c.errorCount()); |
177 c.printCount("error", c.errorCount()); |
165 c.printCount("warn", c.warningCount()); |
178 c.printCount("warn", c.warningCount()); |
166 } |
179 } |
167 |
180 |
168 void processArgs(String... args) throws BadArgs { |
181 void processArgs(String... args) throws BadArgs { |
169 javacOpts = new ArrayList<String>(); |
182 javacOpts = new ArrayList<>(); |
170 javacFiles = new ArrayList<File>(); |
183 javacFiles = new ArrayList<>(); |
171 |
184 |
172 if (args.length == 0) |
185 if (args.length == 0) |
173 needHelp = true; |
186 needHelp = true; |
174 |
187 |
175 for (int i = 0; i < args.length; i++) { |
188 for (int i = 0; i < args.length; i++) { |
212 for (String line: msg.split("\n")) |
225 for (String line: msg.split("\n")) |
213 out.println(line); |
226 out.println(line); |
214 } |
227 } |
215 |
228 |
216 List<File> splitPath(String path) { |
229 List<File> splitPath(String path) { |
217 List<File> files = new ArrayList<File>(); |
230 List<File> files = new ArrayList<>(); |
218 for (String f: path.split(File.pathSeparator)) { |
231 for (String f: path.split(File.pathSeparator)) { |
219 if (f.length() > 0) |
232 if (f.length() > 0) |
220 files.add(new File(f)); |
233 files.add(new File(f)); |
221 } |
234 } |
222 return files; |
235 return files; |