Package org.nutz.aop

Examples of org.nutz.aop.ClassAgent.addInterceptor()


  @Test
  public void test_duplicate_class_exception() throws Exception {
    int[] cc = new int[4];
    ClassAgent ca = getNewClassAgent();
    ca.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));
    ClassAgent ca2 = getNewClassAgent();
    ca2.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));

    ClassDefiner cd = Nutzs.cd();

View Full Code Here


  public void test_duplicate_class_exception() throws Exception {
    int[] cc = new int[4];
    ClassAgent ca = getNewClassAgent();
    ca.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));
    ClassAgent ca2 = getNewClassAgent();
    ca2.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));

    ClassDefiner cd = Nutzs.cd();

    Class<? extends Moose> c = ca.define(cd, Moose.class);
    Moose m = c.newInstance();
View Full Code Here

  @Test
  public void test_return_array_method() {
    int[] cc = new int[4];
    Arrays.fill(cc, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher("returnArrayMethod"), new MethodCounter(cc));
    Class<? extends Buffalo> c = aca.define(Nutzs.cd(), Buffalo.class);// RA.class;
    Buffalo r = Mirror.me(c).born();
    String[] ss = r.returnArrayMethod();
    assertEquals("[1, 1, 0, 0]", Json.toJson(cc));
    assertEquals(3, ss.length);
View Full Code Here

    int[] cc = new int[4];
    int[] crun = new int[4];
    Arrays.fill(cc, 0);
    Arrays.fill(crun, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher("run"), new MethodCounter(crun));
    aca.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));
    aca.addInterceptor(MethodMatcherFactory.matcher("doSomething"), new RhinocerosListener());
    Class<? extends Rhinoceros> c = aca.define(Nutzs.cd(), Rhinoceros.class);// RA.class;
    Rhinoceros r = Mirror.me(c).born();
    r.doSomething(BEH.run);
View Full Code Here

    int[] crun = new int[4];
    Arrays.fill(cc, 0);
    Arrays.fill(crun, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher("run"), new MethodCounter(crun));
    aca.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));
    aca.addInterceptor(MethodMatcherFactory.matcher("doSomething"), new RhinocerosListener());
    Class<? extends Rhinoceros> c = aca.define(Nutzs.cd(), Rhinoceros.class);// RA.class;
    Rhinoceros r = Mirror.me(c).born();
    r.doSomething(BEH.run);
    r.doSomething(BEH.fight);
View Full Code Here

    Arrays.fill(cc, 0);
    Arrays.fill(crun, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher("run"), new MethodCounter(crun));
    aca.addInterceptor(MethodMatcherFactory.matcher(".*"), new MethodCounter(cc));
    aca.addInterceptor(MethodMatcherFactory.matcher("doSomething"), new RhinocerosListener());
    Class<? extends Rhinoceros> c = aca.define(Nutzs.cd(), Rhinoceros.class);// RA.class;
    Rhinoceros r = Mirror.me(c).born();
    r.doSomething(BEH.run);
    r.doSomething(BEH.fight);
    try {
View Full Code Here

    int[] cpub = new int[4];
    int[] cpro = new int[4];
    Arrays.fill(cpub, 0);
    Arrays.fill(cpro, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher(PUBLIC), new MethodCounter(cpub));
    aca.addInterceptor(MethodMatcherFactory.matcher(PROTECTED), new MethodCounter(cpro));
    Class<? extends Hippo> c = aca.define(Nutzs.cd(), Hippo.class);// RA.class;
    Hippo r = Mirror.me(c).born();
    Vegetarians.run(r, 78);
    r.doSomething(BEH.run);
View Full Code Here

    int[] cpro = new int[4];
    Arrays.fill(cpub, 0);
    Arrays.fill(cpro, 0);
    ClassAgent aca = getNewClassAgent();
    aca.addInterceptor(MethodMatcherFactory.matcher(PUBLIC), new MethodCounter(cpub));
    aca.addInterceptor(MethodMatcherFactory.matcher(PROTECTED), new MethodCounter(cpro));
    Class<? extends Hippo> c = aca.define(Nutzs.cd(), Hippo.class);// RA.class;
    Hippo r = Mirror.me(c).born();
    Vegetarians.run(r, 78);
    r.doSomething(BEH.run);
    try {
View Full Code Here

    assertEquals("[2, 2, 0, 0]", Json.toJson(cpro));
  }

  public ClassAgent getNewClassAgent() {
    ClassAgent classAgent = new AsmClassAgent();
    classAgent.addInterceptor(MethodMatcherFactory.matcher(".*"), new LoggingMethodInterceptor());
    return classAgent;
  }
}
View Full Code Here

public class Main2 {

  public static void main(String[] args) throws Throwable {

    ClassAgent agent = new AsmClassAgent();
    agent.addInterceptor(MethodMatcherFactory.matcher(".*"), new MyMethodInterceptor());
    Class<Aop1> classZ = agent.define(Nutzs.cd(), Aop1.class);
    System.out.println(classZ);
    Field[] fields = classZ.getDeclaredFields();
    for (Field field : fields) {
      System.out.println("找到一个Field: " + field);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.