Package org.allspice.bytecode

Examples of org.allspice.bytecode.ClassDef


import org.allspice.bytecode.instructions.Return;
import org.allspice.bytecode.instructions.Store;

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 ;
  }
View Full Code Here


    }
    return cd ;
  }
  public void test1() throws Exception {
   
    ClassDef cd = defadd("int") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",int.class) ;
    m.invoke(obj,42) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),42) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),42) ;
  }
  public void test2() throws Exception {
   
    ClassDef cd = defadd("float") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",float.class) ;
    m.invoke(obj,42F) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),42F) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),42F) ;
  }
  public void test3() throws Exception {
   
    ClassDef cd = defadd("double") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",double.class) ;
    m.invoke(obj,42D) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),42D) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),42D) ;
  }
  public void test4() throws Exception {
   
    ClassDef cd = defadd("long") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",long.class) ;
    m.invoke(obj,42L) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),42L) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),42L) ;
  }
  public void test5() throws Exception {
   
    ClassDef cd = defadd("boolean") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",boolean.class) ;
    m.invoke(obj,true) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),true) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),true) ;
  }
  public void test6() throws Exception {
   
    ClassDef cd = defadd("byte") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",byte.class) ;
    m.invoke(obj,(byte)42) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),(byte)42) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),(byte)42) ;
  }
  public void test7() throws Exception {
   
    ClassDef cd = defadd("short") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",short.class) ;
    m.invoke(obj,(short)42) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),(short)42) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),(short)42) ;
  }
  public void test8() throws Exception {
   
    ClassDef cd = defadd("char") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",char.class) ;
    m.invoke(obj,(char)42) ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),(char)42) ;
View Full Code Here

    m = obj.getClass().getMethod("getFoo") ;
    assertEquals(m.invoke(obj),(char)42) ;
  }
  public void test9() throws Exception {
   
    ClassDef cd = defadd("java.lang.String") ;
    Object obj = makeObject(cd) ;
    Method m = obj.getClass().getMethod("setFoo",String.class) ;
    m.invoke(obj,"42") ;
    Field f = obj.getClass().getField("foo") ;
    assertEquals(f.get(obj),"42") ;
View Full Code Here

TOP

Related Classes of org.allspice.bytecode.ClassDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.