[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Field names for generic aspects

Hi Adrian,

Sorry, my question probably seemed a bit random. Anyway, I'm still digging around trying to get to the bottom of generic aspects. I see that they're not scheduled for release until M4 --- but, will they be in any of the development snapshots ?

So, my previous question was really about the following. In M3 the following compiles and runs:

abstract public aspect Aspect1<T>   {
 interface HasTest {}		
 declare parents : T implements HasTest; 	
 public int HasTest.test = 0;

 public static void set(HasTest x, int v) { x.test = v; }
 public static int get(HasTest x) { return x.test; }
}
>
> public aspect Aspect2 extends Aspect1<Test> { }
> public aspect Aspect3 extends Aspect1<Test> { }
>
public class Test {
 public static void main(String args[]) {
  Test x = new Test();
  Aspect2.set(x,2);
  Aspect3.set(x,3);
  System.out.println("x.test = " + Aspect2.get(x));
}}

And running this gives the output "x.test = 3". Furthermore, looking at the bytecode of Test gives:


public class Test extends java.lang.Object implements Aspect1$HasTest{
    public int ajc$interField$Aspect1$Aspect1$HasTest$test;
    public Test();
    public static void main(java.lang.String[]);
    public int ajc$interFieldGet$Aspect1$Aspect1$HasTest$test();
    public void ajc$interFieldSet$Aspect1$Aspect1$HasTest$test(int);
}

Which all makes sense. Except that it's not what I really want to happen. Instead, I want Test to have two x fields, one for Aspect2
and another one for Aspect3. So, i'm really wondering how to this --- indeed, whether it's even possible.


Looking at the ParentChildRelationship example from the AJ 5 developers notebook, I see that things are done a little differently than above:

public abstract aspect ParentChildRelationship<Parent,Child> {
interface ParentHasChildren<C extends ChildHasParent> { ... } interface ChildHasParent<P extends ParentHasChildren> { ... }
declare parents: Parent implements ParentHasChildren<Child>;
declare parents: Child implements ChildHasParent<Parent>;
private List<C> ParentHasChildren<C>.children;
private P ChildHasParent<P>.parent;
...
> }

But, I confess, I do not follow this --- how can C and P be used when they are not type parameters of the aspect? Can my above example extend in a similar way to give what I want?

Any help on this would be greatly appreciated!

Cheers,

Dave





Adrian Colyer wrote:
Given TestAspect<Test>, the behaviour of the declare parents statement
is exactly as if you had written

declare parents : Test implements HasTest;

so "T" will not appear anywhere.

On 21/09/05, David Pearce <david.pearce@xxxxxxxxxxxxx> wrote:

Hi All,

I have another quick question about generic aspects.  Consider this:

> class Test {}
>
> aspect TestAspect<T> {
>  interface HasTest {}
>
>  declare parents : T implements HasTest;
>
>  private int HasTest.x = 0;
> }

So, the question is, for TestAspect<Test>, what does the actual name for
the x field which is inserted into Test look like?  I imagine something
like this:

> int ajc$interField$TestAspect$Test$HasTest$x;

Does that seem about right?  I guess the crucial point is that Test has
been included in this name, since it is the concrete type of T.

Cheers,

Dave


-- 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






--
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