Exemple #1
0
 public void testAddCatchForConstructor() throws Exception {
   CtClass cc = sloader.get("test2.AddCatchForConstructor");
   CtConstructor m1 = cc.getDeclaredConstructors()[0];
   m1.addCatch("return;", sloader.get("java.lang.Exception"));
   cc.writeFile();
   Object obj = make(cc.getName());
 }
Exemple #2
0
 public void testWhere() throws Exception {
   CtClass cc = sloader.get("test2.Where");
   CtConstructor cons = cc.getClassInitializer();
   cons.instrument(
       new ExprEditor() {
         public void edit(MethodCall m) throws CannotCompileException {
           System.out.println(m.where().getName());
         }
       });
 }
Exemple #3
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"));
 }
Exemple #4
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);
  }