/Users/lyon/j4p/src/classUtils/dumper/Main.java
|
1 /*
2 * dumpclass.java
3 *
4 * Uses the class file decoders in util to dump out a
5 * class file.
6 * Written : 22 - May - 1996 by Chuck McManis
7 */
8 package classUtils.dumper;
9
10 import java.util.Vector;
11
12 public class Main {
13 public static void main(String args[]) {
14 ClassFile cf[] = ClassFile.getClassFiles();
15 printOutClassFilesWithMainMethods(cf);
16 }
17 public static void printOutClassFilesWithMainMethods(ClassFile cf[]) {
18 for (int i=0; i < cf.length; i++)
19 if (cf[i].hasMainMethod())
20 System.out.println(cf[i]);
21 }
22
23 public static void printOutMainMethods(ClassFile cf[]) {
24 for (int i = 0; i < cf.length; i++)
25 printOutMainMethod(cf[i]);
26 }
27
28 public static void printOutMainMethod(ClassFile cf) {
29 //System.out.println("class:" + cf.getClassName() + cf);
30 MethodInfo mi[] = getMainMethods(cf.getMethods());
31 if (mi==null) return;
32 for (int i = 0; i < mi.length; i++)
33 System.out.println(mi[i]);
34 }
35
36 public static MethodInfo[] getMainMethods(MethodInfo mi[]) {
37 Vector v = new Vector();
38 if (mi == null) return null;
39 for (int i = 0; i < mi.length; i++) {
40 String ms = mi[i].toString();
41 boolean b = ms.indexOf("public") >= 0;
42 boolean b1 = ms.indexOf("static") >= 0;
43 boolean b3 = ms.indexOf("main") >= 0;
44 boolean b4 = ms.indexOf("java.lang.String ") >= 0;
45 boolean b5 = ms.indexOf("void") >= 0;
46 if (b && b1 && b3 && b4 && b5)
47 v.addElement(mi[i]);
48 }
49 MethodInfo mi2[] = new MethodInfo[v.size()];
50 v.copyInto(mi2);
51 return mi2;
52 }
53
54 public static MethodInfo[] getPublicStaticMethods(MethodInfo mi[]) {
55 Vector v = new Vector();
56 for (int i = 0; i < mi.length; i++) {
57 String ms = mi[i].toString();
58 if (ms.indexOf("public") >= 0 && ms.indexOf("static") >= 0)
59 v.addElement(mi[i]);
60 }
61 MethodInfo mi2[] = new MethodInfo[v.size()];
62 v.copyInto(mi2);
63 return mi2;
64 }
65
66 public static MethodInfo[] getPublicMethods(MethodInfo mi[]) {
67 Vector v = new Vector();
68 for (int i = 0; i < mi.length; i++) {
69 String ms = mi[i].toString();
70 if (ms.indexOf("public") >= 0)
71 v.addElement(mi[i]);
72 }
73 MethodInfo mi2[] = new MethodInfo[v.size()];
74 v.copyInto(mi2);
75 return mi2;
76 }
77 }
78
79