private static final int DISCOVERED_ANNOTATION_TARGET_KINDS = 0x0008;
private static final int DISCOVERED_DECLARED_SIGNATURE = 0x0010;
private static final int DISCOVERED_WHETHER_ANNOTATION_STYLE = 0x0020;
- private static final int DAMAGED = 0x0040; // see note(2) below
private static final String[] NO_INTERFACE_SIGS = new String[] {};
return javaClass;
}
- public void ensureDelegateConsistent() {
- if ((bitflag & DAMAGED) != 0) {
- resetState();
- }
- }
-
public void resetState() {
if (javaClass == null) {
// we might store the classname and allow reloading?
return wvInfo;
}
- public void addParent(ResolvedType newParent) {
- bitflag |= DAMAGED;
- if (newParent.isClass()) {
- superclassSignature = newParent.getSignature();
- superclassName = newParent.getName();
- // superClass = newParent;
- } else {
- ResolvedType[] oldInterfaceNames = getDeclaredInterfaces();
- int exists = -1;
- for (int i = 0; i < oldInterfaceNames.length; i++) {
- ResolvedType type = oldInterfaceNames[i];
- if (type.equals(newParent)) {
- exists = i;
- break;
- }
- }
- if (exists == -1) {
-
- int len = interfaceSignatures.length;
- String[] newInterfaceSignatures = new String[len + 1];
- System.arraycopy(interfaceSignatures, 0, newInterfaceSignatures, 0, len);
- newInterfaceSignatures[len] = newParent.getSignature();
- interfaceSignatures = newInterfaceSignatures;
- }
- }
- // System.err.println("javaClass: " +
- // Arrays.asList(javaClass.getInterfaceNames()) + " super " +
- // superclassName);
- // if (lazyClassGen != null) lazyClassGen.print();
- }
// -- annotation related
return false;
}
- // evil mutator - adding state not stored in the java class
- public void addAnnotation(AnnotationAJ annotation) {
- bitflag |= DAMAGED;
- int len = annotations.length;
- AnnotationAJ[] ret = new AnnotationAJ[len + 1];
- System.arraycopy(annotations, 0, ret, 0, len);
- ret[len] = annotation;
- annotations = ret;
-
- len = annotationTypes.length;
- ResolvedType[] ret2 = new ResolvedType[len + 1];
- System.arraycopy(annotationTypes, 0, ret2, 0, len);
- ret2[len] = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(annotation.getTypeName()));
- annotationTypes = ret2;
- }
public boolean isAnnotationWithRuntimeRetention() {
return (getRetentionPolicy() == null ? false : getRetentionPolicy().equals("RUNTIME"));
getSourceContext().tidy();
}
- // --- methods for testing
-
- // for testing - if we have this attribute, return it - will return null if
- // it doesnt know anything
- // public AjAttribute[] getAttributes(String name) {
- // List results = new ArrayList();
- // List l =
- // BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass
- // .getAttributes(),
- // getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld(),
- // AjAttribute.WeaverVersionInfo.UNKNOWN);
- // for (Iterator iter = l.iterator(); iter.hasNext();) {
- // AjAttribute element = (AjAttribute) iter.next();
- // if (element.getNameString().equals(name)) results.add(element);
- // }
- // if (results.size()>0) {
- // return (AjAttribute[])results.toArray(new AjAttribute[]{});
- // }
- // return null;
- // }
- //
- // // for testing - use with the method above - this returns *all* including
- // those that are not Aj attributes
- // public String[] getAttributeNames() {
- // Attribute[] as = javaClass.getAttributes();
- // String[] strs = new String[as.length];
- // for (int j = 0; j < as.length; j++) {
- // strs[j] = as[j].getName();
- // }
- // return strs;
- // }
-
- // for testing
- public void addPointcutDefinition(ResolvedPointcutDefinition d) {
- bitflag |= DAMAGED;
- int len = pointcuts.length;
- ResolvedPointcutDefinition[] ret = new ResolvedPointcutDefinition[len + 1];
- System.arraycopy(pointcuts, 0, ret, 0, len);
- ret[len] = d;
- pointcuts = ret;
- }
-
public boolean hasBeenWoven() {
return hasBeenWoven;
}
* The main part of implementing declare parents extends. Modify super ctor calls to target the new type.
*/
public boolean attemptToModifySuperCalls(BcelClassWeaver weaver, LazyClassGen newParentTarget, ResolvedType newParent) {
- String currentParent = newParentTarget.getSuperClassname();
+ String currentParent = newParentTarget.getSuperClass().getName();// getName();
if (newParent.getGenericType() != null)
newParent = newParent.getGenericType(); // target new super calls at
// the generic type if its
gen.addMethodGen(mg1);
- gen.addInterface(munger.getInterfaceType(), getSourceLocation());
+ gen.addInterface(munger.getInterfaceType().resolve(weaver.getWorld()), getSourceLocation());
return true;
} else {
String className = classFile.getClassName();
ResolvedType theType = world.resolve(className);
if (theType != null) {
- BcelObjectType classType = BcelWorld.getBcelObjectType(theType);
- if (classType != null)
- classType.ensureDelegateConsistent();
+ theType.ensureConsistent();
}
}
// itself
// (like transform super calls) - that is done in
// BcelTypeMunger.mungeNewParent()
- classType.addParent(newParent);
+ // classType.addParent(newParent);
+ onType.addParent(newParent);
ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
newParentMunger.setSourceLocation(p.getSourceLocation());
onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p)));
if (!result.isExposedToWeaver())
return; // cant need resetting
ReferenceType rt = (ReferenceType) result;
- rt.getDelegate().ensureDelegateConsistent();
+ rt.ensureConsistent();
+ // rt.getDelegate().ensureDelegateConsistent();
// If we want to rebuild it 'from scratch' then:
// ClassParser cp = new ClassParser(new
// ByteArrayInputStream(newbytes),new String(cs));
// itself
// (like transform super calls) - that is done in
// BcelTypeMunger.mungeNewParent()
- classType.addParent(newParent);
+ // classType.addParent(newParent);
+ onType.addParent(newParent);
ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
newParentMunger.setSourceLocation(p.getSourceLocation());
onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, getCrosscuttingMembersSet()
private long calculatedSerialVersionUID;
private boolean hasClinit = false;
+ private ResolvedType[] extraSuperInterfaces = null;
+ private ResolvedType superclass = null;
+
// ---
static class InlinedSourceFileInfo {
}
/**
- * When working with 1.5 generics, a signature attribute is attached to the type which indicates how it was declared. This
- * routine ensures the signature attribute for what we are about to write out is correct. Basically its responsibilities are: 1.
- * Checking whether the attribute needs changing (i.e. did weaving change the type hierarchy) 2. If it did, removing the old
- * attribute 3. Check if we need an attribute at all, are we generic? are our supertypes parameterized/generic? 4. Build the new
- * attribute which includes all typevariable, supertype and superinterface information
+ * When working with Java generics, a signature attribute is attached to the type which indicates how it was declared. This
+ * routine ensures the signature attribute for the class we are about to write out is correct. Basically its responsibilities
+ * are:
+ * <ol>
+ * <li>
+ * Checking whether the attribute needs changing (ie. did weaving change the type hierarchy) - if it did, remove the old
+ * attribute
+ * <li>
+ * Check if we need an attribute at all, are we generic? are our supertypes parameterized/generic?
+ * <li>
+ * Build the new attribute which includes all typevariable, supertype and superinterface information
+ * </ol>
*/
private void fixupGenericSignatureAttribute() {
- if (getWorld() != null && !getWorld().isInJava5Mode())
+ if (getWorld() != null && !getWorld().isInJava5Mode()) {
return;
+ }
// TODO asc generics Temporarily assume that types we generate dont need a signature attribute (closure/etc).. will need
// revisiting no doubt...
- if (myType == null)
+ if (myType == null) {
return;
+ }
// 1. Has anything changed that would require us to modify this attribute?
- if (!regenerateGenericSignatureAttribute)
+ if (!regenerateGenericSignatureAttribute) {
return;
+ }
// 2. Find the old attribute
Signature sigAttr = null;
if (typeX.isGenericType() || typeX.isParameterizedType())
needAttribute = true;
}
+ if (extraSuperInterfaces != null) {
+ for (int i = 0; i < extraSuperInterfaces.length; i++) {
+ ResolvedType interfaceType = extraSuperInterfaces[i];
+ if (interfaceType.isGenericType() || interfaceType.isParameterizedType())
+ needAttribute = true;
+ }
+ }
// check the supertype
- ResolvedType superclassRTX = myType.getSuperclass();
+ ResolvedType superclassRTX = getSuperClass();
if (superclassRTX.isGenericType() || superclassRTX.isParameterizedType())
needAttribute = true;
}
signature.append(">");
}
// now the supertype
- String supersig = myType.getSuperclass().getSignatureForAttribute();
+ String supersig = getSuperClass().getSignatureForAttribute();
signature.append(supersig);
ResolvedType[] interfaceRTXs = myType.getDeclaredInterfaces();
for (int i = 0; i < interfaceRTXs.length; i++) {
String s = interfaceRTXs[i].getSignatureForAttribute();
signature.append(s);
}
- if (sigAttr != null)
+ if (extraSuperInterfaces != null) {
+ for (int i = 0; i < extraSuperInterfaces.length; i++) {
+ String s = extraSuperInterfaces[i].getSignatureForAttribute();
+ signature.append(s);
+ }
+ }
+ if (sigAttr != null) {
myGen.removeAttribute(sigAttr);
+ }
myGen.addAttribute(createSignatureAttribute(signature.toString()));
}
}
classGens.add(newClass);
}
- public void addInterface(UnresolvedType typeX, ISourceLocation sourceLocation) {
+ public void addInterface(ResolvedType newInterface, ISourceLocation sourceLocation) {
regenerateGenericSignatureAttribute = true;
- myGen.addInterface(typeX.getRawName());
- if (!typeX.equals(UnresolvedType.SERIALIZABLE))
- warnOnAddedInterface(typeX.getName(), sourceLocation);
+
+ if (extraSuperInterfaces == null) {
+ extraSuperInterfaces = new ResolvedType[1];
+ extraSuperInterfaces[0] = newInterface;
+ } else {
+ ResolvedType[] x = new ResolvedType[extraSuperInterfaces.length + 1];
+ System.arraycopy(extraSuperInterfaces, 0, x, 1, extraSuperInterfaces.length);
+ x[0] = newInterface;
+ extraSuperInterfaces = x;
+ }
+ myGen.addInterface(newInterface.getRawName());
+ if (!newInterface.equals(UnresolvedType.SERIALIZABLE))
+ warnOnAddedInterface(newInterface.getName(), sourceLocation);
}
- public void setSuperClass(ResolvedType typeX) {
+ public void setSuperClass(ResolvedType newSuperclass) {
regenerateGenericSignatureAttribute = true;
- myType.addParent(typeX); // used for the attribute
- if (typeX.getGenericType() != null)
- typeX = typeX.getGenericType();
- myGen.setSuperclassName(typeX.getName()); // used in the real class data
+ superclass = newSuperclass;
+ // myType.addParent(typeX); // used for the attribute
+ if (newSuperclass.getGenericType() != null) {
+ newSuperclass = newSuperclass.getGenericType();
+ }
+ myGen.setSuperclassName(newSuperclass.getName()); // used in the real class data
}
- public String getSuperClassname() {
- return myGen.getSuperclassName();
- }
+ // public String getSuperClassname() {
+ // return myGen.getSuperclassName();
+ // }
- // FIXME asc not great that some of these ask the gen and some ask the type ! (see the related setters too)
public ResolvedType getSuperClass() {
+ if (superclass != null) {
+ return superclass;
+ }
return myType.getSuperclass();
}
List ret = new ArrayList();
ret.add(this);
ret.addAll(classGens);
-
return ret;
}