Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: aspects in my aspects project and classes in the same project need to use those introduced methods, how to do this?

On 13 July 2010 16:23, aappddeevv <aappddeevv@xxxxxxxxxxx> wrote:
> I am using ITDs.
>
> Its reusable but I am not sure why you ask that as aren't all libraries
> designed to be reused?
> The ITDs mostly introduce methods and field to types. No introduction of
> parents or an interface.

With ITDs I would say libraries need very careful design otherwise
they aren't particularly reusable

aspect A {
  public void Foo.bar() {}
}

class Foo {
}

that is not a particularly reusable aspect for a library as it only
puts methods into Foo and the aspect
won't compile if Foo isn't around.

aspect A {
  public void Bar.goo() {}
}

interface Bar {
}

that is more common scenario and a little more reusable I would say.
Types implementing Bar interface
will get the goo method().  But probably most common pattern I see:

aspect A {
  interface SomeInterface {
     void someMethod();
  }

  public void SomeInterface.someMethod() {
     System.out.println("default implementation")
  }

  declare parents: @Foo * implements SomeInterface;
}

@interface Foo {}

now anything annotated with Foo will get SomeInterface and my ITD'd method.

Depending on what you are doing, I might suggest different project structures.

> The reason I asked this question is because when I try to code my classes in
> the aspects project (which has both the aspects the client will use to
> enhance their classes and new classes I am providing to the client that
> should be enhanced as well) the eclipse editor flags the ITD methods in the
> classes as not present and they don't compile. Its almost as if the methods
> introduced in the ITD are not visible to the classes in the same project the
> ITDs are declared in.

That is not how it should work - ITDs are fully supported in the
project in which they
are defined.  If it is only the editor flagging the problems (and they
do not appear
in the problems view) then it is an AJDT issue and not an AspectJ
issue (meaning that
the compiler is doing the right thing).  Are you running with JDT
weaving turned on?
(see the preferences page if you aren't sure).  If it is off, I
recommend turning it on.  If it
already is on, i'll hand you over to the AJDT guys for them to answer.

> Downstream, in dependent libraries, everything is fine
> of course.

> >From your comments, are you saying that classes I write in the same project
> that the aspects are declared in SHOULD see the enhanced methods?

Yes, they should be able to if they are in the same project.

Andy
>
> Message: 2
> Date: Tue, 13 Jul 2010 10:10:37 -0700
> From: Andy Clement <andrew.clement@xxxxxxxxx>
> Subject: Re: [aspectj-users] aspects in my aspects project and classes
>        in the  same project need to use those introduced methods, how to do
>        this?
> To: aspectj-users@xxxxxxxxxxx
> Message-ID:
>        <AANLkTin4Wf05kyZLBrrzRgY8fyrMDTaadYGM75LFDIgl@xxxxxxxxxxxxxx>
> Content-Type: text/plain; charset=ISO-8859-1
>
> I guess you mean the aspects are using intertype declarations.
>
> To support your basic use case, sounds like you can just keep
> everything in one project.
>
> However, if you are building a reusable library and the initial target
> classes shouldn't be included, you will need to split the projects.
> However - intertype declarations create a strong coupling between the
> aspect and the target which can make this tricky to set up.  What
> kinds of intertype are you doing?  Are you intertyping onto an
> interface then using declare parents to apply that interface?
>
> Andy
>
> On 9 July 2010 06:59,  <aappddeevv@xxxxxxxxxxx> wrote:
>> I have a project, called MyAspects. It contains several aspects. It also
> contains classes. Those classes need to use the public methods introduced by
> those aspects.
>>
>> How do you setup the project to do this? Do I have to setup 2 projects and
> keep my aspects in one project and everything else in another?
>>
>> The output should ideally be a library that clients use to potentially
> introduce the aspects to their types as well as use the aspectj-enhanced
> classes directly.
>> _______________________________________________
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top