Hi,
Has any progress been made on solving the issues of
privileged access to aspects?
For example, if I have a class:
public class A {
private
int i;
}
and aspect:
@Aspect
public class AspectA {
//
set i after constructor has returned
@AfterReturning("this(a) && execution(public *.new(..))")
public
void setI( A a ){
a.i
= 42;
}
}
then we will get a ‘not visible’ error
for the assignment to i.
It seems to me that it would be generally useful,
outside of AspectJ too, to be able to tell the compiler/editor to allow access
to private, protected and package scope objects.
This would be done by changing the function to:
public
void setI( @PrivilegedAccess(‘private’) A a ){
a.i
= 42;
}
In fact, this would probably equate to an
annotation-based ‘friend’ capability that C++ boasts of.
Naturally, the passing of references would have to
be dealt with, but this should be possible. It may also allow annotations
and an APT plugin to be used rather than having to work around security when
doing reflection on object graphs, for example.
The benefit of standardising something like this is
that it would (with agreement with Sun et al) allow a standard compiler to support
this. The consequences, however, may be rather too scary!
Cheers,
Neale