From: aclement Date: Mon, 1 Sep 2008 04:58:43 +0000 (+0000) Subject: remove unused code X-Git-Tag: V1_6_2~124 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=df779877b56586c5a4e226ac8b73d70386bf5039;p=aspectj.git remove unused code --- diff --git a/weaver/src/org/aspectj/weaver/AnnotationX.java b/weaver/src/org/aspectj/weaver/AnnotationX.java index 5374d5d4a..a882ee5ff 100644 --- a/weaver/src/org/aspectj/weaver/AnnotationX.java +++ b/weaver/src/org/aspectj/weaver/AnnotationX.java @@ -23,197 +23,202 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen; import org.aspectj.apache.bcel.classfile.annotation.EnumElementValueGen; /** - * AnnotationX instances are holders for an annotation from either Bcel or - * eclipse. We have this holder so that types about the bcel weaver package - * can work with something not bytecode toolkit specific. + * AnnotationX instances are holders for an annotation from either Bcel or eclipse. We have this holder so that types about the bcel + * weaver package can work with something not bytecode toolkit specific. */ public class AnnotationX { - - public static final AnnotationX[] NONE = new AnnotationX[0]; - - private AnnotationGen theRealBcelAnnotation; - private AnnotationAJ theRealEclipseAnnotation; // OPTIMIZE push out into compiler, not ever used if purely binary weaving ? - private int mode = -1; - private final static int MODE_ECLIPSE = 1; - private final static int MODE_BCEL = 2; - - private ResolvedType signature = null; - - // @target meta-annotation related stuff, built lazily - private boolean lookedForAtTargetAnnotation = false; - private AnnotationX atTargetAnnotation = null; - private Set supportedTargets = null; - - public AnnotationX(AnnotationGen a,World world) { - theRealBcelAnnotation = a; - signature = UnresolvedType.forSignature(theRealBcelAnnotation.getTypeSignature()).resolve(world); - mode = MODE_BCEL; - } - - public AnnotationX(AnnotationAJ a,World world) { - theRealEclipseAnnotation = a; - signature = UnresolvedType.forSignature(theRealEclipseAnnotation.getTypeSignature()).resolve(world); - mode= MODE_ECLIPSE; - } - - public AnnotationGen getBcelAnnotation() { - return theRealBcelAnnotation; - } - - public UnresolvedType getSignature() { - return signature; - } - - public String toString() { - if (mode==MODE_BCEL) return theRealBcelAnnotation.toString(); - else return theRealEclipseAnnotation.toString(); - } - - - public String getTypeName() { - if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeName(); - else return Utility.signatureToString(theRealEclipseAnnotation.getTypeSignature()); - } - - public String getTypeSignature() { - if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeSignature(); - else return theRealEclipseAnnotation.getTypeSignature(); - } - - - // @target related helpers - /** - * return true if this annotation can target an annotation type - */ - public boolean allowedOnAnnotationType() { - ensureAtTargetInitialized(); - if (atTargetAnnotation == null) return true; // if no target specified, then return true - return supportedTargets.contains("ANNOTATION_TYPE"); - } - - /** - * return true if this annotation is marked with @target() - */ - public boolean specifiesTarget() { - ensureAtTargetInitialized(); - return atTargetAnnotation!=null; - } - - /** - * return true if this annotation can target a 'regular' type. - * A 'regular' type is enum/class/interface - it is *not* annotation. - */ - public boolean allowedOnRegularType() { - ensureAtTargetInitialized(); - if (atTargetAnnotation == null) return true; // if no target specified, then return true - return supportedTargets.contains("TYPE"); - } - - /** - * Use in messages about this annotation - */ - public String stringify() { - return signature.getName(); - } - - public String getValidTargets() { - StringBuffer sb = new StringBuffer(); - sb.append("{"); - for (Iterator iter = supportedTargets.iterator(); iter.hasNext();) { - String evalue = (String) iter.next(); - sb.append(evalue); - if (iter.hasNext()) sb.append(","); - } - sb.append("}"); - return sb.toString(); - } - - - - // privates - - /** - * Helper method to retrieve an annotation on an annotation e.g. - * retrieveAnnotationOnAnnotation(UnresolvedType.AT_TARGET) - */ - private AnnotationX retrieveAnnotationOnAnnotation(UnresolvedType requiredAnnotationSignature) { - AnnotationX[] annos = signature.getAnnotations(); - for (int i = 0; i < annos.length; i++) { - AnnotationX annotationX = annos[i]; - if (annotationX.getSignature().equals(requiredAnnotationSignature)) return annos[i]; - } - return null; - } - - /** - * Makes sure we have looked for the @target() annotation on this annotation. - * Calling this method initializes (and caches) the information for later use. - */ - private void ensureAtTargetInitialized() { - if (!lookedForAtTargetAnnotation) { - lookedForAtTargetAnnotation = true; - atTargetAnnotation = retrieveAnnotationOnAnnotation(UnresolvedType.AT_TARGET); - if (atTargetAnnotation != null) { - supportedTargets = atTargetAnnotation.getTargets(); - } - } - } - - /** - * For the @Target annotation, this will return a set of the elementtypes it can be applied to. - * For non @Target annotations, it returns null. - */ - public Set /* of String */ getTargets() { - if (!signature.equals(UnresolvedType.AT_TARGET)) return null; - Set supportedTargets = new HashSet(); - if (mode==MODE_BCEL) { - List values = getBcelAnnotation().getValues(); - ElementNameValuePairGen envp = (ElementNameValuePairGen)values.get(0); - ArrayElementValueGen aev = (ArrayElementValueGen)envp.getValue(); - ElementValueGen[] evs = aev.getElementValuesArray(); - for (int i = 0; i < evs.length; i++) { - EnumElementValueGen ev = (EnumElementValueGen)evs[i]; - supportedTargets.add(ev.getEnumValueString()); + + public static final AnnotationX[] NONE = new AnnotationX[0]; + + private AnnotationGen theRealBcelAnnotation; + private AnnotationAJ theRealEclipseAnnotation; // OPTIMIZE push out into compiler, not ever used if purely binary weaving ? + private int mode = -1; + private final static int MODE_ECLIPSE = 1; + private final static int MODE_BCEL = 2; + + private ResolvedType signature = null; + + // @target meta-annotation related stuff, built lazily + private boolean lookedForAtTargetAnnotation = false; + private AnnotationX atTargetAnnotation = null; + private Set supportedTargets = null; + + public AnnotationX(AnnotationGen a, World world) { + theRealBcelAnnotation = a; + signature = UnresolvedType.forSignature(theRealBcelAnnotation.getTypeSignature()).resolve(world); + mode = MODE_BCEL; + } + + public AnnotationX(AnnotationAJ a, World world) { + theRealEclipseAnnotation = a; + signature = UnresolvedType.forSignature(theRealEclipseAnnotation.getTypeSignature()).resolve(world); + mode = MODE_ECLIPSE; + } + + public AnnotationGen getBcelAnnotation() { + return theRealBcelAnnotation; + } + + public UnresolvedType getSignature() { + return signature; + } + + public String toString() { + if (mode == MODE_BCEL) + return theRealBcelAnnotation.toString(); + else + return theRealEclipseAnnotation.toString(); + } + + public String getTypeName() { + if (mode == MODE_BCEL) + return theRealBcelAnnotation.getTypeName(); + else + return Utility.signatureToString(theRealEclipseAnnotation.getTypeSignature()); + } + + public String getTypeSignature() { + if (mode == MODE_BCEL) + return theRealBcelAnnotation.getTypeSignature(); + else + return theRealEclipseAnnotation.getTypeSignature(); + } + + // @target related helpers + /** + * return true if this annotation can target an annotation type + */ + public boolean allowedOnAnnotationType() { + ensureAtTargetInitialized(); + if (atTargetAnnotation == null) + return true; // if no target specified, then return true + return supportedTargets.contains("ANNOTATION_TYPE"); + } + + /** + * return true if this annotation is marked with @target() + */ + public boolean specifiesTarget() { + ensureAtTargetInitialized(); + return atTargetAnnotation != null; + } + + /** + * return true if this annotation can target a 'regular' type. A 'regular' type is enum/class/interface - it is *not* + * annotation. + */ + public boolean allowedOnRegularType() { + ensureAtTargetInitialized(); + if (atTargetAnnotation == null) + return true; // if no target specified, then return true + return supportedTargets.contains("TYPE"); + } + + /** + * Use in messages about this annotation + */ + public String stringify() { + return signature.getName(); + } + + public String getValidTargets() { + StringBuffer sb = new StringBuffer(); + sb.append("{"); + for (Iterator iter = supportedTargets.iterator(); iter.hasNext();) { + String evalue = (String) iter.next(); + sb.append(evalue); + if (iter.hasNext()) + sb.append(","); + } + sb.append("}"); + return sb.toString(); + } + + // privates + + /** + * Helper method to retrieve an annotation on an annotation e.g. retrieveAnnotationOnAnnotation(UnresolvedType.AT_TARGET) + */ + private AnnotationX retrieveAnnotationOnAnnotation(UnresolvedType requiredAnnotationSignature) { + AnnotationX[] annos = signature.getAnnotations(); + for (int i = 0; i < annos.length; i++) { + AnnotationX annotationX = annos[i]; + if (annotationX.getSignature().equals(requiredAnnotationSignature)) + return annos[i]; + } + return null; + } + + /** + * Makes sure we have looked for the @target() annotation on this annotation. Calling this method initializes (and caches) the + * information for later use. + */ + private void ensureAtTargetInitialized() { + if (!lookedForAtTargetAnnotation) { + lookedForAtTargetAnnotation = true; + atTargetAnnotation = retrieveAnnotationOnAnnotation(UnresolvedType.AT_TARGET); + if (atTargetAnnotation != null) { + supportedTargets = atTargetAnnotation.getTargets(); + } + } + } + + /** + * For the @Target annotation, this will return a set of the elementtypes it can be applied to. For non @Target annotations, it + * returns null. + */ + public Set /* of String */getTargets() { + if (!signature.equals(UnresolvedType.AT_TARGET)) + return null; + Set supportedTargets = new HashSet(); + if (mode == MODE_BCEL) { + List values = getBcelAnnotation().getValues(); + ElementNameValuePairGen envp = (ElementNameValuePairGen) values.get(0); + ArrayElementValueGen aev = (ArrayElementValueGen) envp.getValue(); + ElementValueGen[] evs = aev.getElementValuesArray(); + for (int i = 0; i < evs.length; i++) { + EnumElementValueGen ev = (EnumElementValueGen) evs[i]; + supportedTargets.add(ev.getEnumValueString()); + } + } else { + List values = theRealEclipseAnnotation.getNameValuePairs(); + AnnotationNameValuePair nvp = (AnnotationNameValuePair) values.get(0); + ArrayAnnotationValue aav = (ArrayAnnotationValue) nvp.getValue(); + AnnotationValue[] avs = aav.getValues(); + for (int i = 0; i < avs.length; i++) { + AnnotationValue value = avs[i]; + supportedTargets.add(value.stringify()); + } } - } else { - List values = theRealEclipseAnnotation.getNameValuePairs(); - AnnotationNameValuePair nvp = (AnnotationNameValuePair)values.get(0); - ArrayAnnotationValue aav = (ArrayAnnotationValue)nvp.getValue(); - AnnotationValue[] avs = aav.getValues(); - for (int i = 0; i < avs.length; i++) { - AnnotationValue value = avs[i]; - supportedTargets.add(value.stringify()); - } - } - return supportedTargets; - } - - /** - * @return true if this annotation can be put on a field - */ - public boolean allowedOnField() { - ensureAtTargetInitialized(); - if (atTargetAnnotation == null) return true; // if no target specified, then return true - return supportedTargets.contains("FIELD"); - } - - public boolean isRuntimeVisible() { - return theRealBcelAnnotation.isRuntimeVisible(); - } - - public void print(StringBuffer sb) { - if (mode==MODE_BCEL) sb.append(theRealBcelAnnotation.toString()); - else sb.append(theRealEclipseAnnotation.stringify()); - } - - public boolean hasNameValuePair(String n, String v) { - if (mode==MODE_BCEL) return theRealBcelAnnotation.hasNameValuePair(n,v); - else return theRealEclipseAnnotation.hasNameValuePair(n,v); - } - - public boolean hasNamedValue(String n) { - if (mode==MODE_BCEL) return theRealBcelAnnotation.hasNamedValue(n); - else return theRealEclipseAnnotation.hasNamedValue(n); - } + return supportedTargets; + } + + /** + * @return true if this annotation can be put on a field + */ + public boolean allowedOnField() { + ensureAtTargetInitialized(); + if (atTargetAnnotation == null) + return true; // if no target specified, then return true + return supportedTargets.contains("FIELD"); + } + + public boolean isRuntimeVisible() { + return theRealBcelAnnotation.isRuntimeVisible(); + } + + public boolean hasNameValuePair(String n, String v) { + if (mode == MODE_BCEL) + return theRealBcelAnnotation.hasNameValuePair(n, v); + else + return theRealEclipseAnnotation.hasNameValuePair(n, v); + } + + public boolean hasNamedValue(String n) { + if (mode == MODE_BCEL) + return theRealBcelAnnotation.hasNamedValue(n); + else + return theRealEclipseAnnotation.hasNamedValue(n); + } } \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipUtils.java b/weaver/src/org/aspectj/weaver/AsmRelationshipUtils.java index e9a1bdbf6..722ddb09c 100644 --- a/weaver/src/org/aspectj/weaver/AsmRelationshipUtils.java +++ b/weaver/src/org/aspectj/weaver/AsmRelationshipUtils.java @@ -16,14 +16,12 @@ import org.aspectj.weaver.patterns.Pointcut; import org.aspectj.weaver.patterns.ReferencePointcut; /** - * Provides utility methods for generating details for IProgramElements - * used when creating the model both from source (via AsmElementFormatter.visit(..)) - * and when filling in the model for binary aspects (via AsmRelationshipProvider - * bug 145963) + * Provides utility methods for generating details for IProgramElements used when creating the model both from source (via + * AsmElementFormatter.visit(..)) and when filling in the model for binary aspects (via AsmRelationshipProvider bug 145963) */ public class AsmRelationshipUtils { - public static final String UNDEFINED=""; + // public static final String UNDEFINED=""; public static final String DECLARE_PRECEDENCE = "precedence"; public static final String DECLARE_SOFT = "soft"; public static final String DECLARE_PARENTS = "parents"; @@ -37,40 +35,38 @@ public class AsmRelationshipUtils { public static final String DEC_LABEL = "declare"; /** - * Generates the declare message used in the details, for example if - * the declare warning statement has message "There should be no printlns" - * will return 'declare warning: "There should be n.."' + * Generates the declare message used in the details, for example if the declare warning statement has message + * "There should be no printlns" will return 'declare warning: "There should be n.."' */ public static String genDeclareMessage(String message) { int length = message.length(); if (length < MAX_MESSAGE_LENGTH) { return message; } else { - return message.substring(0, MAX_MESSAGE_LENGTH-1) + DOUBLE_DOTS; + return message.substring(0, MAX_MESSAGE_LENGTH - 1) + DOUBLE_DOTS; } } /** - * Generates the pointcut details for the given pointcut, for example - * an anonymous pointcut will return '' and - * a named pointcut called p() will return 'p()..' + * Generates the pointcut details for the given pointcut, for example an anonymous pointcut will return '' + * and a named pointcut called p() will return 'p()..' */ public static String genPointcutDetails(Pointcut pcd) { StringBuffer details = new StringBuffer(); if (pcd instanceof ReferencePointcut) { - ReferencePointcut rp = (ReferencePointcut)pcd; + ReferencePointcut rp = (ReferencePointcut) pcd; details.append(rp.name).append(DOUBLE_DOTS); } else if (pcd instanceof AndPointcut) { - AndPointcut ap = (AndPointcut)pcd; + AndPointcut ap = (AndPointcut) pcd; if (ap.getLeft() instanceof ReferencePointcut) { - details.append(ap.getLeft().toString()).append(DOUBLE_DOTS); + details.append(ap.getLeft().toString()).append(DOUBLE_DOTS); } else { details.append(POINTCUT_ANONYMOUS).append(DOUBLE_DOTS); } } else if (pcd instanceof OrPointcut) { - OrPointcut op = (OrPointcut)pcd; + OrPointcut op = (OrPointcut) pcd; if (op.getLeft() instanceof ReferencePointcut) { - details.append(op.getLeft().toString()).append(DOUBLE_DOTS); + details.append(op.getLeft().toString()).append(DOUBLE_DOTS); } else { details.append(POINTCUT_ANONYMOUS).append(DOUBLE_DOTS); } @@ -79,6 +75,5 @@ public class AsmRelationshipUtils { } return details.toString(); } - - + } diff --git a/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java b/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java index 65a485e00..1a3fb248c 100644 --- a/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ConcreteTypeMunger.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver; import java.util.Map; @@ -27,19 +26,18 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab this.aspectType = aspectType; } - // An EclipseTypeMunger and a BcelTypeMunger may say TRUE for equivalentTo()... - public boolean equivalentTo(Object other) { - if (! (other instanceof ConcreteTypeMunger)) return false; - ConcreteTypeMunger o = (ConcreteTypeMunger) other; - return ((o.getMunger() == null) ? (getMunger() == null) : o.getMunger().equals(getMunger())) - && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType())); - } - - //public abstract boolean munge(LazyClassGen gen); + // An EclipseTypeMunger and a BcelTypeMunger may say TRUE for equivalentTo()... + // public boolean equivalentTo(Object other) { + // if (! (other instanceof ConcreteTypeMunger)) return false; + // ConcreteTypeMunger o = (ConcreteTypeMunger) other; + // return ((o.getMunger() == null) ? (getMunger() == null) : o.getMunger().equals(getMunger())) + // && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType())); + // } + // public abstract boolean munge(LazyClassGen gen); - /** returns null for mungers that are used internally, but were not part of a declared - * thing in source code. + /** + * returns null for mungers that are used internally, but were not part of a declared thing in source code. */ public ResolvedTypeMunger getMunger() { return munger; @@ -48,22 +46,24 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab public ResolvedType getAspectType() { return aspectType; } - + public ResolvedMember getSignature() { return munger.getSignature(); } - + public World getWorld() { return aspectType.getWorld(); } - + public ISourceLocation getSourceLocation() { - if (munger == null) return null; - return munger.getSourceLocation(); //XXX + if (munger == null) + return null; + return munger.getSourceLocation(); // XXX } public boolean matches(ResolvedType onType) { - if (munger == null) throw new RuntimeException("huh: " + this); + if (munger == null) + throw new RuntimeException("huh: " + this); return munger.matches(onType, aspectType); } @@ -75,9 +75,9 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab ConcreteTypeMunger o = (ConcreteTypeMunger) other; ResolvedType otherAspect = o.aspectType; - + if (aspectType.equals(otherAspect)) { - return getSignature().getStart() < o.getSignature().getStart() ? -1: +1; + return getSignature().getStart() < o.getSignature().getStart() ? -1 : +1; } else if (aspectType.isAssignableFrom(o.aspectType)) { return +1; } else if (o.aspectType.isAssignableFrom(aspectType)) { @@ -88,41 +88,38 @@ public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparab } public int fallbackCompareTo(Object other) { -// ConcreteTypeMunger o = (ConcreteTypeMunger) other; + // ConcreteTypeMunger o = (ConcreteTypeMunger) other; return 0; } - + /** - * returns true if the ITD target type used type variables, for example I. - * When they are specified like this, the ITDs 'share' type variables with - * the generic type. Usually this method is called because we need to know - * whether to tailor the munger for addition to a particular type. For example: - * + * returns true if the ITD target type used type variables, for example I. When they are specified like this, the ITDs + * 'share' type variables with the generic type. Usually this method is called because we need to know whether to tailor the + * munger for addition to a particular type. For example: * interface I {} * * aspect X implements I { * List I.foo { return null; } * } - * - * In this case the munger matches X but it matches with the form - * + * In this case the munger matches X but it matches with the form * List foo() { return null; } * */ public boolean isTargetTypeParameterized() { - if (munger==null) return false; + if (munger == null) + return false; return munger.sharesTypeVariablesWithGenericType(); } - /** - * For an ITD made on a generic type that shares type variables with - * that target type, this method will tailor the ITD for a particular usage - * of the generic type - either in its raw or parameterized form. - */ + /** + * For an ITD made on a generic type that shares type variables with that target type, this method will tailor the ITD for a + * particular usage of the generic type - either in its raw or parameterized form. + */ public abstract ConcreteTypeMunger parameterizedFor(ResolvedType targetType); - + public boolean isLateMunger() { - if (munger==null) return false; + if (munger == null) + return false; return munger.isLateMunger(); } diff --git a/weaver/src/org/aspectj/weaver/JoinPointSignature.java b/weaver/src/org/aspectj/weaver/JoinPointSignature.java index 6b0a368b6..af4538369 100644 --- a/weaver/src/org/aspectj/weaver/JoinPointSignature.java +++ b/weaver/src/org/aspectj/weaver/JoinPointSignature.java @@ -22,31 +22,26 @@ import org.aspectj.bridge.ISourceLocation; import org.aspectj.weaver.AjAttribute.EffectiveSignatureAttribute; /** - * @author colyer - * Instances of this class are created by ResolvedMember.getSignatures() when collating - * all of the signatures for a member. We need to create entries in the set for the "gaps" - * in the hierarchy. For example: + * @author colyer Instances of this class are created by ResolvedMember.getSignatures() when collating all of the signatures for a + * member. We need to create entries in the set for the "gaps" in the hierarchy. For example: * - * class A { - * void foo(); - * } + * class A { void foo(); } * - * class B extends A {} + * class B extends A {} * - * Join Point : call(* B.foo()) + * Join Point : call(* B.foo()) * - * has signatures: + * has signatures: * - * B.foo() AND A.foo() - * B.foo() will be created as a ResolvedMemberWithSubstituteDeclaringType + * B.foo() AND A.foo() B.foo() will be created as a ResolvedMemberWithSubstituteDeclaringType * - * Oh for a JDK 1.4 dynamic proxy.... we have to run on 1.3 :( + * Oh for a JDK 1.4 dynamic proxy.... we have to run on 1.3 :( */ public class JoinPointSignature implements ResolvedMember { private ResolvedMember realMember; - private ResolvedType substituteDeclaringType; - + private ResolvedType substituteDeclaringType; + public JoinPointSignature(ResolvedMember backing, ResolvedType aType) { this.realMember = backing; this.substituteDeclaringType = aType; @@ -91,7 +86,7 @@ public class JoinPointSignature implements ResolvedMember { public ResolvedType[] getAnnotationTypes() { return realMember.getAnnotationTypes(); } - + public AnnotationX getAnnotationOfType(UnresolvedType ofType) { return realMember.getAnnotationOfType(ofType); } @@ -127,7 +122,7 @@ public class JoinPointSignature implements ResolvedMember { public String[] getParameterNames() { return realMember.getParameterNames(); } - + public void setParameterNames(String[] names) { realMember.setParameterNames(names); } @@ -157,7 +152,7 @@ public class JoinPointSignature implements ResolvedMember { } public void setPosition(int sourceStart, int sourceEnd) { - realMember.setPosition(sourceStart,sourceEnd); + realMember.setPosition(sourceStart, sourceEnd); } public void setSourceContext(ISourceContext sourceContext) { @@ -208,12 +203,14 @@ public class JoinPointSignature implements ResolvedMember { return realMember.getGenericParameterTypes(); } - public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, boolean isParameterized) { + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized) { return realMember.parameterizedWith(typeParameters, newDeclaringType, isParameterized); } - - public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, boolean isParameterized,List aliases) { - return realMember.parameterizedWith(typeParameters, newDeclaringType, isParameterized,aliases); + + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized, List aliases) { + return realMember.parameterizedWith(typeParameters, newDeclaringType, isParameterized, aliases); } public void setTypeVariables(TypeVariable[] types) { @@ -223,15 +220,11 @@ public class JoinPointSignature implements ResolvedMember { public TypeVariable[] getTypeVariables() { return realMember.getTypeVariables(); } - + public TypeVariable getTypeVariableNamed(String name) { return realMember.getTypeVariableNamed(name); } - public ResolvedMember getErasure() { - throw new UnsupportedOperationException("Adrian doesn't think you should be asking for the erasure of one of these..."); - } - public boolean matches(ResolvedMember aCandidateMatch) { return realMember.matches(aCandidateMatch); } @@ -263,11 +256,11 @@ public class JoinPointSignature implements ResolvedMember { public UnresolvedType[] getParameterTypes() { return realMember.getParameterTypes(); } - + public AnnotationX[][] getParameterAnnotations() { return realMember.getParameterAnnotations(); } - + public ResolvedType[][] getParameterAnnotationTypes() { return realMember.getParameterAnnotationTypes(); } @@ -315,61 +308,64 @@ public class JoinPointSignature implements ResolvedMember { public Iterator getJoinPointSignatures(World world) { return realMember.getJoinPointSignatures(world); } - - public String toString() { - StringBuffer buf = new StringBuffer(); - buf.append(getReturnType().getName()); - buf.append(' '); - buf.append(getDeclaringType().getName()); - buf.append('.'); - buf.append(getName()); - if (getKind() != FIELD) { - buf.append("("); - UnresolvedType[] parameterTypes = getParameterTypes(); - if (parameterTypes.length != 0) { - buf.append(parameterTypes[0]); - for (int i=1, len = parameterTypes.length; i < len; i++) { - buf.append(", "); - buf.append(parameterTypes[i].getName()); - } - } - buf.append(")"); - } - return buf.toString(); - } - - public String toGenericString() { - return realMember.toGenericString(); - } - - public String toDebugString() { - return realMember.toDebugString(); - } - - public void resetName(String newName) { - realMember.resetName(newName); - } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(getReturnType().getName()); + buf.append(' '); + buf.append(getDeclaringType().getName()); + buf.append('.'); + buf.append(getName()); + if (getKind() != FIELD) { + buf.append("("); + UnresolvedType[] parameterTypes = getParameterTypes(); + if (parameterTypes.length != 0) { + buf.append(parameterTypes[0]); + for (int i = 1, len = parameterTypes.length; i < len; i++) { + buf.append(", "); + buf.append(parameterTypes[i].getName()); + } + } + buf.append(")"); + } + return buf.toString(); + } + + public String toGenericString() { + return realMember.toGenericString(); + } + + public String toDebugString() { + return realMember.toDebugString(); + } + + public void resetName(String newName) { + realMember.resetName(newName); + } public void resetKind(MemberKind newKind) { realMember.resetKind(newKind); } - + public void resetModifiers(int newModifiers) { realMember.resetModifiers(newModifiers); } - + public void resetReturnTypeToObjectArray() { realMember.resetReturnTypeToObjectArray(); } public boolean equals(Object obj) { - if (! (obj instanceof JoinPointSignature)) return false; + if (!(obj instanceof JoinPointSignature)) + return false; JoinPointSignature other = (JoinPointSignature) obj; - if (!realMember.equals(other.realMember)) return false; - if (!substituteDeclaringType.equals(other.substituteDeclaringType)) return false; + if (!realMember.equals(other.realMember)) + return false; + if (!substituteDeclaringType.equals(other.substituteDeclaringType)) + return false; return true; } - + public int hashCode() { return 17 + (37 * realMember.hashCode()) + (37 * substituteDeclaringType.hashCode()); } @@ -382,10 +378,12 @@ public class JoinPointSignature implements ResolvedMember { return realMember.getBackingGenericMember(); } - public void evictWeavingState() { realMember.evictWeavingState(); } + public void evictWeavingState() { + realMember.evictWeavingState(); + } public ResolvedMember parameterizedWith(Map m, World w) { - return realMember.parameterizedWith(m,w); + return realMember.parameterizedWith(m, w); } public String getAnnotationDefaultValue() { diff --git a/weaver/src/org/aspectj/weaver/ReferenceType.java b/weaver/src/org/aspectj/weaver/ReferenceType.java index 86f9c792d..e587294d2 100644 --- a/weaver/src/org/aspectj/weaver/ReferenceType.java +++ b/weaver/src/org/aspectj/weaver/ReferenceType.java @@ -46,12 +46,6 @@ public class ReferenceType extends ResolvedType { int startPos = 0; int endPos = 0; - public static ReferenceType fromTypeX(UnresolvedType tx, World world) { - ReferenceType rt = new ReferenceType(tx.getErasureSignature(), world); - rt.typeKind = tx.typeKind; - return rt; - } - // cached values for members ResolvedMember[] parameterizedMethods = null; ResolvedMember[] parameterizedFields = null; @@ -69,6 +63,12 @@ public class ReferenceType extends ResolvedType { super(signature, signatureErasure, world); } + public static ReferenceType fromTypeX(UnresolvedType tx, World world) { + ReferenceType rt = new ReferenceType(tx.getErasureSignature(), world); + rt.typeKind = tx.typeKind; + return rt; + } + /** * Constructor used when creating a parameterized type. */ @@ -472,7 +472,6 @@ public class ReferenceType extends ResolvedType { // if (position == -1 ) return null; // return paramTypes[position]; // } - /** * It is possible this type has multiple type variables but the interface we are about to parameterize only uses a subset - this * method determines the subset to use by looking at the type variable names used. For example: @@ -753,10 +752,9 @@ public class ReferenceType extends ResolvedType { */ private static String makeParameterizedSignature(ResolvedType aGenericType, ResolvedType[] someParameters) { String rawSignature = aGenericType.getErasureSignature(); - String prefix = PARAMETERIZED_TYPE_IDENTIFIER + rawSignature.substring(1, rawSignature.length() - 1); - StringBuffer ret = new StringBuffer(); - ret.append(prefix); + ret.append(PARAMETERIZED_TYPE_IDENTIFIER); + ret.append(rawSignature.substring(1, rawSignature.length() - 1)); ret.append("<"); for (int i = 0; i < someParameters.length; i++) { ret.append(someParameters[i].getSignature()); diff --git a/weaver/src/org/aspectj/weaver/ResolvedMember.java b/weaver/src/org/aspectj/weaver/ResolvedMember.java index d987dad01..2b7ab4e43 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMember.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMember.java @@ -33,17 +33,17 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe public UnresolvedType[] getExceptions(); public ShadowMunger getAssociatedShadowMunger(); - + public boolean isAjSynthetic(); public boolean isCompatibleWith(Member am); - + public boolean hasAnnotations(); public boolean hasAnnotation(UnresolvedType ofType); public AnnotationX[] getAnnotations(); - + public ResolvedType[] getAnnotationTypes(); public void setAnnotationTypes(UnresolvedType[] annotationtypes); @@ -61,14 +61,19 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe public ISourceContext getSourceContext(World world); public String[] getParameterNames(); + public void setParameterNames(String[] names); public AnnotationX[][] getParameterAnnotations(); + public ResolvedType[][] getParameterAnnotationTypes(); + public String getAnnotationDefaultValue(); + public String getParameterSignatureErased(); + public String getSignatureErased(); - + public String[] getParameterNames(World world); public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature(); @@ -102,14 +107,14 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe public void setAnnotatedElsewhere(boolean b); public boolean isAnnotatedElsewhere(); - + // like toString but include generic signature info public String toGenericString(); - + public String toDebugString(); - public boolean hasBackingGenericMember(); + public ResolvedMember getBackingGenericMember(); /** @@ -125,49 +130,49 @@ public interface ResolvedMember extends Member, AnnotatedElement, TypeVariableDe // return a resolved member in which all type variables in the signature of this // member have been replaced with the given bindings. // the isParameterized flag tells us whether we are creating a raw type version or not - // if isParameterized List will turn into List (for example), + // if isParameterized List will turn into List (for example), // but if !isParameterized List will turn into List. - public ResolvedMemberImpl parameterizedWith( - UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, boolean isParameterized); - // this variant allows for aliases for type variables (i.e. allowing them to have another name) - // this is used for processing ITDs that share type variables with their target generic type - public ResolvedMemberImpl parameterizedWith( - UnresolvedType[] typeParameters, ResolvedType newDeclaringType, - boolean isParameterized,List aliases); + // this variant allows for aliases for type variables (i.e. allowing them to have another name) + // this is used for processing ITDs that share type variables with their target generic type + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized, List aliases); public void setTypeVariables(TypeVariable[] types); public TypeVariable[] getTypeVariables(); - /** - * If this member is defined by a parameterized super-type, return the erasure - * of that member. - * For example: - * interface I { T foo(T aTea); } - * class C implements I { - * String foo(String aString) { return "something"; } - * } - * The resolved member for C.foo has signature String foo(String). The - * erasure of that member is Object foo(Object) -- use upper bound of type - * variable. - * A type is a supertype of itself. - */ - public ResolvedMember getErasure(); + // /** + // * If this member is defined by a parameterized super-type, return the erasure + // * of that member. + // * For example: + // * interface I { T foo(T aTea); } + // * class C implements I { + // * String foo(String aString) { return "something"; } + // * } + // * The resolved member for C.foo has signature String foo(String). The + // * erasure of that member is Object foo(Object) -- use upper bound of type + // * variable. + // * A type is a supertype of itself. + // */ + // public ResolvedMember getErasure(); /** - * Returns true if this member matches the other. The matching takes into account - * name and parameter types only. When comparing parameter types, we allow any type - * variable to match any other type variable regardless of bounds. + * Returns true if this member matches the other. The matching takes into account name and parameter types only. When comparing + * parameter types, we allow any type variable to match any other type variable regardless of bounds. */ public boolean matches(ResolvedMember aCandidateMatch); - + public void resetName(String newName); + public void resetKind(MemberKind newKind); - public void resetModifiers(int newModifiers); - public void resetReturnTypeToObjectArray(); - + + public void resetModifiers(int newModifiers); + + public void resetReturnTypeToObjectArray(); + public void evictWeavingState(); public ResolvedMember parameterizedWith(Map m, World w); diff --git a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java index a239ba534..60577604a 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMemberImpl.java @@ -10,14 +10,12 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver; import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -28,361 +26,337 @@ import java.util.Set; import org.aspectj.bridge.ISourceLocation; /** - * This is the declared member, i.e. it will always correspond to an - * actual method/... declaration + * This is the declared member, i.e. it will always correspond to an actual method/... declaration */ -public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, AnnotatedElement, TypeVariableDeclaringElement, ResolvedMember { - - private String[] parameterNames = null; - protected UnresolvedType[] checkedExceptions = UnresolvedType.NONE; - /** - * if this member is a parameterized version of a member in a generic type, - * then this field holds a reference to the member we parameterize. - */ - protected ResolvedMember backingGenericMember = null; - - protected Set annotationTypes = null; - protected ResolvedType[][] parameterAnnotationTypes = null; - - // Some members are 'created' to represent other things (for example ITDs). These +public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, AnnotatedElement, TypeVariableDeclaringElement, + ResolvedMember { + + private String[] parameterNames = null; + protected UnresolvedType[] checkedExceptions = UnresolvedType.NONE; + /** + * if this member is a parameterized version of a member in a generic type, then this field holds a reference to the member we + * parameterize. + */ + protected ResolvedMember backingGenericMember = null; + + protected Set annotationTypes = null; + protected ResolvedType[][] parameterAnnotationTypes = null; + + // Some members are 'created' to represent other things (for example ITDs). These // members have their annotations stored elsewhere, and this flag indicates that is - // the case. It is up to the caller to work out where that is! + // the case. It is up to the caller to work out where that is! // Once determined the caller may choose to stash the annotations in this member... private boolean isAnnotatedElsewhere = false; // this field is not serialized. private boolean isAjSynthetic = false; - - // generic methods have type variables + + // generic methods have type variables protected TypeVariable[] typeVariables; - - // these three fields hold the source location of this member + + // these three fields hold the source location of this member protected int start, end; protected ISourceContext sourceContext = null; - - //XXX deprecate this in favor of the constructor below - public ResolvedMemberImpl( - MemberKind kind, - UnresolvedType declaringType, - int modifiers, - UnresolvedType returnType, - String name, - UnresolvedType[] parameterTypes) - { + + // XXX deprecate this in favor of the constructor below + public ResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, UnresolvedType returnType, String name, + UnresolvedType[] parameterTypes) { super(kind, declaringType, modifiers, returnType, name, parameterTypes); } - - - public ResolvedMemberImpl( - MemberKind kind, - UnresolvedType declaringType, - int modifiers, - UnresolvedType returnType, - String name, - UnresolvedType[] parameterTypes, - UnresolvedType[] checkedExceptions) - { + public ResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, UnresolvedType returnType, String name, + UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions) { super(kind, declaringType, modifiers, returnType, name, parameterTypes); this.checkedExceptions = checkedExceptions; } - - public ResolvedMemberImpl( - MemberKind kind, - UnresolvedType declaringType, - int modifiers, - UnresolvedType returnType, - String name, - UnresolvedType[] parameterTypes, - UnresolvedType[] checkedExceptions, - ResolvedMember backingGenericMember) - { - this(kind, declaringType, modifiers, returnType, name, parameterTypes,checkedExceptions); - this.backingGenericMember = backingGenericMember; - this.isAjSynthetic = backingGenericMember.isAjSynthetic(); - } - - public ResolvedMemberImpl( - MemberKind kind, - UnresolvedType declaringType, - int modifiers, - String name, - String signature) - { + + public ResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, UnresolvedType returnType, String name, + UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions, ResolvedMember backingGenericMember) { + this(kind, declaringType, modifiers, returnType, name, parameterTypes, checkedExceptions); + this.backingGenericMember = backingGenericMember; + this.isAjSynthetic = backingGenericMember.isAjSynthetic(); + } + + public ResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, String name, String signature) { super(kind, declaringType, modifiers, name, signature); - } - - /** - * Compute the full set of signatures for a member. This walks up the hierarchy - * giving the ResolvedMember in each defining type in the hierarchy. A shadowMember - * can be created with a target type (declaring type) that does not actually define - * the member. This is ok as long as the member is inherited in the declaring type. - * Each declaring type in the line to the actual declaring type is added as an additional - * signature. For example: - * - * class A { void foo(); } - * class B extends A {} - * - * shadowMember : void B.foo() - * - * gives { void B.foo(), void A.foo() } - * @param joinPointSignature - * @param inAWorld - */ - public static JoinPointSignature[] getJoinPointSignatures(Member joinPointSignature, World inAWorld) { - - // Walk up hierarchy creating one member for each type up to and including the - // first defining type - ResolvedType originalDeclaringType = joinPointSignature.getDeclaringType().resolve(inAWorld); - ResolvedMemberImpl firstDefiningMember = (ResolvedMemberImpl) joinPointSignature.resolve(inAWorld); - if (firstDefiningMember == null) { - return new JoinPointSignature[0]; - } - // declaringType can be unresolved if we matched a synthetic member generated by Aj... - // should be fixed elsewhere but add this resolve call on the end for now so that we can - // focus on one problem at a time... - ResolvedType firstDefiningType = firstDefiningMember.getDeclaringType().resolve(inAWorld); - if (firstDefiningType != originalDeclaringType) { - if (joinPointSignature.getKind() == Member.CONSTRUCTOR) { - return new JoinPointSignature[0]; - } -// else if (shadowMember.isStatic()) { -// return new ResolvedMember[] {firstDefiningMember}; -// } - } - - List declaringTypes = new ArrayList(); - accumulateTypesInBetween(originalDeclaringType, - firstDefiningType, - declaringTypes); - Set memberSignatures = new HashSet(); - for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { + } + + /** + * Compute the full set of signatures for a member. This walks up the hierarchy giving the ResolvedMember in each defining type + * in the hierarchy. A shadowMember can be created with a target type (declaring type) that does not actually define the member. + * This is ok as long as the member is inherited in the declaring type. Each declaring type in the line to the actual declaring + * type is added as an additional signature. For example: + * + * class A { void foo(); } class B extends A {} + * + * shadowMember : void B.foo() + * + * gives { void B.foo(), void A.foo() } + * + * @param joinPointSignature + * @param inAWorld + */ + public static JoinPointSignature[] getJoinPointSignatures(Member joinPointSignature, World inAWorld) { + + // Walk up hierarchy creating one member for each type up to and including the + // first defining type + ResolvedType originalDeclaringType = joinPointSignature.getDeclaringType().resolve(inAWorld); + ResolvedMemberImpl firstDefiningMember = (ResolvedMemberImpl) joinPointSignature.resolve(inAWorld); + if (firstDefiningMember == null) { + return new JoinPointSignature[0]; + } + // declaringType can be unresolved if we matched a synthetic member generated by Aj... + // should be fixed elsewhere but add this resolve call on the end for now so that we can + // focus on one problem at a time... + ResolvedType firstDefiningType = firstDefiningMember.getDeclaringType().resolve(inAWorld); + if (firstDefiningType != originalDeclaringType) { + if (joinPointSignature.getKind() == Member.CONSTRUCTOR) { + return new JoinPointSignature[0]; + } + // else if (shadowMember.isStatic()) { + // return new ResolvedMember[] {firstDefiningMember}; + // } + } + + List declaringTypes = new ArrayList(); + accumulateTypesInBetween(originalDeclaringType, firstDefiningType, declaringTypes); + Set memberSignatures = new HashSet(); + for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { ResolvedType declaringType = (ResolvedType) iter.next(); ResolvedMember member = firstDefiningMember.withSubstituteDeclaringType(declaringType); memberSignatures.add(member); } - if (shouldWalkUpHierarchyFor(firstDefiningMember)) { - // now walk up the hierarchy from the firstDefiningMember and include the signature for - // every type between the firstDefiningMember and the root defining member. - Iterator superTypeIterator = firstDefiningType.getDirectSupertypes(); - List typesAlreadyVisited = new ArrayList(); - accumulateMembersMatching(firstDefiningMember,superTypeIterator,typesAlreadyVisited,memberSignatures); - } - - JoinPointSignature[] ret = new JoinPointSignature[memberSignatures.size()]; - memberSignatures.toArray(ret); - return ret; - } - - private static boolean shouldWalkUpHierarchyFor(Member aMember) { - if (aMember.getKind() == Member.CONSTRUCTOR) return false; - if (aMember.getKind() == Member.FIELD) return false; - if (aMember.isStatic()) return false; - return true; - } - - /** - * Build a list containing every type between subtype and supertype, inclusively. - */ - private static void accumulateTypesInBetween(ResolvedType subType, ResolvedType superType, List types) { - types.add(subType); - if (subType == superType) { - return; - } else { - for (Iterator iter = subType.getDirectSupertypes(); iter.hasNext();) { + if (shouldWalkUpHierarchyFor(firstDefiningMember)) { + // now walk up the hierarchy from the firstDefiningMember and include the signature for + // every type between the firstDefiningMember and the root defining member. + Iterator superTypeIterator = firstDefiningType.getDirectSupertypes(); + List typesAlreadyVisited = new ArrayList(); + accumulateMembersMatching(firstDefiningMember, superTypeIterator, typesAlreadyVisited, memberSignatures); + } + + JoinPointSignature[] ret = new JoinPointSignature[memberSignatures.size()]; + memberSignatures.toArray(ret); + return ret; + } + + private static boolean shouldWalkUpHierarchyFor(Member aMember) { + if (aMember.getKind() == Member.CONSTRUCTOR) + return false; + if (aMember.getKind() == Member.FIELD) + return false; + if (aMember.isStatic()) + return false; + return true; + } + + /** + * Build a list containing every type between subtype and supertype, inclusively. + */ + private static void accumulateTypesInBetween(ResolvedType subType, ResolvedType superType, List types) { + types.add(subType); + if (subType == superType) { + return; + } else { + for (Iterator iter = subType.getDirectSupertypes(); iter.hasNext();) { ResolvedType parent = (ResolvedType) iter.next(); if (superType.isAssignableFrom(parent)) { - accumulateTypesInBetween(parent, superType,types); + accumulateTypesInBetween(parent, superType, types); } } - } - } - - /** - * We have a resolved member, possibly with type parameter references as parameters or return - * type. We need to find all its ancestor members. When doing this, a type parameter matches - * regardless of bounds (bounds can be narrowed down the hierarchy). - */ - private static void accumulateMembersMatching( - ResolvedMemberImpl memberToMatch, - Iterator typesToLookIn, - List typesAlreadyVisited, - Set foundMembers) { - while(typesToLookIn.hasNext()) { - ResolvedType toLookIn = (ResolvedType) typesToLookIn.next(); + } + } + + /** + * We have a resolved member, possibly with type parameter references as parameters or return type. We need to find all its + * ancestor members. When doing this, a type parameter matches regardless of bounds (bounds can be narrowed down the hierarchy). + */ + private static void accumulateMembersMatching(ResolvedMemberImpl memberToMatch, Iterator typesToLookIn, + List typesAlreadyVisited, Set foundMembers) { + while (typesToLookIn.hasNext()) { + ResolvedType toLookIn = (ResolvedType) typesToLookIn.next(); if (!typesAlreadyVisited.contains(toLookIn)) { typesAlreadyVisited.add(toLookIn); - ResolvedMemberImpl foundMember = (ResolvedMemberImpl) toLookIn.lookupResolvedMember(memberToMatch,true); - if (foundMember != null && isVisibleTo(memberToMatch,foundMember)) { + ResolvedMemberImpl foundMember = (ResolvedMemberImpl) toLookIn.lookupResolvedMember(memberToMatch, true); + if (foundMember != null && isVisibleTo(memberToMatch, foundMember)) { List declaringTypes = new ArrayList(); // declaring type can be unresolved if the member can from an ITD... ResolvedType resolvedDeclaringType = foundMember.getDeclaringType().resolve(toLookIn.getWorld()); accumulateTypesInBetween(toLookIn, resolvedDeclaringType, declaringTypes); - for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { + for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { ResolvedType declaringType = (ResolvedType) iter.next(); -// typesAlreadyVisited.add(declaringType); + // typesAlreadyVisited.add(declaringType); ResolvedMember member = foundMember.withSubstituteDeclaringType(declaringType); foundMembers.add(member); - } + } if (toLookIn.isParameterizedType() && (foundMember.backingGenericMember != null)) { - foundMembers.add(new JoinPointSignature(foundMember.backingGenericMember,foundMember.declaringType.resolve(toLookIn.getWorld()))); + foundMembers.add(new JoinPointSignature(foundMember.backingGenericMember, foundMember.declaringType + .resolve(toLookIn.getWorld()))); } - accumulateMembersMatching(foundMember,toLookIn.getDirectSupertypes(),typesAlreadyVisited,foundMembers); + accumulateMembersMatching(foundMember, toLookIn.getDirectSupertypes(), typesAlreadyVisited, foundMembers); // if this was a parameterized type, look in the generic type that backs it too - } + } } } - } - - /** - * Returns true if the parent member is visible to the child member - * In the same declaring type this is always true, otherwise if parent is private - * it is false. - * @param childMember - * @param parentMember - * @return - */ - private static boolean isVisibleTo(ResolvedMember childMember, ResolvedMember parentMember) { - if (childMember.getDeclaringType().equals(parentMember.getDeclaringType())) return true; - if (Modifier.isPrivate(parentMember.getModifiers())) { - return false; - } else { - return true; - } - } - - // ---- - - public final int getModifiers(World world) { - return modifiers; - } - public final int getModifiers() { - return modifiers; - } + } + + /** + * Returns true if the parent member is visible to the child member In the same declaring type this is always true, otherwise if + * parent is private it is false. + * + * @param childMember + * @param parentMember + * @return + */ + private static boolean isVisibleTo(ResolvedMember childMember, ResolvedMember parentMember) { + if (childMember.getDeclaringType().equals(parentMember.getDeclaringType())) + return true; + if (Modifier.isPrivate(parentMember.getModifiers())) { + return false; + } else { + return true; + } + } // ---- - - - public final UnresolvedType[] getExceptions(World world) { - return getExceptions(); - } - - public UnresolvedType[] getExceptions() { - return checkedExceptions; - } - - public ShadowMunger getAssociatedShadowMunger() { + + public final int getModifiers(World world) { + return modifiers; + } + + public final int getModifiers() { + return modifiers; + } + + // ---- + + public final UnresolvedType[] getExceptions(World world) { + return getExceptions(); + } + + public UnresolvedType[] getExceptions() { + return checkedExceptions; + } + + public ShadowMunger getAssociatedShadowMunger() { return null; - } - - // ??? true or false? - public boolean isAjSynthetic() { - return isAjSynthetic; - } - - protected void setAjSynthetic(boolean b) {isAjSynthetic= b;} - + } + + // ??? true or false? + public boolean isAjSynthetic() { + return isAjSynthetic; + } + + protected void setAjSynthetic(boolean b) { + isAjSynthetic = b; + } + public boolean hasAnnotations() { - return (annotationTypes!=null); + return (annotationTypes != null); } /** - * Check if this member has an annotation of the specified type. If the member has a backing generic - * member then this member represents a parameterization of a member in a generic type and the annotations - * available on the backing generic member should be used. + * Check if this member has an annotation of the specified type. If the member has a backing generic member then this member + * represents a parameterization of a member in a generic type and the annotations available on the backing generic member + * should be used. * * @param ofType the type of the annotation being searched for * @return true if the annotation is found on this member or its backing generic member */ - public boolean hasAnnotation(UnresolvedType ofType) { - // The ctors don't allow annotations to be specified ... yet - but - // that doesn't mean it is an error to call this method. - // Normally the weaver will be working with subtypes of - // this type - BcelField/BcelMethod - if (backingGenericMember!=null) { - if (annotationTypes!=null) { - throw new BCException("Unexpectedly found a backing generic member and a local set of annotations"); - } - return backingGenericMember.hasAnnotation(ofType); - } - if (annotationTypes==null) { - return false; - } + public boolean hasAnnotation(UnresolvedType ofType) { + // The ctors don't allow annotations to be specified ... yet - but + // that doesn't mean it is an error to call this method. + // Normally the weaver will be working with subtypes of + // this type - BcelField/BcelMethod + if (backingGenericMember != null) { + if (annotationTypes != null) { + throw new BCException("Unexpectedly found a backing generic member and a local set of annotations"); + } + return backingGenericMember.hasAnnotation(ofType); + } + if (annotationTypes == null) { + return false; + } return annotationTypes.contains(ofType); - } - - public ResolvedType[] getAnnotationTypes() { - // The ctors don't allow annotations to be specified ... yet - but - // that doesn't mean it is an error to call this method. - // Normally the weaver will be working with subtypes of - // this type - BcelField/BcelMethod - if (backingGenericMember != null) { - if (annotationTypes!=null) { - throw new BCException("Unexpectedly found a backing generic member and a local set of annotations"); - } - return backingGenericMember.getAnnotationTypes(); - } - if (annotationTypes == null) return null; - return (ResolvedType[])annotationTypes.toArray(new ResolvedType[]{}); - } - - public String getAnnotationDefaultValue() { - throw new UnsupportedOperationException("You should resolve this member and call getAnnotationDefaultValue() on the result..."); - } - - public AnnotationX[] getAnnotations() { - if (backingGenericMember != null) return backingGenericMember.getAnnotations(); - return super.getAnnotations(); - } - + } + + public ResolvedType[] getAnnotationTypes() { + // The ctors don't allow annotations to be specified ... yet - but + // that doesn't mean it is an error to call this method. + // Normally the weaver will be working with subtypes of + // this type - BcelField/BcelMethod + if (backingGenericMember != null) { + if (annotationTypes != null) { + throw new BCException("Unexpectedly found a backing generic member and a local set of annotations"); + } + return backingGenericMember.getAnnotationTypes(); + } + if (annotationTypes == null) + return null; + return (ResolvedType[]) annotationTypes.toArray(new ResolvedType[] {}); + } + + public String getAnnotationDefaultValue() { + throw new UnsupportedOperationException( + "You should resolve this member and call getAnnotationDefaultValue() on the result..."); + } + + public AnnotationX[] getAnnotations() { + if (backingGenericMember != null) + return backingGenericMember.getAnnotations(); + return super.getAnnotations(); + } + public void setAnnotationTypes(UnresolvedType[] annotationtypes) { - if (annotationTypes == null) annotationTypes = new HashSet(); + if (annotationTypes == null) + annotationTypes = new HashSet(); for (int i = 0; i < annotationtypes.length; i++) { UnresolvedType typeX = annotationtypes[i]; annotationTypes.add(typeX); } } - - public ResolvedType[][] getParameterAnnotationTypes() { - if (parameterAnnotationTypes == null) return null; + + public ResolvedType[][] getParameterAnnotationTypes() { + if (parameterAnnotationTypes == null) + return null; return parameterAnnotationTypes; - } - - - public AnnotationX[][] getParameterAnnotations() { - if (backingGenericMember != null) return backingGenericMember.getParameterAnnotations(); - throw new BCException("Cannot return parameter annotations for a " + this.getClass().getName() + " member"); -// return super.getParameterAnnotations(); - } - - public void addAnnotation(AnnotationX annotation) { - // FIXME asc only allows for annotation types, not instances - should it? - if (annotationTypes == null) annotationTypes = new HashSet(); + } + + public AnnotationX[][] getParameterAnnotations() { + if (backingGenericMember != null) + return backingGenericMember.getParameterAnnotations(); + throw new BCException("Cannot return parameter annotations for a " + this.getClass().getName() + " member"); + // return super.getParameterAnnotations(); + } + + public void addAnnotation(AnnotationX annotation) { + // FIXME asc only allows for annotation types, not instances - should it? + if (annotationTypes == null) + annotationTypes = new HashSet(); annotationTypes.add(annotation.getSignature()); } - - public boolean isBridgeMethod() { - return (modifiers & Constants.ACC_BRIDGE)!=0 && getKind().equals(METHOD); - } - - public boolean isVarargsMethod() { - return (modifiers & Constants.ACC_VARARGS)!=0; - } - - public void setVarargsMethod() { - modifiers = modifiers | Constants.ACC_VARARGS; - } - + + public boolean isBridgeMethod() { + return (modifiers & Constants.ACC_BRIDGE) != 0 && getKind().equals(METHOD); + } + + public boolean isVarargsMethod() { + return (modifiers & Constants.ACC_VARARGS) != 0; + } + + public void setVarargsMethod() { + modifiers = modifiers | Constants.ACC_VARARGS; + } + public boolean isSynthetic() { // See Bcelmethod.isSynthetic() which takes account of preJava5 Synthetic modifier - return (modifiers & 4096)!=0; // do we know better? + return (modifiers & 4096) != 0; // do we know better? } - public void write(DataOutputStream s) throws IOException { - getKind().write(s); - getDeclaringType().write(s); - s.writeInt(modifiers); - s.writeUTF(getName()); - s.writeUTF(getSignature()); + public void write(DataOutputStream s) throws IOException { + getKind().write(s); + getDeclaringType().write(s); + s.writeInt(modifiers); + s.writeUTF(getName()); + s.writeUTF(getSignature()); UnresolvedType.writeArray(getExceptions(), s); s.writeInt(getStart()); @@ -390,7 +364,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno s.writeBoolean(isVarargsMethod()); // Write out any type variables... - if (typeVariables==null) { + if (typeVariables == null) { s.writeInt(0); } else { s.writeInt(typeVariables.length); @@ -410,154 +384,148 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno } returnType.write(s); } - } - - /** - * Return the member generic signature that would be suitable for inclusion in - * a class file Signature attribute. - * For: - * List getThem(T t) {} - * we would create: - * (TT;)Ljava/util/List;; - * - * @return the generic signature for the member that could be inserted into a class file - */ - public String getSignatureForAttribute() { - StringBuffer sb = new StringBuffer(); - if (typeVariables!=null) { - sb.append("<"); - for (int i = 0; i < typeVariables.length; i++) { - sb.append(typeVariables[i].getSignatureForAttribute()); // need a 'getSignatureForAttribute()' - } - sb.append(">"); - } - sb.append("("); - for (int i = 0; i < parameterTypes.length; i++) { - ResolvedType ptype = (ResolvedType)parameterTypes[i]; - sb.append(ptype.getSignatureForAttribute()); - } - sb.append(")"); - sb.append(((ResolvedType)returnType).getSignatureForAttribute()); - return sb.toString(); - } - - public String getGenericSignature() { - StringBuffer sb = new StringBuffer(); - if (typeVariables!=null) { - sb.append("<"); - for (int i = 0; i < typeVariables.length; i++) { - sb.append(typeVariables[i].getSignature()); - } - sb.append(">"); - } - sb.append("("); - for (int i = 0; i < parameterTypes.length; i++) { - UnresolvedType ptype = parameterTypes[i]; - sb.append(ptype.getSignature()); - } - sb.append(")"); - sb.append(returnType.getSignature()); - return sb.toString(); - } - - public static void writeArray(ResolvedMember[] members, DataOutputStream s) throws IOException { + } + + /** + * Return the member generic signature that would be suitable for inclusion in a class file Signature attribute. For: + * List getThem(T t) {} we would create: (TT;)Ljava/util/List;; + * + * @return the generic signature for the member that could be inserted into a class file + */ + public String getSignatureForAttribute() { + StringBuffer sb = new StringBuffer(); + if (typeVariables != null) { + sb.append("<"); + for (int i = 0; i < typeVariables.length; i++) { + sb.append(typeVariables[i].getSignatureForAttribute()); // need a 'getSignatureForAttribute()' + } + sb.append(">"); + } + sb.append("("); + for (int i = 0; i < parameterTypes.length; i++) { + ResolvedType ptype = (ResolvedType) parameterTypes[i]; + sb.append(ptype.getSignatureForAttribute()); + } + sb.append(")"); + sb.append(((ResolvedType) returnType).getSignatureForAttribute()); + return sb.toString(); + } + + public String getGenericSignature() { + StringBuffer sb = new StringBuffer(); + if (typeVariables != null) { + sb.append("<"); + for (int i = 0; i < typeVariables.length; i++) { + sb.append(typeVariables[i].getSignature()); + } + sb.append(">"); + } + sb.append("("); + for (int i = 0; i < parameterTypes.length; i++) { + UnresolvedType ptype = parameterTypes[i]; + sb.append(ptype.getSignature()); + } + sb.append(")"); + sb.append(returnType.getSignature()); + return sb.toString(); + } + + public static void writeArray(ResolvedMember[] members, DataOutputStream s) throws IOException { s.writeInt(members.length); for (int i = 0, len = members.length; i < len; i++) { members[i].write(s); } - } + } + + public static ResolvedMemberImpl readResolvedMember(VersionedDataInputStream s, ISourceContext sourceContext) + throws IOException { - - public static ResolvedMemberImpl readResolvedMember(VersionedDataInputStream s, ISourceContext sourceContext) throws IOException { - - ResolvedMemberImpl m = new ResolvedMemberImpl(MemberKind.read(s), UnresolvedType.read(s), s.readInt(), - s.readUTF(), s.readUTF()); + ResolvedMemberImpl m = new ResolvedMemberImpl(MemberKind.read(s), UnresolvedType.read(s), s.readInt(), s.readUTF(), s + .readUTF()); m.checkedExceptions = UnresolvedType.readArray(s); - + m.start = s.readInt(); m.end = s.readInt(); m.sourceContext = sourceContext; - - - if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) { - - if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) { + + if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) { + + if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) { boolean isvarargs = s.readBoolean(); - if (isvarargs) m.setVarargsMethod(); + if (isvarargs) + m.setVarargsMethod(); } int tvcount = s.readInt(); - if (tvcount!=0) { + if (tvcount != 0) { m.typeVariables = new TypeVariable[tvcount]; - for (int i=0;i=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) { + if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150M4) { boolean hasAGenericSignature = s.readBoolean(); if (hasAGenericSignature) { int ps = s.readInt(); UnresolvedType[] params = new UnresolvedType[ps]; for (int i = 0; i < params.length; i++) { - params[i]=TypeFactory.createTypeFromSignature(s.readUTF()); + params[i] = TypeFactory.createTypeFromSignature(s.readUTF()); } - UnresolvedType rt = TypeFactory.createTypeFromSignature(s.readUTF()); + UnresolvedType rt = TypeFactory.createTypeFromSignature(s.readUTF()); m.parameterTypes = params; - m.returnType = rt; + m.returnType = rt; } } } return m; - } - - public static ResolvedMember[] readResolvedMemberArray(VersionedDataInputStream s, ISourceContext context) throws IOException { - int len = s.readInt(); + } + + public static ResolvedMember[] readResolvedMemberArray(VersionedDataInputStream s, ISourceContext context) throws IOException { + int len = s.readInt(); ResolvedMember[] members = new ResolvedMember[len]; - for (int i=0; i < len; i++) { + for (int i = 0; i < len; i++) { members[i] = ResolvedMemberImpl.readResolvedMember(s, context); } return members; - } - - - - // OPTIMIZE dont like how resolve(world) on ResolvedMemberImpl does something different to world.resolve(member) + } + + // OPTIMIZE dont like how resolve(world) on ResolvedMemberImpl does something different to world.resolve(member) public ResolvedMember resolve(World world) { - // make sure all the pieces of a resolvedmember really are resolved + // make sure all the pieces of a resolvedmember really are resolved try { - if (typeVariables!=null && typeVariables.length>0) { + if (typeVariables != null && typeVariables.length > 0) { for (int i = 0; i < typeVariables.length; i++) { typeVariables[i] = typeVariables[i].resolve(world); } } world.setTypeVariableLookupScope(this); - if (annotationTypes!=null) { - Set r = new HashSet(); - for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) { - UnresolvedType element = (UnresolvedType) iter.next(); - r.add(world.resolve(element)); - } - annotationTypes = r; - } - declaringType = declaringType.resolve(world); - if (declaringType.isRawType()) declaringType = ((ReferenceType)declaringType).getGenericType(); - - - if (parameterTypes!=null && parameterTypes.length>0) { + if (annotationTypes != null) { + Set r = new HashSet(); + for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) { + UnresolvedType element = (UnresolvedType) iter.next(); + r.add(world.resolve(element)); + } + annotationTypes = r; + } + declaringType = declaringType.resolve(world); + if (declaringType.isRawType()) + declaringType = ((ReferenceType) declaringType).getGenericType(); + + if (parameterTypes != null && parameterTypes.length > 0) { for (int i = 0; i < parameterTypes.length; i++) { parameterTypes[i] = parameterTypes[i].resolve(world); } } - + returnType = returnType.resolve(world); - + } finally { world.setTypeVariableLookupScope(null); } return this; } - + public ISourceContext getSourceContext(World world) { return getDeclaringType().resolve(world).getSourceContext(); } @@ -565,26 +533,28 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno public String[] getParameterNames() { return parameterNames; } + public final void setParameterNames(String[] pnames) { parameterNames = pnames; } + public final String[] getParameterNames(World world) { return getParameterNames(); } - + public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() { return null; } - - public ISourceLocation getSourceLocation() { - //System.out.println("get context: " + this + " is " + sourceContext); - if (getSourceContext() == null) { - //System.err.println("no context: " + this); - return null; - } - return getSourceContext().makeSourceLocation(this); - } - + + public ISourceLocation getSourceLocation() { + // System.out.println("get context: " + this + " is " + sourceContext); + if (getSourceContext() == null) { + // System.err.println("no context: " + this); + return null; + } + return getSourceContext().makeSourceLocation(this); + } + public int getEnd() { return end; } @@ -601,7 +571,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno this.start = sourceStart; this.end = sourceEnd; } - + public void setDeclaringType(ReferenceType rt) { declaringType = rt; } @@ -609,7 +579,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno public void setSourceContext(ISourceContext sourceContext) { this.sourceContext = sourceContext; } - + public boolean isAbstract() { return Modifier.isAbstract(modifiers); } @@ -617,24 +587,24 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno public boolean isPublic() { return Modifier.isPublic(modifiers); } - - public boolean isProtected() { - return Modifier.isProtected(modifiers); - } - + + public boolean isProtected() { + return Modifier.isProtected(modifiers); + } + public boolean isNative() { return Modifier.isNative(modifiers); } - - public boolean isDefault() { - return !(isPublic() || isProtected() || isPrivate()); - } + + public boolean isDefault() { + return !(isPublic() || isProtected() || isPrivate()); + } public boolean isVisible(ResolvedType fromType) { World world = fromType.getWorld(); - return ResolvedType.isVisible(getModifiers(), getDeclaringType().resolve(world), - fromType); + return ResolvedType.isVisible(getModifiers(), getDeclaringType().resolve(world), fromType); } + public void setCheckedExceptions(UnresolvedType[] checkedExceptions) { this.checkedExceptions = checkedExceptions; } @@ -646,182 +616,165 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno public boolean isAnnotatedElsewhere() { return isAnnotatedElsewhere; } - + /** * Get the UnresolvedType for the return type, taking generic signature into account */ public UnresolvedType getGenericReturnType() { return getReturnType(); } - + /** * Get the TypeXs of the parameter types, taking generic signature into account */ public UnresolvedType[] getGenericParameterTypes() { return getParameterTypes(); } - - - public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized) { - return parameterizedWith(typeParameters,newDeclaringType,isParameterized,null); + + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized) { + return parameterizedWith(typeParameters, newDeclaringType, isParameterized, null); } - - + /** - * Return a resolvedmember in which all the type variables in the signature - * have been replaced with the given bindings. - * The 'isParameterized' flag tells us whether we are creating a raw type - * version or not. if (isParameterized) then List will turn into - * List (for example) - if (!isParameterized) then List will turn - * into List. + * Return a resolvedmember in which all the type variables in the signature have been replaced with the given bindings. The + * 'isParameterized' flag tells us whether we are creating a raw type version or not. if (isParameterized) then List will + * turn into List (for example) - if (!isParameterized) then List will turn into List. */ - public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters,ResolvedType newDeclaringType, boolean isParameterized,List aliases) { - if (//isParameterized && <-- might need this bit... - !getDeclaringType().isGenericType()) { - throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: "+getDeclaringType()+" kind("+getDeclaringType().typeKind+")"); + public ResolvedMemberImpl parameterizedWith(UnresolvedType[] typeParameters, ResolvedType newDeclaringType, + boolean isParameterized, List aliases) { + if (// isParameterized && <-- might need this bit... + !getDeclaringType().isGenericType()) { + throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: " + getDeclaringType() + + " kind(" + getDeclaringType().typeKind + ")"); } TypeVariable[] typeVariables = getDeclaringType().getTypeVariables(); if (isParameterized && (typeVariables.length != typeParameters.length)) { throw new IllegalStateException("Wrong number of type parameters supplied"); } Map typeMap = new HashMap(); - boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0; - if (typeVariables!=null) { + boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0; + if (typeVariables != null) { // If no 'replacements' were supplied in the typeParameters array then collapse // type variables to their first bound. for (int i = 0; i < typeVariables.length; i++) { - UnresolvedType ut = (!typeParametersSupplied?typeVariables[i].getFirstBound():typeParameters[i]); - typeMap.put(typeVariables[i].getName(),ut); + UnresolvedType ut = (!typeParametersSupplied ? typeVariables[i].getFirstBound() : typeParameters[i]); + typeMap.put(typeVariables[i].getName(), ut); } } // For ITDs on generic types that use type variables from the target type, the aliases // record the alternative names used throughout the ITD expression that must map to // the same value as the type variables real name. - if (aliases!=null) { + if (aliases != null) { int posn = 0; for (Iterator iter = aliases.iterator(); iter.hasNext();) { String typeVariableAlias = (String) iter.next(); - typeMap.put(typeVariableAlias,(!typeParametersSupplied?typeVariables[posn].getFirstBound():typeParameters[posn])); + typeMap.put(typeVariableAlias, (!typeParametersSupplied ? typeVariables[posn].getFirstBound() + : typeParameters[posn])); posn++; } } - - UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(),typeMap,isParameterized); - UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length]; - UnresolvedType[] genericParameterTypes = getGenericParameterTypes(); + + UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(), typeMap, isParameterized); + UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length]; + UnresolvedType[] genericParameterTypes = getGenericParameterTypes(); for (int i = 0; i < parameterizedParameterTypes.length; i++) { - parameterizedParameterTypes[i] = - parameterize(genericParameterTypes[i], typeMap,isParameterized); + parameterizedParameterTypes[i] = parameterize(genericParameterTypes[i], typeMap, isParameterized); } - ResolvedMemberImpl ret = new ResolvedMemberImpl( - getKind(), - newDeclaringType, - getModifiers(), - parameterizedReturnType, - getName(), - parameterizedParameterTypes, - getExceptions(), - this - ); + ResolvedMemberImpl ret = new ResolvedMemberImpl(getKind(), newDeclaringType, getModifiers(), parameterizedReturnType, + getName(), parameterizedParameterTypes, getExceptions(), this); ret.setTypeVariables(getTypeVariables()); ret.setSourceContext(getSourceContext()); - ret.setPosition(getStart(),getEnd()); + ret.setPosition(getStart(), getEnd()); ret.setParameterNames(getParameterNames()); return ret; } - /** - * Replace occurrences of type variables in the signature with values contained in the map. The map is of the form A=String,B=Integer and - * so a signature List Foo.m(B i) {} would become List Foo.m(Integer i) {} + * Replace occurrences of type variables in the signature with values contained in the map. The map is of the form + * A=String,B=Integer and so a signature List Foo.m(B i) {} would become List Foo.m(Integer i) {} */ public ResolvedMember parameterizedWith(Map m, World w) { -// if (//isParameterized && <-- might need this bit... -// !getDeclaringType().isGenericType()) { -// throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: "+getDeclaringType()+" kind("+getDeclaringType().typeKind+")"); -// } - declaringType = declaringType.resolve(w); - if (declaringType.isRawType()) declaringType = ((ResolvedType)declaringType).getGenericType(); -// TypeVariable[] typeVariables = getDeclaringType().getTypeVariables(); -// if (isParameterized && (typeVariables.length != typeParameters.length)) { -// throw new IllegalStateException("Wrong number of type parameters supplied"); -// } -// Map typeMap = new HashMap(); -// boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0; -// if (typeVariables!=null) { -// // If no 'replacements' were supplied in the typeParameters array then collapse -// // type variables to their first bound. -// for (int i = 0; i < typeVariables.length; i++) { -// UnresolvedType ut = (!typeParametersSupplied?typeVariables[i].getFirstBound():typeParameters[i]); -// typeMap.put(typeVariables[i].getName(),ut); -// } -// } -// // For ITDs on generic types that use type variables from the target type, the aliases -// // record the alternative names used throughout the ITD expression that must map to -// // the same value as the type variables real name. -// if (aliases!=null) { -// int posn = 0; -// for (Iterator iter = aliases.iterator(); iter.hasNext();) { -// String typeVariableAlias = (String) iter.next(); -// typeMap.put(typeVariableAlias,(!typeParametersSupplied?typeVariables[posn].getFirstBound():typeParameters[posn])); -// posn++; -// } -// } - - UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(),m,true,w); - UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length]; - UnresolvedType[] genericParameterTypes = getGenericParameterTypes(); + // if (//isParameterized && <-- might need this bit... + // !getDeclaringType().isGenericType()) { + // throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: "+getDeclaringType()+" kind("+ + // getDeclaringType().typeKind+")"); + // } + declaringType = declaringType.resolve(w); + if (declaringType.isRawType()) + declaringType = ((ResolvedType) declaringType).getGenericType(); + // TypeVariable[] typeVariables = getDeclaringType().getTypeVariables(); + // if (isParameterized && (typeVariables.length != typeParameters.length)) { + // throw new IllegalStateException("Wrong number of type parameters supplied"); + // } + // Map typeMap = new HashMap(); + // boolean typeParametersSupplied = typeParameters!=null && typeParameters.length>0; + // if (typeVariables!=null) { + // // If no 'replacements' were supplied in the typeParameters array then collapse + // // type variables to their first bound. + // for (int i = 0; i < typeVariables.length; i++) { + // UnresolvedType ut = (!typeParametersSupplied?typeVariables[i].getFirstBound():typeParameters[i]); + // typeMap.put(typeVariables[i].getName(),ut); + // } + // } + // // For ITDs on generic types that use type variables from the target type, the aliases + // // record the alternative names used throughout the ITD expression that must map to + // // the same value as the type variables real name. + // if (aliases!=null) { + // int posn = 0; + // for (Iterator iter = aliases.iterator(); iter.hasNext();) { + // String typeVariableAlias = (String) iter.next(); + // typeMap.put(typeVariableAlias,(!typeParametersSupplied?typeVariables[posn].getFirstBound():typeParameters[posn])); + // posn++; + // } + // } + + UnresolvedType parameterizedReturnType = parameterize(getGenericReturnType(), m, true, w); + UnresolvedType[] parameterizedParameterTypes = new UnresolvedType[getGenericParameterTypes().length]; + UnresolvedType[] genericParameterTypes = getGenericParameterTypes(); for (int i = 0; i < parameterizedParameterTypes.length; i++) { - parameterizedParameterTypes[i] = - parameterize(genericParameterTypes[i], m,true,w); + parameterizedParameterTypes[i] = parameterize(genericParameterTypes[i], m, true, w); } - ResolvedMemberImpl ret = new ResolvedMemberImpl( - getKind(), - declaringType, - getModifiers(), - parameterizedReturnType, - getName(), - parameterizedParameterTypes, - getExceptions(), - this - ); + ResolvedMemberImpl ret = new ResolvedMemberImpl(getKind(), declaringType, getModifiers(), parameterizedReturnType, + getName(), parameterizedParameterTypes, getExceptions(), this); ret.setTypeVariables(getTypeVariables()); ret.setSourceContext(getSourceContext()); - ret.setPosition(getStart(),getEnd()); + ret.setPosition(getStart(), getEnd()); ret.setParameterNames(getParameterNames()); return ret; } - + public void setTypeVariables(TypeVariable[] tvars) { typeVariables = tvars; } - + public TypeVariable[] getTypeVariables() { return typeVariables; } protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType) { - return parameterize(aType,typeVariableMap,inParameterizedType,null); + return parameterize(aType, typeVariableMap, inParameterizedType, null); } - - protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType,World w) { + + protected UnresolvedType parameterize(UnresolvedType aType, Map typeVariableMap, boolean inParameterizedType, World w) { if (aType instanceof TypeVariableReference) { - String variableName = ((TypeVariableReference)aType).getTypeVariable().getName(); + String variableName = ((TypeVariableReference) aType).getTypeVariable().getName(); if (!typeVariableMap.containsKey(variableName)) { return aType; // if the type variable comes from the method (and not the type) thats OK } return (UnresolvedType) typeVariableMap.get(variableName); } else if (aType.isParameterizedType()) { if (inParameterizedType) { -// if (!(getDeclaringType() instanceof ResolvedType)) { -// int stop = 1; -// } -// if (aType!=null) {// instanceof UnresolvedType) { - if (w!=null) aType = aType.resolve(w); - else { - aType= aType.resolve(((ResolvedType)getDeclaringType()).getWorld()); - } -// } + // if (!(getDeclaringType() instanceof ResolvedType)) { + // int stop = 1; + // } + // if (aType!=null) {// instanceof UnresolvedType) { + if (w != null) + aType = aType.resolve(w); + else { + aType = aType.resolve(((ResolvedType) getDeclaringType()).getWorld()); + } + // } return aType.parameterize(typeVariableMap); } else { return aType.getRawType(); @@ -830,99 +783,101 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno // The component type might be a type variable (pr150095) int dims = 1; String sig = aType.getSignature(); - while (sig.charAt(dims)=='[') dims++; + while (sig.charAt(dims) == '[') + dims++; UnresolvedType componentSig = UnresolvedType.forSignature(sig.substring(dims)); - UnresolvedType arrayType = ResolvedType.makeArray(parameterize(componentSig,typeVariableMap,inParameterizedType),dims); + UnresolvedType arrayType = ResolvedType.makeArray(parameterize(componentSig, typeVariableMap, inParameterizedType), + dims); return arrayType; } - return aType; + return aType; } - - + /** - * If this member is defined by a parameterized super-type, return the erasure - * of that member. - * For example: - * interface I { T foo(T aTea); } - * class C implements I { - * String foo(String aString) { return "something"; } - * } - * The resolved member for C.foo has signature String foo(String). The - * erasure of that member is Object foo(Object) -- use upper bound of type - * variable. + * If this member is defined by a parameterized super-type, return the erasure of that member. For example: interface I { T + * foo(T aTea); } class C implements I { String foo(String aString) { return "something"; } } The resolved member for + * C.foo has signature String foo(String). The erasure of that member is Object foo(Object) -- use upper bound of type variable. * A type is a supertype of itself. */ - public ResolvedMember getErasure() { - if (calculatedMyErasure) return myErasure; - calculatedMyErasure = true; - ResolvedType resolvedDeclaringType = (ResolvedType) getDeclaringType(); - // this next test is fast, and the result is cached. - if (!resolvedDeclaringType.hasParameterizedSuperType()) { - return null; - } else { - // we have one or more parameterized super types. - // this member may be defined by one of them... we need to find out. - Collection declaringTypes = this.getDeclaringTypes(resolvedDeclaringType.getWorld()); - for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { - ResolvedType aDeclaringType = (ResolvedType) iter.next(); - if (aDeclaringType.isParameterizedType()) { - // we've found the (a?) parameterized type that defines this member. - // now get the erasure of it - ResolvedMemberImpl matchingMember = (ResolvedMemberImpl) aDeclaringType.lookupMemberNoSupers(this); - if (matchingMember != null && matchingMember.backingGenericMember != null) { - myErasure = matchingMember.backingGenericMember; - return myErasure; - } - } - } - } - return null; - } - - private ResolvedMember myErasure = null; - private boolean calculatedMyErasure = false; - + // public ResolvedMember getErasure() { + // if (calculatedMyErasure) return myErasure; + // calculatedMyErasure = true; + // ResolvedType resolvedDeclaringType = (ResolvedType) getDeclaringType(); + // // this next test is fast, and the result is cached. + // if (!resolvedDeclaringType.hasParameterizedSuperType()) { + // return null; + // } else { + // // we have one or more parameterized super types. + // // this member may be defined by one of them... we need to find out. + // Collection declaringTypes = this.getDeclaringTypes(resolvedDeclaringType.getWorld()); + // for (Iterator iter = declaringTypes.iterator(); iter.hasNext();) { + // ResolvedType aDeclaringType = (ResolvedType) iter.next(); + // if (aDeclaringType.isParameterizedType()) { + // // we've found the (a?) parameterized type that defines this member. + // // now get the erasure of it + // ResolvedMemberImpl matchingMember = (ResolvedMemberImpl) aDeclaringType.lookupMemberNoSupers(this); + // if (matchingMember != null && matchingMember.backingGenericMember != null) { + // myErasure = matchingMember.backingGenericMember; + // return myErasure; + // } + // } + // } + // } + // return null; + // } + // + // private ResolvedMember myErasure = null; + // private boolean calculatedMyErasure = false; public boolean hasBackingGenericMember() { - return backingGenericMember!=null; + return backingGenericMember != null; } - + public ResolvedMember getBackingGenericMember() { return backingGenericMember; } - + /** - * For ITDs, we use the default factory methods to build a resolved member, then alter a couple of characteristics - * using this method - this is safe. - */ - public void resetName(String newName) {this.name = newName;} - public void resetKind(MemberKind newKind) { this.kind = newKind; } - public void resetModifiers(int newModifiers) {this.modifiers=newModifiers;} + * For ITDs, we use the default factory methods to build a resolved member, then alter a couple of characteristics using this + * method - this is safe. + */ + public void resetName(String newName) { + this.name = newName; + } + + public void resetKind(MemberKind newKind) { + this.kind = newKind; + } + + public void resetModifiers(int newModifiers) { + this.modifiers = newModifiers; + } public void resetReturnTypeToObjectArray() { returnType = UnresolvedType.OBJECTARRAY; } - + /** - * Returns a copy of this member but with the declaring type swapped. - * Copy only needs to be shallow. + * Returns a copy of this member but with the declaring type swapped. Copy only needs to be shallow. + * * @param newDeclaringType */ public JoinPointSignature withSubstituteDeclaringType(ResolvedType newDeclaringType) { - JoinPointSignature ret = new JoinPointSignature(this,newDeclaringType); + JoinPointSignature ret = new JoinPointSignature(this, newDeclaringType); return ret; } - + /** - * Returns true if this member matches the other. The matching takes into account - * name and parameter types only. When comparing parameter types, we allow any type - * variable to match any other type variable regardless of bounds. + * Returns true if this member matches the other. The matching takes into account name and parameter types only. When comparing + * parameter types, we allow any type variable to match any other type variable regardless of bounds. */ public boolean matches(ResolvedMember aCandidateMatch) { - ResolvedMemberImpl candidateMatchImpl = (ResolvedMemberImpl)aCandidateMatch; - if (!getName().equals(aCandidateMatch.getName())) return false; + ResolvedMemberImpl candidateMatchImpl = (ResolvedMemberImpl) aCandidateMatch; + if (!getName().equals(aCandidateMatch.getName())) + return false; UnresolvedType[] myParameterTypes = getGenericParameterTypes(); UnresolvedType[] candidateParameterTypes = aCandidateMatch.getGenericParameterTypes(); - if (myParameterTypes.length != candidateParameterTypes.length) return false; + if (myParameterTypes.length != candidateParameterTypes.length) + return false; String myParameterSignature = getParameterSigWithBoundsRemoved(); String candidateParameterSignature = candidateMatchImpl.getParameterSigWithBoundsRemoved(); if (myParameterSignature.equals(candidateParameterSignature)) { @@ -934,20 +889,22 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno return myParameterSignature.equals(candidateParameterSignature); } } - - /** converts e.g. .... List to just Ljava/util/List; - * whereas the full signature would be Ljava/util/List; + + /** + * converts e.g. .... List to just Ljava/util/List; whereas the full signature would be + * Ljava/util/List; */ private String myParameterSignatureWithBoundsRemoved = null; /** - * converts e.g. .... List to just Ljava/util/List; + * converts e.g. .... List to just Ljava/util/List; */ private String myParameterSignatureErasure = null; - + // does NOT produce a meaningful java signature, but does give a unique string suitable for // comparison. private String getParameterSigWithBoundsRemoved() { - if (myParameterSignatureWithBoundsRemoved != null) return myParameterSignatureWithBoundsRemoved; + if (myParameterSignatureWithBoundsRemoved != null) + return myParameterSignatureWithBoundsRemoved; StringBuffer sig = new StringBuffer(); UnresolvedType[] myParameterTypes = getGenericParameterTypes(); for (int i = 0; i < myParameterTypes.length; i++) { @@ -956,28 +913,29 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno myParameterSignatureWithBoundsRemoved = sig.toString(); return myParameterSignatureWithBoundsRemoved; } - + /** - * Return the erased form of the signature with bounds collapsed for type variables, etc. - * Does not include the return type, @see getParam + * Return the erased form of the signature with bounds collapsed for type variables, etc. Does not include the return type, @see + * getParam */ public String getParameterSignatureErased() { - if (myParameterSignatureErasure != null) return myParameterSignatureErasure; + if (myParameterSignatureErasure != null) + return myParameterSignatureErasure; StringBuffer sig = new StringBuffer(); UnresolvedType[] myParameterTypes = getParameterTypes(); for (int i = 0; i < myParameterTypes.length; i++) { UnresolvedType thisParameter = myParameterTypes[i]; if (thisParameter.isTypeVariableReference()) { - TypeVariableReferenceType typeVariableRT = (TypeVariableReferenceType) thisParameter; - sig.append(typeVariableRT.getUpperBound().getSignature()); + TypeVariableReferenceType typeVariableRT = (TypeVariableReferenceType) thisParameter; + sig.append(typeVariableRT.getUpperBound().getSignature()); } else { - sig.append(thisParameter.getErasureSignature()); + sig.append(thisParameter.getErasureSignature()); } } myParameterSignatureErasure = sig.toString(); - return myParameterSignatureErasure; + return myParameterSignatureErasure; } - + public String getSignatureErased() { StringBuffer sb = new StringBuffer(); sb.append("("); @@ -986,20 +944,20 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno sb.append(getReturnType().getErasureSignature()); return sb.toString(); } - + // does NOT produce a meaningful java signature, but does give a unique string suitable for // comparison. public static void appendSigWithTypeVarBoundsRemoved(UnresolvedType aType, StringBuffer toBuffer, Set alreadyUsedTypeVars) { if (aType.isTypeVariableReference()) { - TypeVariableReferenceType typeVariableRT = (TypeVariableReferenceType) aType; + TypeVariableReferenceType typeVariableRT = (TypeVariableReferenceType) aType; // pr204505 - if (alreadyUsedTypeVars.contains(aType)) { - toBuffer.append("..."); - } else { - alreadyUsedTypeVars.add(aType); - appendSigWithTypeVarBoundsRemoved(typeVariableRT.getUpperBound(), toBuffer, alreadyUsedTypeVars); - } -// toBuffer.append("T;"); + if (alreadyUsedTypeVars.contains(aType)) { + toBuffer.append("..."); + } else { + alreadyUsedTypeVars.add(aType); + appendSigWithTypeVarBoundsRemoved(typeVariableRT.getUpperBound(), toBuffer, alreadyUsedTypeVars); + } + // toBuffer.append("T;"); } else if (aType.isParameterizedType()) { toBuffer.append(aType.getRawType().getSignature()); toBuffer.append("<"); @@ -1011,117 +969,130 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno toBuffer.append(aType.getSignature()); } } - - /** - * Useful for writing tests, returns *everything* we know about this member. - */ - public String toDebugString() { - StringBuffer r = new StringBuffer(); - - // modifiers - int mods = modifiers; - if ((mods & 4096)>0) mods = mods -4096; // remove synthetic (added in the ASM case but not in the BCEL case...) - if ((mods & 512)>0) mods = mods -512; // remove interface (added in the BCEL case but not in the ASM case...) - if ((mods & 131072)>0) mods = mods -131072; // remove deprecated (added in the ASM case but not in the BCEL case...) - String modsStr = Modifier.toString(mods); - if (modsStr.length()!=0) r.append(modsStr).append("("+mods+")").append(" "); - - // type variables - if (typeVariables!=null && typeVariables.length>0) { - r.append("<"); - for (int i = 0; i < typeVariables.length; i++) { - if (i>0) r.append(","); - TypeVariable t = typeVariables[i]; - r.append(t.toDebugString()); - } - r.append("> "); - } - - // 'declaring' type - r.append(getGenericReturnType().toDebugString()); - r.append(' '); - - // name - r.append(declaringType.getName()); - r.append('.'); - r.append(name); - - // parameter signature if a method - if (kind != FIELD) { - r.append("("); - UnresolvedType[] params = getGenericParameterTypes(); - boolean parameterNamesExist = showParameterNames && parameterNames!=null && parameterNames.length==params.length; - if (params.length != 0) { - for (int i=0, len = params.length; i < len; i++) { - if (i>0) r.append(", "); - r.append(params[i].toDebugString()); - if (parameterNamesExist) r.append(" ").append(parameterNames[i]); - } - } - r.append(")"); - } - return r.toString(); - } - - // SECRETAPI - controlling whether parameter names come out in the debug string (for testing purposes) - public static boolean showParameterNames = true; - - public String toGenericString() { - StringBuffer buf = new StringBuffer(); - buf.append(getGenericReturnType().getSimpleName()); - buf.append(' '); - buf.append(declaringType.getName()); - buf.append('.'); - buf.append(name); - if (kind != FIELD) { - buf.append("("); - UnresolvedType[] params = getGenericParameterTypes(); - if (params.length != 0) { - buf.append(params[0].getSimpleName()); - for (int i=1, len = params.length; i < len; i++) { - buf.append(", "); - buf.append(params[i].getSimpleName()); - } - } - buf.append(")"); - } - return buf.toString(); - } - - public boolean isCompatibleWith(Member am) { - if (kind != METHOD || am.getKind() != METHOD) return true; - if (! name.equals(am.getName())) return true; - if (! equalTypes(getParameterTypes(), am.getParameterTypes())) return true; - return getReturnType().equals(am.getReturnType()); - } - - private static boolean equalTypes(UnresolvedType[] a, UnresolvedType[] b) { - int len = a.length; - if (len != b.length) return false; - for (int i = 0; i < len; i++) { - if (!a[i].equals(b[i])) return false; - } - return true; - } - - + + /** + * Useful for writing tests, returns *everything* we know about this member. + */ + public String toDebugString() { + StringBuffer r = new StringBuffer(); + + // modifiers + int mods = modifiers; + if ((mods & 4096) > 0) + mods = mods - 4096; // remove synthetic (added in the ASM case but not in the BCEL case...) + if ((mods & 512) > 0) + mods = mods - 512; // remove interface (added in the BCEL case but not in the ASM case...) + if ((mods & 131072) > 0) + mods = mods - 131072; // remove deprecated (added in the ASM case but not in the BCEL case...) + String modsStr = Modifier.toString(mods); + if (modsStr.length() != 0) + r.append(modsStr).append("(" + mods + ")").append(" "); + + // type variables + if (typeVariables != null && typeVariables.length > 0) { + r.append("<"); + for (int i = 0; i < typeVariables.length; i++) { + if (i > 0) + r.append(","); + TypeVariable t = typeVariables[i]; + r.append(t.toDebugString()); + } + r.append("> "); + } + + // 'declaring' type + r.append(getGenericReturnType().toDebugString()); + r.append(' '); + + // name + r.append(declaringType.getName()); + r.append('.'); + r.append(name); + + // parameter signature if a method + if (kind != FIELD) { + r.append("("); + UnresolvedType[] params = getGenericParameterTypes(); + boolean parameterNamesExist = showParameterNames && parameterNames != null && parameterNames.length == params.length; + if (params.length != 0) { + for (int i = 0, len = params.length; i < len; i++) { + if (i > 0) + r.append(", "); + r.append(params[i].toDebugString()); + if (parameterNamesExist) + r.append(" ").append(parameterNames[i]); + } + } + r.append(")"); + } + return r.toString(); + } + + // SECRETAPI - controlling whether parameter names come out in the debug string (for testing purposes) + public static boolean showParameterNames = true; + + public String toGenericString() { + StringBuffer buf = new StringBuffer(); + buf.append(getGenericReturnType().getSimpleName()); + buf.append(' '); + buf.append(declaringType.getName()); + buf.append('.'); + buf.append(name); + if (kind != FIELD) { + buf.append("("); + UnresolvedType[] params = getGenericParameterTypes(); + if (params.length != 0) { + buf.append(params[0].getSimpleName()); + for (int i = 1, len = params.length; i < len; i++) { + buf.append(", "); + buf.append(params[i].getSimpleName()); + } + } + buf.append(")"); + } + return buf.toString(); + } + + public boolean isCompatibleWith(Member am) { + if (kind != METHOD || am.getKind() != METHOD) + return true; + if (!name.equals(am.getName())) + return true; + if (!equalTypes(getParameterTypes(), am.getParameterTypes())) + return true; + return getReturnType().equals(am.getReturnType()); + } + + private static boolean equalTypes(UnresolvedType[] a, UnresolvedType[] b) { + int len = a.length; + if (len != b.length) + return false; + for (int i = 0; i < len; i++) { + if (!a[i].equals(b[i])) + return false; + } + return true; + } + public TypeVariable getTypeVariableNamed(String name) { // Check locally... - if (typeVariables!=null) { + if (typeVariables != null) { for (int i = 0; i < typeVariables.length; i++) { - if (typeVariables[i].getName().equals(name)) return typeVariables[i]; + if (typeVariables[i].getName().equals(name)) + return typeVariables[i]; } } // check the declaring type! return declaringType.getTypeVariableNamed(name); - // Do generic aspects with ITDs that share type variables with the aspect and the target type and have their own tvars cause this to be messier? + // Do generic aspects with ITDs that share type variables with the aspect and the target type and have their own tvars cause + // this to be messier? } - public void evictWeavingState() { } - - public AnnotationX getAnnotationOfType(UnresolvedType ofType) { - throw new UnsupportedOperationException("You should resolve this member and call getAnnotationOfType() on the result..."); - } + public void evictWeavingState() { + } + + public AnnotationX getAnnotationOfType(UnresolvedType ofType) { + throw new UnsupportedOperationException("You should resolve this member and call getAnnotationOfType() on the result..."); + } } - diff --git a/weaver/src/org/aspectj/weaver/ResolvedType.java b/weaver/src/org/aspectj/weaver/ResolvedType.java index f9af41da6..d61ecfe20 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedType.java +++ b/weaver/src/org/aspectj/weaver/ResolvedType.java @@ -1818,15 +1818,6 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl return null; } - /** - * overriden by ReferenceType to return the gsig for a generic type - * - * @return - */ - public String getGenericSignature() { - return ""; - } - public ResolvedType parameterizedWith(UnresolvedType[] typeParameters) { if (!(isGenericType() || isParameterizedType())) return this; @@ -1867,10 +1858,10 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl } } - public boolean hasParameterizedSuperType() { - getParameterizedSuperTypes(); - return parameterizedSuperTypes.length > 0; - } + // public boolean hasParameterizedSuperType() { + // getParameterizedSuperTypes(); + // return parameterizedSuperTypes.length > 0; + // } // public boolean hasGenericSuperType() { // ResolvedType[] superTypes = getDeclaredInterfaces(); @@ -1881,43 +1872,34 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl // return false; // } - private ResolvedType[] parameterizedSuperTypes = null; + // private ResolvedType[] parameterizedSuperTypes = null; /** * Similar to the above method, but accumulates the super types * * @return */ - public ResolvedType[] getParameterizedSuperTypes() { - if (parameterizedSuperTypes != null) - return parameterizedSuperTypes; - List accumulatedTypes = new ArrayList(); - accumulateParameterizedSuperTypes(this, accumulatedTypes); - ResolvedType[] ret = new ResolvedType[accumulatedTypes.size()]; - parameterizedSuperTypes = (ResolvedType[]) accumulatedTypes.toArray(ret); - return parameterizedSuperTypes; - } - - private void accumulateParameterizedSuperTypes(ResolvedType forType, List parameterizedTypeList) { - if (forType.isParameterizedType()) { - parameterizedTypeList.add(forType); - } - if (forType.getSuperclass() != null) { - accumulateParameterizedSuperTypes(forType.getSuperclass(), parameterizedTypeList); - } - ResolvedType[] interfaces = forType.getDeclaredInterfaces(); - for (int i = 0; i < interfaces.length; i++) { - accumulateParameterizedSuperTypes(interfaces[i], parameterizedTypeList); - } - } - - /** - * Types may have pointcuts just as they have methods and fields. - */ - public ResolvedPointcutDefinition findPointcut(String name, World world) { - throw new UnsupportedOperationException("Not yet implemenented"); - } - + // public ResolvedType[] getParameterizedSuperTypes() { + // if (parameterizedSuperTypes != null) + // return parameterizedSuperTypes; + // List accumulatedTypes = new ArrayList(); + // accumulateParameterizedSuperTypes(this, accumulatedTypes); + // ResolvedType[] ret = new ResolvedType[accumulatedTypes.size()]; + // parameterizedSuperTypes = (ResolvedType[]) accumulatedTypes.toArray(ret); + // return parameterizedSuperTypes; + // } + // private void accumulateParameterizedSuperTypes(ResolvedType forType, List parameterizedTypeList) { + // if (forType.isParameterizedType()) { + // parameterizedTypeList.add(forType); + // } + // if (forType.getSuperclass() != null) { + // accumulateParameterizedSuperTypes(forType.getSuperclass(), parameterizedTypeList); + // } + // ResolvedType[] interfaces = forType.getDeclaredInterfaces(); + // for (int i = 0; i < interfaces.length; i++) { + // accumulateParameterizedSuperTypes(interfaces[i], parameterizedTypeList); + // } + // } /** * @return true if assignable to java.lang.Exception */ diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java index f3c631399..1a76644f9 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java @@ -11,7 +11,6 @@ * Alexandre Vasseur @AspectJ ITDs * ******************************************************************/ - package org.aspectj.weaver; import java.io.DataInputStream; @@ -33,32 +32,30 @@ import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.SourceLocation; import org.aspectj.util.TypeSafeEnum; -/** This is an abstraction over method/field introduction. It might not have the chops - * to handle other inter-type declarations. This is the thing that is used on the - * eclipse side and serialized into a ConcreteTypeMunger. +/** + * This is an abstraction over method/field introduction. It might not have the chops to handle other inter-type declarations. This + * is the thing that is used on the eclipse side and serialized into a ConcreteTypeMunger. */ public abstract class ResolvedTypeMunger { protected Kind kind; protected ResolvedMember signature; - + /** - * The declared signature is filled in when a type munger is parameterized for application to - * a particular type. It represents the signature originally declared in the source file. + * The declared signature is filled in when a type munger is parameterized for application to a particular type. It represents + * the signature originally declared in the source file. */ protected ResolvedMember declaredSignature; - - - - // This list records the occurences (in order) of any names specified in the <> - // for a target type for the ITD. So for example, for List this list + + // This list records the occurences (in order) of any names specified in the <> + // for a target type for the ITD. So for example, for List this list // will be C,B,A - the list is used later to map other occurrences of C,B,A // across the intertype declaration to the right type variables in the generic // type upon which the itd is being made. // might need serializing the class file for binary weaving. - protected List /*String*/ typeVariableAliases; - - private Set /* resolvedMembers */ superMethodsCalled = Collections.EMPTY_SET; - + protected List /* String */typeVariableAliases; + + private Set /* resolvedMembers */superMethodsCalled = Collections.EMPTY_SET; + private ISourceLocation location; // Lost during serialize/deserialize ! public ResolvedTypeMunger(Kind kind, ResolvedMember signature) { @@ -66,73 +63,77 @@ public abstract class ResolvedTypeMunger { this.signature = signature; UnresolvedType declaringType = signature != null ? signature.getDeclaringType() : null; if (declaringType != null) { - if (declaringType.isRawType()) throw new IllegalStateException("Use generic type, not raw type"); - if (declaringType.isParameterizedType()) throw new IllegalStateException("Use generic type, not parameterized type"); + if (declaringType.isRawType()) + throw new IllegalStateException("Use generic type, not raw type"); + if (declaringType.isParameterizedType()) + throw new IllegalStateException("Use generic type, not parameterized type"); } -// boolean aChangeOccurred = false; -// -// UnresolvedType rt = signature.getReturnType(); -// if (rt.isParameterizedType() || rt.isGenericType()) {rt = rt.getRawType();aChangeOccurred=true;} -// UnresolvedType[] pt = signature.getParameterTypes(); -// for (int i = 0; i < pt.length; i++) { -// if (pt[i].isParameterizedType() || pt[i].isGenericType()) { pt[i] = pt[i].getRawType();aChangeOccurred=true;} -// } -// if (aChangeOccurred) { -// this.signature = new ResolvedMemberImpl(signature.getKind(),signature.getDeclaringType(),signature.getModifiers(),rt,signature.getName(),pt,signature.getExceptions()); -// } + // boolean aChangeOccurred = false; + // + // UnresolvedType rt = signature.getReturnType(); + // if (rt.isParameterizedType() || rt.isGenericType()) {rt = rt.getRawType();aChangeOccurred=true;} + // UnresolvedType[] pt = signature.getParameterTypes(); + // for (int i = 0; i < pt.length; i++) { + // if (pt[i].isParameterizedType() || pt[i].isGenericType()) { pt[i] = pt[i].getRawType();aChangeOccurred=true;} + // } + // if (aChangeOccurred) { + // this.signature = new + // ResolvedMemberImpl(signature.getKind(),signature.getDeclaringType(),signature.getModifiers(),rt,signature + // .getName(),pt,signature.getExceptions()); + // } } - + public void setSourceLocation(ISourceLocation isl) { location = isl; } - + public ISourceLocation getSourceLocation() { return location; } // ---- - // fromType is guaranteed to be a non-abstract aspect - public ConcreteTypeMunger concretize(World world, ResolvedType aspectType) { - - ConcreteTypeMunger munger = world.concreteTypeMunger(this, aspectType); - return munger; - } - - - public boolean matches(ResolvedType matchType, ResolvedType aspectType) { - ResolvedType onType = matchType.getWorld().resolve(signature.getDeclaringType()); - if (onType.isRawType()) onType = onType.getGenericType(); - //System.err.println("matching: " + this + " to " + matchType + " onType = " + onType); - if (matchType.equals(onType)) { - if (!onType.isExposedToWeaver()) { - // if the onType is an interface, and it already has the member we are about - // to munge, then this is ok... - boolean ok = (onType.isInterface() && (onType.lookupMemberWithSupersAndITDs(getSignature()) != null)); - - if (!ok && onType.getWeaverState() == null) { - if (matchType.getWorld().getLint().typeNotExposedToWeaver.isEnabled()) { - matchType.getWorld().getLint().typeNotExposedToWeaver.signal( - matchType.getName(), signature.getSourceLocation()); - } - } - } - return true; - } - //System.err.println("NO MATCH DIRECT"); - - if (onType.isInterface()) { - return matchType.isTopmostImplementor(onType); - } else { - return false; - } - } + // fromType is guaranteed to be a non-abstract aspect + // public ConcreteTypeMunger concretize(World world, ResolvedType aspectType) { + // + // ConcreteTypeMunger munger = world.concreteTypeMunger(this, aspectType); + // return munger; + // } + + public boolean matches(ResolvedType matchType, ResolvedType aspectType) { + ResolvedType onType = matchType.getWorld().resolve(signature.getDeclaringType()); + if (onType.isRawType()) + onType = onType.getGenericType(); + // System.err.println("matching: " + this + " to " + matchType + " onType = " + onType); + if (matchType.equals(onType)) { + if (!onType.isExposedToWeaver()) { + // if the onType is an interface, and it already has the member we are about + // to munge, then this is ok... + boolean ok = (onType.isInterface() && (onType.lookupMemberWithSupersAndITDs(getSignature()) != null)); + + if (!ok && onType.getWeaverState() == null) { + if (matchType.getWorld().getLint().typeNotExposedToWeaver.isEnabled()) { + matchType.getWorld().getLint().typeNotExposedToWeaver.signal(matchType.getName(), signature + .getSourceLocation()); + } + } + } + return true; + } + // System.err.println("NO MATCH DIRECT"); + + if (onType.isInterface()) { + return matchType.isTopmostImplementor(onType); + } else { + return false; + } + } // ---- public String toString() { - return "ResolvedTypeMunger(" + getKind() + ", " + getSignature() +")"; - //.superMethodsCalled + ")"; + return "ResolvedTypeMunger(" + getKind() + ", " + getSignature() + ")"; + // .superMethodsCalled + ")"; } // ---- @@ -145,66 +146,66 @@ public abstract class ResolvedTypeMunger { return NewMethodTypeMunger.readMethod(s, context); } else if (kind == Constructor) { return NewConstructorTypeMunger.readConstructor(s, context); - } else if (kind == MethodDelegate) { - return MethodDelegateTypeMunger.readMethod(s, context); - } else if (kind == FieldHost) { - return MethodDelegateTypeMunger.FieldHostTypeMunger.readFieldHost(s, context); - } else { + } else if (kind == MethodDelegate) { + return MethodDelegateTypeMunger.readMethod(s, context); + } else if (kind == FieldHost) { + return MethodDelegateTypeMunger.FieldHostTypeMunger.readFieldHost(s, context); + } else { throw new RuntimeException("unimplemented"); } } - - protected static Set readSuperMethodsCalled(VersionedDataInputStream s) throws IOException { - + Set ret = new HashSet(); int n = s.readInt(); - if (n<0) throw new BCException("Problem deserializing type munger"); - for (int i=0; i < n; i++) { + if (n < 0) + throw new BCException("Problem deserializing type munger"); + for (int i = 0; i < n; i++) { ret.add(ResolvedMemberImpl.readResolvedMember(s, null)); } return ret; } - + protected void writeSuperMethodsCalled(DataOutputStream s) throws IOException { - - if (superMethodsCalled == null || superMethodsCalled.size()==0) { + + if (superMethodsCalled == null || superMethodsCalled.size() == 0) { s.writeInt(0); return; } - + List ret = new ArrayList(superMethodsCalled); Collections.sort(ret); int n = ret.size(); s.writeInt(n); - for (Iterator i = ret.iterator(); i.hasNext(); ) { - ResolvedMember m = (ResolvedMember)i.next(); + for (Iterator i = ret.iterator(); i.hasNext();) { + ResolvedMember m = (ResolvedMember) i.next(); m.write(s); } - + } protected static ISourceLocation readSourceLocation(VersionedDataInputStream s) throws IOException { // Location persistence for type mungers was added after 1.2.1 was shipped... - if (s.getMajorVersion()=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) { + if (s.getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) { int count = s.readInt(); - if (count!=0) { + if (count != 0) { List aliases = new ArrayList(); - for (int i=0;i0); + return (typeVariableAliases != null && typeVariableAliases.size() > 0); } - + /** - * return true if type variables are specified with the target type for - * this ITD. e.g. this would return true: "int I.m() { return 42; }" + * return true if type variables are specified with the target type for this ITD. e.g. this would return true: + * "int I.m() { return 42; }" */ public boolean sharesTypeVariablesWithGenericType() { - return (typeVariableAliases!=null && typeVariableAliases.size()>0); + return (typeVariableAliases != null && typeVariableAliases.size() > 0); } - + /** - * Parameterizes a resolved type munger for a particular usage of - * its target type (this is used when the target type is generic - * and the ITD shares type variables with the target) - * see ConcreteTypeMunger.parameterizedFor - */ + * Parameterizes a resolved type munger for a particular usage of its target type (this is used when the target type is generic + * and the ITD shares type variables with the target) see ConcreteTypeMunger.parameterizedFor + */ public ResolvedTypeMunger parameterizedFor(ResolvedType target) { - throw new BCException("Dont call parameterizedFor on a type munger of this kind: "+this.getClass()); + throw new BCException("Dont call parameterizedFor on a type munger of this kind: " + this.getClass()); } -// ResolvedType genericType = target; -// if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType(); -// ResolvedMember parameterizedSignature = null; -// // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used -// // in the original ITD declaration to the ones used in the actual target type declaration. -// if (target.isGenericType()) { -// TypeVariable vars[] = target.getTypeVariables(); -// UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length]; -// for (int i = 0; i < vars.length; i++) { -// varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]); -// } -// parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases); -// } else { -// // For raw and 'normal' parameterized targets (e.g. Interface, Interface) -// parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); -// } -// return new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); -// } -// /** -// * see ResolvedTypeMunger.parameterizedFor(ResolvedType) -// */ -// public ResolvedTypeMunger parameterizedFor(ResolvedType target) { -// ResolvedType genericType = target; -// if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType(); -// ResolvedMember parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); -// return new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); -// } - + + // ResolvedType genericType = target; + // if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType(); + // ResolvedMember parameterizedSignature = null; + // // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used + // // in the original ITD declaration to the ones used in the actual target type declaration. + // if (target.isGenericType()) { + // TypeVariable vars[] = target.getTypeVariables(); + // UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length]; + // for (int i = 0; i < vars.length; i++) { + // varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]); + // } + // parameterizedSignature = getSignature().parameterizedWith(varRefs,genericType,true,typeVariableAliases); + // } else { + // // For raw and 'normal' parameterized targets (e.g. Interface, Interface) + // parameterizedSignature = + // getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); + // } + // return new NewMethodTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); + // } + // /** + // * see ResolvedTypeMunger.parameterizedFor(ResolvedType) + // */ + // public ResolvedTypeMunger parameterizedFor(ResolvedType target) { + // ResolvedType genericType = target; + // if (target.isRawType() || target.isParameterizedType()) genericType = genericType.getGenericType(); + // ResolvedMember parameterizedSignature = + // getSignature().parameterizedWith(target.getTypeParameters(),genericType,target.isParameterizedType(),typeVariableAliases); + // return new NewFieldTypeMunger(parameterizedSignature,getSuperMethodsCalled(),typeVariableAliases); + // } + public void setDeclaredSignature(ResolvedMember rm) { declaredSignature = rm; } - + public ResolvedMember getDeclaredSignature() { return declaredSignature; } - + /** - * A late munger has to be done after shadow munging since which shadows are matched - * can affect the operation of the late munger. e.g. perobjectinterfacemunger + * A late munger has to be done after shadow munging since which shadows are matched can affect the operation of the late + * munger. e.g. perobjectinterfacemunger */ public boolean isLateMunger() { return false; } - + /** - * Some type mungers are created purely to help with the implementation of shadow mungers. - * For example to support the cflow() pointcut we create a new cflow field in the aspect, and - * that is added via a BcelCflowCounterFieldAdder. + * Some type mungers are created purely to help with the implementation of shadow mungers. For example to support the cflow() + * pointcut we create a new cflow field in the aspect, and that is added via a BcelCflowCounterFieldAdder. * - * During compilation we need to compare sets of type mungers, and if some only come into - * existence after the 'shadowy' type things have been processed, we need to ignore - * them during the comparison. + * During compilation we need to compare sets of type mungers, and if some only come into existence after the 'shadowy' type + * things have been processed, we need to ignore them during the comparison. * - * Returning true from this method indicates the type munger exists to support 'shadowy' stuff - - * and so can be ignored in some comparison. + * Returning true from this method indicates the type munger exists to support 'shadowy' stuff - and so can be ignored in some + * comparison. */ public boolean existsToSupportShadowMunging() { return false; } public ResolvedTypeMunger parameterizeWith(Map m, World w) { - throw new BCException("Dont call parameterizeWith() on a type munger of this kind: "+this.getClass()); + throw new BCException("Dont call parameterizeWith() on a type munger of this kind: " + this.getClass()); } - + } diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index 2726b82eb..eec19ac69 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver; import java.io.DataInputStream; @@ -44,295 +43,309 @@ import org.aspectj.weaver.bcel.BcelAdvice; public abstract class Shadow { // every Shadow has a unique id, doesn't matter if it wraps... - private static int nextShadowID = 100; // easier to spot than zero. // OPTIMIZE is this a bug? static? - - private final Kind kind; - private final Member signature; - private Member matchingSignature; - private ResolvedMember resolvedSignature; + private static int nextShadowID = 100; // easier to spot than zero. // OPTIMIZE is this a bug? static? + + private final Kind kind; + private final Member signature; + private Member matchingSignature; + private ResolvedMember resolvedSignature; protected final Shadow enclosingShadow; - protected List mungers = Collections.EMPTY_LIST; + protected List mungers = Collections.EMPTY_LIST; - public int shadowId = nextShadowID++; // every time we build a shadow, it gets a new id + public int shadowId = nextShadowID++; // every time we build a shadow, it gets a new id // ---- - protected Shadow(Kind kind, Member signature, Shadow enclosingShadow) { - this.kind = kind; - this.signature = signature; - this.enclosingShadow = enclosingShadow; - } + protected Shadow(Kind kind, Member signature, Shadow enclosingShadow) { + this.kind = kind; + this.signature = signature; + this.enclosingShadow = enclosingShadow; + } // ---- - public abstract World getIWorld(); + public abstract World getIWorld(); - public List /*ShadowMunger*/ getMungers() { + public List /* ShadowMunger */getMungers() { return mungers; } - - /** - * could this(*) pcd ever match - */ - public final boolean hasThis() { - if (getKind().neverHasThis()) { - return false; - } else if (getKind().isEnclosingKind()) { - return !getSignature().isStatic(); - } else if (enclosingShadow == null) { - return false; - } else { - return enclosingShadow.hasThis(); - } - } - - /** - * the type of the this object here - * - * @throws IllegalStateException if there is no this here - */ - public final UnresolvedType getThisType() { - if (!hasThis()) throw new IllegalStateException("no this"); - if (getKind().isEnclosingKind()) { - return getSignature().getDeclaringType(); - } else { - return enclosingShadow.getThisType(); - } - } - - /** - * a var referencing this - * - * @throws IllegalStateException if there is no target here - */ - public abstract Var getThisVar(); - - - - /** - * could target(*) pcd ever match - */ - public final boolean hasTarget() { - if (getKind().neverHasTarget()) { - return false; - } else if (getKind().isTargetSameAsThis()) { - return hasThis(); - } else { - return !getSignature().isStatic(); - } - } - - /** - * the type of the target object here - * - * @throws IllegalStateException if there is no target here - */ - public final UnresolvedType getTargetType() { - if (!hasTarget()) throw new IllegalStateException("no target"); - return getSignature().getDeclaringType(); - } - - /** - * a var referencing the target - * - * @throws IllegalStateException if there is no target here - */ - public abstract Var getTargetVar(); - - public UnresolvedType[] getArgTypes() { - if (getKind() == FieldSet) return new UnresolvedType[] { getSignature().getReturnType() }; - return getSignature().getParameterTypes(); - } - - public boolean isShadowForArrayConstructionJoinpoint() { - return (getKind()==ConstructorCall && signature.getDeclaringType().isArray()); - } - - public boolean isShadowForMonitor() { - return (getKind()==SynchronizationLock || getKind()==SynchronizationUnlock); - } - - // will return the right length array of ints depending on how many dimensions the array has - public ResolvedType[] getArgumentTypesForArrayConstructionShadow() { - String s = signature.getDeclaringType().getSignature(); + + /** + * could this(*) pcd ever match + */ + public final boolean hasThis() { + if (getKind().neverHasThis()) { + return false; + } else if (getKind().isEnclosingKind()) { + return !getSignature().isStatic(); + } else if (enclosingShadow == null) { + return false; + } else { + return enclosingShadow.hasThis(); + } + } + + /** + * the type of the this object here + * + * @throws IllegalStateException if there is no this here + */ + public final UnresolvedType getThisType() { + if (!hasThis()) + throw new IllegalStateException("no this"); + if (getKind().isEnclosingKind()) { + return getSignature().getDeclaringType(); + } else { + return enclosingShadow.getThisType(); + } + } + + /** + * a var referencing this + * + * @throws IllegalStateException if there is no target here + */ + public abstract Var getThisVar(); + + /** + * could target(*) pcd ever match + */ + public final boolean hasTarget() { + if (getKind().neverHasTarget()) { + return false; + } else if (getKind().isTargetSameAsThis()) { + return hasThis(); + } else { + return !getSignature().isStatic(); + } + } + + /** + * the type of the target object here + * + * @throws IllegalStateException if there is no target here + */ + public final UnresolvedType getTargetType() { + if (!hasTarget()) + throw new IllegalStateException("no target"); + return getSignature().getDeclaringType(); + } + + /** + * a var referencing the target + * + * @throws IllegalStateException if there is no target here + */ + public abstract Var getTargetVar(); + + public UnresolvedType[] getArgTypes() { + if (getKind() == FieldSet) + return new UnresolvedType[] { getSignature().getReturnType() }; + return getSignature().getParameterTypes(); + } + + public boolean isShadowForArrayConstructionJoinpoint() { + return (getKind() == ConstructorCall && signature.getDeclaringType().isArray()); + } + + public boolean isShadowForMonitor() { + return (getKind() == SynchronizationLock || getKind() == SynchronizationUnlock); + } + + // will return the right length array of ints depending on how many dimensions the array has + public ResolvedType[] getArgumentTypesForArrayConstructionShadow() { + String s = signature.getDeclaringType().getSignature(); int pos = s.indexOf("["); int dims = 1; - while (pos=names.length) return null; - return names[i]; - } - - public abstract UnresolvedType getEnclosingType(); + } + + public UnresolvedType[] getGenericArgTypes() { + if (isShadowForArrayConstructionJoinpoint()) { + return getArgumentTypesForArrayConstructionShadow(); + } + if (isShadowForMonitor()) { + return UnresolvedType.ARRAY_WITH_JUST_OBJECT; + } + if (getKind() == FieldSet) + return new UnresolvedType[] { getResolvedSignature().getGenericReturnType() }; + return getResolvedSignature().getGenericParameterTypes(); + } + + public UnresolvedType getArgType(int arg) { + if (getKind() == FieldSet) + return getSignature().getReturnType(); + return getSignature().getParameterTypes()[arg]; + } + + public int getArgCount() { + if (getKind() == FieldSet) + return 1; + return getSignature().getParameterTypes().length; + } + + // /** + // * Return name of the argument at position 'i' at this shadow. This does not make sense for all shadows - but can be useful in + // * the case of, for example, method-execution. + // * + // * @return null if it cannot be determined + // */ + // public String getArgName(int i, World w) { + // String[] names = getSignature().getParameterNames(w); + // if (names == null || i >= names.length) + // return null; + // return names[i]; + // } + + public abstract UnresolvedType getEnclosingType(); public abstract Var getArgVar(int i); - + public abstract Var getThisJoinPointVar(); + public abstract Var getThisJoinPointStaticPartVar(); + public abstract Var getThisEnclosingJoinPointStaticPartVar(); - + // annotation variables public abstract Var getKindedAnnotationVar(UnresolvedType forAnnotationType); + public abstract Var getWithinAnnotationVar(UnresolvedType forAnnotationType); + public abstract Var getWithinCodeAnnotationVar(UnresolvedType forAnnotationType); + public abstract Var getThisAnnotationVar(UnresolvedType forAnnotationType); + public abstract Var getTargetAnnotationVar(UnresolvedType forAnnotationType); + public abstract Var getArgAnnotationVar(int i, UnresolvedType forAnnotationType); - + public abstract Member getEnclosingCodeSignature(); - - - /** returns the kind of shadow this is, representing what happens under this shadow - */ - public Kind getKind() { - return kind; - } - - /** returns the signature of the thing under this shadow - */ - public Member getSignature() { - return signature; - } - - /** - * returns the signature of the thing under this shadow, with - * any synthetic arguments removed - */ - public Member getMatchingSignature() { - return matchingSignature != null ? matchingSignature : signature; - } - - public void setMatchingSignature(Member member) { - this.matchingSignature = member; - } - - /** - * returns the resolved signature of the thing under this shadow - * - */ - public ResolvedMember getResolvedSignature() { - if (resolvedSignature == null) { - resolvedSignature = signature.resolve(getIWorld()); - } - return resolvedSignature; - } - - + + /** + * returns the kind of shadow this is, representing what happens under this shadow + */ + public Kind getKind() { + return kind; + } + + /** + * returns the signature of the thing under this shadow + */ + public Member getSignature() { + return signature; + } + + /** + * returns the signature of the thing under this shadow, with any synthetic arguments removed + */ + public Member getMatchingSignature() { + return matchingSignature != null ? matchingSignature : signature; + } + + public void setMatchingSignature(Member member) { + this.matchingSignature = member; + } + + /** + * returns the resolved signature of the thing under this shadow + * + */ + public ResolvedMember getResolvedSignature() { + if (resolvedSignature == null) { + resolvedSignature = signature.resolve(getIWorld()); + } + return resolvedSignature; + } + public UnresolvedType getReturnType() { - if (kind == ConstructorCall) return getSignature().getDeclaringType(); - else if (kind == FieldSet) return ResolvedType.VOID; - else if (kind == SynchronizationLock || kind==SynchronizationUnlock) return ResolvedType.VOID; + if (kind == ConstructorCall) + return getSignature().getDeclaringType(); + else if (kind == FieldSet) + return ResolvedType.VOID; + else if (kind == SynchronizationLock || kind == SynchronizationUnlock) + return ResolvedType.VOID; return getResolvedSignature().getGenericReturnType(); } - - /** - * These names are the ones that will be returned by thisJoinPoint.getKind() - * Those need to be documented somewhere - */ - public static final Kind MethodCall = new Kind(JoinPoint.METHOD_CALL, 1, true); - public static final Kind ConstructorCall = new Kind(JoinPoint.CONSTRUCTOR_CALL, 2, true); - public static final Kind MethodExecution = new Kind(JoinPoint.METHOD_EXECUTION, 3, false); - public static final Kind ConstructorExecution = new Kind(JoinPoint.CONSTRUCTOR_EXECUTION, 4, false); - public static final Kind FieldGet = new Kind(JoinPoint.FIELD_GET, 5, true); - public static final Kind FieldSet = new Kind(JoinPoint.FIELD_SET, 6, true); - public static final Kind StaticInitialization = new Kind(JoinPoint.STATICINITIALIZATION, 7, false); - public static final Kind PreInitialization = new Kind(JoinPoint.PREINITIALIZATION, 8, false); - public static final Kind AdviceExecution = new Kind(JoinPoint.ADVICE_EXECUTION, 9, false); - public static final Kind Initialization = new Kind(JoinPoint.INITIALIZATION, 10, false); - public static final Kind ExceptionHandler = new Kind(JoinPoint.EXCEPTION_HANDLER, 11, true); - public static final Kind SynchronizationLock = new Kind(JoinPoint.SYNCHRONIZATION_LOCK, 12, true); - public static final Kind SynchronizationUnlock= new Kind(JoinPoint.SYNCHRONIZATION_UNLOCK, 13, true); - - // Bits here are 1<<(Kind.getKey()) - and unfortunately keys didn't start at zero so bits here start at 2 - public static final int MethodCallBit = 0x002; - public static final int ConstructorCallBit = 0x004; - public static final int MethodExecutionBit = 0x008; - public static final int ConstructorExecutionBit = 0x010; - public static final int FieldGetBit = 0x020; - public static final int FieldSetBit = 0x040; - public static final int StaticInitializationBit = 0x080; - public static final int PreInitializationBit = 0x100; - public static final int AdviceExecutionBit = 0x200; - public static final int InitializationBit = 0x400; - public static final int ExceptionHandlerBit = 0x800; - public static final int SynchronizationLockBit =0x1000; - public static final int SynchronizationUnlockBit=0x2000; - - public static final int MAX_SHADOW_KIND = 13; - public static final Kind[] SHADOW_KINDS = new Kind[] { - MethodCall, ConstructorCall, MethodExecution, ConstructorExecution, - FieldGet, FieldSet, StaticInitialization, PreInitialization, - AdviceExecution, Initialization, ExceptionHandler,SynchronizationLock,SynchronizationUnlock - }; - - public static final int ALL_SHADOW_KINDS_BITS; - public static final int NO_SHADOW_KINDS_BITS; - - static { - ALL_SHADOW_KINDS_BITS = 0x3ffe; - NO_SHADOW_KINDS_BITS = 0x0000; - } - - /** - * Return count of how many bits set in the supplied parameter. - */ + /** + * These names are the ones that will be returned by thisJoinPoint.getKind() Those need to be documented somewhere + */ + public static final Kind MethodCall = new Kind(JoinPoint.METHOD_CALL, 1, true); + public static final Kind ConstructorCall = new Kind(JoinPoint.CONSTRUCTOR_CALL, 2, true); + public static final Kind MethodExecution = new Kind(JoinPoint.METHOD_EXECUTION, 3, false); + public static final Kind ConstructorExecution = new Kind(JoinPoint.CONSTRUCTOR_EXECUTION, 4, false); + public static final Kind FieldGet = new Kind(JoinPoint.FIELD_GET, 5, true); + public static final Kind FieldSet = new Kind(JoinPoint.FIELD_SET, 6, true); + public static final Kind StaticInitialization = new Kind(JoinPoint.STATICINITIALIZATION, 7, false); + public static final Kind PreInitialization = new Kind(JoinPoint.PREINITIALIZATION, 8, false); + public static final Kind AdviceExecution = new Kind(JoinPoint.ADVICE_EXECUTION, 9, false); + public static final Kind Initialization = new Kind(JoinPoint.INITIALIZATION, 10, false); + public static final Kind ExceptionHandler = new Kind(JoinPoint.EXCEPTION_HANDLER, 11, true); + public static final Kind SynchronizationLock = new Kind(JoinPoint.SYNCHRONIZATION_LOCK, 12, true); + public static final Kind SynchronizationUnlock = new Kind(JoinPoint.SYNCHRONIZATION_UNLOCK, 13, true); + + // Bits here are 1<<(Kind.getKey()) - and unfortunately keys didn't start at zero so bits here start at 2 + public static final int MethodCallBit = 0x002; + public static final int ConstructorCallBit = 0x004; + public static final int MethodExecutionBit = 0x008; + public static final int ConstructorExecutionBit = 0x010; + public static final int FieldGetBit = 0x020; + public static final int FieldSetBit = 0x040; + public static final int StaticInitializationBit = 0x080; + public static final int PreInitializationBit = 0x100; + public static final int AdviceExecutionBit = 0x200; + public static final int InitializationBit = 0x400; + public static final int ExceptionHandlerBit = 0x800; + public static final int SynchronizationLockBit = 0x1000; + public static final int SynchronizationUnlockBit = 0x2000; + + public static final int MAX_SHADOW_KIND = 13; + public static final Kind[] SHADOW_KINDS = new Kind[] { MethodCall, ConstructorCall, MethodExecution, ConstructorExecution, + FieldGet, FieldSet, StaticInitialization, PreInitialization, AdviceExecution, Initialization, ExceptionHandler, + SynchronizationLock, SynchronizationUnlock }; + + public static final int ALL_SHADOW_KINDS_BITS; + public static final int NO_SHADOW_KINDS_BITS; + + static { + ALL_SHADOW_KINDS_BITS = 0x3ffe; + NO_SHADOW_KINDS_BITS = 0x0000; + } + + /** + * Return count of how many bits set in the supplied parameter. + */ public static int howMany(int i) { int count = 0; - for (int j = 0; j 1) { - + if (sorted != null && getIWorld().getLint().unorderedAdviceAtShadow.isEnabled() && mungers.size() > 1) { + // Stores a set of strings of the form 'aspect1:aspect2' which indicates there is no // precedence specified between the two aspects at this shadow. Set clashingAspects = new HashSet(); int max = mungers.size(); - + // Compare every pair of advice mungers - for (int i = max-1; i >=0; i--) { - for (int j=0; j= 0; i--) { + for (int j = 0; j < i; j++) { + Object a = mungers.get(i); + Object b = mungers.get(j); + + // Make sure they are the right type + if (a instanceof BcelAdvice && b instanceof BcelAdvice) { + BcelAdvice adviceA = (BcelAdvice) a; + BcelAdvice adviceB = (BcelAdvice) b; + if (!adviceA.concreteAspect.equals(adviceB.concreteAspect)) { + AdviceKind adviceKindA = adviceA.getKind(); + AdviceKind adviceKindB = adviceB.getKind(); + + // make sure they are the nice ones (<6) and not any synthetic advice ones we + // create to support other features of the language. + if (adviceKindA.getKey() < (byte) 6 && adviceKindB.getKey() < (byte) 6 + && adviceKindA.getPrecedence() == adviceKindB.getPrecedence()) { + + // Ask the world if it knows about precedence between these + Integer order = getIWorld().getPrecedenceIfAny(adviceA.concreteAspect, adviceB.concreteAspect); + + if (order != null && order.equals(new Integer(0))) { + String key = adviceA.getDeclaringAspect() + ":" + adviceB.getDeclaringAspect(); + String possibleExistingKey = adviceB.getDeclaringAspect() + ":" + adviceA.getDeclaringAspect(); + if (!clashingAspects.contains(possibleExistingKey)) + clashingAspects.add(key); + } + } + } + } + } + } for (Iterator iter = clashingAspects.iterator(); iter.hasNext();) { String element = (String) iter.next(); - String aspect1 = element.substring(0,element.indexOf(":")); - String aspect2 = element.substring(element.indexOf(":")+1); - getIWorld().getLint().unorderedAdviceAtShadow.signal( - new String[]{this.toString(),aspect1,aspect2}, - this.getSourceLocation(),null); - } + String aspect1 = element.substring(0, element.indexOf(":")); + String aspect2 = element.substring(element.indexOf(":") + 1); + getIWorld().getLint().unorderedAdviceAtShadow.signal(new String[] { this.toString(), aspect1, aspect2 }, this + .getSourceLocation(), null); + } } } - - /** Prepare the shadow for implementation. After this is done, the shadow - * should be in such a position that each munger simply needs to be implemented. + + /** + * Prepare the shadow for implementation. After this is done, the shadow should be in such a position that each munger simply + * needs to be implemented. */ protected void prepareForMungers() { - throw new RuntimeException("Generic shadows cannot be prepared"); + throw new RuntimeException("Generic shadows cannot be prepared"); } - + /* - * Ensure we report a nice source location - particular in the case - * where the source info is missing (binary weave). + * Ensure we report a nice source location - particular in the case where the source info is missing (binary weave). */ private String beautifyLocation(ISourceLocation isl) { StringBuffer nice = new StringBuffer(); - if (isl==null || isl.getSourceFile()==null || isl.getSourceFile().getName().indexOf("no debug info available")!=-1) { + if (isl == null || isl.getSourceFile() == null || isl.getSourceFile().getName().indexOf("no debug info available") != -1) { nice.append("no debug info available"); - } else { - // can't use File.getName() as this fails when a Linux box encounters a path created on Windows and vice-versa - int takeFrom = isl.getSourceFile().getPath().lastIndexOf('/'); - if (takeFrom == -1) { - takeFrom = isl.getSourceFile().getPath().lastIndexOf('\\'); - } - int binary = isl.getSourceFile().getPath().lastIndexOf('!'); - if (binary != -1 && binary < takeFrom) { + } else { + // can't use File.getName() as this fails when a Linux box encounters a path created on Windows and vice-versa + int takeFrom = isl.getSourceFile().getPath().lastIndexOf('/'); + if (takeFrom == -1) { + takeFrom = isl.getSourceFile().getPath().lastIndexOf('\\'); + } + int binary = isl.getSourceFile().getPath().lastIndexOf('!'); + if (binary != -1 && binary < takeFrom) { // we have been woven by a binary aspect - String pathToBinaryLoc = isl.getSourceFile().getPath().substring(0,binary + 1); - if (pathToBinaryLoc.indexOf(".jar") != -1) { - // only want to add the extra info if we're from a jar file - int lastSlash = pathToBinaryLoc.lastIndexOf('/'); - if (lastSlash == -1) { + String pathToBinaryLoc = isl.getSourceFile().getPath().substring(0, binary + 1); + if (pathToBinaryLoc.indexOf(".jar") != -1) { + // only want to add the extra info if we're from a jar file + int lastSlash = pathToBinaryLoc.lastIndexOf('/'); + if (lastSlash == -1) { lastSlash = pathToBinaryLoc.lastIndexOf('\\'); } - nice.append(pathToBinaryLoc.substring(lastSlash + 1)); + nice.append(pathToBinaryLoc.substring(lastSlash + 1)); } } - nice.append(isl.getSourceFile().getPath().substring(takeFrom +1)); - if (isl.getLine()!=0) nice.append(":").append(isl.getLine()); - // if it's a binary file then also want to give the file name - if (isl.getSourceFileName() != null ) nice.append("(from " + isl.getSourceFileName() + ")"); + nice.append(isl.getSourceFile().getPath().substring(takeFrom + 1)); + if (isl.getLine() != 0) + nice.append(":").append(isl.getLine()); + // if it's a binary file then also want to give the file name + if (isl.getSourceFileName() != null) + nice.append("(from " + isl.getSourceFileName() + ")"); } return nice.toString(); } - + /* - * Report a message about the advice weave that has occurred. Some messing about - * to make it pretty ! This code is just asking for an NPE to occur ... + * Report a message about the advice weave that has occurred. Some messing about to make it pretty ! This code is just asking + * for an NPE to occur ... */ private void reportWeavingMessage(ShadowMunger munger) { - Advice advice = (Advice)munger; + Advice advice = (Advice) munger; AdviceKind aKind = advice.getKind(); // Only report on interesting advice kinds ... - if (aKind == null || advice.getConcreteAspect()==null) { - // We suspect someone is programmatically driving the weaver + if (aKind == null || advice.getConcreteAspect() == null) { + // We suspect someone is programmatically driving the weaver // (e.g. IdWeaveTestCase in the weaver testcases) return; } - if (!( aKind.equals(AdviceKind.Before) || - aKind.equals(AdviceKind.After) || - aKind.equals(AdviceKind.AfterReturning) || - aKind.equals(AdviceKind.AfterThrowing) || - aKind.equals(AdviceKind.Around) || - aKind.equals(AdviceKind.Softener))) return; - + if (!(aKind.equals(AdviceKind.Before) || aKind.equals(AdviceKind.After) || aKind.equals(AdviceKind.AfterReturning) + || aKind.equals(AdviceKind.AfterThrowing) || aKind.equals(AdviceKind.Around) || aKind.equals(AdviceKind.Softener))) + return; + // synchronized blocks are implemented with multiple monitor_exit instructions in the bytecode // (one for normal exit from the method, one for abnormal exit), we only want to tell the user // once we have advised the end of the sync block, even though under the covers we will have // woven both exit points - if (this.kind==Shadow.SynchronizationUnlock) { - if (advice.lastReportedMonitorExitJoinpointLocation==null) { + if (this.kind == Shadow.SynchronizationUnlock) { + if (advice.lastReportedMonitorExitJoinpointLocation == null) { // this is the first time through, let's continue... advice.lastReportedMonitorExitJoinpointLocation = getSourceLocation(); } else { - if (areTheSame(getSourceLocation(),advice.lastReportedMonitorExitJoinpointLocation)) { - // Don't report it again! - advice.lastReportedMonitorExitJoinpointLocation=null; - return; - } - // hmmm, this means some kind of nesting is going on, urgh - advice.lastReportedMonitorExitJoinpointLocation=getSourceLocation(); + if (areTheSame(getSourceLocation(), advice.lastReportedMonitorExitJoinpointLocation)) { + // Don't report it again! + advice.lastReportedMonitorExitJoinpointLocation = null; + return; + } + // hmmm, this means some kind of nesting is going on, urgh + advice.lastReportedMonitorExitJoinpointLocation = getSourceLocation(); } } - + String description = advice.getKind().toString(); String advisedType = this.getEnclosingType().getName(); - String advisingType= advice.getConcreteAspect().getName(); + String advisingType = advice.getConcreteAspect().getName(); Message msg = null; if (advice.getKind().equals(AdviceKind.Softener)) { - msg = WeaveMessage.constructWeavingMessage( - WeaveMessage.WEAVEMESSAGE_SOFTENS, - new String[]{advisedType,beautifyLocation(getSourceLocation()), - advisingType,beautifyLocation(munger.getSourceLocation())}, - advisedType, - advisingType); + msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_SOFTENS, new String[] { advisedType, + beautifyLocation(getSourceLocation()), advisingType, beautifyLocation(munger.getSourceLocation()) }, + advisedType, advisingType); } else { - boolean runtimeTest = ((BcelAdvice)advice).hasDynamicTests(); + boolean runtimeTest = ((BcelAdvice) advice).hasDynamicTests(); String joinPointDescription = this.toString(); - msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ADVISES, - new String[]{ joinPointDescription, advisedType, beautifyLocation(getSourceLocation()), - description, - advisingType,beautifyLocation(munger.getSourceLocation()), - (runtimeTest?" [with runtime test]":"")}, - advisedType, + msg = WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ADVISES, new String[] { joinPointDescription, + advisedType, beautifyLocation(getSourceLocation()), description, advisingType, + beautifyLocation(munger.getSourceLocation()), (runtimeTest ? " [with runtime test]" : "") }, advisedType, advisingType); - // Boolean.toString(runtimeTest)}); + // Boolean.toString(runtimeTest)}); } getIWorld().getMessageHandler().handleMessage(msg); } - private boolean areTheSame(ISourceLocation locA, ISourceLocation locB) { - if (locA==null) return locB==null; - if (locB==null) return false; - if (locA.getLine()!=locB.getLine()) return false; + if (locA == null) + return locB == null; + if (locB == null) + return false; + if (locA.getLine() != locB.getLine()) + return false; File fA = locA.getSourceFile(); File fB = locA.getSourceFile(); - if (fA==null) return fB==null; - if (fB==null) return false; + if (fA == null) + return fB == null; + if (fB == null) + return false; return fA.getName().equals(fB.getName()); } public IRelationship.Kind determineRelKind(ShadowMunger munger) { - AdviceKind ak = ((Advice)munger).getKind(); - if (ak.getKey()==AdviceKind.Before.getKey()) - return IRelationship.Kind.ADVICE_BEFORE; - else if (ak.getKey()==AdviceKind.After.getKey()) - return IRelationship.Kind.ADVICE_AFTER; - else if (ak.getKey()==AdviceKind.AfterThrowing.getKey()) - return IRelationship.Kind.ADVICE_AFTERTHROWING; - else if (ak.getKey()==AdviceKind.AfterReturning.getKey()) - return IRelationship.Kind.ADVICE_AFTERRETURNING; - else if (ak.getKey()==AdviceKind.Around.getKey()) - return IRelationship.Kind.ADVICE_AROUND; - else if (ak.getKey()==AdviceKind.CflowEntry.getKey() || - ak.getKey()==AdviceKind.CflowBelowEntry.getKey() || - ak.getKey()==AdviceKind.InterInitializer.getKey() || - ak.getKey()==AdviceKind.PerCflowEntry.getKey() || - ak.getKey()==AdviceKind.PerCflowBelowEntry.getKey() || - ak.getKey()==AdviceKind.PerThisEntry.getKey() || - ak.getKey()==AdviceKind.PerTargetEntry.getKey() || - ak.getKey()==AdviceKind.Softener.getKey() || - ak.getKey()==AdviceKind.PerTypeWithinEntry.getKey()) { - //System.err.println("Dont want a message about this: "+ak); - return null; - } - throw new RuntimeException("Shadow.determineRelKind: What the hell is it? "+ak); - } - - /** Actually implement the (non-empty) mungers associated with this shadow */ + AdviceKind ak = ((Advice) munger).getKind(); + if (ak.getKey() == AdviceKind.Before.getKey()) + return IRelationship.Kind.ADVICE_BEFORE; + else if (ak.getKey() == AdviceKind.After.getKey()) + return IRelationship.Kind.ADVICE_AFTER; + else if (ak.getKey() == AdviceKind.AfterThrowing.getKey()) + return IRelationship.Kind.ADVICE_AFTERTHROWING; + else if (ak.getKey() == AdviceKind.AfterReturning.getKey()) + return IRelationship.Kind.ADVICE_AFTERRETURNING; + else if (ak.getKey() == AdviceKind.Around.getKey()) + return IRelationship.Kind.ADVICE_AROUND; + else if (ak.getKey() == AdviceKind.CflowEntry.getKey() || ak.getKey() == AdviceKind.CflowBelowEntry.getKey() + || ak.getKey() == AdviceKind.InterInitializer.getKey() || ak.getKey() == AdviceKind.PerCflowEntry.getKey() + || ak.getKey() == AdviceKind.PerCflowBelowEntry.getKey() || ak.getKey() == AdviceKind.PerThisEntry.getKey() + || ak.getKey() == AdviceKind.PerTargetEntry.getKey() || ak.getKey() == AdviceKind.Softener.getKey() + || ak.getKey() == AdviceKind.PerTypeWithinEntry.getKey()) { + // System.err.println("Dont want a message about this: "+ak); + return null; + } + throw new RuntimeException("Shadow.determineRelKind: What the hell is it? " + ak); + } + + /** Actually implement the (non-empty) mungers associated with this shadow */ private void implementMungers() { World world = getIWorld(); for (Iterator iter = mungers.iterator(); iter.hasNext();) { ShadowMunger munger = (ShadowMunger) iter.next(); munger.implementOn(this); - + if (world.getCrossReferenceHandler() != null) { - world.getCrossReferenceHandler().addCrossReference( - munger.getSourceLocation(), // What is being applied - this.getSourceLocation(), // Where is it being applied - determineRelKind(munger), // What kind of advice? - ((BcelAdvice)munger).hasDynamicTests() // Is a runtime test being stuffed in the code? - ); + world.getCrossReferenceHandler().addCrossReference(munger.getSourceLocation(), // What is being applied + this.getSourceLocation(), // Where is it being applied + determineRelKind(munger), // What kind of advice? + ((BcelAdvice) munger).hasDynamicTests() // Is a runtime test being stuffed in the code? + ); } - + // TAG: WeavingMessage if (!getIWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)) { reportWeavingMessage(munger); - } - + } + if (world.getModel() != null) { - //System.err.println("munger: " + munger + " on " + this); + // System.err.println("munger: " + munger + " on " + this); AsmRelationshipProvider.getDefault().adviceMunger(world.getModel(), this, munger); } } } - public String makeReflectiveFactoryString() { - return null; //XXX - } - public abstract ISourceLocation getSourceLocation(); // ---- utility - - public String toString() { - return getKind() + "(" + getSignature() + ")"; // + getSourceLines(); - } - - public String toResolvedString(World world) { - StringBuffer sb = new StringBuffer(); - sb.append(getKind()); - sb.append("("); - Member m = getSignature(); - if (m==null) { - sb.append("<>"); - } else { - ResolvedMember rm = world.resolve(m); - if (rm==null) { - sb.append("<>"); - } else { - String genString = rm.toGenericString(); - if (genString==null) { - sb.append("<>"); - } else { - sb.append(genString); - } - - } - } - sb.append(")"); - return sb.toString(); - // was: return getKind() + "(" + world.resolve(getSignature()).toGenericString() + ")"; - } - - /** - * Convert a bit array for the shadow kinds into a set of them... should only - * be used for testing - mainline code should do bit manipulation! - */ + + public String toString() { + return getKind() + "(" + getSignature() + ")"; // + getSourceLines(); + } + + public String toResolvedString(World world) { + StringBuffer sb = new StringBuffer(); + sb.append(getKind()); + sb.append("("); + Member m = getSignature(); + if (m == null) { + sb.append("<>"); + } else { + ResolvedMember rm = world.resolve(m); + if (rm == null) { + sb.append("<>"); + } else { + String genString = rm.toGenericString(); + if (genString == null) { + sb.append("<>"); + } else { + sb.append(genString); + } + + } + } + sb.append(")"); + return sb.toString(); + // was: return getKind() + "(" + world.resolve(getSignature()).toGenericString() + ")"; + } + + /** + * Convert a bit array for the shadow kinds into a set of them... should only be used for testing - mainline code should do bit + * manipulation! + */ public static Set toSet(int i) { Set results = new HashSet(); for (int j = 0; j < Shadow.SHADOW_KINDS.length; j++) { Kind k = Shadow.SHADOW_KINDS[j]; - if (k.isSet(i)) results.add(k); + if (k.isSet(i)) + results.add(k); } return results; } diff --git a/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java b/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java index 26812dc8e..3f0bdb8bd 100644 --- a/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java +++ b/weaver/src/org/aspectj/weaver/WeakClassLoaderReference.java @@ -11,61 +11,55 @@ * ******************************************************************/ package org.aspectj.weaver; -import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import org.aspectj.apache.bcel.util.ClassLoaderReference; /** - * Wraps a reference to a classloader inside a WeakReference. This should be used where we do not want the existence of - * a classloader reference to prevent garbage collection of that classloader (and possibly an associated weaver instance - * in the case of load time weaving). + * Wraps a reference to a classloader inside a WeakReference. This should be used where we do not want the existence of a + * classloader reference to prevent garbage collection of that classloader (and possibly an associated weaver instance in the case + * of load time weaving). *

* In more detail:
- * When load time weaving, the class Aj maintains a WeakHashMap from the classloader instance to a weaver instance. The - * aim is that the weaver is around as long as the classloader is and should the classloader be dereferenced then the - * weaver can also be garbage collected. The problem is that if there are many references to the classloader from within - * the weaver, these are considered hard references and cause the classloader to be long lived - even if the user of the - * classloader has dereferenced it in their code. The solution is that the weaver should use instances of - * WeakClassLoaderReference objects - so that when the users hard reference to the classloader goes, nothing in the - * weaver will cause it to hang around. There is a big assertion here that the WeakClassLoaderReference instances will - * not 'lose' their ClassLoader references until the top level ClassLoader reference is null'd. This means there is no - * need to check for the null case on get() in this WeakReference logic below, because we shouldn't be using this weaver - * if its associated ClassLoader has been collected. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=210470 + * When load time weaving, the class Aj maintains a WeakHashMap from the classloader instance to a weaver instance. The aim is that + * the weaver is around as long as the classloader is and should the classloader be dereferenced then the weaver can also be garbage + * collected. The problem is that if there are many references to the classloader from within the weaver, these are considered hard + * references and cause the classloader to be long lived - even if the user of the classloader has dereferenced it in their code. + * The solution is that the weaver should use instances of WeakClassLoaderReference objects - so that when the users hard reference + * to the classloader goes, nothing in the weaver will cause it to hang around. There is a big assertion here that the + * WeakClassLoaderReference instances will not 'lose' their ClassLoader references until the top level ClassLoader reference is + * null'd. This means there is no need to check for the null case on get() in this WeakReference logic below, because we shouldn't + * be using this weaver if its associated ClassLoader has been collected. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=210470 * * * @author Andy Clement */ public class WeakClassLoaderReference implements ClassLoaderReference { - private int hashcode; - - private WeakReference loaderRef; - - public WeakClassLoaderReference(ClassLoader loader) { - loaderRef = new WeakReference(loader); - hashcode = loader.hashCode() * 37; - } + private int hashcode; - public WeakClassLoaderReference(ClassLoader loader, ReferenceQueue q) { - loaderRef = new WeakReference(loader, q); - hashcode = loader.hashCode() * 37; - } - - public ClassLoader getClassLoader() { - ClassLoader instance = (ClassLoader) loaderRef.get(); - // Assert instance!=null - return instance; - } + private WeakReference loaderRef; - public boolean equals(Object obj) { - if (!(obj instanceof WeakClassLoaderReference)) return false; - WeakClassLoaderReference other = (WeakClassLoaderReference) obj; - return (other.hashcode == hashcode); - } + public WeakClassLoaderReference(ClassLoader loader) { + loaderRef = new WeakReference(loader); + hashcode = loader.hashCode() * 37; + } + + public ClassLoader getClassLoader() { + ClassLoader instance = (ClassLoader) loaderRef.get(); + // Assert instance!=null + return instance; + } + + public boolean equals(Object obj) { + if (!(obj instanceof WeakClassLoaderReference)) + return false; + WeakClassLoaderReference other = (WeakClassLoaderReference) obj; + return (other.hashcode == hashcode); + } + + public int hashCode() { + return hashcode; + } - public int hashCode() { - return hashcode; - } - } diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 9360c9c4a..b0aa54587 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -1018,24 +1018,24 @@ public abstract class World implements Dump.INode { return sb.toString(); } - public ResolvedType[] getAllTypes() { - List/* ResolvedType */results = new ArrayList(); - - collectTypes(expendableMap, results); - collectTypes(tMap, results); - return (ResolvedType[]) results.toArray(new ResolvedType[results.size()]); - } - - private void collectTypes(Map map, List/* ResolvedType */results) { - for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) { - String key = (String) iterator.next(); - ResolvedType type = get(key); - if (type != null) - results.add(type); - else - System.err.println("null!:" + key); - } - } + // public ResolvedType[] getAllTypes() { + // List/* ResolvedType */results = new ArrayList(); + // + // collectTypes(expendableMap, results); + // collectTypes(tMap, results); + // return (ResolvedType[]) results.toArray(new ResolvedType[results.size()]); + // } + // + // private void collectTypes(Map map, List/* ResolvedType */results) { + // for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) { + // String key = (String) iterator.next(); + // ResolvedType type = get(key); + // if (type != null) + // results.add(type); + // else + // System.err.println("null!:" + key); + // } + // } }