[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-dev] AspectJ Runtime: Signatures for interface initialization and type staticinitialization
|
This discussion relates to https://bugs.eclipse.org/bugs/show_bug.cgi?id=157054.
I have also found https://bugs.eclipse.org/bugs/show_bug.cgi?id=49295 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=60936 which concern the removal
from the language of the interface constructor execution pcd. Unfortunately
the documentation for this part of the API is terse and the tests almost
non-existent so it is very difficult to determine the intended behaviour.
One thing I am sure of: we should not return null.
There seems to be a discrepancy between
classes and interfaces when it comes to the initialization join point.
In the example below we advise the initialization of a single class both
as an extender of Parent and an implementer of Interface:
public
class
Test extends
Parent implements
Interface {
public
static
void
main(String[] args) {
new
Test();
}
}
public
interface
Interface {
}
public
class
Parent {
}
public
aspect
Aspect {
before
() : (initialization(Interface.new())
|| initialization(Parent+.new()))
&& !within(Parent)
{
Signature signature = thisJoinPoint.getSignature();
System.err.println("Aspect.before()
this=" + thisJoinPoint.getThis()
+ ",
signature=" + signature.getClass()
+ ",
declaringType=" + thisJoinPoint.getSignature().getDeclaringTypeName()
+ ",
" + ((ConstructorSignature)signature).getConstructor());
}
}
However the output in each case is different:
Aspect.before() this=Test@1833955,
signature=class org.aspectj.runtime.reflect.ConstructorSignatureImpl, declaringType=Test,
public Test()
Aspect.before() this=Test@1833955,
signature=class org.aspectj.runtime.reflect.ConstructorSignatureImpl, declaringType=Interface,
null
Firstly while the declaring type for
a class initializer is the target class in the case of the interface it
is not. Secondly an interface cannot have a constructor. There are two
possible solutions:
1. Make the implementing type the declaring
type and remove the discrepancy between class and interface.
2. Return an InitializerSignature instead
of a ConstructorSignature. Unfortunately this interface has getInitializer()
which also returns a java.lang.reflect.Constructor. What is slightly bizarre
is that this interface is also used for staticinitializer join points and
in this case the interface returns the signature for the default constructor
of the target class!
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/