From 8287abe6bd065542825c32a427ad357b95d7d0dc Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 26 Oct 2005 16:51:03 +0000 Subject: [PATCH] see pr112105 comment #13: bridge method handling for ITD fields/methods --- .../aspectj/weaver/bcel/BcelTypeMunger.java | 184 ++++++++++++++---- 1 file changed, 146 insertions(+), 38 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 6d39bf0af..bc56bb9d5 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -147,11 +147,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } } else { + ResolvedMember declaredSig = munger.getDeclaredSignature(); + if (declaredSig==null) declaredSig= munger.getSignature(); weaver.getWorld().getMessageHandler().handleMessage(WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ITD, new String[]{weaver.getLazyClassGen().getType().getName(), tName,munger.getKind().toString().toLowerCase(), getAspectType().getName(), - fName+":'"+munger.getSignature()+"'"}, + fName+":'"+declaredSig+"'"}, weaver.getLazyClassGen().getClassName(), getAspectType().getName())); } } @@ -730,18 +732,17 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // Resolving it will sort out the tvars ResolvedMember unMangledInterMethod = munger.getSignature().resolve(w); // do matching on the unMangled one, but actually add them to the mangled method - ResolvedMember interMethodBody = munger.getInterMethodBody(aspectType); - ResolvedMember interMethodDispatcher = munger.getInterMethodDispatcher(aspectType); + ResolvedMember interMethodBody = munger.getDeclaredInterMethodBody(aspectType,w); + ResolvedMember interMethodDispatcher = munger.getDeclaredInterMethodDispatcher(aspectType,w); ResolvedMember memberHoldingAnyAnnotations = interMethodDispatcher; ResolvedType onType = weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation()); - - LazyClassGen gen = weaver.getLazyClassGen(); - boolean mungingInterface = gen.isInterface(); + LazyClassGen gen = weaver.getLazyClassGen(); + boolean mungingInterface = gen.isInterface(); if (onType.isRawType()) onType = onType.getGenericType(); boolean onInterface = onType.isInterface(); - + // Simple checks, can't ITD on annotations or enums if (onType.isAnnotation()) { @@ -754,8 +755,6 @@ public class BcelTypeMunger extends ConcreteTypeMunger { return false; } - - if (onInterface && gen.getLazyMethodGen(unMangledInterMethod.getName(), unMangledInterMethod.getSignature(),true) != null) { // this is ok, we could be providing the default implementation of a method // that the target has already declared @@ -764,11 +763,10 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // If we are processing the intended ITD target type (might be an interface) if (onType.equals(gen.getType())) { - - ResolvedMember mangledInterMethod = AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, onInterface); + LazyMethodGen newMethod = makeMethodGen(gen, mangledInterMethod); if (mungingInterface) { // we want the modifiers of the ITD to be used for all *implementors* of the @@ -870,7 +868,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { ResolvedMember mangledInterMethod = AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false); - + LazyMethodGen mg = makeMethodGen(gen, mangledInterMethod); if (mungingInterface) { // we want the modifiers of the ITD to be used for all *implementors* of the @@ -894,21 +892,73 @@ public class BcelTypeMunger extends ConcreteTypeMunger { body.append(InstructionFactory.createLoad(paramType, pos)); pos+=paramType.getSize(); } + body.append(Utility.createInvoke(fact, weaver.getWorld(), interMethodBody)); + Type t= BcelWorld.makeBcelType(interMethodBody.getReturnType()); + if (!t.equals(returnType)) { + body.append(fact.createCast(t,returnType)); + } body.append(InstructionFactory.createReturn(returnType)); mg.definingType = onType; weaver.addOrReplaceLazyMethodGen(mg); addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled()); - + + // Work out if we need a bridge method for the new method added to the topmostimplementor. + if (munger.getDeclaredSignature()!=null) { // Check if the munger being processed is a parameterized form of some original munger. + boolean needsbridging = false; + ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,munger.getSignature().getDeclaringType().resolve(getWorld()),false,munger.getTypeVariableAliases()); + if (!toBridgeTo.getReturnType().getErasureSignature().equals(munger.getSignature().getReturnType().getErasureSignature())) needsbridging = true; + UnresolvedType[] originalParams = toBridgeTo.getParameterTypes(); + UnresolvedType[] newParams = munger.getSignature().getParameterTypes(); + for (int ii = 0;ii