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?

Did not see this response before my other comments. 

Thanks for your responses. I'll try your suggestions. Perhaps it is AJDT. 

I had to do the first approach as the class is a very common base class that
I need to enhance but true to your comments, I just found another class that
needs roughly the same code so I'll probably move slightly to the more
popular scenario you describe.

I should have added that my aspects library (aspects and classes) processes
2 other libraries on its inpath to add methods/attributes to those classes.
In fact, the base class I am enhancing comes from that
external-to-the-project library and the class in the aspects project that
needs to see those methods inherits from that base.


> 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



Back to the top