langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PathAndPackageVerifier.java
changeset 31115 8d8e98052d5d
parent 26992 92e69fa21956
child 34752 9c262a013456
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PathAndPackageVerifier.java	Tue Jun 09 11:52:13 2015 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/comp/PathAndPackageVerifier.java	Tue Jun 09 15:57:45 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
 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 {
 
@@ -50,30 +51,37 @@
 
     @Override
     @DefinedBy(Api.COMPILER_TREE)
-    public void started(TaskEvent e) {
+    public void finished(TaskEvent e) {
+        if (e.getKind() == TaskEvent.Kind.ANALYZE) {
+
+            CompilationUnitTree cu = e.getCompilationUnit();
+            if (cu == null)
+                return;
+
+            JavaFileObject jfo = cu.getSourceFile();
+            if (jfo == null)
+                return; // No source file -> package doesn't matter
+
+            JCTree pkg = (JCTree) cu.getPackageName();
+            if (pkg == null)
+                return; // Default package. See JDK-8048144.
+
+            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());
+            }
+        }
     }
 
-    @Override
-    @DefinedBy(Api.COMPILER_TREE)
-    public void finished(TaskEvent e) {
-        if (e.getKind() != TaskEvent.Kind.ANALYZE)
-            return;
-
-        CompilationUnitTree cu = e.getCompilationUnit();
-        if (cu == null)
-            return;
-
-        JavaFileObject jfo = cu.getSourceFile();
-        if (jfo == null)
-            return; // No source file -> package doesn't matter
-
-        JCTree pkg = (JCTree) cu.getPackageName();
-        if (pkg == null)
-            return; // Default package. See JDK-8048144.
-
-        Path dir = Paths.get(jfo.toUri()).normalize().getParent();
-        if (!checkPathAndPackage(dir, pkg))
-            misplacedCompilationUnits.add(cu);
+    public boolean errorsDiscovered() {
+        return misplacedCompilationUnits.size() > 0;
     }
 
     /* Returns true if dir matches pkgName.
@@ -94,10 +102,6 @@
         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
      */