diff --git a/README.md b/README.md index 6eff6a5..f439d73 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Join the chat at https://gitter.im/JavaDataFlow/community](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/JavaDataFlow/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![maven-central](https://img.shields.io/maven-central/v/com.github.daanvdh.javadataflow/JavaDataFlow.svg)](https://search.maven.org/search?q=g:com.github.daanvdh.javadataflow) + # JavaDataFlow Creating Data Flow Graphs from java input classes @@ -39,15 +42,15 @@ A DataFlowGraph represents a single class. Now if we want to gather all input nodes to this class that can influence the output of the method "getA", we can do that as given below. First get the given method. Now we need to walk back until we reach a node that is an input parameter of a method, for this we can use the method DataFlowNode::isInputParameter. -For this example we don't want to go outside this class so we add dfg::owns as scope to the method walkBackUntil. -The scope determines when to stop walking over the nodes, this can become important multiple data flow graphs are connected to each other. +For this example we don't want to go outside of this class so we add dfg::owns as scope to the method walkBackUntil. +The scope determines when to stop walking over the nodes, this can become important if multiple data flow graphs are connected to each other. However, this is currently not supported yet. DataFlowMethod getA = dfg.getMethods().stream().filter(m -> m.getName().equals("getA")).findFirst().get(); List inputNodes = getA.getReturnNode().get().walkBackUntil(DataFlowNode::isInputParameter, dfg::owns); System.out.println(inputNodes.get(0).getName()); -The above code will output the name "inputA". +The above code will output the name "inputA". All code above is also given in an [example project](https://github.com/daanvdh/JavaDataFlowExample). ## Setup Add the dependency below to the pom of your project. @@ -57,7 +60,6 @@ Add the dependency below to the pom of your project. JavaDataFlow 0.0.5 - ## Definitions - Any **object or primitive** is modelled as a DataFlowNode. @@ -93,4 +95,4 @@ Add the dependency below to the pom of your project. ## License -JavaDataFlow is available under the terms of the Apache License. http://www.apache.org/licenses/LICENSE-2.0 \ No newline at end of file +JavaDataFlow is available under the terms of the Apache License. http://www.apache.org/licenses/LICENSE-2.0 diff --git a/pom.xml b/pom.xml index 962a3f2..97d0b23 100644 --- a/pom.xml +++ b/pom.xml @@ -140,7 +140,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/src/main/java/factory/MethodNodeHandler.java b/src/main/java/factory/MethodNodeHandler.java index 444c0a9..c6127a4 100644 --- a/src/main/java/factory/MethodNodeHandler.java +++ b/src/main/java/factory/MethodNodeHandler.java @@ -274,7 +274,7 @@ private Optional getDataFlowNode(DataFlowGraph graph, DataFlowMeth if (optionalResolvedNode.isPresent()) { Node resolvedNode = optionalResolvedNode.get(); flowNode = getLastFlowNode(graph, method, overwriddenValues, resolvedNode); - flowNode = (flowNode != null && !(resolvedNode instanceof VariableDeclarationExpr)) ? flowNode + flowNode = (flowNode != null || !(resolvedNode instanceof VariableDeclarationExpr)) ? flowNode : ((VariableDeclarationExpr) resolvedNode).getVariables().stream().map(child -> getLastFlowNode(graph, method, overwriddenValues, child)) .filter(n -> n != null).findFirst().orElse(null); }