[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Question about Generic Aspects
|
#: David Pearce changed the world a bit at a time by saying on 9/13/2005 11:41 PM :#
Hi Adrian,
Adrian Colyer wrote:
The inter-type declarations refered to in that paragraph are
inter-type method, field, and constructor declarations. The declare
family are exempt from this restriction :)
Thanks for that!
So, I have another question about generic aspects. Given what you've
said I can do the following:
> aspect AddStudents<T> {
>
> interface HasStudents {}
>
> declare parents : X implements HasStudents;
>
> List<Student> HasStudents.students = new ArrayList<Student>();
> }
To add a field to any class which is the type parameter of a concrete
instance of AddStudents. So,
> aspect FooStudents extends AddStudents<Foo> {}
Adds students to all instances of Foo.
David, I cannot see the connection between the generic type T, X and Student. Would the following be
what you thought about:
[code]
aspect AddStudents<T> {
[...]
declare parents: T implements HasStudents;
[...]
}
I kind of imagine that this will
work in much the same way as C++ templates (i.e. some specialised aspect
AddStudents__Foo is created with T replaced by Foo and FooStudents
extending this). Anyway, i also presume that if I have another aspect
extending AddStudents where T=Foo then there will be a compile time error?
afaik java generics are different that C++ templates (where new types are created). Foo extends
AddStudents<T> and Bar extends AddStudents<T> should work (at least this is my understand).
Right, so the case that I'm really interested is the following:
> public aspect Assoc<X,Y> {
> interface HasXs {}
> interface HasYs {}
>
> declare parents : Y implements HasXs;
> declare parents : X implements HasYs;
>
> public List<Y> HasYs.ys = new ArrayList<Y>();
> public List<X> HasXs.xs = new ArrayList<X>();
> }
So, what I'm doing is effectively creating a bidirectional association
between X and Y. The thing is, I need to choose a name for xs and ys.
This is annoying because it means I cannot have the following:
> aspect FooBarAssoc extends Assoc<Foo,Bar> {}
> aspect FooCarAssoc extends Assoc<Foo,Car> {}
Since, the ys name will clash. So, my question (at last!) is: is there
anyway around this ? I guess what I really want to write is:
> public List<Y> HasYs.XY_ys = new ArrayList<Y>();
> public List<X> HasXs.XY_xs = new ArrayList<X>();
Where XY is just textually replaced with the actually type parameters.
I don't think this may result in a name clash, but rather in a compilation error: you will have a
Foo.ys field having 2 different types: List<Bar> and List<Car>.
:alex |.::the_mindstorm::.|
Cheers,
Dave
On 09/09/05, David Pearce <david.pearce@xxxxxxxxxxxxx> wrote:
Hi all,
I have been reading the Aspectj 1.5 note book and have a question about
generic aspects, which I'm hoping someone can help me with. The
documentation says:
"The type parameter variables from a generic aspect declaration may be
used in place of a type within any member of the aspect, except for
within inter-type declarations."
But, it seems that the example goes on to do just this. Namely:
> public abstract aspect ParentChildRelationship<Parent,Child> {
> ...
> declare parents: Parent implements ParentHasChildren<Child>;
> ...
> }
So, I'm wondering whether I just missed something or, if not, which way
around it should be.
Thanks,
David J. Pearce
--
Lecturer in Computer Science,
School of Mathematics, Statistics and Computer Science,
Victoria University of Wellington,
PO Box 600,
Wellington,
New Zealand.
Office: Cotton 231
Telephone: +64 4 463 5833
URL: http://www.mcs.vuw.ac.nz/~djp
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users