Add Gradle build setup and updated analyzer files

This commit is contained in:
Nicolas Amaya
2025-10-26 21:28:55 -06:00
parent 82249f76ae
commit 1157885d92
11 changed files with 525 additions and 31 deletions

View File

@@ -0,0 +1,13 @@
package CFGGraph;
import org.jgrapht.graph.DefaultEdge;
public class CFGEdge extends DefaultEdge {
//path defines if its a True or False or Null (when either T or F resulkt on the same node)
private boolean path;
public CFGEdge(boolean path) {
this.path = path;
}
}

View File

@@ -0,0 +1,41 @@
package CFGGraph;
import java.util.ArrayList;
import japa.parser.ast.stmt.Statement;
public class CFGNode {
static int id_counter = 1;
private final int ID;
private String label;
private ArrayList<Statement> statements;
public CFGNode(String label) {
this.label = label;
this.ID = id_counter++;
this.statements = new ArrayList<>();
}
public int getID() {
return this.ID;
}
public String getLabel() {
return this.label;
}
public ArrayList<Statement> getStatements() {
return this.statements;
}
public void addStatement(Statement s) {
statements.add(s);
}
@Override
public String toString() {
return label;
}
}

View File

@@ -1,3 +1,4 @@
import japa.parser.JavaParser;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.body.*;
@@ -6,6 +7,23 @@ import japa.parser.ast.visitor.VoidVisitorAdapter;
import java.io.FileInputStream;
import java.io.File;
//graph imports
import org.jgrapht.*;
import org.jgrapht.graph.*;
import org.jgrapht.nio.*;
import org.jgrapht.nio.dot.*;
import org.jgrapht.traverse.*;
import java.io.*;
import java.net.*;
import java.util.*;
import japa.parser.ast.stmt.ExpressionStmt;
import CFGGraph.CFGNode;
import CFGGraph.CFGEdge;
public class LCA_JP1_0_0 {
public static void main(String[] args) throws Exception {
@@ -18,24 +36,37 @@ public class LCA_JP1_0_0 {
CompilationUnit cu = JavaParser.parse(in);
in.close();
LocalClassVisitor visitor = new LocalClassVisitor();
CFGVisitor visitor = new CFGVisitor();
visitor.visit(cu, null);
}
static class LocalClassVisitor extends VoidVisitorAdapter<Void> {
private boolean insideMethod = false;
static class CFGVisitor extends VoidVisitorAdapter<Void> {
private Graph<CFGNode, CFGEdge> currCFG = new DefaultDirectedGraph<>(CFGEdge.class);
private CFGNode currentBlock;
@Override
public void visit(MethodDeclaration n, Void arg) {
insideMethod = true;
CFGNode funcNode = new CFGNode(n.getName());
System.out.println("CFG Building Root: " + n.getName());
//we assign root node
currCFG.addVertex(funcNode);
//update curr node
currentBlock = funcNode;
super.visit(n, arg);
insideMethod = false;
System.out.println(currCFG.toString());
}
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
System.out.println("Local class: " + n.getName());
super.visit(n, arg);
public void visit(ExpressionStmt n, Void arg) {
// CFGNode exprNode = new CFGNode(n.toString())
// currCFG.addVertex(exprNode)
// //link nodes
// currCFG.addEdge(currentBlock, exprNode);
// currentBlock = exprNode;
// super.visit(n, arg);
}
}
}

View File

@@ -0,0 +1,27 @@
public class Test {
public void methodOne() {
class Helper234 {
int val = 1;
int compute() {
for (int i = 0; i < 10; i++) {
val += 1;
if (val == 5) {
val = 5;
} else if (val < 5) {
val = 3;
}
}
return val;
}
}
// Example of using Helper234 inside methodOne
Helper234 helper = new Helper234();
int result = helper.compute();
System.out.println("Result: " + result);
}
void methodTwo() {
System.out.println("Hello");
}
}

View File

@@ -1,17 +0,0 @@
public class test {
void methodOne() {
public class Helper234 {
void doStuff() {
}
}
private class Helper2 {
void doStuff() {
}
}
}
void methodTwo() {
System.out.println("Hello");
}
}