@Test public void callgraphTest() { Graph<org.eclipse.steady.shared.json.model.ConstructId> graph = SlowSparseNumberedGraph.make(); ConstructId a = JavaId.toSharedType(JavaId.parseMethodQName("test.a()")); graph.addNode(a); ConstructId b = JavaId.toSharedType(JavaId.parseMethodQName("test.b()")); graph.addNode(b); ConstructId c = JavaId.toSharedType(JavaId.parseMethodQName("test.c()")); graph.addNode(c); ConstructId d = JavaId.toSharedType(JavaId.parseMethodQName("test.d()")); graph.addNode(d); ConstructId e = JavaId.toSharedType(JavaId.parseMethodQName("test.e()")); graph.addNode(e); ConstructId f = JavaId.toSharedType(JavaId.parseMethodQName("test.f()")); graph.addNode(f); ConstructId g = JavaId.toSharedType(JavaId.parseMethodQName("test.g()")); graph.addNode(g); ConstructId h = JavaId.toSharedType(JavaId.parseMethodQName("test.h()")); graph.addNode(h); ConstructId i = JavaId.toSharedType(JavaId.parseMethodQName("test.i()")); graph.addNode(i); ConstructId j = JavaId.toSharedType(JavaId.parseMethodQName("test.j()")); graph.addNode(j); graph.addEdge(a, b); graph.addEdge(a, c); graph.addEdge(b, d); graph.addEdge(b, e); graph.addEdge(b, f); graph.addEdge(c, f); graph.addEdge(c, g); graph.addEdge(e, h); graph.addEdge(f, i); graph.addEdge(h, i); graph.addEdge(h, j); graph.addEdge(i, j); graph.addEdge(g, j); graph.addEdge(i, e); Callgraph cg = new Callgraph(graph); Map<ConstructId, Integer> distance = cg.getDist(j); int dist = distance.get(a); assertEquals(dist, 3); Map<ConstructId, LinkedList<Integer>> shortestPaths = cg.getShortestPath(j, null); LinkedList<ConstructId> expectedShortestPath = new LinkedList<ConstructId>(); expectedShortestPath.add(c); expectedShortestPath.add(g); expectedShortestPath.add(j); LinkedList<Integer> spath = shortestPaths.get(a); LinkedList<ConstructId> computedShortestPath = new LinkedList<ConstructId>(); if (spath != null) { for (int n = (spath.size() - 1); n >= 0; n--) { computedShortestPath.add(cg.getConstructForId(spath.get(n))); } } assertEquals(computedShortestPath, expectedShortestPath); AbstractGetPaths getpaths = new DepthFirstGetPaths(cg.getGraph(), cg.getNodeId()); HashSet<LinkedList<ConstructId>> paths = getpaths.getAllPaths(a, j); for (LinkedList<ConstructId> p : paths) { for (ConstructId cid : p) System.out.print(cid.getQname() + " "); System.out.println(); } assertEquals(paths.size(), 7); getpaths = new PrunedGraphGetPaths(cg.getGraph(), cg.getNodeId()); paths = getpaths.getAllPaths(a, j); for (LinkedList<ConstructId> p : paths) { for (ConstructId cid : p) System.out.print(cid.getQname() + " "); System.out.println(); } assertEquals(paths.size(), 7); }
public Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g) { if (_g != null) { if (!this.cachedJarUrls.isEmpty()) { log.warn("JAR URL cache not empty, clearing now..."); this.cachedJarUrls.clear(); } if (!this.jarAnalyzersCache.isEmpty()) { log.warn("JarAnalyzer cache not empty, clearing now ..."); this.jarAnalyzersCache.clear(); } Iterator<org.eclipse.steady.shared.json.model.ConstructId> iter = _g.iterator(); org.eclipse.steady.shared.json.model.ConstructId src_node = null, tgt_node = null; Iterator<org.eclipse.steady.shared.json.model.ConstructId> succNodes = null; Integer src_id = null, tgt_id = null, count = -1; while (iter.hasNext()) { this.nodeCount++; src_node = iter.next(); src_id = this.nodeMap.get(src_node); if (src_id == null) { src_id = ++count; this.nodeMap.put(src_node, src_id); this.nodeInfoMap.put(src_id, this.createNodeMetaInformation(src_node, src_id)); this.nodeId.add(src_node); this.idgraph.addNode(src_id); } succNodes = _g.getSuccNodes(src_node); while (succNodes.hasNext()) { this.edgeCount++; tgt_node = succNodes.next(); tgt_id = this.nodeMap.get(tgt_node); if (tgt_id == null) { tgt_id = ++count; this.nodeMap.put(tgt_node, tgt_id); this.nodeInfoMap.put(tgt_id, this.createNodeMetaInformation(tgt_node, tgt_id)); this.nodeId.add(tgt_node); this.idgraph.addNode(tgt_id); } this.idgraph.addEdge(src_id, tgt_id); } } Callgraph.log.info("Built Graph<Integer> of " + this.idgraph.getNumberOfNodes() + " nodes"); } }
Callgraph { public Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g) { if (_g != null) { if (!this.cachedJarUrls.isEmpty()) { log.warn("JAR URL cache not empty, clearing now..."); this.cachedJarUrls.clear(); } if (!this.jarAnalyzersCache.isEmpty()) { log.warn("JarAnalyzer cache not empty, clearing now ..."); this.jarAnalyzersCache.clear(); } Iterator<org.eclipse.steady.shared.json.model.ConstructId> iter = _g.iterator(); org.eclipse.steady.shared.json.model.ConstructId src_node = null, tgt_node = null; Iterator<org.eclipse.steady.shared.json.model.ConstructId> succNodes = null; Integer src_id = null, tgt_id = null, count = -1; while (iter.hasNext()) { this.nodeCount++; src_node = iter.next(); src_id = this.nodeMap.get(src_node); if (src_id == null) { src_id = ++count; this.nodeMap.put(src_node, src_id); this.nodeInfoMap.put(src_id, this.createNodeMetaInformation(src_node, src_id)); this.nodeId.add(src_node); this.idgraph.addNode(src_id); } succNodes = _g.getSuccNodes(src_node); while (succNodes.hasNext()) { this.edgeCount++; tgt_node = succNodes.next(); tgt_id = this.nodeMap.get(tgt_node); if (tgt_id == null) { tgt_id = ++count; this.nodeMap.put(tgt_node, tgt_id); this.nodeInfoMap.put(tgt_id, this.createNodeMetaInformation(tgt_node, tgt_id)); this.nodeId.add(tgt_node); this.idgraph.addNode(tgt_id); } this.idgraph.addEdge(src_id, tgt_id); } } Callgraph.log.info("Built Graph<Integer> of " + this.idgraph.getNumberOfNodes() + " nodes"); } } }
Callgraph { public Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g) { if (_g != null) { if (!this.cachedJarUrls.isEmpty()) { log.warn("JAR URL cache not empty, clearing now..."); this.cachedJarUrls.clear(); } if (!this.jarAnalyzersCache.isEmpty()) { log.warn("JarAnalyzer cache not empty, clearing now ..."); this.jarAnalyzersCache.clear(); } Iterator<org.eclipse.steady.shared.json.model.ConstructId> iter = _g.iterator(); org.eclipse.steady.shared.json.model.ConstructId src_node = null, tgt_node = null; Iterator<org.eclipse.steady.shared.json.model.ConstructId> succNodes = null; Integer src_id = null, tgt_id = null, count = -1; while (iter.hasNext()) { this.nodeCount++; src_node = iter.next(); src_id = this.nodeMap.get(src_node); if (src_id == null) { src_id = ++count; this.nodeMap.put(src_node, src_id); this.nodeInfoMap.put(src_id, this.createNodeMetaInformation(src_node, src_id)); this.nodeId.add(src_node); this.idgraph.addNode(src_id); } succNodes = _g.getSuccNodes(src_node); while (succNodes.hasNext()) { this.edgeCount++; tgt_node = succNodes.next(); tgt_id = this.nodeMap.get(tgt_node); if (tgt_id == null) { tgt_id = ++count; this.nodeMap.put(tgt_node, tgt_id); this.nodeInfoMap.put(tgt_id, this.createNodeMetaInformation(tgt_node, tgt_id)); this.nodeId.add(tgt_node); this.idgraph.addNode(tgt_id); } this.idgraph.addEdge(src_id, tgt_id); } } Callgraph.log.info("Built Graph<Integer> of " + this.idgraph.getNumberOfNodes() + " nodes"); } } Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g); }
Callgraph { public Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g) { if (_g != null) { if (!this.cachedJarUrls.isEmpty()) { log.warn("JAR URL cache not empty, clearing now..."); this.cachedJarUrls.clear(); } if (!this.jarAnalyzersCache.isEmpty()) { log.warn("JarAnalyzer cache not empty, clearing now ..."); this.jarAnalyzersCache.clear(); } Iterator<org.eclipse.steady.shared.json.model.ConstructId> iter = _g.iterator(); org.eclipse.steady.shared.json.model.ConstructId src_node = null, tgt_node = null; Iterator<org.eclipse.steady.shared.json.model.ConstructId> succNodes = null; Integer src_id = null, tgt_id = null, count = -1; while (iter.hasNext()) { this.nodeCount++; src_node = iter.next(); src_id = this.nodeMap.get(src_node); if (src_id == null) { src_id = ++count; this.nodeMap.put(src_node, src_id); this.nodeInfoMap.put(src_id, this.createNodeMetaInformation(src_node, src_id)); this.nodeId.add(src_node); this.idgraph.addNode(src_id); } succNodes = _g.getSuccNodes(src_node); while (succNodes.hasNext()) { this.edgeCount++; tgt_node = succNodes.next(); tgt_id = this.nodeMap.get(tgt_node); if (tgt_id == null) { tgt_id = ++count; this.nodeMap.put(tgt_node, tgt_id); this.nodeInfoMap.put(tgt_id, this.createNodeMetaInformation(tgt_node, tgt_id)); this.nodeId.add(tgt_node); this.idgraph.addNode(tgt_id); } this.idgraph.addEdge(src_id, tgt_id); } } Callgraph.log.info("Built Graph<Integer> of " + this.idgraph.getNumberOfNodes() + " nodes"); } } Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g); Graph<Integer> getGraph(); int getIdForConstruct(org.eclipse.steady.shared.json.model.ConstructId _c); boolean existsInCallgraph(org.eclipse.steady.shared.json.model.ConstructId _c); ArrayList<org.eclipse.steady.shared.json.model.ConstructId> getNodeId(); org.eclipse.steady.shared.json.model.ConstructId getConstructForId(int _id); NodeMetaInformation getInformationForConstructId(
      org.eclipse.steady.shared.json.model.ConstructId target); Set<org.eclipse.steady.shared.json.model.ConstructId> getConstructsWithoutJarUrl(); NodeMetaInformation getInformationForId(Integer id); int getNodeCount(); int getEdgeCount(); Map<org.eclipse.steady.shared.json.model.ConstructId, Integer> getDist(
      org.eclipse.steady.shared.json.model.ConstructId _tgt); Map<org.eclipse.steady.shared.json.model.ConstructId, LinkedList<Integer>> getShortestPath(
      org.eclipse.steady.shared.json.model.ConstructId _tgt,
      final Set<org.eclipse.steady.shared.json.model.ConstructId> _stop_if_path_found); }
Callgraph { public Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g) { if (_g != null) { if (!this.cachedJarUrls.isEmpty()) { log.warn("JAR URL cache not empty, clearing now..."); this.cachedJarUrls.clear(); } if (!this.jarAnalyzersCache.isEmpty()) { log.warn("JarAnalyzer cache not empty, clearing now ..."); this.jarAnalyzersCache.clear(); } Iterator<org.eclipse.steady.shared.json.model.ConstructId> iter = _g.iterator(); org.eclipse.steady.shared.json.model.ConstructId src_node = null, tgt_node = null; Iterator<org.eclipse.steady.shared.json.model.ConstructId> succNodes = null; Integer src_id = null, tgt_id = null, count = -1; while (iter.hasNext()) { this.nodeCount++; src_node = iter.next(); src_id = this.nodeMap.get(src_node); if (src_id == null) { src_id = ++count; this.nodeMap.put(src_node, src_id); this.nodeInfoMap.put(src_id, this.createNodeMetaInformation(src_node, src_id)); this.nodeId.add(src_node); this.idgraph.addNode(src_id); } succNodes = _g.getSuccNodes(src_node); while (succNodes.hasNext()) { this.edgeCount++; tgt_node = succNodes.next(); tgt_id = this.nodeMap.get(tgt_node); if (tgt_id == null) { tgt_id = ++count; this.nodeMap.put(tgt_node, tgt_id); this.nodeInfoMap.put(tgt_id, this.createNodeMetaInformation(tgt_node, tgt_id)); this.nodeId.add(tgt_node); this.idgraph.addNode(tgt_id); } this.idgraph.addEdge(src_id, tgt_id); } } Callgraph.log.info("Built Graph<Integer> of " + this.idgraph.getNumberOfNodes() + " nodes"); } } Callgraph(Graph<org.eclipse.steady.shared.json.model.ConstructId> _g); Graph<Integer> getGraph(); int getIdForConstruct(org.eclipse.steady.shared.json.model.ConstructId _c); boolean existsInCallgraph(org.eclipse.steady.shared.json.model.ConstructId _c); ArrayList<org.eclipse.steady.shared.json.model.ConstructId> getNodeId(); org.eclipse.steady.shared.json.model.ConstructId getConstructForId(int _id); NodeMetaInformation getInformationForConstructId(
      org.eclipse.steady.shared.json.model.ConstructId target); Set<org.eclipse.steady.shared.json.model.ConstructId> getConstructsWithoutJarUrl(); NodeMetaInformation getInformationForId(Integer id); int getNodeCount(); int getEdgeCount(); Map<org.eclipse.steady.shared.json.model.ConstructId, Integer> getDist(
      org.eclipse.steady.shared.json.model.ConstructId _tgt); Map<org.eclipse.steady.shared.json.model.ConstructId, LinkedList<Integer>> getShortestPath(
      org.eclipse.steady.shared.json.model.ConstructId _tgt,
      final Set<org.eclipse.steady.shared.json.model.ConstructId> _stop_if_path_found);  }