1 31 32 33 34 package jbet.cmd; 35 import jbet.*; 36 import java.io.*; 37 38 public class makesubclass implements Command 39 { 40 public int helplevel() { return 3; } 41 public String shorthelp() { return "make subclass skeleton"; } 42 public String longhelp() { return "jbet makesubclass <class> <outname>\n"; } 43 44 public void run (Lexer lexer) throws Exception 45 { 46 boolean callsuper = true; 47 String precode = null; 48 49 loop: 50 while(true) { 51 switch(lexer.read().type) { 52 case 'p': lexer.push (Lexer.ST_STRING); precode = lexer.parse_string(); lexer.pop(); break; 53 case 'r': lexer.push (Lexer.ST_STRING); precode = lexer.parse_string(); lexer.pop(); callsuper = false; break; 54 case Token.END_OF_OPTS: break loop; 55 default: System.out.println ("!!!!"); lexer.unexpected(lexer.justread()); 56 } 57 } 58 59 ClassInfo cr = lexer.getClass(null); 60 lexer.push (Lexer.ST_STRING); 61 String out = lexer.parse_string(); 62 lexer.pop(); 63 lexer.term(); 64 65 FileOutputStream outf = new FileOutputStream (out + ".java"); 66 PrintStream outp = new PrintStream (outf); 67 68 if (out.indexOf ('/') != -1) 69 outp.println ("package " + out.substring (0, out.lastIndexOf ('/')).replace ('/','.') + ";\n"); 70 outp.println ("class " + out.substring (1 + out.lastIndexOf ('/')) + " extends " + Util.srcClassName (cr.name())); 71 outp.println ("{\n"); 72 73 for (int i = 0; i < cr.numMethods(); i++) { 74 MethodInfo mi = cr.methodAt (i); 75 76 if (!mi.name.equals ("<init>") && 77 (mi.accessFlags & MethodInfo.ACC_STATIC) == 0 && 78 (mi.accessFlags & MethodInfo.ACC_FINAL) == 0 && 79 (mi.accessFlags & MethodInfo.ACC_PRIVATE) == 0 && 80 ((mi.accessFlags & MethodInfo.ACC_PROTECTED) != 0 || 81 (mi.accessFlags & MethodInfo.ACC_PUBLIC) != 0)) { 82 83 outp.println (" " + Util.flags2str (mi.accessFlags, false) + " " + mi.descriptor.ret.declaration() + " " + mi.name + " " + 84 mi.descriptor.declaration() + " {"); 85 if (precode != null) 86 outp.println (" " + precode + ";"); 87 if (callsuper) { 88 StringBuffer b = new StringBuffer (mi.descriptor.ret.base == 'V' ? " super." : " return super."); 89 b.append (mi.name); 90 b.append (" ("); 91 for (int j = 0; j < mi.descriptor.args.length; j++) { 92 b.append ("arg"); 93 b.append (j); 94 if (j != mi.descriptor.args.length - 1) 95 b.append (", "); 96 } 97 98 b.append (");"); 99 outp.println (b); 100 } 101 outp.println (" }\n"); 102 } 103 } 104 105 outp.println ("}"); 106 } 107 } 108 | Popular Tags |