1 30 31 35 36 package jbet.cmd; 37 import jbet.*; 38 import java.io.*; 39 import java.util.*; 40 41 class rename implements Command 42 { 43 public int helplevel() { return 4; } 44 public String shorthelp() { return "rename a method"; } 45 public String longhelp() { 46 return 47 "jbet delete <class>.<method> <newname>\t\tRename <method> to <newname>\n"; } 48 49 public void run (Lexer lexer) throws Exception 50 { 51 lexer.match(Token.END_OF_OPTS); 52 Thing p = lexer.parse_element_with_default (Jbet.default_class, true); 53 String name = lexer.parse_name(); 54 lexer.term(); 55 renameMethod (p.cls, p.name, p.elem, name); 56 } 57 58 void renameMethod(String cname, String mname, String type, String newname) throws Exception { 59 ClassInfo cr = Jbet.loader.getClass(cname); 60 MethodInfo method = cr.findMethod(mname, type); 61 if (method == null) 62 throw new GlobalException (Util.methString (cname, mname, type) + " not found in " + 63 cname); 64 if ( cr.findMethod(newname, method.descriptor) != null ) 65 throw new GlobalException(newname + ":" + method.descriptor + 66 " allready exists in " + cname); 67 method.name = newname; 68 Jbet.info.println("renamed " + cname + "." + mname + ":" + 69 method.descriptor + " to " + newname ); 70 cr.setDirty(); 71 } 72 73 } 74 | Popular Tags |