Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] accessing members of this in intertype declarations

The Programming Guide, Semantics appendix, section
"Inter-type member declarations" says:

  Any occurrence of the identifier this in the body of an
  inter-type constructor or method declaration, or in the
  initializer of an inter-type field declaration, refers
  to the OnType object rather than to the aspect type;
  it is an error to access this in such a position from
  a static inter-type member declaration.

http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/semantics-declare.html#d0e6005

So use "this" in non-static contexts to refer to the type being
declared on.

  aspect A {
     public void C.foo() {
         this.bar(); // for C.bar()
     }
  }

You can't refer to either the aspect type or
to subtypes of the type declared on, so in your case you
cannot refer to a member of type C that implements
interface I in the body of a method declared on I.

You can declare the method on C directly, or surface the
instance of C with this(), target() or  args() and then use
that, if the member is accessible.

In any case, if C is to be affected by

  declare parents : C implements I

then C has to be in the code the compiler controls, as a
source file or in the -injars.

And if C is affected (implements I), then any subclass
of C is also affected (will implement I).  This is just
straight Java.

Wes

Lendvai Attila wrote:
hi!

if i define an aspect with inter-type member declarations, is there any
way to access the this pointer of the type it's applied to.

i have a class C {}. i apply aspect A {} to a few subclasses of C. in
the body of a method in A i would like to access the C instance...

class C
{
	void bar()
	{
	}
}

class D extends C {}
class E extends C {}

aspect A
{
	private interface IA {};

	declare parents (C || D) implements IA;

	void IA.foo()
	{
		?.bar();
	}
}

C is in a library without an interface and i would not like to use
injar, but E should not get the functinality in A anyways.

or should i do this in a different way?

thanks,

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




Back to the top