Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/commons-configuration-1.6.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/commons-lang-2.5.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.core.contenttype_3.4.1.R35x_v20090826-0451.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.core.jobs_3.4.100.v20090429-1800.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.core.resources_3.5.2.R35x_v20091203-1235.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.core.runtime_3.5.0.v20090525.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.equinox.preferences_3.2.301.R35x_v20091117.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.jdt.core_3.5.2.v_981_R35x.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.jdt.core-3.10.0.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.osgi_3.5.2.R35x_v20100126.jar"/>
<classpathentry kind="lib" path="/Users/Bowen/GoogleDrive/Study/PHD/PhD/2019-2020/Term2/IS706/W2/JDT2AST2DOT/lib/org.eclipse.osgi_3.12.0.v20170512-1932.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/commons-collections-3.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/commons-configuration-1.6.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/commons-lang-2.5.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/commons-logging-1.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.core.contenttype_3.4.1.R35x_v20090826-0451.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.core.jobs_3.4.100.v20090429-1800.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.core.resources_3.5.2.R35x_v20091203-1235.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.core.runtime_3.5.0.v20090525.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.equinox.preferences_3.2.301.R35x_v20091117.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.jdt.core_3.5.2.v_981_R35x.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.jdt.core-3.10.0.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.osgi_3.5.2.R35x_v20100126.jar"/>
<classpathentry exported="true" kind="lib" path="/Users/rnatella/git/Java-to-AST-with-Visualization/lib/org.eclipse.osgi_3.12.0.v20170512-1932.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1740856740019</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
19 changes: 19 additions & 0 deletions DemoAST.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

public class DemoAST {
int bart(int x) { return x+1; }
int lisa(int x) { return x+2; }

int homer(int x) {
int y, a, b;

if(x>0) {
y = 0;
} else {
a = bart(1);
b = lisa(2);
y = a + b;
}
return y;
}

}
Binary file modified bin/main/ASTGenerator.class
Binary file not shown.
Binary file modified bin/main/ASTtoDOT.class
Binary file not shown.
Binary file modified bin/main/Main.class
Binary file not shown.
24 changes: 24 additions & 0 deletions output/DemoAST.java_bart.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
digraph "DirectedGraph" {
graph [label = "bart", labelloc=t, concentrate = true];
"1686369710" [ label=<<b>Method<br/>Declaration</b><br/>int bart(int x) ... } > type=31 startLineNumber=3 endLineNumber=3 ]
"194706439" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=3 endLineNumber=3 ]
"942518407" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>bart> type=42 startLineNumber=3 endLineNumber=3 ]
"1943325854" [ label=<<b>Single<br/>Variable<br/>Declaration</b><br/>int x> type=44 startLineNumber=3 endLineNumber=3 ]
"134310351" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=3 endLineNumber=3 ]
"1411892748" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=3 endLineNumber=3 ]
"22805895" [ label=<<b>Block</b><br/>{ return x + 1 ... } > type=8 startLineNumber=3 endLineNumber=3 ]
"1413378318" [ label=<<b>Return<br/>Statement</b><br/>return x + 1; > type=41 startLineNumber=3 endLineNumber=3 ]
"1475491159" [ label=<<b>Infix<br/>Expression</b><br/>x + 1> type=27 startLineNumber=3 endLineNumber=3 ]
"1024429571" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=3 endLineNumber=3 ]
"1667689440" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>1> type=34 startLineNumber=3 endLineNumber=3 ]
"1686369710" -> "194706439"
"1686369710" -> "942518407"
"1686369710" -> "1943325854"
"1943325854" -> "134310351"
"1943325854" -> "1411892748"
"1686369710" -> "22805895"
"22805895" -> "1413378318"
"1413378318" -> "1475491159"
"1475491159" -> "1024429571"
"1475491159" -> "1667689440"
}
92 changes: 92 additions & 0 deletions output/DemoAST.java_homer.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
digraph "DirectedGraph" {
graph [label = "homer", labelloc=t, concentrate = true];
"79290965" [ label=<<b>Method<br/>Declaration</b><br/>int homer(int x ... } > type=31 startLineNumber=6 endLineNumber=17 ]
"1582785598" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=6 endLineNumber=6 ]
"322836221" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>homer> type=42 startLineNumber=6 endLineNumber=6 ]
"1370651081" [ label=<<b>Single<br/>Variable<br/>Declaration</b><br/>int x> type=44 startLineNumber=6 endLineNumber=6 ]
"450003680" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=6 endLineNumber=6 ]
"2134991632" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=6 endLineNumber=6 ]
"480971771" [ label=<<b>Block</b><br/>{ int y, a, b; ... } > type=8 startLineNumber=6 endLineNumber=17 ]
"1586845078" [ label=<<b>Variable<br/>Declaration<br/>Statement</b><br/>int y, a, b; > type=60 startLineNumber=7 endLineNumber=7 ]
"1356728614" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=7 endLineNumber=7 ]
"611563982" [ label=<<b>Variable<br/>Declaration<br/>Fragment</b><br/>y> type=59 startLineNumber=7 endLineNumber=7 ]
"1615039080" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>y> type=42 startLineNumber=7 endLineNumber=7 ]
"336484883" [ label=<<b>Variable<br/>Declaration<br/>Fragment</b><br/>a> type=59 startLineNumber=7 endLineNumber=7 ]
"876213901" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>a> type=42 startLineNumber=7 endLineNumber=7 ]
"230528013" [ label=<<b>Variable<br/>Declaration<br/>Fragment</b><br/>b> type=59 startLineNumber=7 endLineNumber=7 ]
"1909546776" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>b> type=42 startLineNumber=7 endLineNumber=7 ]
"392781299" [ label=<<b>If<br/>Statement</b><br/>if (x &gt; 0) { y ... } > type=25 startLineNumber=9 endLineNumber=15 ]
"1822383117" [ label=<<b>Infix<br/>Expression</b><br/>x &gt; 0> type=27 startLineNumber=9 endLineNumber=9 ]
"233021551" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=9 endLineNumber=9 ]
"1991313236" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>0> type=34 startLineNumber=9 endLineNumber=9 ]
"736778932" [ label=<<b>Block</b><br/>{ y=0; } > type=8 startLineNumber=9 endLineNumber=11 ]
"1032000752" [ label=<<b>Expression<br/>Statement</b><br/>y=0; > type=21 startLineNumber=10 endLineNumber=10 ]
"770911223" [ label=<<b>Assignment</b><br/>y=0> type=7 startLineNumber=10 endLineNumber=10 ]
"1392906938" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>y> type=42 startLineNumber=10 endLineNumber=10 ]
"708890004" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>0> type=34 startLineNumber=10 endLineNumber=10 ]
"255944888" [ label=<<b>Block</b><br/>{ a=bart(1); ... } > type=8 startLineNumber=11 endLineNumber=15 ]
"1004095028" [ label=<<b>Expression<br/>Statement</b><br/>a=bart(1); > type=21 startLineNumber=12 endLineNumber=12 ]
"1487470647" [ label=<<b>Assignment</b><br/>a=bart(1)> type=7 startLineNumber=12 endLineNumber=12 ]
"1948863195" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>a> type=42 startLineNumber=12 endLineNumber=12 ]
"1890187342" [ label=<<b>Method<br/>Invocation</b><br/>bart(1)> type=32 startLineNumber=12 endLineNumber=12 ]
"19986569" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>bart> type=42 startLineNumber=12 endLineNumber=12 ]
"294184992" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>1> type=34 startLineNumber=12 endLineNumber=12 ]
"793315160" [ label=<<b>Expression<br/>Statement</b><br/>b=lisa(2); > type=21 startLineNumber=13 endLineNumber=13 ]
"270397815" [ label=<<b>Assignment</b><br/>b=lisa(2)> type=7 startLineNumber=13 endLineNumber=13 ]
"376416077" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>b> type=42 startLineNumber=13 endLineNumber=13 ]
"1089504328" [ label=<<b>Method<br/>Invocation</b><br/>lisa(2)> type=32 startLineNumber=13 endLineNumber=13 ]
"660879561" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>lisa> type=42 startLineNumber=13 endLineNumber=13 ]
"1485697819" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>2> type=34 startLineNumber=13 endLineNumber=13 ]
"867398280" [ label=<<b>Expression<br/>Statement</b><br/>y=a + b; > type=21 startLineNumber=14 endLineNumber=14 ]
"2007331442" [ label=<<b>Assignment</b><br/>y=a + b> type=7 startLineNumber=14 endLineNumber=14 ]
"1904324159" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>y> type=42 startLineNumber=14 endLineNumber=14 ]
"1176735295" [ label=<<b>Infix<br/>Expression</b><br/>a + b> type=27 startLineNumber=14 endLineNumber=14 ]
"1848415041" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>a> type=42 startLineNumber=14 endLineNumber=14 ]
"843467284" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>b> type=42 startLineNumber=14 endLineNumber=14 ]
"1313532469" [ label=<<b>Return<br/>Statement</b><br/>return y; > type=41 startLineNumber=16 endLineNumber=16 ]
"339924917" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>y> type=42 startLineNumber=16 endLineNumber=16 ]
"79290965" -> "1582785598"
"79290965" -> "322836221"
"79290965" -> "1370651081"
"1370651081" -> "450003680"
"1370651081" -> "2134991632"
"79290965" -> "480971771"
"480971771" -> "1586845078"
"1586845078" -> "1356728614"
"1586845078" -> "611563982"
"611563982" -> "1615039080"
"1586845078" -> "336484883"
"336484883" -> "876213901"
"1586845078" -> "230528013"
"230528013" -> "1909546776"
"480971771" -> "392781299"
"392781299" -> "1822383117"
"1822383117" -> "233021551"
"1822383117" -> "1991313236"
"392781299" -> "736778932"
"736778932" -> "1032000752"
"1032000752" -> "770911223"
"770911223" -> "1392906938"
"770911223" -> "708890004"
"392781299" -> "255944888"
"255944888" -> "1004095028"
"1004095028" -> "1487470647"
"1487470647" -> "1948863195"
"1487470647" -> "1890187342"
"1890187342" -> "19986569"
"1890187342" -> "294184992"
"255944888" -> "793315160"
"793315160" -> "270397815"
"270397815" -> "376416077"
"270397815" -> "1089504328"
"1089504328" -> "660879561"
"1089504328" -> "1485697819"
"255944888" -> "867398280"
"867398280" -> "2007331442"
"2007331442" -> "1904324159"
"2007331442" -> "1176735295"
"1176735295" -> "1848415041"
"1176735295" -> "843467284"
"480971771" -> "1313532469"
"1313532469" -> "339924917"
}
24 changes: 24 additions & 0 deletions output/DemoAST.java_lisa.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
digraph "DirectedGraph" {
graph [label = "lisa", labelloc=t, concentrate = true];
"1157058691" [ label=<<b>Method<br/>Declaration</b><br/>int lisa(int x) ... } > type=31 startLineNumber=4 endLineNumber=4 ]
"40472007" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=4 endLineNumber=4 ]
"1138193439" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>lisa> type=42 startLineNumber=4 endLineNumber=4 ]
"398110318" [ label=<<b>Single<br/>Variable<br/>Declaration</b><br/>int x> type=44 startLineNumber=4 endLineNumber=4 ]
"1765250898" [ label=<<b>Primitive<br/>Type</b><br/>int> type=39 startLineNumber=4 endLineNumber=4 ]
"670971910" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=4 endLineNumber=4 ]
"1601292138" [ label=<<b>Block</b><br/>{ return x + 2 ... } > type=8 startLineNumber=4 endLineNumber=4 ]
"494586676" [ label=<<b>Return<br/>Statement</b><br/>return x + 2; > type=41 startLineNumber=4 endLineNumber=4 ]
"1218593486" [ label=<<b>Infix<br/>Expression</b><br/>x + 2> type=27 startLineNumber=4 endLineNumber=4 ]
"508198356" [ label=<<b><font color="blue">Simple<br/>Name</font></b><br/>x> type=42 startLineNumber=4 endLineNumber=4 ]
"1330754528" [ label=<<b><font color="red">Number<br/>Literal</font></b><br/>2> type=34 startLineNumber=4 endLineNumber=4 ]
"1157058691" -> "40472007"
"1157058691" -> "1138193439"
"1157058691" -> "398110318"
"398110318" -> "1765250898"
"398110318" -> "670971910"
"1157058691" -> "1601292138"
"1601292138" -> "494586676"
"494586676" -> "1218593486"
"1218593486" -> "508198356"
"1218593486" -> "1330754528"
}
16 changes: 14 additions & 2 deletions src/main/ASTtoDOT.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import structure.MyASTNode;
import structure.MyMethodNode;
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;

public class ASTtoDOT {

Expand All @@ -20,7 +21,7 @@ public static String ASTtoDotParser(MyMethodNode m) {
ASTNode astNode = mn.astNode;
int hashcode = astNode.hashCode();
int nodeType = astNode.getNodeType();
str += ("\"" + String.valueOf(hashcode) + "\" [ label=\""+buildLabel(mn)+"\" type=" + String.valueOf(nodeType) + " startLineNumber="
str += ("\"" + String.valueOf(hashcode) + "\" [ label=<"+buildLabel(mn)+"> type=" + String.valueOf(nodeType) + " startLineNumber="
+ String.valueOf(mn.startLineNum)+" endLineNumber="
+ String.valueOf(mn.endLineNum) + " ]\n");
}
Expand All @@ -41,6 +42,17 @@ public static String ASTtoDotParser(MyMethodNode m) {
public static String buildLabel(MyASTNode node) {
String contentString=node.astNode.toString().replace("\n", " ").replace("\"", "\\\"").replace(" ", " ");
String nodeType=ASTNode.nodeClassForType(node.astNode.getNodeType()).getName().replace("org.eclipse.jdt.core.dom.", "");
return "("+contentString+","+nodeType+","+node.startLineNum+","+node.endLineNum+")";

nodeType = nodeType.replaceAll("(?<!^)([A-Z])", "<br/>$1");

if(nodeType.toLowerCase().contains("name")) {
nodeType = "<font color=\"blue\">"+nodeType+"</font>";
}
else if(nodeType.toLowerCase().contains("literal")) {
nodeType = "<font color=\"red\">"+nodeType+"</font>";
}

return "<b>"+nodeType+"</b><br/>"+(contentString.length()>15 ? escapeHtml(contentString.substring(0,15))+" ... "+escapeHtml(contentString.substring(contentString.length()-2)) : escapeHtml(contentString));

}
}
4 changes: 2 additions & 2 deletions src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class Main {
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String FilePath = "PATH/HelloWorld.java";
String outputDir = "PATH/output/";
String FilePath = "./input/DemoAST.java";
String outputDir = "./output/";
File f = new File(FilePath);
ASTGenerator astGenerator = new ASTGenerator(f);
List<MyMethodNode> methodNodeList = astGenerator.getMethodNodeList();
Expand Down