Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sazzer
Copy link
Contributor

@sazzer sazzer commented Dec 20, 2024

No description provided.


public class AnalyzeUnitTest {
@Test
void whenAnalyzingTheJVM_thenWeCanListClasses() {
Copy link
Collaborator

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

Suggested change
void whenAnalyzingTheJVM_thenWeCanListClasses() {
void whenAnalyzingTheJvm_thenWeCanListClasses() {


JavaView view = new JavaView(inputLocation);

assertTrue(view.getClasses().size() > 0);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Comment on lines +59 to +74
@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) {}
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants