9

It would be nice to be able to define my own method interceptors (advice) and weave them in to my client-side GWT methods, and have GWT automagicallly compile them down into JavaScript with the rest of my app.

I checked out gwt-ent, but it doesn't look like there's been solid development on it since 2009 and there were quite a number of issues. I've also heard of gwt-tiny-aop but heard it was very limited.

Do I have any other options here? I know AOP requires dynamic bytecode generation, which in turn requires heavy reflection, and that GWT doesn't contain a lot of support (and seems to discourage) the practice of reflection, but I was wondering if there are any stable, well-known AOP libs out there for GWT. At least something that I could use for writing AOP Alliance-like interceptors:

public class MyInterceptor implements MethodInterceptor {
    @Override
    public void onIntercept(MethodInvocation mi) {
        // Do some stuff...

        // Let the method execute
        Object results = mi.proceed();

        // Analyze results...

        // Returns results
        return results;
}
5
  • 1
    why not use javascript (wrapped in JSNI) to simulate that behavior? Commented Aug 25, 2012 at 3:04
  • 1
    Something like dotvoid perhaps? Not a bad idea...definitely a candidate, but still would prefer a Java solution if at all possible Commented Aug 25, 2012 at 3:07
  • 2
    To use AOP with GWT, you'd have to massage the source code before giving it to GWT, rather than massage bytecode. Commented Aug 25, 2012 at 9:33
  • 1
    Thanks @ThomasBroyer (+1) - can you please explain what you mean by "massage the source code" and perhaps provide a code example? Thanks again! Commented Aug 25, 2012 at 10:26
  • I mean create new source with the interceptors merged into the original methods. You could then pass those enhanced sources to the GWT compiler. Commented Aug 25, 2012 at 12:13

1 Answer 1

2

You could use GWT generators:

https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsDeferred#generators

1
  • 2
    @IAmYourFaja: This is the answer for all that involves or depends on the Reflexion API on GWT client code... believe me, there is no way to do it but with generators.
    – Chepech
    Commented Aug 16, 2013 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.