private ClassStub makeJavaClassStub(JavaClass realClass) {
ClassStub stub;
StubResolver superc ;
if (realClass.getSuperclassName() != null && !realClass.getSuperclassName().equals(realClass.getClassName())) {
superc = new SimpleResolver(new TypeName(realClass.getSuperclassName())) ;
}
else {
superc = null ;
}
final TypeName cname = new TypeName(realClass.getClassName());
stub = new ClassStub(cname,superc,realClass.isInterface()) ;
StubResolver myStub = new SimpleResolver(cname) ;
final com.sun.org.apache.bcel.internal.classfile.Method[] methods = realClass.getMethods();
for(com.sun.org.apache.bcel.internal.classfile.Method meth: methods) {
Type[] type = meth.getArgumentTypes();
FIFO<StubResolver> types = new FIFO<StubResolver>() ;
for(Type ptype: type) {
types = types.insert(new SimpleResolver(new TypeName(ptype.toString()))) ;
}
boolean isStatic = false ;
boolean isPrivate = false ;
if ((meth.getModifiers() & Modifier.STATIC) != 0) {
isStatic = true ;
}
if ((meth.getModifiers() & Modifier.PRIVATE) != 0) {
isPrivate = true ;
}
final TypeName mname = new TypeName(meth.getReturnType().toString()) ;
StubResolver retType = new SimpleResolver(mname) ;
stub = stub.addMethod(new MethodStub(meth.getName(),myStub,retType,types,isStatic,isPrivate)) ;
}
com.sun.org.apache.bcel.internal.classfile.Field[] fields = realClass.getFields();
for(com.sun.org.apache.bcel.internal.classfile.Field fld: fields) {
final boolean isStatic = (fld.getModifiers() & Modifier.STATIC) != 0;
final boolean isFinal = (fld.getModifiers() & Modifier.FINAL) != 0;
StubResolver fldstub = new SimpleResolver(new TypeName(fld.getType().toString())) ;
if (isStatic && isFinal) {
ConstantValue cv = fld.getConstantValue();
Object o ;
if (cv != null) {
Constant c = cv.getConstantPool().getConstant(cv.getConstantValueIndex());
if (c instanceof ConstantObject) {
o = ((ConstantObject)c).getConstantValue(cv.getConstantPool()) ;
try {
o = StdJavaExpressions.cast( this, fldstub, new ConstObj(o)) ;
} catch (CompilerException e) {
o = null ;
}
}
else {
o = null ;
}
}
else {
o = null ;
}
if (o != null) {
final FieldStub fldDef = new FieldStub(fld.getName(),myStub,fldstub,isStatic,isFinal,new ConstExpr(o,null));
stub = stub.addField(fldDef) ;
continue ;
}
}
stub = stub.addField(new FieldStub(fld.getName(),myStub,fldstub,isStatic,isFinal,null));
}
String[] ifaces = realClass.getInterfaceNames();
for(String iface: ifaces) {
stub = stub.addInterface(new SimpleResolver(new TypeName(iface))) ;
}
return stub;
}