This project is a simple Java Control Flow Graph (CFG) Analyzer using JavaParser.
The Java CFG Analyzer parses a Java source file, extracts control flow information, and generates a CFG in JSON format. The project demonstrates how to use JavaParser to work with Abstract Syntax Trees (AST) and analyze the structure of if-else blocks.
-
Clone the repository:
git clone https://github.com/Chayan199916/java-cfg-analyzer.git
-
Navigate to the project directory:
cd java-cfg-analyzer
-
Place your Java source files in the src/main/resources directory.
For example, if your file is named "Sample2.java":
- src
- main
- resources
- Sample2.java
- resources
- main
- src
-
Build the project using Maven:
mvn clean package
-
Run the Java CFG Analyzer:
mvn exec:java
-
This will generate the control flow graph (CFG) in JSON format in the target directory and display the number of distinct paths.
JavaParser: A Java library for parsing and analyzing Java source code.
Gson: A Java library for JSON serialization and deserialization.
Contributions are welcome! Feel free to open issues, suggest improvements, or contribute additional features to enhance the analyzer example.