Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ajdt-dev] Re: [aspectj-users] Finding if a selected piece of code is being affected by an advice

Hi Fernando,

If you get the PointcutElement, you can cast it to ISourceReference
then call getSource().
But to keep JDT happy by default "Java-compatible" contents are
returned, not the real contents. You have to request this from the
containing AJCompilationUnit, by calling requestOriginalContentMode(),
and then discardOriginalContentMode() afterwards.

There is an example of this in the org.eclipse.ajdt.core plugin, in
AspectRenameParticipant.java around line 206.

Regards,

Matt.

On 02/05/07, Fernando Calheiros <xfernando@xxxxxxxxx> wrote:
Hey Matt, I checked the link you gave me and used AJModel to obtain the
information, but from what I see there's no way to obtain more information
other than the type of advice (before, after, around), its return type and
parameters from an AJRelationship, isn't there a way to obtain the pointcuts
used in it?

(What I really need is to check if a within or withincode was used in the
advice pointcut expression that matched a piece of code that was selected by
the user)

Thanks in advance,
Fernando Calheiros


On 5/2/07, Matt Chapman <mpchapman@xxxxxxxxx> wrote:
> This is really a question for the ajdt-dev mailing list... I think
> it'd be easier to get the info you need directly from the AJModel
> class, as described here:
>
>
http://wiki.eclipse.org/index.php/Developer%27s_guide_to_building_tools_on_top_of_AJDT_and_AspectJ#Obtaining_crosscutting_relationship_information_from_AJDT
>
> --Matt
>
> On 02/05/07, Fernando Calheiros < xfernando@xxxxxxxxx> wrote:
> > Hi everyone, I'm trying to get some information about whether a piece of
> > method code selected from the user is being affected by an advice and if
the
> > advice uses withincode.
> >
> > Since apparently most of this information is available in the
> > cross-references view, I thought AJDT's visualizer content provider
would be
> > the right place to look, and just as a test I tried the following code:
> >
> >         AJXReferenceProvider provider = new AJXReferenceProvider();
> >
> >         LinkedList<AJRelationshipType> relations = new
> > LinkedList<AJRelationshipType>();
> >
> >         //adding all relationship types, just to see if anything is
returned
> >         AJRelationshipType[] types =
> > AJRelationshipManager.getAllRelationshipTypes();
> >         for (AJRelationshipType type : types) {
> >             relations.add(type);
> >         }
> >
> >         //refactoringInfo.getOrigin() returns the IFile for the .java
class
> > open in the eclipse editor
> >         Collection references = provider.getXReferences(JavaCore
> >                 .createCompilationUnitFrom(refactoringInfo.getOrigin()),
> >                 relations);
> >
> >         //print the references
> >         for (Object object : references) {
> >             IXReference reference = (IXReference) object;
> >
> >             System.out.println(reference.getName());
> >         }
> >
> > The IFile passed as parameter to create the ICompilationUnit is being
> > affected by advices and inter-type declarations, which are correctly
> > displayed in the cross-references view, but getXReferences is returning
an
> > empty Collection, can anyone tell me what I'm doing wrong?
> >
> > Thanks in advance,
> > Fernando Calheiros
> >
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>




Back to the top