/** * Goes over the {@code innerComponents} collection checking if any reference is a {@link MacroExpansionModuleModel#TNS_PREFIX}, * in which case it adds an edge to the current vertex {@code sourceOperationVertex} * * @param directedGraph graph to contain all the vertex operations and linkage with other operations * @param sourceOperationVertex current vertex we are working on * @param innerComponents collection of elements to introspect and assembly the graph with */ private void fillGraphWithTnsReferences(DirectedGraph<String, DefaultEdge> directedGraph, String sourceOperationVertex, final List<ComponentModel> innerComponents) { innerComponents.forEach(childMPComponentModel -> { if (TNS_PREFIX.equals(childMPComponentModel.getIdentifier().getNamespace())) { // we will take the current component model name, as any child of it are actually TNS child references (aka: parameters) final String targetOperationVertex = childMPComponentModel.getIdentifier().getName(); if (!directedGraph.containsVertex(targetOperationVertex)) { directedGraph.addVertex(targetOperationVertex); } directedGraph.addEdge(sourceOperationVertex, targetOperationVertex); } else { // scenario for nested scopes that might be having cyclic references to operations childMPComponentModel.getInnerComponents() .forEach(childChildMPComponentModel -> fillGraphWithTnsReferences(directedGraph, sourceOperationVertex, childMPComponentModel.getInnerComponents())); } }); }
/** * <p>containsVertex</p> * * @param v a V object. * @return a boolean. */ public boolean containsVertex(V v) { // documentation says containsVertex() returns false on when given null return graph.containsVertex(v); }
@Override public boolean contains(MethodGraph element) { return directedGraph.containsVertex(element); }
public boolean containsVertex(ExecutableMethod v) { return graph.containsVertex(v); }
public boolean containsVertex(ExecutableMethod v) { return graph.containsVertex(v); }
public BfsIterator(DirectedGraph<V, ?> g, V startPos) { Preconditions.checkArgument(g.containsVertex(startPos)); elements = createOrderedVertexList(g, startPos); listIterator = elements.iterator(); }
/** * <p> * getUsesForDef * </p> * * @param def * a {@link org.evosuite.coverage.dataflow.Definition} object. * @return a {@link java.util.Set} object. */ public Set<Use> getUsesForDef(Definition def) { if (!graph.containsVertex(def)) throw new IllegalArgumentException("unknown Definition"); return getUsesForDef(def, def, new HashSet<BytecodeInstruction>()); }
/** * Removes vertices from graph * @param graph raph to mutate * @param vertices vertices to remove */ public static <V> void removeVertices(DirectedGraph<V, DefaultEdge> graph, Set<V> vertices) { for (V vertex : vertices) { if (graph.containsVertex(vertex)) { graph.removeVertex(vertex); } } } }
/** * TODO can be done more efficiently * @param graph * @param from * @param to * @return */ public static <V> boolean pathExists(DirectedGraph<V, ?> graph, V from, V to) { Preconditions.checkArgument(graph.containsVertex(from)); Preconditions.checkArgument(graph.containsVertex(to)); BfsIterator<V> iter = new BfsIterator<V>(graph, from); while (iter.hasNext()) { if (iter.next().equals(to)) { return true; } } return false; }
/** * <p> * hasDefClearPathFromMethodEntry * </p> * * @param duVertex * a {@link org.evosuite.coverage.dataflow.Use} object. * @return a boolean. */ public boolean hasDefClearPathFromMethodEntry(Use duVertex) { if (!graph.containsVertex(duVertex)) throw new IllegalArgumentException("vertex not in graph"); if (duVertex.isLocalDU()) return false; return hasDefClearPathFromMethodEntry(duVertex, duVertex, new HashSet<BytecodeInstruction>()); }
/** * <p> * hasDefClearPathToMethodExit * </p> * * @param duVertex * a {@link org.evosuite.coverage.dataflow.Definition} object. * @return a boolean. */ public boolean hasDefClearPathToMethodExit(Definition duVertex) { if (!graph.containsVertex(duVertex)) throw new IllegalArgumentException("vertex not in graph"); if (duVertex.isLocalDU()) return false; return hasDefClearPathToMethodExit(duVertex, duVertex, new HashSet<BytecodeInstruction>()); }
/** * Add dependencies to the given source vertex. Whether duplicates are created is dependent * on the underlying {@link DirectedGraph} implementation. * @param graph graph to be mutated * @param source source vertex of the new edges * @param targets target vertices for the new edges */ public static <V> void addOutgoingEdges(DirectedGraph<V, DefaultEdge> graph, V source, Set<V> targets) { if (!graph.containsVertex(source)) { graph.addVertex(source); } for (V target : targets) { if (!graph.containsVertex(target)) { graph.addVertex(target); } graph.addEdge(source, target); } }
/** * Add dependents on the give target vertex. Whether duplicates are created is dependent * on the underlying {@link DirectedGraph} implementation. * @param graph graph to be mutated * @param target target vertex for the new edges * @param sources source vertices for the new edges */ public static <N> void addIncomingEdges(DirectedGraph<N, DefaultEdge> graph, N target, Set<N> sources) { if (!graph.containsVertex(target)) { graph.addVertex(target); } for (N source : sources) { if (!graph.containsVertex(source)) { graph.addVertex(source); } graph.addEdge(source, target); } }
private void updateParentReferences(JavaClass parentClass) { for (String child : parentClass.getImports()) { JavaClass childClass = findJavaClass(child); if ((childClass != null) && !childClass.equals(parentClass)) { if (graph.containsVertex(childClass)) { graph.addEdge(parentClass, childClass); } } } }
private boolean hasDefClearPathFromMethodEntry(Use targetDefUse, BytecodeInstruction currentVertex, Set<BytecodeInstruction> handled) { if (!graph.containsVertex(currentVertex)) throw new IllegalArgumentException("vertex not in graph"); if (handled.contains(currentVertex)) return false; handled.add(currentVertex); Set<ControlFlowEdge> incomingEdges = graph.incomingEdgesOf(currentVertex); if (incomingEdges.size() == 0) return true; for (ControlFlowEdge e : incomingEdges) { BytecodeInstruction edgeStart = graph.getEdgeSource(e); // skip edges coming from a def for the same field if (canOverwriteDU(targetDefUse, edgeStart, new HashSet<String>())) continue; // if (edgeTarget.getInstructionId() > // currentVertex.getInstructionId() // dont follow backedges (loops) // && hasDefClearPathToMethodExit(targetDefUse, edgeTarget, // handled)) if (hasDefClearPathFromMethodEntry(targetDefUse, edgeStart, handled)) return true; } return false; }
/** * If the given node is contained within this graph and has exactly one * child v this method will return v. Otherwise it will return null * * @param node a V object. * @return a V object. */ public V getSingleChild(V node) { if (node == null) return null; if (!graph.containsVertex(node)) return null; if (outDegreeOf(node) != 1) return null; for (V r : getChildren(node)) return r; // should be unreachable return null; }
private void createOrUpdateJavaElementWithDependencies(JavaElement javaElement, List<Path> files) { for (Path file : files) { final FileElement fileElement = new FileElement(file); if (!graph.containsVertex(fileElement)) { graph.addVertex(fileElement); } if (!graph.containsEdge(javaElement, fileElement)) { graph.addEdge(javaElement, fileElement); } } }
public void addClassVariable(ClassVariable cv) { if (!this.typeGraph.containsVertex(cv)) { this.typeGraph.addVertex(cv); for (ClassVariable parent : cv.getParents()) { addClassVariable(parent); this.typeGraph.addEdge(parent, cv); } } }
protected DirectedGraph<Figure, DefaultEdge> extractMentionNetwork(JCas jcas) { DirectedGraph<Figure, DefaultEdge> graph = new DirectedPseudograph<Figure, DefaultEdge>(DefaultEdge.class); for (Utterance utterance : JCasUtil.select(jcas, Utterance.class)) { Speaker speaker = DramaUtil.getFirstSpeaker(utterance); if (speaker != null) for (FigureMention mention : JCasUtil.selectCovered(jcas, FigureMention.class, utterance)) { if (speaker.getFigure() != null && mention.getFigure() != null) { if (!graph.containsVertex(speaker.getFigure())) graph.addVertex(speaker.getFigure()); if (!graph.containsVertex(mention.getFigure())) graph.addVertex(mention.getFigure()); graph.addEdge(speaker.getFigure(), mention.getFigure()); } } } return graph; }
private boolean addImport(JavaElement javaElementParentClass, String importz) { if (coreJava.shouldBeIncluded(importz)) { JavaElement importClass = new JavaElement(importz); if (!importClass.equals(javaElementParentClass)) { if (!graph.containsVertex(importClass)) { graph.addVertex(importClass); } // This condition is required because we are flattening imports in graph if (!graph.containsEdge(javaElementParentClass, importClass)) { graph.addEdge(javaElementParentClass, importClass); return true; } } } return false; }