public class TestField extends MyTestCase {
public ClassDef defadd(String type) {
ClassDef cd = makeClass() ;
FieldDef fd = new FieldDef(Scope.PUBLIC,new TypeName(type),"foo") ;
cd = cd.addField(fd) ;
{
Var x = new Var(1,new TypeName(type)) ;
MethodDef md = new MethodDef(TypeName.VOID,"setFoo",x) ;
md = md.addInstructions(
new Load(new Var(0,new TypeName("TestClass"))),
new Load(x),
new Store(new FieldRef(cd.name,new TypeName(type),"foo")),
new Return(TypeCode.VOID)
) ;
cd = cd.addMethod(md) ;
}
{
MethodDef md = new MethodDef(new TypeName(type),"getFoo") ;
md = md.addInstructions(
new Load(new Var(0,new TypeName("TestClass"))),
new Load(new FieldRef(cd.name,new TypeName(type),"foo")),
new Return(TypeCode.getType(type))
) ;
cd = cd.addMethod(md) ;
}
return cd ;