-
Notifications
You must be signed in to change notification settings - Fork 54.4k
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
BAEL-7881: Introduction to SootUp #18106
base: master
Are you sure you want to change the base?
Conversation
|
||
public class AnalyzeUnitTest { | ||
@Test | ||
void whenAnalyzingTheJVM_thenWeCanListClasses() { |
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.
We follow https://google.github.io/styleguide/javaguide.html#s5.3-camel-case
void whenAnalyzingTheJVM_thenWeCanListClasses() { | |
void whenAnalyzingTheJvm_thenWeCanListClasses() { |
|
||
JavaView view = new JavaView(inputLocation); | ||
|
||
assertTrue(view.getClasses().size() > 0); |
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.
For complex assertions we use AssertJ
StmtGraph<?> stmtGraph = methodBody.getStmtGraph(); | ||
List<Stmt> stmts = stmtGraph.getStmts(); | ||
for (Stmt stmt : stmts) { | ||
System.out.println(stmt); |
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.
Can we assert here instead of printing?
|
||
private void someMethod(String name) { | ||
var capitald = name.toUpperCase(); | ||
System.out.println("Hello, " + capitald); |
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.
We have a guideline to use SLF4J not System.out for print statements
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.
This method isn't being used. It's purely here so that it can be analyzed. I just needed to do something with the capitals
variable was all.
@Test | ||
void whenAnalyzingThisClass_thenWeCanListMethodsByName() { | ||
Path javaFile = Path.of("src/test/java/com/baeldung/sootup/MethodUnitTest.java"); | ||
AnalysisInputLocation inputLocation = new OTFCompileAnalysisInputLocation(javaFile); | ||
|
||
JavaView view = new JavaView(inputLocation); | ||
|
||
IdentifierFactory identifierFactory = view.getIdentifierFactory(); | ||
ClassType javaClass = identifierFactory.getClassType("com.baeldung.sootup.MethodUnitTest"); | ||
|
||
SootClass sootClass = view.getClassOrThrow(javaClass); | ||
Set<? extends SootMethod> method = sootClass.getMethodsByName("someMethod"); | ||
assertEquals(1, method.size()); | ||
} | ||
|
||
private void someMethod(String 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.
Can we show multiple overloaded methods with the same name listed here perhaps?
No description provided.