Patching JDT with AspectJ

28 views
Skip to first unread message

Simon Schäfer

unread,
May 19, 2013, 11:05:15 PM5/19/13
to scala-...@googlegroups.com
Because of debugging purposes I had the idea to patch Java methods of the Eclipse API with AspectJ. I have never used AspectJ before, thus I don't know if this is a good idea or even possible.

I installed the AspectJ plugin, imported project org.scala-ide.sdt.aspects and created the following Aspect:

package org.eclipse.jface.text.source;

import java.util.Map;

public aspect AnnotationModelAspect {

  pointcut testtest(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged):
    execution(protected* AnnotationModel.replaceAnnotations(Annotation[], Map, boolean)) &&
    args(annotationsToRemove, annotationsToAdd, fireModelChanged);
 
  before(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged):
    testtest(annotationsToRemove, annotationsToAdd, fireModelChanged) {
    System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>TEST");
  }
}

When I execute a debug session it seems that my Aspect isn't loaded - I can't see its entry among the other Aspects in the logging output. Do I need to register the Aspect somewhere (or its package)?
Or do I have an error in the Aspect?

Greetings,
Simon

iulian dragos

unread,
May 20, 2013, 4:54:24 AM5/20/13
to scala-ide-dev
Hi Simon,

You need to add your aspect to META-INF/aop.xml and possibly add the bundle you intend to weave in your MANIFEST.MF file, under Eclipse-SupplementBundle: 

Be aware that weaving into the JDT is pretty fragile, since you're probably depending on non-APIs, and they might change in minor releases. Moreover, the Groovy plugin forked the JDT, so when you install the Groovy plugin you have a slightly different JDT. My advice is to do as much as possible without weaving, even if it means re-implementing some code that exists in the JDT. Weaving should be used only as a last resort.

iulian



--
You received this message because you are subscribed to the Google Groups "Scala IDE Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

Simon Schäfer

unread,
May 20, 2013, 10:00:01 AM5/20/13
to scala-...@googlegroups.com

On 05/20/2013 10:54 AM, iulian dragos wrote:
Hi Simon,

You need to add your aspect to META-INF/aop.xml and possibly add the bundle you intend to weave in your MANIFEST.MF file, under Eclipse-SupplementBundle:
I managed to successfully load the aspect (I believe) but it seems that the aspect is not executed (don't get any output on the console).

I also get an error message for every loaded aspect:

2013-05-20 15:46:02,921 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.configuration.IsWovenTester
2013-05-20 15:46:02,925 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.builderoptions.ScalaJavaBuilderAspect
...

But I don't know if these errors are related or what they mean.

Maybe I have some error in the aspect, could you please take a look? This commit contains all changes I did: https://github.com/sschaef/scala-ide/commit/0154f656025a9d45352a96bfcf90521b43255c03



Be aware that weaving into the JDT is pretty fragile, since you're probably depending on non-APIs, and they might change in minor releases. Moreover, the Groovy plugin forked the JDT, so when you install the Groovy plugin you have a slightly different JDT. My advice is to do as much as possible without weaving, even if it means re-implementing some code that exists in the JDT. Weaving should be used only as a last resort.
The intention was to get access to internal information of JDT not to use it in production. If I find a way to extend JDT or to build something around it I will do it.

iulian dragos

unread,
May 20, 2013, 11:10:41 AM5/20/13
to scala-ide-dev
On Mon, May 20, 2013 at 4:00 PM, Simon Schäfer <ma...@antoras.de> wrote:

On 05/20/2013 10:54 AM, iulian dragos wrote:
Hi Simon,

You need to add your aspect to META-INF/aop.xml and possibly add the bundle you intend to weave in your MANIFEST.MF file, under Eclipse-SupplementBundle:
I managed to successfully load the aspect (I believe) but it seems that the aspect is not executed (don't get any output on the console).

I also get an error message for every loaded aspect:

2013-05-20 15:46:02,921 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.configuration.IsWovenTester
2013-05-20 15:46:02,925 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.builderoptions.ScalaJavaBuilderAspect
...

Is your aspect in that list? I think those are expected messages.
 

But I don't know if these errors are related or what they mean.

Maybe I have some error in the aspect, could you please take a look? This commit contains all changes I did: https://github.com/sschaef/scala-ide/commit/0154f656025a9d45352a96bfcf90521b43255c03


Things look good to me, but I'm not so familiar with AspectJ.
 


Be aware that weaving into the JDT is pretty fragile, since you're probably depending on non-APIs, and they might change in minor releases. Moreover, the Groovy plugin forked the JDT, so when you install the Groovy plugin you have a slightly different JDT. My advice is to do as much as possible without weaving, even if it means re-implementing some code that exists in the JDT. Weaving should be used only as a last resort.
The intention was to get access to internal information of JDT not to use it in production. If I find a way to extend JDT or to build something around it I will do it.

I find it much easier to set breakpoints at the places I am interested in. If you have Eclipse classic (or the source bundles for PDE/JDT) it should work quite well.

iulian

Simon Schäfer

unread,
May 20, 2013, 12:22:19 PM5/20/13
to scala-...@googlegroups.com

On 05/20/2013 05:10 PM, iulian dragos wrote:



On Mon, May 20, 2013 at 4:00 PM, Simon Schäfer <ma...@antoras.de> wrote:

On 05/20/2013 10:54 AM, iulian dragos wrote:
Hi Simon,

You need to add your aspect to META-INF/aop.xml and possibly add the bundle you intend to weave in your MANIFEST.MF file, under Eclipse-SupplementBundle:
I managed to successfully load the aspect (I believe) but it seems that the aspect is not executed (don't get any output on the console).

I also get an error message for every loaded aspect:

2013-05-20 15:46:02,921 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.configuration.IsWovenTester
2013-05-20 15:46:02,925 ERROR [main] - System.err - [org.eclipse.jdt.debug.ui] info register aspect scala.tools.eclipse.contribution.weaving.jdt.builderoptions.ScalaJavaBuilderAspect
...

Is your aspect in that list? I think those are expected messages.
Yes, it occurs in that list too.

 

But I don't know if these errors are related or what they mean.

Maybe I have some error in the aspect, could you please take a look? This commit contains all changes I did: https://github.com/sschaef/scala-ide/commit/0154f656025a9d45352a96bfcf90521b43255c03


Things look good to me, but I'm not so familiar with AspectJ.
Ok, maybe someone else knows more.

 


Be aware that weaving into the JDT is pretty fragile, since you're probably depending on non-APIs, and they might change in minor releases. Moreover, the Groovy plugin forked the JDT, so when you install the Groovy plugin you have a slightly different JDT. My advice is to do as much as possible without weaving, even if it means re-implementing some code that exists in the JDT. Weaving should be used only as a last resort.
The intention was to get access to internal information of JDT not to use it in production. If I find a way to extend JDT or to build something around it I will do it.

I find it much easier to set breakpoints at the places I am interested in. If you have Eclipse classic (or the source bundles for PDE/JDT) it should work quite well.
Yes, that is what I did now. And it helped me to finally find the place I searched for. :D
The problem is that when a method is called too many times or too much data needs to be looked up, it is easier to read a well formatted logging output than looking at every variable change in the debugger.
Reply all
Reply to author
Forward
0 new messages