Ability to replace dispatch methods via active annotation

42 views
Skip to first unread message

rsmit...@rpstechnologies.net

unread,
May 7, 2014, 10:59:25 PM5/7/14
to xtend...@googlegroups.com
I need to be able to substitute methods in a class in an active annotation, including methods that are dispatch methods.  More specifically, I'm intercepting the method calls, doing some additional behavior, then delegating to the original dispatch method.  The active annotation generates a new method with the same signature and different body, and renames the original method.

Unfortunately, I don't see a way to do this in XTend for dispatch methods.

I'm currently getting a "Cannot call method 'getSimpleName()' on a inferred type" error.

Is this achievable in XTend in some other way.  Should I raise a bugzilla bug?

Ron

Sebastian Zarnekow

unread,
May 8, 2014, 1:35:40 AM5/8/14
to xtend...@googlegroups.com
Hi Ron,

this should already be fixed for the upcoming 2.6 version. Would you mind to try one of the recent nightly builds (http://www.eclipse.org/xtend/download.html)?

Best regards,
Sebastian


--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

rsmit...@rpstechnologies.net

unread,
May 12, 2014, 12:38:34 AM5/12/14
to xtend...@googlegroups.com
I'm trying it out, but not sure what the difference is.  What was the specific fix in 2.6?

I'm still seeing the getSimpleName() error, but I may see a way I can substitute these methods.  By the time my annotation runs, the dispatch method generation has already occurred, and I see methods like:

  protected void _uno(final int i) {

  }

  protected void _uno(final String i) {

  }  

  public void uno(final Object i) {

    if (i instanceof Integer) {

      _uno((Integer)i);

      return;

    } else if (i instanceof String) {

      _uno((String)i);

      return;

    } else {

      throw new IllegalArgumentException("Unhandled parameter types: " +

        Arrays.<Object>asList(i).toString());

    }

  }


I should be able to look for the protected '_' methods, and wrap those.

This enhancement would help make detecting the generated dispatch methods clearer.  Otherwise I'll have to go off the '_' naming convention which isn't as reliable.

Thanks
Ron

Sebastian Zarnekow

unread,
May 12, 2014, 2:34:52 AM5/12/14
to xtend...@googlegroups.com
Hi Ron,

maybe I got your initial request wrong. The fix was related to newly introduced dispatch signatures in active annotations. Those caused problems previously. What exactly did you try to do, e.g. could you attach the annotation processor and some input / output files?

I'm afraid the referenced enhancement request won't make it into 2.6 so you have to go for a heuristic wrt to dispatch methods. A leading underscore and a paired method without an underscore should provide enough confidence. The visiblity is not necessarily protected, e.g. for private dispatch methods.

Best regards,
Sebastian
signature.asc

rsmit...@rpstechnologies.net

unread,
May 15, 2014, 10:01:25 AM5/15/14
to xtend...@googlegroups.com
Using the leading underscore worked, thanks.  If bug 375701 gets implemented in the future, I'll be able to go back and simplify this, but in the meantime this works well.
Reply all
Reply to author
Forward
0 new messages