List<ClassDef> defs = new ArrayList<ClassDef>() ;
Collection<Exception> errors = new ArrayList<Exception>() ;
for(ClassDecl cdecl: fu.classDecl) {
ClassDef cd ;
FileUnitInfo fuinfo = classPool.findFileUnit(fu) ;
TypeName cname = ClassPool.getClassName(fu,cdecl) ;
switch(cdecl.classType) {
case ABSTRACT:
cd = new ClassDef(ClassDefType.ABSTRACT,fu.filename,cname,fuinfo.getFullQualified(cdecl.superClass)) ;
break ;
case INTERFACE:
cd = new ClassDef(ClassDefType.INTERFACE,fu.filename,cname,fuinfo.getFullQualified(cdecl.superClass)) ;
break ;
default:
cd = new ClassDef(ClassDefType.DEFAULT,fu.filename,cname,fuinfo.getFullQualified(cdecl.superClass)) ;
break ;
}
VarStack fdcls = new VarStack() ;
try {
fdcls = StdJavaExpressions.makeFieldDecls(classPool,classPool.new SimpleResolver(cname),fdcls);
} catch (CompilerException e) {
errors.add(e) ;
}
for(String iface: cdecl.interfaces) {
cd = cd.addInterface(fuinfo.getFullQualified(iface)) ;
}
for(FieldOrMethod fom: cdecl.decls) {
if (fom instanceof FieldDecl) {
try {
cd = cd.addField(getDef(converter,classPool,cdecl,(FieldDecl)fom,fuinfo)) ;
} catch (CompilerException e) {
errors.add(e) ;
}
}
}
boolean foundInit = false ;
FieldAttrs fa = new FieldAttrs().setVisibility(Visibility.PUBLIC).setStatic(true) ;
ImmutableCollection<Statement> body = new FIFO<Statement>() ;
for(FieldOrMethod fom: cdecl.decls) {
if (fom instanceof MethodDecl) {
MethodDecl mdd = (MethodDecl)fom ;
if (mdd.name.equals("<clinit>")) {
body = body.insertAll(mdd.body) ;
continue ;
}
try {
MethodDef def = getDef(converter,classPool,cdecl,mdd,fuinfo,fdcls,errors);
if (def.name.equals("<init>")) {
foundInit = true ;
}
cd = cd.addMethod(def) ;
} catch (CompilerException e) {
errors.add(e) ;
}
}
else if (fom instanceof FieldDecl) {
FieldDecl fdecl = (FieldDecl)fom ;
if (fdecl.fieldAttrs.isStatic && fdecl.intializer != null) {
SetValueExpr se = new SetValueExpr(new FieldVarExpr(cname.toString(),fdecl.name,null),fdecl.intializer,null) ;
body = body.insert(new ExprStatement(se,null)) ;
}
}
}
MethodDecl clinit = new MethodDecl(fa,"void","<clinit>",new FIFO<VarDecl>(),new FIFO<String>(),body) ;