From 257e39e557a0ca5f4a058726b6ccc72fdda22397 Mon Sep 17 00:00:00 2001 From: avasseur Date: Mon, 17 Oct 2005 12:26:41 +0000 Subject: polish for last commit (implement @AspectJ ITD @DeclareParents and @DeclareImplements changed AjType as ITD field is meaningless (as @AJ ITD is interface driven)) --- .../aspectj/weaver/MethodDelegateTypeMunger.java | 48 ++++++++++++----- .../org/aspectj/weaver/bcel/AtAjAttributes.java | 26 +-------- .../org/aspectj/weaver/bcel/BcelTypeMunger.java | 63 +--------------------- 3 files changed, 38 insertions(+), 99 deletions(-) (limited to 'weaver') diff --git a/weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java b/weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java index 17906b6f9..1d4a2e84a 100644 --- a/weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java @@ -21,12 +21,34 @@ import java.io.IOException; import java.util.Set; import java.util.Iterator; +/** + * Type munger for @AspectJ ITD declare parents ie with an interface AND an implementation. + * Given the aspect that has a field public static Interface fieldI = ... // impl. + * we will weave in the Interface' methods and delegate to the aspect public static field fieldI + * + * Note: this munger DOES NOT handles the interface addition to the target classes - a regular Parent kinded munger + * must be added in coordination. + */ public class MethodDelegateTypeMunger extends ResolvedTypeMunger { + /** + * The field in the aspect that hosts the mixin instance + */ private final ResolvedMember aspectFieldDelegate; + /** + * Type pattern this munger applies to + */ private final TypePattern typePattern; + /** + * Construct a new type munger for @AspectJ ITD + * + * @param signature + * @param aspect + * @param fieldName + * @param typePattern + */ public MethodDelegateTypeMunger(ResolvedMember signature, ResolvedType aspect, String fieldName, TypePattern typePattern) { super(MethodDelegate, signature); this.typePattern = typePattern; @@ -50,14 +72,6 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger { return aspectFieldDelegate; } -// public ResolvedMember getInterMethodBody(UnresolvedType aspectType) { -// return AjcMemberMaker.interMethodBody(signature, aspectType); -// } -// -// public ResolvedMember getInterMethodDispatcher(UnresolvedType aspectType) { -// return AjcMemberMaker.interMethodDispatcher(signature, aspectType); -// } - public void write(DataOutputStream s) throws IOException { ;//FIXME AVITD needed as changes public signature throw new RuntimeException("unimplemented"); } @@ -69,14 +83,15 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger { // ResolvedTypeMunger munger = new MethodDelegateTypeMunger(rmi, superMethodsCalled); // if (sLoc != null) munger.setSourceLocation(sLoc); // return munger; -// } -// -// public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) { -// ResolvedMember ret = AjcMemberMaker.interMethodDispatcher(getSignature(), aspectType); -// if (ResolvedType.matches(ret, member)) return getSignature(); -// return super.getMatchingSyntheticMember(member, aspectType); // } + /** + * Match based on given type pattern, only classes can be matched + * + * @param matchType + * @param aspectType + * @return true if match + */ public boolean matches(ResolvedType matchType, ResolvedType aspectType) { // match only on class if (matchType.isEnum() || matchType.isInterface() || matchType.isAnnotation()) { @@ -86,6 +101,11 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger { return typePattern.matchesStatically(matchType); } + /** + * Needed for reweavable + * + * @return true + */ public boolean changesPublicSignature() { return true; } diff --git a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java index d4ea69307..cdcc3ac59 100644 --- a/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -444,30 +444,8 @@ public class AtAjAttributes { * @return list of AjAttributes, always empty for now */ public static List readAj5FieldAttributes(Field field, BcelField bField, ResolvedType type, ISourceContext context, IMessageHandler msgHandler) { - //TODO use ? if (field.getName().startsWith(NameMangler.PREFIX)) return Collections.EMPTY_LIST; // already dealt with by ajc... -// -// // bypass primitive type fields - useless for @DeclareParents/Implements (interface) -// if (bField.getType().isPrimitiveType()) return Collections.EMPTY_LIST; -// -// AjAttributeFieldStruct struct = new AjAttributeFieldStruct(field, bField, type, context, msgHandler); -// Attribute[] attributes = field.getAttributes(); -// -// boolean hasAtAspectJAnnotation = false; -// for (int i = 0; i < attributes.length; i++) { -// Attribute attribute = attributes[i]; -// try { -// if (acceptAttribute(attribute)) { -// RuntimeAnnotations rvs = (RuntimeAnnotations) attribute; -// hasAtAspectJAnnotation = hasAtAspectJAnnotation || handleDeclareImplementsAnnotation( -// rvs, struct//, preResolvedPointcut//FIXME add in src layer -// ); -// } -// } catch (Exception e) { -// -// } -// } -// - return Collections.EMPTY_LIST;//struct.ajAttributes; + // Note: field annotation are for ITD and DEOW - processed at class level directly + return Collections.EMPTY_LIST; } /** diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 8f7e418a7..a53078312 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -235,7 +235,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { boolean satisfiedByITD = false; for (Iterator ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii.hasNext(); ) { ConcreteTypeMunger m = (ConcreteTypeMunger)ii.next(); - if (m.getMunger().getKind() == ResolvedTypeMunger.Method) {//FIXME AVITD was instanceof + if (m.getMunger().getKind() == ResolvedTypeMunger.Method) { ResolvedMember sig = m.getSignature(); if (!Modifier.isAbstract(sig.getModifiers())) { if (ResolvedType @@ -246,7 +246,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { } } } else if (m.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate) { - satisfiedByITD = true;//FIXME AVITD that should be enough, no need to check more + satisfiedByITD = true;//AV - that should be enough, no need to check more } } if (!satisfiedByITD) { @@ -973,65 +973,6 @@ public class BcelTypeMunger extends ConcreteTypeMunger { return true; } return false; -// else if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) { -// -// // This means the 'gen' should be the top most implementor -// // - if it is *not* then something went wrong after we worked -// // out that it was the top most implementor (see pr49657) -// if (!gen.getType().isTopmostImplementor(onType)) { -// ResolvedType rtx = gen.getType().getTopmostImplementor(onType); -// if (!rtx.isExposedToWeaver()) { -// ISourceLocation sLoc = munger.getSourceLocation(); -// weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error( -// WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR,rtx,getAspectType().getName()), -// (sLoc==null?getAspectType().getSourceLocation():sLoc))); -// } else { -// // XXX what does this state mean? -// // We have incorrectly identified what is the top most implementor and its not because -// // a type wasn't exposed to the weaver -// } -// return false; -// } else { -// -// 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 -// // interface, but the method itself we add to the interface must be public abstract -// mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT); -// } -// -// Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes()); -// Type returnType = BcelWorld.makeBcelType(mangledInterMethod.getReturnType()); -// -// InstructionList body = mg.getBody(); -// InstructionFactory fact = gen.getFactory(); -// int pos = 0; -// -// if (!mangledInterMethod.isStatic()) { -// body.append(InstructionFactory.createThis()); -// pos++; -// } -// for (int i = 0, len = paramTypes.length; i < len; i++) { -// Type paramType = paramTypes[i]; -// body.append(InstructionFactory.createLoad(paramType, pos)); -// pos+=paramType.getSize(); -// } -// body.append(Utility.createInvoke(fact, weaver.getWorld(), interMethodBody)); -// body.append(InstructionFactory.createReturn(returnType)); -// mg.definingType = onType; -// -// weaver.addOrReplaceLazyMethodGen(mg); -// -// addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled()); -// -// return true; -// } -// } else { -// return false; -// } } private ResolvedMember getRealMemberForITDFromAspect(ResolvedType aspectType,ResolvedMember lookingFor,boolean isCtorRelated) { -- cgit v1.2.3