From: aclement Date: Mon, 9 Mar 2009 22:09:12 +0000 (+0000) Subject: declareMixin X-Git-Tag: pre268419~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c1e8c788a7b5f3856e65815e67bd9209a90ac32;p=aspectj.git declareMixin --- diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index eb3c1dd8d..c6c54d516 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -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(); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 44f4713fa..5fee7ed95 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -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))); }