[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] problem with inter-type declaration - inserting a method override


Hi Lee,

Actually it looks to me like AspectJ is behaving as expected. I quote from the "Static crosscutting" section of the AspectJ Programming Guide where it discusses conflicts (see http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/printable.html#d0e6543 )

"Conflicts are resolved as much as possible as per Java's conflict resolution rules ... A subclass can only inherit multiple methods with the same name and argument types from its superclasses if only zero or one of them is concrete (i.e., all but one is abstract, or all are abstract)."

It looks like your aspect is creating a situation where type SubclassData is going to inherit two concrete methods - one from the super class BaseClass and one from the interface IToString. If you wanted to "inject" a method override for the toString() method then you could just change the method introduction to be

    public String SubclassData.toString() {
         return "eliminated commons-lang dependency for testcase";
    }


I think there is still something more to be explained here though.  Just as I was about to press send on the above response, I noticed that, with your original code still in place, removing the implementation of toString() from BaseClass resulted in the compiler error going away. Which is surprising (to me anyway) since the class SubclassData is surely still inheriting the toString() method from its more distant ancestor java.lang.Object. Perhaps java.lang.Object is a special case in the Java conflict resolution rules. Now, where did I put that language spec ... ?

George
________________________________________
George C. Harley




"Lee Sanders" <lee.sanders@xxxxxxxxxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

06/12/2004 17:49

Please respond to
aspectj-users@xxxxxxxxxxx

To
<aspectj-users@xxxxxxxxxxx>
cc
"Lee Sanders" <lee.sanders@xxxxxxxxxxxxxxx>
Subject
[aspectj-users] problem with inter-type declaration - inserting a method override





Problem: I want to statically add a toString method into a specified set of
classes but
I'm having a problem with the ajc 1.2.1 compiler in the case where the
baseclass already
defines a toString method.  It says there is a conflict with an existing
member.
I've created a simplified test case below to concretely illustrate the
problem.

So is this some kind of correct limitation in the aspectj language that I've
missed?  It seems like this is a natural way of injecting method overrides
for
any superclass method implementation(s)...

Thanks for any help.

=========== ajc 1.2.1 compiler messages  ==================

    [iajc] Extending interface set for type 'SubclassData'
(SubclassData.java) to include 'ToStringInjector$IToString'
(ToStringInjector.aj)
    [iajc]                  
    [iajc]
C:\Projects\AspectJ\ToStringInjectorBug\src\ToStringInjector.aj:8 [error]
inter-type declaration from ToStringInjector conflicts with existing member:
java.lang.String BaseClass.toString()
    [iajc] public String IToString.toString() {
    [iajc]                         ^^^^^
    [iajc] MessageHolder:  (1 weaveinfo)  (1 error)
    [iajc] [error   0]: error at public String IToString.toString() {
    [iajc]                         ^^^^^
    [iajc]
C:\Projects\AspectJ\ToStringInjectorBug\src\ToStringInjector.aj:8:0
inter-type declaration from ToStringInjector conflicts with existing member:
java.lang.String BaseClass.toString()

=========== ToStringInjector.aj ==================
aspect ToStringInjector {
   private interface IToString {};
   declare parents: (SubclassData) implements IToString;
   public String IToString.toString() {
                return "eliminated commons-lang dependency for testcase";
   }
};
=========== BaseClass.java ==================
public class BaseClass {
   public void foo() {}
   public String toString() {
                return "BaseClass";
   }
};
=========== SubclassData.java ==================
public class SubclassData extends BaseClass {
   public void bar() {}
};

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