Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Question on static cross-cutting and queries

This is a good question for the aspectj-users@xxxxxxxxxxx mail list.

> The idea would be to apply the interface Stringable to every class with
> a single-argument constructor that takes a String as an argument.

You're right: there's no way in AspectJ to specify a type pattern
based on the type's methods or constructors.

It's a curious rule, since a subclass of a Stringable class
might not have a String constructor, but is Stringable.

If it helps, you can find all such types:

  declare warning: execution(new(String)) : "Stringable?";

And also signal an error if they should be Stringable:

  declare error: execution((!Stringable).new(String)) :
      "Not Stringable!";

(I can't write an error when they are Stringable but
don't have a String constructor.)

> [...] I
> can imagine the difficulties with this sort of query as related to
> precendence of operation and other aspects that may have already been
> applied.

I see no problem with a declare parent for each target type.

Perhaps if you tell folks on the users list more about what
you're trying to do, an AspectJ solution can emerge.

Thanks -
Wes

Paul Brown wrote:

I'd like to be able to write something like the following:

  public aspect ApplyStringable {
	declare parents: *..* where new(String) implements Stringable;
  }

The idea would be to apply the interface Stringable to every class with
a single-argument constructor that takes a String as an argument.

From what I know and have used of AspectJ, the only way to do this is to
actually enumerate all of the classes that this would apply to.  (And I
can imagine the difficulties with this sort of query as related to
precendence of operation and other aspects that may have already been
applied.)

Has this sort of functionality been tried?  Is there another way to
accomplish the same thing?  (I know how to do it with BCEL, but that's
not the point...)

Thanks in advance for any ideas.

	-- Paul
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-dev




Back to the top