[BCEL-info]help MethodGen
Brought to you by:
dahm
|
From: <fa...@vo...> - 2005-04-11 14:40:36
|
Hello,
I try to create a class from 2 different classes.
So I copy fields and methos of both in a ClassGen.
But I 've a problem with methods which use a field in the body
for example:
class A{
int a1;
A(){}
void m1(){
a1 = 2;
}
When I decompile the class that I create, instead of the method m1 there is this comment:
// JavaClassFileOutputException: get_constant: invalid tag
Some help will be great appreciate!
Here is my code:
c1 and c2 are 2 java.lang.Class
String nomGen = "tests/bin/gen/"
+ c1.getShortName()
+ c2.getShortName()
+ ".class";
JavaClass clazz1 = Repository.lookupClass(c1.getName());
JavaClass clazz2 = Repository.lookupClass(c2.getName());
String nom = c1.getShortName() + C2.getShortName();
ClassGen classGen = new ClassGen(clazz1);
classGen.setClassName(nom);
ConstantPoolGen cp = classGen.getConstantPool();
Field[] tfields = clazz2.getFields();
for (int i = 0; i < tfields.length; i++) {
FieldGen fg = new FieldGen(tfields[i], cp);
classGen.addField(fg.getField());
}
Method[] tmeth = clazz2.getMethods();
for (int j = 0; j < tmeth.length; j++) {
MethodGen mg = new MethodGen(tmeth[j], classGen.getClassName(), cp);
classGen.getConstantPool().addNameAndType(mg.getName(), mg.getSignature());
classGen.addMethod(mg.getMethod());
}
try {
classGen.getJavaClass().dump(nomGen);
} catch(java.io.IOException e) { System.err.println(e); }
------------------------------------------
Faites un voeu et puis Voila ! www.voila.fr
|