src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PathAndPackageVerifier.java
Print this page
rev 2819 : imported patch my-classpath-deps-00
@@ -39,27 +39,23 @@
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.util.DefinedBy;
import com.sun.tools.javac.util.DefinedBy.Api;
import com.sun.tools.javac.util.Name;
+import com.sun.tools.sjavac.Log;
public class PathAndPackageVerifier implements TaskListener {
// Stores the set of compilation units whose source file path does not
// match the package declaration.
Set<CompilationUnitTree> misplacedCompilationUnits = new HashSet<>();
@Override
@DefinedBy(Api.COMPILER_TREE)
- public void started(TaskEvent e) {
- }
-
- @Override
- @DefinedBy(Api.COMPILER_TREE)
public void finished(TaskEvent e) {
- if (e.getKind() != TaskEvent.Kind.ANALYZE)
- return;
+ if (e.getKind() == TaskEvent.Kind.ANALYZE) {
+
CompilationUnitTree cu = e.getCompilationUnit();
if (cu == null)
return;
@@ -74,10 +70,24 @@
Path dir = Paths.get(jfo.toUri()).normalize().getParent();
if (!checkPathAndPackage(dir, pkg))
misplacedCompilationUnits.add(cu);
}
+ if (e.getKind() == TaskEvent.Kind.COMPILATION) {
+
+ for (CompilationUnitTree cu : misplacedCompilationUnits) {
+ Log.error("Misplaced compilation unit.");
+ Log.error(" Directory: " + Paths.get(cu.getSourceFile().toUri()).getParent());
+ Log.error(" Package: " + cu.getPackageName());
+ }
+ }
+ }
+
+ public boolean errorsDiscovered() {
+ return misplacedCompilationUnits.size() > 0;
+ }
+
/* Returns true if dir matches pkgName.
*
* Examples:
* (a/b/c, a.b.c) gives true
* (i/j/k, i.x.k) gives false
@@ -92,14 +102,10 @@
return false;
}
return !pkgIter.hasNext(); /*&& !pathIter.hasNext() See JDK-8059598 */
}
- public Set<CompilationUnitTree> getMisplacedCompilationUnits() {
- return misplacedCompilationUnits;
- }
-
/* Iterates over the names of the parents of the given path:
* Example: dir1/dir2/dir3 results in dir3 -> dir2 -> dir1
*/
private static class ParentIterator implements Iterator<String> {
Path next;