Giter Club home page Giter Club logo

auto-weave's Introduction

I do the clickety-clackety that make the computer go brrr

auto-weave's People

Contributors

bnorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

auto-weave's Issues

Make advice target annotations available via join point

It is possible to retrieve the target annotations via reflection but it would also (hopefully) be easy to generate the values into the static pointcut. However, we should be careful to only store those annotations that have a retention of source.

But, maybe this is all pointless and the advice writer should have to deal with it themselves? Is this feature creep? Since a single piece of advice can apply to many different target annotations, maybe this is worth it?

Break library into compile time and runtime modules

Even though it won't reduce the runtime dependencies by much, it is still a good idea to do so. This would allow extended dependencies in the compile time module without effecting the size of the runtime. It's also just a good practice being adopted by a lot of annotation processing libraries.

Chain is not throwing MethodException

Currently the Chain class is rethrowing the method exception as a runtime exception. It is expected by the generated code that this will be a MethodException. Maybe this is were the exception should be sneaky thrown? At the very least, it should be thrown as a MethodException.

Performance improvements

The current implementation requires creating a lot of objects for each call to a weaved method. Use the following implementation design to reduce that number.

final class ManualWeave_Target extends Target {

    private static final StaticPointcut methodPointcut = StaticPointcut.create("method",
                                                                               Target.class,
                                                                               String.class,
                                                                               Arrays.<Class<?>>asList());

    private final TraceAspect traceAspect = new TraceAspect();

    private final Advice[] methodAdvice = new Advice[] {new AroundAdvice() {
        @Override
        public Object around(Tracer tracer) {
            return traceAspect.around(tracer);
        }
    }, new AroundAdvice() {
        @Override
        public Object around(Tracer tracer) {
            return traceAspect.around(tracer);
        }
    }, new AroundAdvice() {
        @Override
        public Object around(Tracer tracer) {
            return traceAspect.around(tracer);
        }
    }};

    public ManualWeave_Target() {
        super();
    }

    @Override
    @Trace
    String method(int i) {
        try {
            return (String) new Tracer(methodAdvice, this, methodPointcut, i) {
                @Override
                protected Object call() throws Throwable {
                    return ManualWeave_Target.super.method(i);
                }
            }.proceed();
        } catch (MethodException e) {
            if (e.getCause() instanceof Error) {
                throw (Error) e.getCause();
            } else if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else {
                throw new AssertionError("Please contact the library developer", e.getCause());
            }
        }
    }
}


public abstract class Tracer { // implements all the joinpoints!

    private final Advice[] advice;
    private int index;

    protected Tracer(Advice[] advice, Object target, StaticPointcut staticPointcut, Object... args) {
        this.advice = advice;
        this.index = 0;
    }

    public Object proceed() {
        if (index < advice.length) {
            return advice[index++].call(this);
        } else {
            try {
                return call();
            } catch (Throwable error) {
                throw new RuntimeException(error);
            }
        }
    }

    protected abstract Object call() throws Throwable;
}

AutoWeave basics

  • AutoAdvice instead of AutoAspect? Aspect is the class, advice is the method?
  • Handle method exception in try-catch block.
  • Cast to method return type in around chain? This might help catch bad advice.
  • Pull more information into JoinPoint. Use AspectJ as a model.
  • Override all constructors of parent class.
  • Special exception to wrap super method call exceptions. This is so advice cannot throw checked exceptions and avoids use of Throwable.

Arguments list might be hindering performance

Probably the largest performance impact besides the chain class and stack navigation is the Arrays.asList() call for every method invocation. Maybe this should be an object array? This would mean that it is mutable and can be changed by advice. Does this matter? Is this a premature optimization?

AutoWeave advanced

  • Look through all parents for annotated methods and override them all.
  • All aspects to be defined as static in class. Maybe also singletons aspects?

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.