示例#1
0
 public void testConstBody() throws Exception {
   CtClass cc = sloader.get("test2.ConstBody");
   CtConstructor cons =
       new CtConstructor(
           new CtClass[] {sloader.get("java.lang.String"), sloader.get("java.lang.Integer")}, cc);
   cons.setBody("super((String)$1, (Integer)$2);");
   cc.addConstructor(cons);
   cc.writeFile();
   Object obj = make(cc.getName());
   assertEquals(1, invoke(obj, "bar"));
 }
示例#2
0
  public void testStaticArrays() throws Exception {
    CtClass cc = sloader.makeClass("StaticArrays");
    CtField f = new CtField(sloader.get("test2.StaticArraysMem[]"), "myStaticField", cc);

    f.setModifiers(Modifier.STATIC);
    cc.addField(f);
    CtConstructor init = cc.makeClassInitializer();
    String body = "{\n";
    body += ("myStaticField = new test2.StaticArraysMem[2];\n");
    body += ("\n}");
    init.setBody(body);
  }