From: aclement Date: Tue, 6 Jan 2009 23:53:58 +0000 (+0000) Subject: 164016, 258788: test and fix X-Git-Tag: pre268419~236 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=22bac4e4a64139cdaa200b45a59bdb05fece8a7f;p=aspectj.git 164016, 258788: test and fix --- diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/MethodDelegateTypeMunger.java b/org.aspectj.matcher/src/org/aspectj/weaver/MethodDelegateTypeMunger.java index 3ecac9882..a9d0982c0 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/MethodDelegateTypeMunger.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/MethodDelegateTypeMunger.java @@ -10,7 +10,6 @@ * Alexandre Vasseur initial implementation * ******************************************************************/ - package org.aspectj.weaver; import java.io.DataOutputStream; @@ -19,184 +18,201 @@ import java.io.IOException; import org.aspectj.weaver.patterns.TypePattern; /** - * 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. + * 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 { - private final UnresolvedType aspect; - - /** - * The mixin impl (no arg ctor) - */ - private final String implClassName; - - /** - * Type pattern this munger applies to - */ - private final TypePattern typePattern; - - /** - * Construct a new type munger for @AspectJ ITD - * - * @param signature - * @param aspect - * @param implClassName - * @param typePattern - */ - public MethodDelegateTypeMunger(ResolvedMember signature, UnresolvedType aspect, String implClassName, TypePattern typePattern) { - super(MethodDelegate, signature); - this.aspect = aspect; - this.typePattern = typePattern; - this.implClassName = implClassName; - } - - public boolean equals(Object other) { - if (!(other instanceof MethodDelegateTypeMunger)) return false; - MethodDelegateTypeMunger o = (MethodDelegateTypeMunger)other; - return ((o.aspect == null) ? (aspect == null ) : aspect.equals(o.aspect)) - && ((o.typePattern == null) ? (typePattern == null ) : typePattern.equals(o.typePattern)) - && ((o.implClassName == null) ? (implClassName == null) : implClassName.equals(o.implClassName)); - } - - private volatile int hashCode = 0; - public int hashCode() { - if (hashCode == 0) { - int result = 17; - result = 37*result + ((aspect == null) ? 0 : aspect.hashCode()); - result = 37*result + ((typePattern == null) ? 0 : typePattern.hashCode()); - result = 37*result + ((implClassName == null) ? 0 : implClassName.hashCode()); - hashCode = result; + private final UnresolvedType aspect; + + private UnresolvedType fieldType; + + /** + * The mixin impl (no arg ctor) + */ + private final String implClassName; + + /** + * Type pattern this munger applies to + */ + private final TypePattern typePattern; + + /** + * Construct a new type munger for @AspectJ ITD + * + * @param signature + * @param aspect + * @param implClassName + * @param typePattern + */ + public MethodDelegateTypeMunger(ResolvedMember signature, UnresolvedType aspect, String implClassName, TypePattern typePattern) { + super(MethodDelegate2, signature); + this.aspect = aspect; + this.typePattern = typePattern; + this.implClassName = implClassName; + } + + public boolean equals(Object other) { + if (!(other instanceof MethodDelegateTypeMunger)) + return false; + MethodDelegateTypeMunger o = (MethodDelegateTypeMunger) other; + return ((o.aspect == null) ? (aspect == null) : aspect.equals(o.aspect)) + && ((o.typePattern == null) ? (typePattern == null) : typePattern.equals(o.typePattern)) + && ((o.implClassName == null) ? (implClassName == null) : implClassName.equals(o.implClassName)) + && ((o.fieldType == null ? (fieldType == null) : fieldType.equals(o.fieldType))); + } + + private volatile int hashCode = 0; + + public int hashCode() { + if (hashCode == 0) { + int result = 17; + result = 37 * result + ((aspect == null) ? 0 : aspect.hashCode()); + result = 37 * result + ((typePattern == null) ? 0 : typePattern.hashCode()); + result = 37 * result + ((implClassName == null) ? 0 : implClassName.hashCode()); + result = 37 * result + ((fieldType == null) ? 0 : fieldType.hashCode()); + hashCode = result; + } + return hashCode; + } + + public ResolvedMember getDelegate(ResolvedType targetType) { + return AjcMemberMaker.itdAtDeclareParentsField(targetType, fieldType, aspect); + } + + public String getImplClassName() { + return implClassName; + } + + public void write(DataOutputStream s) throws IOException { + kind.write(s); + signature.write(s); + aspect.write(s); + s.writeUTF(implClassName); + typePattern.write(s); + fieldType.write(s); + } + + public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context, + boolean willFindFieldTypeInStream) throws IOException { + ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context); + UnresolvedType aspect = UnresolvedType.read(s); + String implClassName = s.readUTF(); + TypePattern tp = TypePattern.read(s, context); + MethodDelegateTypeMunger typeMunger = new MethodDelegateTypeMunger(signature, aspect, implClassName, tp); + UnresolvedType fieldType = null; + if (willFindFieldTypeInStream) { + fieldType = UnresolvedType.read(s); + } else { + fieldType = signature.getDeclaringType(); // a guess... that will work in a lot of cases + } + typeMunger.setFieldType(fieldType); + return typeMunger; + } + + /** + * 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()) { + return false; + } + + return typePattern.matchesStatically(matchType); + } + + /** + * Needed for reweavable + * + * @return true + */ + public boolean changesPublicSignature() { + return true; + } + + public static class FieldHostTypeMunger extends ResolvedTypeMunger { + + private UnresolvedType aspect; + + /** + * Type pattern this munger applies to + */ + private final TypePattern typePattern; + + /** + * Construct a new type munger for @AspectJ ITD + * + * @param field + * @param aspect + * @param typePattern + */ + public FieldHostTypeMunger(ResolvedMember field, UnresolvedType aspect, TypePattern typePattern) { + super(FieldHost, field); + this.aspect = aspect; + this.typePattern = typePattern; + } + + public boolean equals(Object other) { + if (!(other instanceof FieldHostTypeMunger)) + return false; + FieldHostTypeMunger o = (FieldHostTypeMunger) other; + return ((o.aspect == null) ? (aspect == null) : aspect.equals(o.aspect)) + && ((o.typePattern == null) ? (typePattern == null) : typePattern.equals(o.typePattern)); + } + + public int hashCode() { + int result = 17; + result = 37 * result + ((aspect == null) ? 0 : aspect.hashCode()); + result = 37 * result + ((typePattern == null) ? 0 : typePattern.hashCode()); + return result; } - return hashCode; - } - - public ResolvedMember getDelegate(ResolvedType targetType) { - return AjcMemberMaker.itdAtDeclareParentsField( - targetType, - signature.getDeclaringType(), - aspect - ); - } - - public String getImplClassName() { - return implClassName; - } - - public void write(DataOutputStream s) throws IOException { - kind.write(s); - signature.write(s); - aspect.write(s); - s.writeUTF(implClassName); - typePattern.write(s); - } - - public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException { - ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context); - UnresolvedType aspect = UnresolvedType.read(s); - String implClassName = s.readUTF(); - TypePattern tp = TypePattern.read(s, context); - return new MethodDelegateTypeMunger(signature, aspect, implClassName, tp); - } - - /** - * 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()) { - return false; - } - - return typePattern.matchesStatically(matchType); - } - - /** - * Needed for reweavable - * - * @return true - */ - public boolean changesPublicSignature() { - return true; - } - - public static class FieldHostTypeMunger extends ResolvedTypeMunger { - - private UnresolvedType aspect; - - /** - * Type pattern this munger applies to - */ - private final TypePattern typePattern; - - /** - * Construct a new type munger for @AspectJ ITD - * - * @param field - * @param aspect - * @param typePattern - */ - public FieldHostTypeMunger(ResolvedMember field, UnresolvedType aspect, TypePattern typePattern) { - super(FieldHost, field); - this.aspect = aspect; - this.typePattern = typePattern; - } - - public boolean equals(Object other) { - if (!(other instanceof FieldHostTypeMunger)) return false; - FieldHostTypeMunger o = (FieldHostTypeMunger)other; - return ((o.aspect == null) ? (aspect == null ) : aspect.equals(o.aspect)) - && ((o.typePattern == null) ? (typePattern == null ) : typePattern.equals(o.typePattern)); - } - - public int hashCode() { - int result = 17; - result = 37*result + ((aspect == null) ? 0 : aspect.hashCode()); - result = 37*result + ((typePattern == null) ? 0 : typePattern.hashCode()); - return result; - } - - public void write(DataOutputStream s) throws IOException { - kind.write(s); - signature.write(s); - aspect.write(s); - typePattern.write(s); - } - - public static ResolvedTypeMunger readFieldHost(VersionedDataInputStream s, ISourceContext context) throws IOException { - ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context); - UnresolvedType aspect = UnresolvedType.read(s); - TypePattern tp = TypePattern.read(s, context); - return new FieldHostTypeMunger(signature, aspect, tp); - } - - /** - * 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()) { - return false; - } - - return typePattern.matchesStatically(matchType); - } - - public boolean changesPublicSignature() { - return false; - } - - } + + public void write(DataOutputStream s) throws IOException { + kind.write(s); + signature.write(s); + aspect.write(s); + typePattern.write(s); + } + + public static ResolvedTypeMunger readFieldHost(VersionedDataInputStream s, ISourceContext context) throws IOException { + ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context); + UnresolvedType aspect = UnresolvedType.read(s); + TypePattern tp = TypePattern.read(s, context); + return new FieldHostTypeMunger(signature, aspect, tp); + } + + /** + * 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()) { + return false; + } + + return typePattern.matchesStatically(matchType); + } + + public boolean changesPublicSignature() { + return false; + } + + } + + public void setFieldType(UnresolvedType fieldType) { + this.fieldType = fieldType; + } } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java index eb7806026..e0c2e91ec 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java @@ -1195,7 +1195,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl for (Iterator iter = getInterTypeMungersIncludingSupers().iterator(); iter.hasNext();) { ConcreteTypeMunger munger = (ConcreteTypeMunger) iter.next(); if (munger.getSignature() != null && munger.getSignature().isAbstract()) { // Rule 1 - if (munger.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate) { + if (munger.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate2) { // ignore for @AJ ITD as munger.getSignature() is the // interface method hence abstract } else { diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java index 1a76644f9..b53268e00 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedTypeMunger.java @@ -147,9 +147,11 @@ public abstract class ResolvedTypeMunger { } else if (kind == Constructor) { return NewConstructorTypeMunger.readConstructor(s, context); } else if (kind == MethodDelegate) { - return MethodDelegateTypeMunger.readMethod(s, context); + return MethodDelegateTypeMunger.readMethod(s, context, false); } else if (kind == FieldHost) { return MethodDelegateTypeMunger.FieldHostTypeMunger.readFieldHost(s, context); + } else if (kind == MethodDelegate2) { + return MethodDelegateTypeMunger.readMethod(s, context, true); } else { throw new RuntimeException("unimplemented"); } @@ -256,6 +258,8 @@ public abstract class ResolvedTypeMunger { return MethodDelegate; case 10: return FieldHost; + case 11: + return MethodDelegate2; } throw new BCException("bad kind: " + key); } @@ -263,7 +267,7 @@ public abstract class ResolvedTypeMunger { public String toString() { // we want MethodDelegate to appear as Method in WeaveInfo messages // TODO we may want something for fieldhost ? - if (MethodDelegate.getName().equals(getName())) { + if (getName().startsWith(MethodDelegate.getName())) {// startsWith will cover MethodDelegate2 as well return Method.toString(); } else { return super.toString(); @@ -283,13 +287,15 @@ public abstract class ResolvedTypeMunger { public static final Kind Parent = new Kind("Parent", 6); public static final Kind PerTypeWithinInterface = new Kind("PerTypeWithinInterface", 7); // PTWIMPL not serialized, used during - // concretization of aspects + // concretization of aspects public static final Kind AnnotationOnType = new Kind("AnnotationOnType", 8); // not serialized public static final Kind MethodDelegate = new Kind("MethodDelegate", 9);// serialized, @AJ ITDs public static final Kind FieldHost = new Kind("FieldHost", 10);// serialized, @AJ ITDs + public static final Kind MethodDelegate2 = new Kind("MethodDelegate2", 11);// serialized, @AJ ITDs + public static final String SUPER_DISPATCH_NAME = "superDispatch"; public void setSuperMethodsCalled(Set c) {