8080870: Open up Dependencies for use from other packages
authoralundblad
Thu, 21 May 2015 21:15:28 +0200
changeset 30731 38eaf2ca243e
parent 30730 d3ce7619db2c
child 30733 f4b21d02e886
8080870: Open up Dependencies for use from other packages Summary: Opened up Dependencies for use outside of the package. Reviewed-by: mcimadamore
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java	Thu May 21 11:41:04 2015 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Dependencies.java	Thu May 21 21:15:28 2015 +0200
@@ -145,8 +145,8 @@
 
     /**
      * This class creates a graph of all dependencies as symbols are completed;
-     * when compilation finishes, the resulting dependecy graph is then dumped
-     * onto a dot file. Several options are provided to customise the output of the graph.
+     * when compilation finishes, the resulting dependency graph is then dumped
+     * onto a dot file. Several options are provided to customize the output of the graph.
      */
     public static class GraphDependencies extends Dependencies implements Closeable, Completer {
 
@@ -233,13 +233,13 @@
          * (either from source or classfile); (ii) attribution nodes, corresponding to
          * attribution actions triggered during (source) completion.
          */
-        static abstract class Node extends GraphUtils.AbstractNode<String, Node>
+        public static abstract class Node extends GraphUtils.AbstractNode<String, Node>
                 implements GraphUtils.DottableNode<String, Node> {
 
             /**
              * Model the dependencies between nodes.
              */
-            enum DependencyKind implements GraphUtils.DependencyKind {
+            public enum DependencyKind implements GraphUtils.DependencyKind {
                 /**
                  * standard dependency - i.e. completion of the source node depends
                  * on completion of the sink node.
@@ -326,7 +326,7 @@
          * This is a dependency node used to model symbol completion requests.
          * Completion requests can come from either source or class.
          */
-        static class CompletionNode extends Node {
+        public static class CompletionNode extends Node {
 
             /**
              * Completion kind (source vs. classfile)
@@ -349,9 +349,11 @@
             }
 
             final Kind ck;
+            final ClassSymbol sym;
 
             CompletionNode(ClassSymbol sym) {
                 super(sym.getQualifiedName().toString());
+                this.sym = sym;
                 //infer completion kind by looking at the symbol fields
                 boolean fromClass = (sym.classfile == null && sym.sourcefile == null) ||
                         (sym.classfile != null && sym.classfile.getKind() == JavaFileObject.Kind.CLASS);
@@ -367,6 +369,10 @@
                 p.put("shape", "ellipse");
                 return p;
             }
+
+            public ClassSymbol getClassSymbol() {
+                return sym;
+            }
         }
 
         /**
@@ -437,23 +443,23 @@
 
         @Override
         public void close() throws IOException {
+            if (!dependenciesModes.contains(DependenciesMode.REDUNDANT)) {
+                //prune spurious edges
+                new PruneVisitor().visit(dependencyNodeMap.values(), null);
+            }
+            if (!dependenciesModes.contains(DependenciesMode.CLASS)) {
+                //filter class completions
+                new FilterVisitor(CompletionNode.Kind.SOURCE).visit(dependencyNodeMap.values(), null);
+            }
+            if (!dependenciesModes.contains(DependenciesMode.SOURCE)) {
+                //filter source completions
+                new FilterVisitor(CompletionNode.Kind.CLASS).visit(dependencyNodeMap.values(), null);
+            }
+            if (dependenciesModes.contains(DependenciesMode.SIDE_EFFECTS)) {
+                //add side-effects edges
+                new SideEffectVisitor().visit(dependencyNodeMap.values(), null);
+            }
             if (dependenciesFile != null) {
-                if (!dependenciesModes.contains(DependenciesMode.REDUNDANT)) {
-                    //prune spurious edges
-                    new PruneVisitor().visit(dependencyNodeMap.values(), null);
-                }
-                if (!dependenciesModes.contains(DependenciesMode.CLASS)) {
-                    //filter class completions
-                    new FilterVisitor(CompletionNode.Kind.SOURCE).visit(dependencyNodeMap.values(), null);
-                }
-                if (!dependenciesModes.contains(DependenciesMode.SOURCE)) {
-                    //filter source completions
-                    new FilterVisitor(CompletionNode.Kind.CLASS).visit(dependencyNodeMap.values(), null);
-                }
-                if (dependenciesModes.contains(DependenciesMode.SIDE_EFFECTS)) {
-                    //add side-effects edges
-                    new SideEffectVisitor().visit(dependencyNodeMap.values(), null);
-                }
                 //write to file
                 try (FileWriter fw = new FileWriter(dependenciesFile)) {
                     fw.append(GraphUtils.toDot(dependencyNodeMap.values(), "CompletionDeps", ""));
@@ -473,6 +479,10 @@
             return true;
         }
 
+        public Collection<Node> getNodes() {
+            return dependencyNodeMap.values();
+        }
+
         /**
          * This visitor is used to generate the special side-effect dependencies
          * given a graph containing only standard dependencies.