@Override public void validate() { Map<String, Binding<?>> allBindings = linkEverything(); new ProblemDetector().detectProblems(allBindings.values()); }
public void detectProblems(Collection<Binding<?>> values) { detectCircularDependencies(values); detectUnusedBinding(values); }
try { bindings = processCompleteModule(moduleType, false); new ProblemDetector().detectCircularDependencies(bindings.values()); } catch (ModuleValidationException e) { error("Graph validation failed: " + e.getMessage(), e.source); Map<String, Binding<?>> bindings = processCompleteModule(moduleType, true); try { new ProblemDetector().detectUnusedBinding(bindings.values()); } catch (IllegalStateException e) { error("Graph validation failed: " + e.getMessage(), moduleType);
public void detectCircularDependencies(Collection<Binding<?>> bindings) { detectCircularDependencies(bindings, new ArrayList<Binding<?>>()); }
private static void detectCircularDependencies(Collection<Binding<?>> bindings, List<Binding<?>> path) { for (Binding<?> binding : bindings) { if (binding.isCycleFree()) { continue; } if (binding.isVisiting()) { int index = path.indexOf(binding); StringBuilder message = new StringBuilder() .append("Dependency cycle:"); for (int i = index; i < path.size(); i++) { message.append("\n ").append(i - index).append(". ") .append(path.get(i).provideKey).append(" bound by ").append(path.get(i)); } message.append("\n ").append(0).append(". ").append(binding.provideKey); throw new IllegalStateException(message.toString()); } binding.setVisiting(true); path.add(binding); try { ArraySet<Binding<?>> dependencies = new ArraySet<Binding<?>>(); binding.getDependencies(dependencies, dependencies); detectCircularDependencies(dependencies, path); binding.setCycleFree(true); } finally { path.remove(path.size() - 1); binding.setVisiting(false); } } }
/** * Do runtime graph problem detection. For fastest graph creation, rely on * build time tools for graph validation. * * @throws IllegalStateException if this graph has problems. */ public void validate() { Map<String, Binding<?>> allBindings = linkEverything(); new ProblemDetector().detectProblems(allBindings.values()); }
public void detectProblems(Collection<Binding<?>> bindings) { detectCircularDependencies(bindings, new ArrayList<Binding<?>>()); }
public void detectCircularDependencies(Collection<Binding<?>> bindings, List<Binding<?>> path) { for (Binding<?> binding : bindings) { if (binding.isCycleFree()) { continue; } if (binding.isVisiting()) { int index = path.indexOf(binding); StringBuilder message = new StringBuilder() .append("Dependency cycle:"); for (int i = index; i < path.size(); i++) { message.append("\n ").append(i - index).append(". ") .append(path.get(i).provideKey).append(" bound by ").append(path.get(i)); } message.append("\n ").append(0).append(". ").append(binding.provideKey); throw new IllegalStateException(message.toString()); } binding.setVisiting(true); path.add(binding); try { ArraySet<Binding<?>> dependencies = new ArraySet<Binding<?>>(); binding.getDependencies(dependencies, dependencies); detectCircularDependencies(dependencies, path); binding.setCycleFree(true); } finally { path.remove(path.size() - 1); binding.setVisiting(false); } } }