#ast-generator AST-generator project creates an Abstract Syntax Tree (AST) for each file of a Java project, translates them to graph models and inserts them to Neo4J (Graph Distributed DB) instance.
###Details
Compilers, like java (javacc), often use an Abstract Syntax Tree (AST) for the following bullets:
- AST summarizes grammatical structures without including all the details of the derivation.
- ASTs are kind of intermediate representation which helps the compilation procedure
- Visualisation of Abstract Syntax Tree
Ast-generator project builds a basic AST for a Java project, using javaparser project
###Installation / Running
To run this project you have to create a file (config.properties) under the resource file (like the screenshot below) with the Neo4J instance credentials
host = x.x.x.x
neo4j_username = username
neo4j_password = password
####Running with Maven
mvn clean install
mvn -Dexec.args="path_to_project URL_Of_project" -Dexec.mainClass="com.elasticthree.ASTCreator.ASTCreator.ASTCreator" exec:java
Observation
URL_Of_project parameter is useful for Neo4j stats. If you don't have an unique URL, you can pass the same value as path_to_project
###Results
Using the following bullets you will see the graphs using Neo4j browser
-
Go to Neo4j browser
-
Run this command
START n=node(*) RETURN n;
- Visualization of results
- Query for Total number of Java Code lines and total number of Repos in Neo4j instance
MATCH (nodes:Repo) RETURN SUM(nodes.linesOfJavaCode) as TotalJavaCode, count(nodes) as TotalNodes;
###Results
We present some important and practical queries on AST datasets !
######Query1: Returns all the parameters of a specific method "name"
Match (m:Method) -[:HAS_PARAMETER]-> (p:Parameter)Where m.name = "name" return p.name as Name, p.type as Type;
######Query2: Returns all the parameters from a method, whch has annotation '@Override'
Match (m:Method) -[:HAS_PARAMETER]-> (p:Parameter) MATCH (m:Method) -[:HAS_ANNOTATION]-> (ann:Annotation) Where ann.name = "@Override" return p.name as Name, p.type as Type;
######Query3: Returns all the methods, whch has parameter type "type"
Match (m:Method) -[:HAS_PARAMETER]-> (p:Parameter) Where p.type = "type" return m.name as Name, m.package as Package;