New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CFG Visualizer (implemented as a test detector) #2014
Conversation
Sometimes, during development it is an advantage if the CFG can be seen visually. This patch adds a detector that generates the CFG in DOT format so it can be viewed (or converted to a graphical format) using GraphViz.
I do not see exactly what failed here... |
it just means SpotBugs found problems in the codebase. We can reproduce it by |
Yes, that was clear but I could not understand how a disabled detector can make the tests fail. However, it seems that even disabled detectors are enabled during all tests. Is this intentional? Anyway, I fixed the error and now all tests pass. |
private void analyzeMethod(ClassContext classContext, Method method, Path classDir) throws CFGBuilderException { | ||
Path methodFile = getMethodFile(classDir, method.getName()); | ||
|
||
try (PrintStream out = new PrintStream(Files.createFile(methodFile).toFile(), Charset.defaultCharset().name())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods of the PrintStream
class does not throw IOException
, so better to check problems by the checkError()
method after you finish using the stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creation of PrintStream throws IOException
. Is it OK now that I moved this to a conventional try
block?
|
||
try (PrintStream out = new PrintStream(Files.createFile(methodFile).toFile(), Charset.defaultCharset().name())) { | ||
CFG cfg = classContext.getCFG(method); | ||
out.println("digraph " + method.getName() + " {"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we need to wrap the method name by "
, to support special names like <new>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is worse. Characters like < and > are not supported on Windows so I changed method names like <init>
to ____init
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is LGTM, please add a changelog entry into CHANGELOG.md
under the ### Added
part.
Sometimes, during development it is an advantage if the CFG can be seen visually. This patch adds a detector
that generates the CFG in DOT format so it can be viewed (or converted to a graphical format) using GraphViz.
Make sure these boxes are checked before submitting your PR -- thank you!
CHANGELOG.md
if you have changed SpotBugs code