@Test public void priorityOrder() throws Exception { File basedir = util.resolveFile("src/test/resources/priority"); List<ClassDef> classes = scan(basedir); assertThat(classes, hasSize(5)); ClassDef poo = classes.get(0); assertThat(poo.getName(), is("Poo")); ClassDef ick = classes.get(1); assertThat(ick.getName(), is("Ick")); assertThat(ick.getDependencies(), contains("Poo")); ClassDef baz = classes.get(2); assertThat(baz.getName(), is("Baz")); ClassDef bar = classes.get(3); assertThat(bar.getName(), is("Bar")); assertThat(bar.getDependencies(), contains("Baz")); ClassDef foo = classes.get(4); assertThat(foo.getName(), is("Foo")); assertThat(foo.getDependencies(), contains("Bar")); }
public List<ClassDef> scan(final Scanner files) throws Exception { checkNotNull(files); final boolean debug = log.isDebugEnabled(); classes.clear(); log.debug("Finding files to scan..."); files.scan(); String[] included = files.getIncludedFiles(); log.debug("Scanning " + included.length + " files..."); for (String path : included) { File file = new File(files.getBasedir(), path); scan(file); } Map<String, ClassDef> classNames = new HashMap<>(); List<ClassDef> allClasses = new ArrayList<>(); for (ClassDef def : classes.values()) { log.debug("Processing: " + def); classNames.put(def.getName(), def); for (String alt : def.getAlternateClassName()) { classNames.put(alt, def); } resolve(def); allClasses.add(def); } Collections.sort(allClasses, new Comparator<ClassDef>() { @Override public int compare(final ClassDef a, final ClassDef b) { return Double.compare(b.getPriority(), a.getPriority()); } }); if (debug) { log.debug("All classes:"); for (ClassDef def : allClasses) { log.debug(" " + def.getName()); } } DAG graph = new DAG(); for (ClassDef def : allClasses) { graph.addVertex(def.getName()); for (String name : def.getDependencies()) { ClassDef dep = classNames.get(name); if (dep != null) { name = dep.getName(); } graph.addEdge(def.getName(), name); } } if (debug) { log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); } } if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel()); } } } } Set<ClassDef> results = new LinkedHashSet<>(); log.debug("Ordered classes:"); for (String className : TopologicalSorter.sort(graph)) { ClassDef def = classNames.get(className); if (def != null && !results.contains(def)) { log.debug(" " + def.getName()); results.add(def); } } log.debug("Found " + results.size() + " classes"); return new ArrayList<>(results); }
ClassDefScanner { public List<ClassDef> scan(final Scanner files) throws Exception { checkNotNull(files); final boolean debug = log.isDebugEnabled(); classes.clear(); log.debug("Finding files to scan..."); files.scan(); String[] included = files.getIncludedFiles(); log.debug("Scanning " + included.length + " files..."); for (String path : included) { File file = new File(files.getBasedir(), path); scan(file); } Map<String, ClassDef> classNames = new HashMap<>(); List<ClassDef> allClasses = new ArrayList<>(); for (ClassDef def : classes.values()) { log.debug("Processing: " + def); classNames.put(def.getName(), def); for (String alt : def.getAlternateClassName()) { classNames.put(alt, def); } resolve(def); allClasses.add(def); } Collections.sort(allClasses, new Comparator<ClassDef>() { @Override public int compare(final ClassDef a, final ClassDef b) { return Double.compare(b.getPriority(), a.getPriority()); } }); if (debug) { log.debug("All classes:"); for (ClassDef def : allClasses) { log.debug(" " + def.getName()); } } DAG graph = new DAG(); for (ClassDef def : allClasses) { graph.addVertex(def.getName()); for (String name : def.getDependencies()) { ClassDef dep = classNames.get(name); if (dep != null) { name = dep.getName(); } graph.addEdge(def.getName(), name); } } if (debug) { log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); } } if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel()); } } } } Set<ClassDef> results = new LinkedHashSet<>(); log.debug("Ordered classes:"); for (String className : TopologicalSorter.sort(graph)) { ClassDef def = classNames.get(className); if (def != null && !results.contains(def)) { log.debug(" " + def.getName()); results.add(def); } } log.debug("Found " + results.size() + " classes"); return new ArrayList<>(results); } }
ClassDefScanner { public List<ClassDef> scan(final Scanner files) throws Exception { checkNotNull(files); final boolean debug = log.isDebugEnabled(); classes.clear(); log.debug("Finding files to scan..."); files.scan(); String[] included = files.getIncludedFiles(); log.debug("Scanning " + included.length + " files..."); for (String path : included) { File file = new File(files.getBasedir(), path); scan(file); } Map<String, ClassDef> classNames = new HashMap<>(); List<ClassDef> allClasses = new ArrayList<>(); for (ClassDef def : classes.values()) { log.debug("Processing: " + def); classNames.put(def.getName(), def); for (String alt : def.getAlternateClassName()) { classNames.put(alt, def); } resolve(def); allClasses.add(def); } Collections.sort(allClasses, new Comparator<ClassDef>() { @Override public int compare(final ClassDef a, final ClassDef b) { return Double.compare(b.getPriority(), a.getPriority()); } }); if (debug) { log.debug("All classes:"); for (ClassDef def : allClasses) { log.debug(" " + def.getName()); } } DAG graph = new DAG(); for (ClassDef def : allClasses) { graph.addVertex(def.getName()); for (String name : def.getDependencies()) { ClassDef dep = classNames.get(name); if (dep != null) { name = dep.getName(); } graph.addEdge(def.getName(), name); } } if (debug) { log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); } } if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel()); } } } } Set<ClassDef> results = new LinkedHashSet<>(); log.debug("Ordered classes:"); for (String className : TopologicalSorter.sort(graph)) { ClassDef def = classNames.get(className); if (def != null && !results.contains(def)) { log.debug(" " + def.getName()); results.add(def); } } log.debug("Found " + results.size() + " classes"); return new ArrayList<>(results); } ClassDefScanner(final Log log); }
ClassDefScanner { public List<ClassDef> scan(final Scanner files) throws Exception { checkNotNull(files); final boolean debug = log.isDebugEnabled(); classes.clear(); log.debug("Finding files to scan..."); files.scan(); String[] included = files.getIncludedFiles(); log.debug("Scanning " + included.length + " files..."); for (String path : included) { File file = new File(files.getBasedir(), path); scan(file); } Map<String, ClassDef> classNames = new HashMap<>(); List<ClassDef> allClasses = new ArrayList<>(); for (ClassDef def : classes.values()) { log.debug("Processing: " + def); classNames.put(def.getName(), def); for (String alt : def.getAlternateClassName()) { classNames.put(alt, def); } resolve(def); allClasses.add(def); } Collections.sort(allClasses, new Comparator<ClassDef>() { @Override public int compare(final ClassDef a, final ClassDef b) { return Double.compare(b.getPriority(), a.getPriority()); } }); if (debug) { log.debug("All classes:"); for (ClassDef def : allClasses) { log.debug(" " + def.getName()); } } DAG graph = new DAG(); for (ClassDef def : allClasses) { graph.addVertex(def.getName()); for (String name : def.getDependencies()) { ClassDef dep = classNames.get(name); if (dep != null) { name = dep.getName(); } graph.addEdge(def.getName(), name); } } if (debug) { log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); } } if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel()); } } } } Set<ClassDef> results = new LinkedHashSet<>(); log.debug("Ordered classes:"); for (String className : TopologicalSorter.sort(graph)) { ClassDef def = classNames.get(className); if (def != null && !results.contains(def)) { log.debug(" " + def.getName()); results.add(def); } } log.debug("Found " + results.size() + " classes"); return new ArrayList<>(results); } ClassDefScanner(final Log log); boolean isWarnings(); void setWarnings(final boolean warnings); @Nullable String getNamespace(); void setNamespace(@Nullable final String namespace); List<ClassDef> scan(final Scanner files); }
ClassDefScanner { public List<ClassDef> scan(final Scanner files) throws Exception { checkNotNull(files); final boolean debug = log.isDebugEnabled(); classes.clear(); log.debug("Finding files to scan..."); files.scan(); String[] included = files.getIncludedFiles(); log.debug("Scanning " + included.length + " files..."); for (String path : included) { File file = new File(files.getBasedir(), path); scan(file); } Map<String, ClassDef> classNames = new HashMap<>(); List<ClassDef> allClasses = new ArrayList<>(); for (ClassDef def : classes.values()) { log.debug("Processing: " + def); classNames.put(def.getName(), def); for (String alt : def.getAlternateClassName()) { classNames.put(alt, def); } resolve(def); allClasses.add(def); } Collections.sort(allClasses, new Comparator<ClassDef>() { @Override public int compare(final ClassDef a, final ClassDef b) { return Double.compare(b.getPriority(), a.getPriority()); } }); if (debug) { log.debug("All classes:"); for (ClassDef def : allClasses) { log.debug(" " + def.getName()); } } DAG graph = new DAG(); for (ClassDef def : allClasses) { graph.addVertex(def.getName()); for (String name : def.getDependencies()) { ClassDef dep = classNames.get(name); if (dep != null) { name = dep.getName(); } graph.addEdge(def.getName(), name); } } if (debug) { log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); } } if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel()); } } } } Set<ClassDef> results = new LinkedHashSet<>(); log.debug("Ordered classes:"); for (String className : TopologicalSorter.sort(graph)) { ClassDef def = classNames.get(className); if (def != null && !results.contains(def)) { log.debug(" " + def.getName()); results.add(def); } } log.debug("Found " + results.size() + " classes"); return new ArrayList<>(results); } ClassDefScanner(final Log log); boolean isWarnings(); void setWarnings(final boolean warnings); @Nullable String getNamespace(); void setNamespace(@Nullable final String namespace); List<ClassDef> scan(final Scanner files);  }