77import java .net .URL ;
88import java .util .ArrayList ;
99import java .util .Arrays ;
10+ import java .util .Collection ;
1011import java .util .Enumeration ;
1112import java .util .HashSet ;
1213import java .util .List ;
1314import java .util .Set ;
1415
1516import edu .rosehulman .cjjb .asm .QualifiedMethod ;
1617import edu .rosehulman .cjjb .javaModel .visitor .ISequenceVisitor ;
18+ import edu .rosehulman .cjjb .javaModel .visitor .IUMLVisitor ;
1719import edu .rosehulman .cjjb .javaModel .visitor .SDSequenceVisitor ;
20+ import edu .rosehulman .cjjb .javaModel .visitor .UMLDotVisitor ;
1821
1922public class Main {
2023
@@ -35,28 +38,120 @@ public class Main {
3538 public static final String boilerPlate = "digraph G { fontname = \" Bitstream Vera Sans\" fontsize = 8 node [ fontname = \" Bitstream Vera Sans\" fontsize = 8 shape = \" record\" ] edge [ fontname = \" Bitstream Vera Sans\" fontsize = 8 ]" ;
3639
3740 public static void main (String [] args ) throws IOException , ClassNotFoundException {
41+ if (args .length == 0 ) {
42+ System .out .println ("Calls shown bellow" );
43+ System .out .println ("UML -c <List of Classes> -p <List of Packages>" );
44+ System .out .println ("SEQ -c <Class> -m <Method> -d <ASM Desc>" );
45+ System .out .println ("EXAMPLE" );
46+ return ;
47+ }
3848 OutputStream out = new FileOutputStream ("output.txt" );
49+ switch (args [0 ]) {
50+ case "SEQ" :
51+ QualifiedMethod qm = new QualifiedMethod (getMethodFromArgs (args ), getDescFromArgs (args ));
52+ // QualifiedMethod qm = new QualifiedMethod("shuffle", "(Ljava/util/List;)V");
53+ String clazz = getClassFromArgs (args );
54+ JavaModelClassVisitor visitor = new JavaModelClassVisitor (out , clazz , qm , 2 );
55+
56+ visitor .buildSeqModel ();
57+ ISequenceVisitor seqVisitor = new SDSequenceVisitor (clazz , qm , 2 , out );
58+ visitor .getModel ().accept (seqVisitor );
59+ break ;
60+ case "UML" :
61+ Set <String > classesToVisit = new HashSet <String >();
62+ classesToVisit .addAll (getClassesFromArgs (args ));
63+
64+ for (String s : getPackagesFromArgs (args )) {
65+ classesToVisit .addAll (getClasses (s ));
66+ }
67+
68+ visitor = new JavaModelClassVisitor (classesToVisit , out );
69+ visitor .buildUMLModel ();
70+ IUMLVisitor umlVisitor = new UMLDotVisitor (out );
71+ visitor .getModel ().accept (umlVisitor );
72+ break ;
73+ case "EXAMPLE" :
74+ exampleCall (new FileOutputStream ("output.txt" ));
75+ break ;
76+ default :
77+ System .out .println ("Not a valid diagram type. Valid Types: SEQ|UML|EXAMPLE" );
78+ }
79+ }
80+
81+ private static String getClassFromArgs (String [] args ) {
82+ int index = 0 ;
83+ while (index < args .length && !args [index ++].equals ("-c" )) { }
84+
85+ return args [index ];
86+ }
87+
88+
89+ private static String getDescFromArgs (String [] args ) {
90+ int index = 0 ;
91+ while (index < args .length && !args [index ++].equals ("-d" )) { }
92+
93+ return args [index ];
94+ }
95+
96+ private static String getMethodFromArgs (String [] args ) {
97+ int index = 0 ;
98+ while (index < args .length && !args [index ++].equals ("-m" )) { }
99+
100+ return args [index ];
101+ }
39102
103+ private static List <String > getPackagesFromArgs (String [] args ) {
104+ List <String > toReturn = new ArrayList <String >();
105+
106+ int index = 0 ;
107+ while (index < args .length && !args [index ++].equals ("-p" )) { }
108+
109+ for (int i = index ; i < args .length ; i ++) {
110+ if (args [i ].equals ("-c" )) {
111+ break ;
112+ }
113+
114+ toReturn .add (args [i ]);
115+ }
116+
117+ return toReturn ;
118+ }
119+
120+ private static List <String > getClassesFromArgs (String [] args ) {
121+ List <String > toReturn = new ArrayList <String >();
122+
123+ int index = 0 ;
124+ while (index < args .length && !args [index ++].equals ("-c" )) { }
125+
126+ for (int i = index ; i < args .length ; i ++) {
127+ if (args [i ].equals ("-p" )) {
128+ break ;
129+ }
130+
131+ toReturn .add (args [i ]);
132+ }
133+
134+ return toReturn ;
135+ }
136+
137+ private static void exampleCall (OutputStream out ) throws IOException , ClassNotFoundException {
40138 Set <String > classesToVisit = new HashSet <String >();
41139 classesToVisit .addAll (Arrays .asList (CLASSES ));
42-
140+
43141 for (String s : PACKAGES ) {
44142 classesToVisit .addAll (getClasses (s ));
45143 }
46-
144+
47145 QualifiedMethod qm = new QualifiedMethod ("shuffle" , "(Ljava/util/List;)V" );
48146 JavaModelClassVisitor visitor = new JavaModelClassVisitor (classesToVisit , out , "java.util.Collections" , qm , 2 );
49147
50- // visitor.buildUMLModel();
51- // IUMLVisitor umlVisitor = new UMLDotVisitor(out);
52- // visitor.getModel().accept(umlVisitor);
53-
148+ visitor .buildUMLModel ();
149+ IUMLVisitor umlVisitor = new UMLDotVisitor (out );
150+ visitor .getModel ().accept (umlVisitor );
151+
54152 visitor .buildSeqModel ();
55153 ISequenceVisitor seqVisitor = new SDSequenceVisitor ("java.util.Collections" , qm , 2 , out );
56154 visitor .getModel ().accept (seqVisitor );
57-
58- //java.util.Collections.shuffle(list, rnd);
59- //java.util.Random;
60155 }
61156
62157 /* From
@@ -71,7 +166,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
71166 * @return The classes
72167 * @throws ClassNotFoundException
73168 * @throws IOException
74- */ private static List <String > getClasses (String packageName ) throws ClassNotFoundException , IOException {
169+ */
170+ private static List <String > getClasses (String packageName ) throws ClassNotFoundException , IOException {
75171 ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
76172 assert classLoader != null ;
77173 String path = packageName .replace ('.' , '/' );
0 commit comments