returnType.write(s);
}
}
+
+ /**
+ * Return the member generic signature that would be suitable for inclusion in
+ * a class file Signature attribute.
+ * For:
+ * <T> List<String> getThem(T t) {}
+ * we would create:
+ * <T:Ljava/lang/Object;>(TT;)Ljava/util/List<Ljava/lang/String;>;;
+ *
+ * @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() {
+ public String getGenericSignature() {
StringBuffer sb = new StringBuffer();
if (typeVariables!=null) {
sb.append("<");
}
sb.append("(");
for (int i = 0; i < parameterTypes.length; i++) {
- UnresolvedType array_element = parameterTypes[i];
- sb.append(array_element.getSignature());
- }
+ 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);
}
/**
- * Return *full* signature for insertion in signature attribute, e.g. "T extends Number" would return "T:Ljava/lang/Number;"
+ * Return complete signature, e.g. "T extends Number" would return "T:Ljava/lang/Number;"
+ * note: MAY INCLUDE P types if bounds are parameterized types
*/
public String getSignature() {
StringBuffer sb = new StringBuffer();
return sb.toString();
}
+ /**
+ * @return signature for inclusion in an attribute, there must be no 'P' in it signatures
+ */
+ public String getSignatureForAttribute() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(name);
+ sb.append(":");
+ sb.append(((ResolvedType)upperBound).getSignatureForAttribute());
+ if (additionalInterfaceBounds!=null && additionalInterfaceBounds.length!=0) {
+ sb.append(":");
+ for (int i = 0; i < additionalInterfaceBounds.length; i++) {
+ ResolvedType iBound = (ResolvedType)additionalInterfaceBounds[i];
+ sb.append(iBound.getSignatureForAttribute());
+ }
+ }
+ return sb.toString();
+ }
+
+
public void setRank(int rank) {
this.rank=rank;
}
public String getErasureSignature() {
return getFirstBound().getErasureSignature();
}
+
}
import org.aspectj.apache.bcel.generic.FieldGen;
import org.aspectj.apache.bcel.generic.InstructionBranch;
import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.weaver.PerObjectInterfaceTypeMunger;
import org.aspectj.weaver.PrivilegedAccessMunger;
import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedMemberImpl;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.ResolvedTypeMunger;
import org.aspectj.weaver.Shadow;
}
+ if (weaver.getWorld().isInJava5Mode()){
+ String basicSignature = mangledInterMethod.getSignature();
+ String genericSignature = ((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
+ if (!basicSignature.equals(genericSignature)) {
+ // Add a signature attribute to it
+ newMethod.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+ }
+ }
// XXX make sure to check that we set exceptions properly on this guy.
weaver.addLazyMethodGen(newMethod);
weaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(),getSignature().getSourceLocation());
body.append(InstructionFactory.createReturn(returnType));
mg.definingType = onType;
+
+ if (weaver.getWorld().isInJava5Mode()) {
+ String basicSignature = mangledInterMethod.getSignature();
+ String genericSignature = ((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
+ if (!basicSignature.equals(genericSignature)) {
+ // Add a signature attribute to it
+ mg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+ }
+ }
+
weaver.addOrReplaceLazyMethodGen(mg);
addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled());
}
}
+ /**
+ * Helper method to create a signature attribute based on a string signature:
+ * e.g. "Ljava/lang/Object;LI<Ljava/lang/Double;>;"
+ */
+ private Signature createSignatureAttribute(ConstantPool cp,String signature) {
+ int nameIndex = cp.addUtf8("Signature");
+ int sigIndex = cp.addUtf8(signature);
+ return new Signature(nameIndex,2,sigIndex,cp);
+ }
+
/**
* Create any bridge method required because of covariant returns being used. This method is used in the case
* where an ITD is applied to some type and it may be in an override relationship with a method from the supertype - but
}
}
+
+
+ if (weaver.getWorld().isInJava5Mode()){
+ String basicSignature = field.getSignature();
+ String genericSignature = field.getReturnType().resolve(weaver.getWorld()).getSignatureForAttribute();
+ // String genericSignature = ((ResolvedMemberImpl)field).getSignatureForAttribute();
+ if (!basicSignature.equals(genericSignature)) {
+ // Add a signature attribute to it
+ fg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
+ }
+ }
gen.addField(fg,getSourceLocation());
}