diff --git a/deps4j/build.gradle b/deps4j/build.gradle index 463eee5caeb1caacc2a1eb9d89eaac2240277903..87727a20be7a551bbae71267f065f2ea494da514 100644 --- a/deps4j/build.gradle +++ b/deps4j/build.gradle @@ -50,10 +50,13 @@ jastadd { imports "java8 frontend" jastadd { - include "src/gen/jastadd/Java.ast" - include "src/gen/jastadd/Java.jadd" - include "src/main/jastadd/*.jrag" - include "src/main/jastadd/*.jadd" + basedir ".." + include "deps4j/src/gen/jastadd/Java.ast" + include "deps4j/src/gen/jastadd/Java.jadd" + include "deps4j/src/main/jastadd/*.jrag" + include "deps4j/src/main/jastadd/*.jadd" + include "dg/src/main/jastadd/*.jrag" + include "dg/src/main/jastadd/*.jadd" excludeFrom "java8 frontend", "grammar/ConstructorReference.ast" excludeFrom "java8 frontend", "grammar/IntersectionCasts.ast" diff --git a/deps4j/src/main/jastadd/DGtoDotG.jrag b/deps4j/src/main/jastadd/DGtoDotG.jrag deleted file mode 100644 index 27c54fb4066f906a0ec126c82039e0147527e4d9..0000000000000000000000000000000000000000 --- a/deps4j/src/main/jastadd/DGtoDotG.jrag +++ /dev/null @@ -1,65 +0,0 @@ -aspect DGtoDotG { - - syn DotGraph DependencyGraph.dotGraph() { - DotGraph dg = new DotGraph(); - //create DotGraph - dg.setDependencyGraph(this); - Map<Component,DotNode> componentMap = new HashMap<>(); - for (Component component: getComponentList()) { - DotNode n = new DotNode(); - n.setComponent(component); - dg.addDotNode(n); - componentMap.put(component, n); - } - - for (Component from: getComponentList()) { - for (Component to: from.getToList()) { - if (to.getToList().contains(from)) { - if (to.hashCode() < from.hashCode()) { - componentMap.get(from).addRel(componentMap.get(to)); - } - } else { - componentMap.get(from).addRef(componentMap.get(to)); - } - } - } - - return dg; - } - - syn DotGraph DependencyGraph.dotGraph(Set<Component> components) { - DotGraph dg = new DotGraph(); - //Ensure that components are part of DependencyGraph - Set<Component> subset=new HashSet(); - for (Component c:getComponentList()) - subset.add(c); - subset.retainAll(components); - - //create DotGraph - dg.setDependencyGraph(this); - Map<Component,DotNode> componentMap = new HashMap<>(); - for (Component component: subset) { - DotNode n = new DotNode(); - n.setComponent(component); - dg.addDotNode(n); - componentMap.put(component, n); - } - - for (Component from: subset) { - for (Component to: from.getToList()) { - if (subset.contains(to)) { - if (to.getToList().contains(from)) { - if (to.hashCode() < from.hashCode()) { - componentMap.get(from).addRel(componentMap.get(to)); - } - } else { - componentMap.get(from).addRef(componentMap.get(to)); - } - } - } - } - - return dg; - } - -} diff --git a/deps4j/src/main/jastadd/DependencyGraphReachability.jrag b/deps4j/src/main/jastadd/DependencyGraphReachability.jrag deleted file mode 100644 index 757ab2a229246167dd8dab56e88e8b92e16f1ed3..0000000000000000000000000000000000000000 --- a/deps4j/src/main/jastadd/DependencyGraphReachability.jrag +++ /dev/null @@ -1,59 +0,0 @@ -import java.util.*; -import java.util.stream.Collectors; - -aspect Naviagation { - inh DependencyGraph Component.dg(); - eq DependencyGraph.getComponent().dg() = this; -} - -aspect Reachability { - -// old, dependency-based algorithm for SCC - -// coll Set<Component> Component.successors() circular [new HashSet<>()] with add root DependencyGraph; -// Component contributes this to Component.successors() for each getToList(); -// Component contributes each this.successors() to Component.successors() for each getToList(); - -// coll Set<Component> Component.predecessors() [new HashSet<>()] with add root DependencyGraph; -// Component contributes this to Component.predecessors() for each successors(); - -// coll HashSet<Component> Component.SCC() with add root DependencyGraph; -// Component contributes each predecessors() when (successors().contains(this)) to Component.SCC() for this; - -// coll HashSet<Set<Component>> DependencyGraph.SCC() with add root DependencyGraph; -// Component contributes SCC() when SCC().size() > 0 to DependencyGraph.SCC(); - - /** - * Kosaraju's algorithm - */ - syn Set<Set<Component>> DependencyGraph.SCC() { - Map<Component, Set> visited = new HashMap<>(); - LinkedList<Component> locked = new LinkedList<>(); - - for (Component c : getComponentList()) - if (!visited.containsKey(c)) - c.visit(visited, locked); // forward search - - for (Component c : locked) - if (visited.get(c) == null) - c.assign(visited, new HashSet()); // backward search - - return new HashSet(visited.values()); - } - - void Component.visit(Map<Component, Set> visited, LinkedList<Component> locked) { - visited.put(this, null); - for (Component c : getFromList()) - if (!visited.containsKey(c)) - c.visit(visited, locked); - locked.addFirst(this); - } - - void Component.assign(Map<Component, Set> visited, Set scc) { - scc.add(this); - visited.put(this, scc); - for (Component c : getToList()) - if (visited.get(c) == null) - c.assign(visited, scc); - } -} diff --git a/deps4j/src/main/jastadd/DotGraph.jrag b/deps4j/src/main/jastadd/DotGraph.jrag deleted file mode 100644 index a6ee204eb2ce04b0840395e48f933c290dc2de14..0000000000000000000000000000000000000000 --- a/deps4j/src/main/jastadd/DotGraph.jrag +++ /dev/null @@ -1,58 +0,0 @@ -aspect DotGraphToPlantUML { - - inh String DotNode.name(); - eq DotGraph.getDotNode(int i).name() = "v" + i; - - syn String DotNode.label() = name(); - - syn String DotGraph.toDot() { - StringBuilder b = new StringBuilder(); - b.append("strict digraph cycles {\n"); - - for (DotNode from: getDotNodeList()) { - b.append(" ").append(from.name()).append("[label=\"").append(from.label()).append("\"];\n"); - - for (DotNode to: from.getRefList()) { - b.append(" ").append(from.name()).append(" -> ").append(to.name()).append(";\n"); - } - for (DotNode to: from.getRelList()) { - b.append(" ").append(from.name()).append(" -> ").append(to.name()).append("[dir=\"both\"];\n"); - } - } - - b.append("}\n"); - return b.toString(); - } - - syn String DotGraph.toPlant(String shape, String relation) { - StringBuilder b = new StringBuilder(); - b.append("@startuml\n") - .append("hide circle\n") - .append("skinparam shadowing false\n") - .append("skinparam monochrome true\n") - .append("skinparam classAttributeIconSize 0\n") - .append("/'Remove automatic namespace generation'/\n") - .append("set namespaceSeparator none\n"); - - for (DotNode from: getDotNodeList()) { - b.append(shape).append(" ") - .append(from.label()).append("\n"); - } - - for (DotNode from: getDotNodeList()) { - for (DotNode to: from.getRefList()) { - b.append(from.label()) - .append(" ").append(relation).append("> ") - .append(to.label()).append("\n"); - } - for (DotNode to: from.getRelList()) { - b.append(from.label()) - .append(" <").append(relation).append("> ") - .append(to.label()).append("\n"); - } - } - - b.append("@enduml\n"); - return b.toString(); - } -}