1414
1515import edu .rosehulman .cjjb .asm .QualifiedMethod ;
1616import edu .rosehulman .cjjb .javaModel .visitor .ISequenceVisitor ;
17+ import edu .rosehulman .cjjb .javaModel .visitor .IUMLVisitor ;
1718import edu .rosehulman .cjjb .javaModel .visitor .SDSequenceVisitor ;
19+ import edu .rosehulman .cjjb .javaModel .visitor .UMLDotVisitor ;
1820
1921public class Main {
2022
@@ -35,28 +37,120 @@ public class Main {
3537 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 ]" ;
3638
3739 public static void main (String [] args ) throws IOException , ClassNotFoundException {
40+ if (args .length == 0 ) {
41+ System .out .println ("Calls shown bellow" );
42+ System .out .println ("UML -c <List of Classes> -p <List of Packages>" );
43+ System .out .println ("SEQ -c <Class> -m <Method> -d <ASM Desc>" );
44+ System .out .println ("EXAMPLE" );
45+ return ;
46+ }
3847 OutputStream out = new FileOutputStream ("output.txt" );
48+ switch (args [0 ]) {
49+ case "SEQ" :
50+ QualifiedMethod qm = new QualifiedMethod (getMethodFromArgs (args ), getDescFromArgs (args ));
51+ // QualifiedMethod qm = new QualifiedMethod("shuffle", "(Ljava/util/List;)V");
52+ String clazz = getClassFromArgs (args );
53+ JavaModelClassVisitor visitor = new JavaModelClassVisitor (out , clazz , qm , 2 );
54+
55+ visitor .buildSeqModel ();
56+ ISequenceVisitor seqVisitor = new SDSequenceVisitor (clazz , qm , 2 , out );
57+ visitor .getModel ().accept (seqVisitor );
58+ break ;
59+ case "UML" :
60+ Set <String > classesToVisit = new HashSet <String >();
61+ classesToVisit .addAll (getClassesFromArgs (args ));
62+
63+ for (String s : getPackagesFromArgs (args )) {
64+ classesToVisit .addAll (getClasses (s ));
65+ }
66+
67+ visitor = new JavaModelClassVisitor (classesToVisit , out );
68+ visitor .buildUMLModel ();
69+ IUMLVisitor umlVisitor = new UMLDotVisitor (out );
70+ visitor .getModel ().accept (umlVisitor );
71+ break ;
72+ case "EXAMPLE" :
73+ exampleCall (new FileOutputStream ("output.txt" ));
74+ break ;
75+ default :
76+ System .out .println ("Not a valid diagram type. Valid Types: SEQ|UML|EXAMPLE" );
77+ }
78+ }
79+
80+ private static String getClassFromArgs (String [] args ) {
81+ int index = 0 ;
82+ while (index < args .length && !args [index ++].equals ("-c" )) { }
83+
84+ return args [index ];
85+ }
86+
87+
88+ private static String getDescFromArgs (String [] args ) {
89+ int index = 0 ;
90+ while (index < args .length && !args [index ++].equals ("-d" )) { }
91+
92+ return args [index ];
93+ }
94+
95+ private static String getMethodFromArgs (String [] args ) {
96+ int index = 0 ;
97+ while (index < args .length && !args [index ++].equals ("-m" )) { }
98+
99+ return args [index ];
100+ }
39101
102+ private static List <String > getPackagesFromArgs (String [] args ) {
103+ List <String > toReturn = new ArrayList <String >();
104+
105+ int index = 0 ;
106+ while (index < args .length && !args [index ++].equals ("-p" )) { }
107+
108+ for (int i = index ; i < args .length ; i ++) {
109+ if (args [i ].equals ("-c" )) {
110+ break ;
111+ }
112+
113+ toReturn .add (args [i ]);
114+ }
115+
116+ return toReturn ;
117+ }
118+
119+ private static List <String > getClassesFromArgs (String [] args ) {
120+ List <String > toReturn = new ArrayList <String >();
121+
122+ int index = 0 ;
123+ while (index < args .length && !args [index ++].equals ("-c" )) { }
124+
125+ for (int i = index ; i < args .length ; i ++) {
126+ if (args [i ].equals ("-p" )) {
127+ break ;
128+ }
129+
130+ toReturn .add (args [i ]);
131+ }
132+
133+ return toReturn ;
134+ }
135+
136+ private static void exampleCall (OutputStream out ) throws IOException , ClassNotFoundException {
40137 Set <String > classesToVisit = new HashSet <String >();
41138 classesToVisit .addAll (Arrays .asList (CLASSES ));
42-
139+
43140 for (String s : PACKAGES ) {
44141 classesToVisit .addAll (getClasses (s ));
45142 }
46-
143+
47144 QualifiedMethod qm = new QualifiedMethod ("shuffle" , "(Ljava/util/List;)V" );
48145 JavaModelClassVisitor visitor = new JavaModelClassVisitor (classesToVisit , out , "java.util.Collections" , qm , 2 );
49146
50- // visitor.buildUMLModel();
51- // IUMLVisitor umlVisitor = new UMLDotVisitor(out);
52- // visitor.getModel().accept(umlVisitor);
53-
147+ visitor .buildUMLModel ();
148+ IUMLVisitor umlVisitor = new UMLDotVisitor (out );
149+ visitor .getModel ().accept (umlVisitor );
150+
54151 visitor .buildSeqModel ();
55152 ISequenceVisitor seqVisitor = new SDSequenceVisitor ("java.util.Collections" , qm , 2 , out );
56153 visitor .getModel ().accept (seqVisitor );
57-
58- //java.util.Collections.shuffle(list, rnd);
59- //java.util.Random;
60154 }
61155
62156 /* From
@@ -71,7 +165,8 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio
71165 * @return The classes
72166 * @throws ClassNotFoundException
73167 * @throws IOException
74- */ private static List <String > getClasses (String packageName ) throws ClassNotFoundException , IOException {
168+ */
169+ private static List <String > getClasses (String packageName ) throws ClassNotFoundException , IOException {
75170 ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
76171 assert classLoader != null ;
77172 String path = packageName .replace ('.' , '/' );
0 commit comments