Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 #589674] Wed, 27 July 2005 15:03
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
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
Previous Topic:AspectJ model
Next Topic:static crosscutting & intertype member declarations: is this a bug, a feature, a bird, a plane,
Goto Forum:
  


Current Time: Fri Apr 19 21:37:38 GMT 2024

Powered by FUDForum. Page generated in 0.03052 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top