Return-Path: Delivered-To: apmail-jakarta-bcel-user-archive@www.apache.org Received: (qmail 76584 invoked from network); 19 Jul 2004 17:18:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Jul 2004 17:18:49 -0000 Received: (qmail 21558 invoked by uid 500); 19 Jul 2004 17:18:49 -0000 Delivered-To: apmail-jakarta-bcel-user-archive@jakarta.apache.org Received: (qmail 21365 invoked by uid 500); 19 Jul 2004 17:18:48 -0000 Mailing-List: contact bcel-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "BCEL Users List" Reply-To: "BCEL Users List" Delivered-To: mailing list bcel-user@jakarta.apache.org Received: (qmail 21348 invoked by uid 99); 19 Jul 2004 17:18:48 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [66.33.215.16] (HELO unicron.dreamservers.com) (66.33.215.16) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 19 Jul 2004 10:18:46 -0700 Received: by unicron.dreamservers.com (Postfix, from userid 23727) id 0CE421B5F7; Mon, 19 Jul 2004 10:18:46 -0700 (PDT) Date: Mon, 19 Jul 2004 10:18:46 -0700 From: James Sasitorn To: bcel-user@jakarta.apache.org Cc: James Sasitorn Subject: copy method to different class Message-ID: <20040719171846.GC7460@unicron.dreamservers.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I am trying to copy methods from one class to another. This is the code I have been woking on. I am getting errors with the resulting constant pool. Is this the correct way to copy a method, or am i misunderstanding the API. thanks, james public static void main(String[] args) { JavaClass j1 = new ClassParser("A.class").parse(); JavaClass j2 = new ClassParser("B.class").parse(); copyCode(j1,j2); } public static void copyCode(JavaClass src, JavaClass dest) { ClassGen cg1 = new ClassGen(dest); ClassGen cg2 = new ClassGen(dest); ConstantPoolGen cp1 = cg1.getConstantPool(); ConstantPoolGen cp2 = cg2.getConstantPool(); Method[] methods = src.getMethods(); for (int i=0; i< methods.length; i++) { MethodGen m = new MethodGen(methods[i], src.getClassName(), cp1); MethodGen m2 = m.copy(cg2.getClassName(), cp2); printCode(new Method[] {m2.getMethod()}, true); cg2.addMethod(m2.getMethod()); } JavaClass c3 = cg2.getJavaClass(); c3.setConstantPool(cp2.getFinalConstantPool()); try { c3.dump("test.class"); } catch (IOException e) { System.out.println(e.getStackTrace()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: bcel-user-help@jakarta.apache.org