]> source.dussan.org Git - aspectj.git/commitdiff
declareMixin
authoraclement <aclement>
Mon, 9 Mar 2009 22:09:12 +0000 (22:09 +0000)
committeraclement <aclement>
Mon, 9 Mar 2009 22:09:12 +0000 (22:09 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java

index eb3c1dd8d3b797e505758fdf24104b6f8f664597..c6c54d516c58daad8ed7ecd5ea2140a9f90a7ebf 100644 (file)
@@ -135,25 +135,31 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        String fName = getShortname(getAspectType().getSourceLocation().getSourceFile().getPath());
                        if (munger.getKind().equals(ResolvedTypeMunger.Parent)) {
                                // This message could come out of AjLookupEnvironment.addParent
-                               // if doing parents
-                               // munging at compile time only...
+                               // if doing parents munging at compile time only...
                                NewParentTypeMunger parentTM = (NewParentTypeMunger) munger;
-                               if (parentTM.getNewParent().isInterface()) {
+                               if (parentTM.isMixin()) {
                                        weaver.getWorld().getMessageHandler().handleMessage(
-                                                       WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS,
-                                                                       new String[] { weaver.getLazyClassGen().getType().getName(), tName,
-                                                                                       parentTM.getNewParent().getName(), fName }, weaver.getLazyClassGen().getClassName(),
-                                                                       getAspectType().getName()));
+                                                       WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_MIXIN,
+                                                                       new String[] { parentTM.getNewParent().getName(), fName,
+                                                                                       weaver.getLazyClassGen().getType().getName(), tName }, weaver.getLazyClassGen()
+                                                                                       .getClassName(), getAspectType().getName()));
                                } else {
-                                       weaver.getWorld().getMessageHandler().handleMessage(
-                                                       WeaveMessage
-                                                                       .constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSEXTENDS, new String[] {
-                                                                                       weaver.getLazyClassGen().getType().getName(), tName, parentTM.getNewParent().getName(),
-                                                                                       fName }));
-                                       // TAG: WeavingMessage DECLARE PARENTS: EXTENDS
-                                       // reportDeclareParentsMessage(WeaveMessage.
-                                       // WEAVEMESSAGE_DECLAREPARENTSEXTENDS,sourceType,parent);
+                                       if (parentTM.getNewParent().isInterface()) {
+                                               weaver.getWorld().getMessageHandler().handleMessage(
+                                                               WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS,
+                                                                               new String[] { weaver.getLazyClassGen().getType().getName(), tName,
+                                                                                               parentTM.getNewParent().getName(), fName },
+                                                                               weaver.getLazyClassGen().getClassName(), getAspectType().getName()));
+                                       } else {
+                                               weaver.getWorld().getMessageHandler().handleMessage(
+                                                               WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSEXTENDS, new String[] {
+                                                                               weaver.getLazyClassGen().getType().getName(), tName, parentTM.getNewParent().getName(),
+                                                                               fName }));
+                                               // TAG: WeavingMessage DECLARE PARENTS: EXTENDS
+                                               // reportDeclareParentsMessage(WeaveMessage.
+                                               // WEAVEMESSAGE_DECLAREPARENTSEXTENDS,sourceType,parent);
 
+                                       }
                                }
                        } else if (munger.getKind().equals(ResolvedTypeMunger.FieldHost)) {
                                // hidden
@@ -1140,7 +1146,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
         * @param unMangledInterMethod the method to bridge 'to' that we have already created in the 'subtype'
         * @param clazz the class in which to put the bridge method
         * @param paramTypes Parameter types for the bridge method, passed in as an optimization since the caller is likely to have
-        *            already created them.
+        *        already created them.
         * @param theBridgeMethod
         */
        private void createBridgeMethod(BcelWorld world, NewMethodTypeMunger munger, ResolvedMember unMangledInterMethod,
@@ -1312,6 +1318,15 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        if (munger.specifiesDelegateFactoryMethod()) {
                                ResolvedMember rm = munger.getDelegateFactoryMethod(weaver.getWorld());
 
+                               // Check the method parameter is compatible with the type of the instance to be passed
+                               if (rm.getArity() != 0) {
+                                       ResolvedType parameterType = rm.getParameterTypes()[0].resolve(weaver.getWorld());
+                                       if (!parameterType.isAssignableFrom(weaver.getLazyClassGen().getType())) {
+                                               signalError("For mixin factory method '" + rm + "': Instance type '" + weaver.getLazyClassGen().getType()
+                                                               + "' is not compatible with factory parameter type '" + parameterType + "'", weaver);
+                                               return false;
+                                       }
+                               }
                                if (rm.isStatic()) {
                                        if (rm.getArity() != 0) {
                                                body.append(InstructionConstants.ALOAD_0);
@@ -1476,6 +1491,11 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                weaver.getWorld().getMessageHandler().handleMessage(msg);
        }
 
+       private void signalError(String msgString, BcelClassWeaver weaver) {
+               IMessage msg = MessageUtil.error(msgString, getSourceLocation());
+               weaver.getWorld().getMessageHandler().handleMessage(msg);
+       }
+
        private boolean mungeNewConstructor(BcelClassWeaver weaver, NewConstructorTypeMunger newConstructorTypeMunger) {
 
                final LazyClassGen currentClass = weaver.getLazyClassGen();
index 44f4713faaa7079ca594eeb9edcbfe7b2db89ef6..5fee7ed9509b200553af05b3a0a0bc9b5bfc72d1 100644 (file)
@@ -1666,7 +1666,10 @@ public class BcelWeaver {
                                // BcelTypeMunger.mungeNewParent()
                                // classType.addParent(newParent);
                                onType.addParent(newParent);
-                               ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
+                               NewParentTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
+                               if (p.isMixin()) {
+                                       newParentMunger.setIsMixin(true);
+                               }
                                newParentMunger.setSourceLocation(p.getSourceLocation());
                                onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p)));
                        }