Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » How to retrieve AspectJ model during build in eclipse?
How to retrieve AspectJ model during build in eclipse? [message #67399] Thu, 26 October 2006 10:01 Go to next message
Eclipse UserFriend
Originally posted by: m.bartsch.rdg.ac.uk

Hi all,

I am writing an eclipse plugin and I would like to know if the following
is possible with AJDT.

1. Whenever an AspectJ project is being built within Eclipse, my plug-in
needs to be notified and I would like to retrieve information about the
currently compiled or woven aspect. In short: can a listener be added to
the Eclipse build system?

2. The kind of information I am looking for is reflective information
about an aspect or a class in the system, for example I would like to
find out all the types that are dynamically crosscut by a given advice
or a list of all methods and their signatures. I know there is a
reflection API in AspectJ, but this will not give me the weaving
information. Can this kind of information be extracted from AJDT during
a build in Eclipse, e.g. through an AST? (I found some hints here
http://dev.eclipse.org/newslists/news.eclipse.technology.ajd t/msg01110.html
but I do not want to write a new builder but use the existing one.)

Any hints are greatly appreciated,

Marc.
Re: How to retrieve AspectJ model during build in eclipse? [message #67420 is a reply to message #67399] Thu, 26 October 2006 11:41 Go to previous messageGo to next message
Matt Chapman is currently offline Matt ChapmanFriend
Messages: 429
Registered: July 2009
Senior Member
Hi Marc,

Yes, everything you need should be in the org.eclipse.ajdt.core plug-in.
There is an IAdviceChangedListener interface with a single
adviceChanged() method. Register this with the AJBuilder class like this
(in your plug-in's start() method for example):

AJBuilder.addAdviceListener(new MyAdviceListener());

Currently (AJDT 1.4) this is called after every build of an AspectJ
project (i.e. every *potential* advice change). In a future release this
may be optimized to be only called if the advice has actually changed.
AJDT/UI uses this mechanism to update the orange arrow image decorator.

Crosscutting information can be obtained from the AJModel class. Here's
an example:

public class MyAdviceListener implements IAdviceChangedListener {
public void adviceChanged() {
IProject project = AspectJPlugin.getDefault()
.getCurrentProject();
System.out.println("build detected for project: " + project);
AJRelationshipType[] relsTypes = AJRelationshipManager
.getAllRelationshipTypes();
List rels = AJModel.getInstance().getAllRelationships(
project, relsTypes);
for (Iterator iter = rels.iterator(); iter.hasNext();) {
AJRelationship ajrel = (AJRelationship) iter.next();
System.out.println("Relationship: "
+ ajrel.getSource().getElementName() + " "
+ ajrel.getRelationship().getDisplayName() + " "
+ ajrel.getTarget().getElementName());
}
}
}

For the "TJP Example" project, this prints:

build detected for project: P/TJP Example
Relationship: around advises main
Relationship: around advises foo
Relationship: around advises bar
Relationship: bar advised by around
Relationship: foo advised by around
Relationship: main advised by around

As you can see, you get the relationship in both directions. See
AJRelationshipManager for the full list of relationships, so you can
just ask for the relationship types you're interested in.

AJRelationship.getSource() and getTarget() return instances of
IJavaElement so you can obtain further information from that, such as
the parent or underlying resource.

Your plug-in will need to depend on org.eclipse.ajdt.core,
org.eclipse.core.resources and org.eclipse.jdt.core.

Regards,

Matt.

Marc Bartsch wrote:
> Hi all,
>
> I am writing an eclipse plugin and I would like to know if the following
> is possible with AJDT.
>
> 1. Whenever an AspectJ project is being built within Eclipse, my plug-in
> needs to be notified and I would like to retrieve information about the
> currently compiled or woven aspect. In short: can a listener be added to
> the Eclipse build system?
>
> 2. The kind of information I am looking for is reflective information
> about an aspect or a class in the system, for example I would like to
> find out all the types that are dynamically crosscut by a given advice
> or a list of all methods and their signatures. I know there is a
> reflection API in AspectJ, but this will not give me the weaving
> information. Can this kind of information be extracted from AJDT during
> a build in Eclipse, e.g. through an AST? (I found some hints here
> http://dev.eclipse.org/newslists/news.eclipse.technology.ajd t/msg01110.html
> but I do not want to write a new builder but use the existing one.)
>
> Any hints are greatly appreciated,
>
> Marc.
Re: How to retrieve AspectJ model during build in eclipse? [message #67502 is a reply to message #67420] Fri, 27 October 2006 08:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m.bartsch.rdg.ac.uk

Hi Matt,

Thanks a lot! It works like a charm!

There are two more question that I have.

1.The solution that you describe gives me all the relationships and thus
all aspects and classes that somehow appear in any kind of relationship.
Is there a way to also retrieve those classes in an AspectJ project that
are not affected by an aspect and that do not appear in any relationship?

2. Is there a way to map from an IJavaElement to an AJType or to a Class
object? The reason for this question is that I would like to exploit the
reflection API of AspectJ and Java because they are so convenient to
query the structure of an aspect or of a class.

Anyway, thanks for your help so far,

Marc.

Matt Chapman schrieb:
> Hi Marc,
>
> Yes, everything you need should be in the org.eclipse.ajdt.core plug-in.
> There is an IAdviceChangedListener interface with a single
> adviceChanged() method. Register this with the AJBuilder class like this
> (in your plug-in's start() method for example):
>
> AJBuilder.addAdviceListener(new MyAdviceListener());
>
> Currently (AJDT 1.4) this is called after every build of an AspectJ
> project (i.e. every *potential* advice change). In a future release this
> may be optimized to be only called if the advice has actually changed.
> AJDT/UI uses this mechanism to update the orange arrow image decorator.
>
> Crosscutting information can be obtained from the AJModel class. Here's
> an example:
>
> public class MyAdviceListener implements IAdviceChangedListener {
> public void adviceChanged() {
> IProject project = AspectJPlugin.getDefault()
> .getCurrentProject();
> System.out.println("build detected for project: " + project);
> AJRelationshipType[] relsTypes = AJRelationshipManager
> .getAllRelationshipTypes();
> List rels = AJModel.getInstance().getAllRelationships(
> project, relsTypes);
> for (Iterator iter = rels.iterator(); iter.hasNext();) {
> AJRelationship ajrel = (AJRelationship) iter.next();
> System.out.println("Relationship: "
> + ajrel.getSource().getElementName() + " "
> + ajrel.getRelationship().getDisplayName() + " "
> + ajrel.getTarget().getElementName());
> }
> }
> }
>
> For the "TJP Example" project, this prints:
>
> build detected for project: P/TJP Example
> Relationship: around advises main
> Relationship: around advises foo
> Relationship: around advises bar
> Relationship: bar advised by around
> Relationship: foo advised by around
> Relationship: main advised by around
>
> As you can see, you get the relationship in both directions. See
> AJRelationshipManager for the full list of relationships, so you can
> just ask for the relationship types you're interested in.
>
> AJRelationship.getSource() and getTarget() return instances of
> IJavaElement so you can obtain further information from that, such as
> the parent or underlying resource.
>
> Your plug-in will need to depend on org.eclipse.ajdt.core,
> org.eclipse.core.resources and org.eclipse.jdt.core.
>
> Regards,
>
> Matt.
>
> Marc Bartsch wrote:
>> Hi all,
>>
>> I am writing an eclipse plugin and I would like to know if the
>> following is possible with AJDT.
>>
>> 1. Whenever an AspectJ project is being built within Eclipse, my
>> plug-in needs to be notified and I would like to retrieve information
>> about the currently compiled or woven aspect. In short: can a listener
>> be added to the Eclipse build system?
>>
>> 2. The kind of information I am looking for is reflective information
>> about an aspect or a class in the system, for example I would like to
>> find out all the types that are dynamically crosscut by a given advice
>> or a list of all methods and their signatures. I know there is a
>> reflection API in AspectJ, but this will not give me the weaving
>> information. Can this kind of information be extracted from AJDT
>> during a build in Eclipse, e.g. through an AST? (I found some hints
>> here
>> http://dev.eclipse.org/newslists/news.eclipse.technology.ajd t/msg01110.html
>> but I do not want to write a new builder but use the existing one.)
>>
>> Any hints are greatly appreciated,
>>
>> Marc.
Re: How to retrieve AspectJ model during build in eclipse? [message #67543 is a reply to message #67502] Wed, 01 November 2006 10:20 Go to previous messageGo to next message
Matt Chapman is currently offline Matt ChapmanFriend
Messages: 429
Registered: July 2009
Senior Member
Marc Bartsch wrote:
> 1.The solution that you describe gives me all the relationships and thus
> all aspects and classes that somehow appear in any kind of relationship.
> Is there a way to also retrieve those classes in an AspectJ project that
> are not affected by an aspect and that do not appear in any relationship?

You can determine the classes in a project in the same way as with a
Java project, by getting all the package fragments and calling
getCompilationUnits() on each.

> 2. Is there a way to map from an IJavaElement to an AJType or to a Class
> object? The reason for this question is that I would like to exploit the
> reflection API of AspectJ and Java because they are so convenient to
> query the structure of an aspect or of a class.

There are various types in the org.eclipse.ajdt.core.javaelements
package, such as AspectElement, which are instances of IJavaElement. You
can get some structure information from these, such as
AspectElement.getPointcuts(). If you need more detailed info, you
probably need to use the AspectJ AST parser.

Regards,

Matt.
Re: How to retrieve AspectJ model during build in eclipse? [message #67601 is a reply to message #67543] Wed, 01 November 2006 14:25 Go to previous message
Eclipse UserFriend
Originally posted by: m.bartsch.rdg.ac.uk

Hi Matt,

I probably need to use the AspectJ AST parser, but thanks again for your
support.

Best wishes,

Marc.

Matt Chapman schrieb:
> Marc Bartsch wrote:
>> 1.The solution that you describe gives me all the relationships and
>> thus all aspects and classes that somehow appear in any kind of
>> relationship. Is there a way to also retrieve those classes in an
>> AspectJ project that are not affected by an aspect and that do not
>> appear in any relationship?
>
> You can determine the classes in a project in the same way as with a
> Java project, by getting all the package fragments and calling
> getCompilationUnits() on each.
>
>> 2. Is there a way to map from an IJavaElement to an AJType or to a
>> Class object? The reason for this question is that I would like to
>> exploit the reflection API of AspectJ and Java because they are so
>> convenient to query the structure of an aspect or of a class.
>
> There are various types in the org.eclipse.ajdt.core.javaelements
> package, such as AspectElement, which are instances of IJavaElement. You
> can get some structure information from these, such as
> AspectElement.getPointcuts(). If you need more detailed info, you
> probably need to use the AspectJ AST parser.
>
> Regards,
>
> Matt.
Re: How to retrieve AspectJ model during build in eclipse? [message #595146 is a reply to message #67399] Thu, 26 October 2006 11:41 Go to previous message
Matt Chapman is currently offline Matt ChapmanFriend
Messages: 429
Registered: July 2009
Senior Member
Hi Marc,

Yes, everything you need should be in the org.eclipse.ajdt.core plug-in.
There is an IAdviceChangedListener interface with a single
adviceChanged() method. Register this with the AJBuilder class like this
(in your plug-in's start() method for example):

AJBuilder.addAdviceListener(new MyAdviceListener());

Currently (AJDT 1.4) this is called after every build of an AspectJ
project (i.e. every *potential* advice change). In a future release this
may be optimized to be only called if the advice has actually changed.
AJDT/UI uses this mechanism to update the orange arrow image decorator.

Crosscutting information can be obtained from the AJModel class. Here's
an example:

public class MyAdviceListener implements IAdviceChangedListener {
public void adviceChanged() {
IProject project = AspectJPlugin.getDefault()
.getCurrentProject();
System.out.println("build detected for project: " + project);
AJRelationshipType[] relsTypes = AJRelationshipManager
.getAllRelationshipTypes();
List rels = AJModel.getInstance().getAllRelationships(
project, relsTypes);
for (Iterator iter = rels.iterator(); iter.hasNext();) {
AJRelationship ajrel = (AJRelationship) iter.next();
System.out.println("Relationship: "
+ ajrel.getSource().getElementName() + " "
+ ajrel.getRelationship().getDisplayName() + " "
+ ajrel.getTarget().getElementName());
}
}
}

For the "TJP Example" project, this prints:

build detected for project: P/TJP Example
Relationship: around advises main
Relationship: around advises foo
Relationship: around advises bar
Relationship: bar advised by around
Relationship: foo advised by around
Relationship: main advised by around

As you can see, you get the relationship in both directions. See
AJRelationshipManager for the full list of relationships, so you can
just ask for the relationship types you're interested in.

AJRelationship.getSource() and getTarget() return instances of
IJavaElement so you can obtain further information from that, such as
the parent or underlying resource.

Your plug-in will need to depend on org.eclipse.ajdt.core,
org.eclipse.core.resources and org.eclipse.jdt.core.

Regards,

Matt.

Marc Bartsch wrote:
> Hi all,
>
> I am writing an eclipse plugin and I would like to know if the following
> is possible with AJDT.
>
> 1. Whenever an AspectJ project is being built within Eclipse, my plug-in
> needs to be notified and I would like to retrieve information about the
> currently compiled or woven aspect. In short: can a listener be added to
> the Eclipse build system?
>
> 2. The kind of information I am looking for is reflective information
> about an aspect or a class in the system, for example I would like to
> find out all the types that are dynamically crosscut by a given advice
> or a list of all methods and their signatures. I know there is a
> reflection API in AspectJ, but this will not give me the weaving
> information. Can this kind of information be extracted from AJDT during
> a build in Eclipse, e.g. through an AST? (I found some hints here
> http://dev.eclipse.org/newslists/news.eclipse.technology.ajd t/msg01110.html
> but I do not want to write a new builder but use the existing one.)
>
> Any hints are greatly appreciated,
>
> Marc.
Re: How to retrieve AspectJ model during build in eclipse? [message #595176 is a reply to message #67420] Fri, 27 October 2006 08:24 Go to previous message
Eclipse UserFriend
Originally posted by: m.bartsch.rdg.ac.uk

Hi Matt,

Thanks a lot! It works like a charm!

There are two more question that I have.

1.The solution that you describe gives me all the relationships and thus
all aspects and classes that somehow appear in any kind of relationship.
Is there a way to also retrieve those classes in an AspectJ project that
are not affected by an aspect and that do not appear in any relationship?

2. Is there a way to map from an IJavaElement to an AJType or to a Class
object? The reason for this question is that I would like to exploit the
reflection API of AspectJ and Java because they are so convenient to
query the structure of an aspect or of a class.

Anyway, thanks for your help so far,

Marc.

Matt Chapman schrieb:
> Hi Marc,
>
> Yes, everything you need should be in the org.eclipse.ajdt.core plug-in.
> There is an IAdviceChangedListener interface with a single
> adviceChanged() method. Register this with the AJBuilder class like this
> (in your plug-in's start() method for example):
>
> AJBuilder.addAdviceListener(new MyAdviceListener());
>
> Currently (AJDT 1.4) this is called after every build of an AspectJ
> project (i.e. every *potential* advice change). In a future release this
> may be optimized to be only called if the advice has actually changed.
> AJDT/UI uses this mechanism to update the orange arrow image decorator.
>
> Crosscutting information can be obtained from the AJModel class. Here's
> an example:
>
> public class MyAdviceListener implements IAdviceChangedListener {
> public void adviceChanged() {
> IProject project = AspectJPlugin.getDefault()
> .getCurrentProject();
> System.out.println("build detected for project: " + project);
> AJRelationshipType[] relsTypes = AJRelationshipManager
> .getAllRelationshipTypes();
> List rels = AJModel.getInstance().getAllRelationships(
> project, relsTypes);
> for (Iterator iter = rels.iterator(); iter.hasNext();) {
> AJRelationship ajrel = (AJRelationship) iter.next();
> System.out.println("Relationship: "
> + ajrel.getSource().getElementName() + " "
> + ajrel.getRelationship().getDisplayName() + " "
> + ajrel.getTarget().getElementName());
> }
> }
> }
>
> For the "TJP Example" project, this prints:
>
> build detected for project: P/TJP Example
> Relationship: around advises main
> Relationship: around advises foo
> Relationship: around advises bar
> Relationship: bar advised by around
> Relationship: foo advised by around
> Relationship: main advised by around
>
> As you can see, you get the relationship in both directions. See
> AJRelationshipManager for the full list of relationships, so you can
> just ask for the relationship types you're interested in.
>
> AJRelationship.getSource() and getTarget() return instances of
> IJavaElement so you can obtain further information from that, such as
> the parent or underlying resource.
>
> Your plug-in will need to depend on org.eclipse.ajdt.core,
> org.eclipse.core.resources and org.eclipse.jdt.core.
>
> Regards,
>
> Matt.
>
> Marc Bartsch wrote:
>> Hi all,
>>
>> I am writing an eclipse plugin and I would like to know if the
>> following is possible with AJDT.
>>
>> 1. Whenever an AspectJ project is being built within Eclipse, my
>> plug-in needs to be notified and I would like to retrieve information
>> about the currently compiled or woven aspect. In short: can a listener
>> be added to the Eclipse build system?
>>
>> 2. The kind of information I am looking for is reflective information
>> about an aspect or a class in the system, for example I would like to
>> find out all the types that are dynamically crosscut by a given advice
>> or a list of all methods and their signatures. I know there is a
>> reflection API in AspectJ, but this will not give me the weaving
>> information. Can this kind of information be extracted from AJDT
>> during a build in Eclipse, e.g. through an AST? (I found some hints
>> here
>> http://dev.eclipse.org/newslists/news.eclipse.technology.ajd t/msg01110.html
>> but I do not want to write a new builder but use the existing one.)
>>
>> Any hints are greatly appreciated,
>>
>> Marc.
Re: How to retrieve AspectJ model during build in eclipse? [message #595201 is a reply to message #67502] Wed, 01 November 2006 10:20 Go to previous message
Matt Chapman is currently offline Matt ChapmanFriend
Messages: 429
Registered: July 2009
Senior Member
Marc Bartsch wrote:
> 1.The solution that you describe gives me all the relationships and thus
> all aspects and classes that somehow appear in any kind of relationship.
> Is there a way to also retrieve those classes in an AspectJ project that
> are not affected by an aspect and that do not appear in any relationship?

You can determine the classes in a project in the same way as with a
Java project, by getting all the package fragments and calling
getCompilationUnits() on each.

> 2. Is there a way to map from an IJavaElement to an AJType or to a Class
> object? The reason for this question is that I would like to exploit the
> reflection API of AspectJ and Java because they are so convenient to
> query the structure of an aspect or of a class.

There are various types in the org.eclipse.ajdt.core.javaelements
package, such as AspectElement, which are instances of IJavaElement. You
can get some structure information from these, such as
AspectElement.getPointcuts(). If you need more detailed info, you
probably need to use the AspectJ AST parser.

Regards,

Matt.
Re: How to retrieve AspectJ model during build in eclipse? [message #595233 is a reply to message #67543] Wed, 01 November 2006 14:25 Go to previous message
Eclipse UserFriend
Originally posted by: m.bartsch.rdg.ac.uk

Hi Matt,

I probably need to use the AspectJ AST parser, but thanks again for your
support.

Best wishes,

Marc.

Matt Chapman schrieb:
> Marc Bartsch wrote:
>> 1.The solution that you describe gives me all the relationships and
>> thus all aspects and classes that somehow appear in any kind of
>> relationship. Is there a way to also retrieve those classes in an
>> AspectJ project that are not affected by an aspect and that do not
>> appear in any relationship?
>
> You can determine the classes in a project in the same way as with a
> Java project, by getting all the package fragments and calling
> getCompilationUnits() on each.
>
>> 2. Is there a way to map from an IJavaElement to an AJType or to a
>> Class object? The reason for this question is that I would like to
>> exploit the reflection API of AspectJ and Java because they are so
>> convenient to query the structure of an aspect or of a class.
>
> There are various types in the org.eclipse.ajdt.core.javaelements
> package, such as AspectElement, which are instances of IJavaElement. You
> can get some structure information from these, such as
> AspectElement.getPointcuts(). If you need more detailed info, you
> probably need to use the AspectJ AST parser.
>
> Regards,
>
> Matt.
Previous Topic:How to find fully qualified type name from simple type name?
Next Topic:Using changed ajde.jar in plugin project
Goto Forum:
  


Current Time: Mon Dec 22 20:51:49 GMT 2014

Powered by FUDForum. Page generated in 0.01848 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software