Giter VIP home page Giter VIP logo

jaop's Introduction

jaop

一个类似cglib的aop框架

代码示例

public class Computer {

public <E> boolean isEmptyArray(E... array) {
    return null == array
            || array.length == 0;
}

public int sum(int... numberArray) {
    if (isEmptyArray(numberArray)) {
        return 0;
    }
    int sum = 0;
    for (int n : numberArray) {
        sum += n;
    }
    return sum;
}

}

AOP aop = new AOP.Builder().
        targetClass(Computer.class)
        .targetMethodName("sum")
        .eventListener(new EventListener() {
            @Override
            public void onEvent(Event event) throws Throwable {
                if(event instanceof BeforeEvent) {
                    final BeforeEvent beforeEvent = (BeforeEvent) event;
                    System.err.println("hello 我是before事件");

                    final int[] numberArray = (int[]) beforeEvent.argumentArray[0];

                    numberArray[0] = 100;
                    numberArray[1] = 101;

                    System.err.println("hello 我修改了参数值");

                }else if(event instanceof ReturnEvent) {

                    System.err.println("hello 我是return事件");
                }
            }
        })
        .build();

Computer computer = (Computer) aop.createIntance();

System.err.println(computer.sum(new int[]{1,1}));

输出结果

hello 我是before事件
hello 我修改了参数值
hello 我是return事件
201

jaop's People

Contributors

cderlearner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.