Home » Language IDEs » AspectJ » static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a plane,
static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a plane, [message #55618] |
Wed, 27 July 2005 11:03  |
Eclipse User |
|
|
|
I am having a severe problem understanding static crosscutting (cf. see
my recent append in the AspectJ-NG, but since that NG is much less
reactive I post this here):
I boiled my problen down to the following simple example:
Assume some interface definition A, e.g.:
----%<----%<----%<----
public interface A
{
int foo();
}
----%<----%<----%<----
Assume a class B that doesn't know anything about A:
----%<----%<----%<----
public class B
{
int bar = 5;
public String toString() {
return super.toString() + "[bar=" + bar + "]";
}
public static void main(String[] args) {
B b = new B();
System.out.println("b.toString()=" + b.toString());
System.out.println("b " + (b instanceof A ? "IS" : "IS NOT") + " an
instance of A");
}
}
----%<----%<----%<----
Now, we create an aspect that does a static crosscut and defines B to
also implement A plus we directly implement the necessary methods:
----%<----%<----%<----
public aspect C {
declare parents: B extends A;
// we extend the interface A to hold another field plus the method
defined in A:
public int A.foo = 2;
public int A.foo() {
return this.foo;
}
// and we override the toString()-method:
public String A.toString() {
final StringBuffer buf = new StringBuffer(super.toString());
return buf
.append("[foo=")
.append(foo)
.append("]")
.toString();
}
}
----%<----%<----%<----
Now, if I run B.main() I get:
----%<----%<----%<----
b.toString()=B@26f95321[bar=5]
b IS an instance of A
----%<----%<----%<----
So, if B now IS and instance of A (and - at least that's how I
understand this - now de facto derives from A), why is the resulting
output string not:
b.toString()=B@26f95321[foo=2][bar=5] <<< note the [foo=2] portion
i.e. why is B's super.toString() call (in its toString()-method) not
calling the introduced A.toString()???
So, apparently, even though the declare parent ... clause declares "B to
extend A" the class B is not a full or normal subclass of A.
Is this working as designed or is this a bug in the current
AspectJ-implementation or what else?
Hope, I could make myself clear.
Michael
|
|
|
Re: static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a pla [message #55645 is a reply to message #55618] |
Thu, 28 July 2005 03:54  |
Eclipse User |
|
|
|
Andy Clement sent me a direct reply and in the meantime I also read the
corresponding chapter in the eclipse AspectJ book (very good BTW!)
According to these sources, the code that can be added to interfaces
using AspectJ provides only a *default* implementation of those methods.
If a class defines its own method with the same signature, then THAT
code superceedes the aspect-code and is NOT called when the
deriving/implementing class calls a super.<...>.-method.
So, declaring a class to be the parent of another does not come with the
full super-class semantic as I thought, but has a slightly different
twist...
Michael
|
|
|
Re: static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a pla [message #589689 is a reply to message #55618] |
Thu, 28 July 2005 03:54  |
Eclipse User |
|
|
|
Andy Clement sent me a direct reply and in the meantime I also read the
corresponding chapter in the eclipse AspectJ book (very good BTW!)
According to these sources, the code that can be added to interfaces
using AspectJ provides only a *default* implementation of those methods.
If a class defines its own method with the same signature, then THAT
code superceedes the aspect-code and is NOT called when the
deriving/implementing class calls a super.<...>.-method.
So, declaring a class to be the parent of another does not come with the
full super-class semantic as I thought, but has a slightly different
twist...
Michael
|
|
|
Goto Forum:
Current Time: Wed Apr 30 17:40:13 EDT 2025
Powered by FUDForum. Page generated in 0.07160 seconds
|