Skip to content

Commit

Permalink
Fix DotResult removal and use TypeUtils in Flow
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Leitschuh <[email protected]>
  • Loading branch information
JLLeitschuh committed Jun 13, 2023
1 parent cf8b622 commit 6db9bc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.marker.DotResult;
import org.openrewrite.marker.SearchResult;

import java.util.*;
Expand All @@ -45,7 +44,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, P
J.MethodDeclaration m = super.visitMethodDeclaration(method, p);
String dotFile = getCursor().pollMessage(CONTROL_FLOW_SUMMARY_CURSOR_MESSAGE);
if (dotFile != null) {
return m.withMarkers(m.getMarkers().add(new DotResult(Tree.randomId(), dotFile)));
return SearchResult.mergingFound(m, dotFile);
}
return m;
}
Expand Down Expand Up @@ -78,16 +77,16 @@ public J.Block visitBlock(J.Block block, P p) {

final String searchResultText =
"BB: " + controlFlow.getBasicBlocks().size() +
" CN: " + controlFlow.getConditionNodeCount() +
" EX: " + controlFlow.getExitCount();
" CN: " + controlFlow.getConditionNodeCount() +
" EX: " + controlFlow.getExitCount();
if (dotFileGenerator != null) {
String graphName = methodDeclaration != null ? methodDeclaration.getSimpleName() : b.isStatic() ? "static block" : "init block";
String dotFile = dotFileGenerator.visualizeAsDotfile(graphName, darkMode, controlFlow);
if (isMethodDeclaration) {
getCursor().dropParentUntil(J.MethodDeclaration.class::isInstance).putMessage(CONTROL_FLOW_SUMMARY_CURSOR_MESSAGE, dotFile);
} else {
J.Block b2 = SearchResult.found(b, searchResultText);
return b2.withMarkers(b2.getMarkers().add(new DotResult(Tree.randomId(), dotFile)));
return SearchResult.mergingFound(b2, dotFile);
}
}
return SearchResult.found(b, searchResultText);
Expand Down Expand Up @@ -121,7 +120,7 @@ public Statement visitStatement(Statement statement, P p) {
SearchResult searchResult = maybeSearchResult.get();
String newDescription =
(searchResult.getDescription() == null ? "" : searchResult.getDescription()) +
" | " + number + label;
" | " + number + label;
return statement.withMarkers(
statement
.getMarkers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static boolean isStringAddTaintStep(
J.Binary binary = (J.Binary) sinkExpression;
return J.Binary.Type.Addition.equals(binary.getOperator()) &&
(binary.getLeft() == srcExpression || binary.getRight() == srcExpression) &&
TypeUtils.isOfClassType(binary.getType(), "java.lang.String");
TypeUtils.isString(binary.getType());
}
return false;
}
Expand Down

0 comments on commit 6db9bc5

Please sign in to comment.