av.visit("name", classNameSeparatedBySlash.substring(classNameSeparatedBySlash.lastIndexOf('/') + 1));
}
av.visitEnd();
// Public No-Arg Constructor
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(superType), "<init>", "()V");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
if(!componentType.isPrimitive() && ArrayValue.class.isAssignableFrom(superType)){
//@Override
//public Object getItem() {
// if(null == adaptedValue) {
// return null;
// }
// int len = adaptedValue.size();
// Float[] array = new Float[len];
// adaptedValue.toArray(array);
// return array;
// }
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getItem", "()Ljava/lang/Object;", null, null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
Label l0 = new Label();
mv.visitJumpInsn(Opcodes.IFNONNULL, l0);
mv.visitInsn(Opcodes.ACONST_NULL);
mv.visitInsn(Opcodes.ARETURN);
mv.visitLabel(l0);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I");
mv.visitVarInsn(Opcodes.ISTORE, 1);
mv.visitVarInsn(Opcodes.ILOAD, 1);
mv.visitTypeInsn(Opcodes.ANEWARRAY, componentClassNameSeparatedBySlash);
mv.visitVarInsn(Opcodes.ASTORE, 2);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
mv.visitVarInsn(Opcodes.ALOAD, 2);
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
mv.visitInsn(Opcodes.POP);
mv.visitVarInsn(Opcodes.ALOAD, 2);
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(2, 3);
mv.visitEnd();
//@Override
//public void setItem(Object array) {
// Float[] floatArray = (Float[])array;
// adaptedValue = (Collection<T>) Arrays.asList(floatArray);
//}
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(Ljava/lang/Object;)V", null, null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitTypeInsn(Opcodes.CHECKCAST, "[L"+componentClassNameSeparatedBySlash+";");
mv.visitVarInsn(Opcodes.ASTORE, 2);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ALOAD, 2);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "asList", "([Ljava/lang/Object;)Ljava/util/List;");
mv.visitFieldInsn(Opcodes.PUTFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(2, 3);
mv.visitEnd();
}
// @XmlElement(name="item", nillable=true)
// public Collection<COMPONENT_TYPE> getAdaptedValue() {
// return super.getAdaptedValue();
// }
// OR
// @XmlValue
// public Collection<COMPONENT_TYPE> getAdaptedValue() {
// return super.getAdaptedValue();
// }
if("[B".equals(componentClassNameSeparatedBySlash)) {
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getAdaptedValue", "()Ljava/util/Collection;", "()Ljava/util/Collection<" + componentClassNameSeparatedBySlash + ">;", null);
} else {
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getAdaptedValue", "()Ljava/util/Collection;", "()Ljava/util/Collection<L" + componentClassNameSeparatedBySlash + ";>;", null);
}
// Copy annotations
boolean hasXmlList = false;
Annotation[] annotations;
if (typeMappingInfo != null && ((annotations = getAnnotations(typeMappingInfo)) != null)) {
for (Annotation annotation : annotations) {
if(!(annotation instanceof XmlElement || annotation instanceof XmlJavaTypeAdapter)) {
Class<? extends Annotation> annotationType = annotation.annotationType();
//if(annotationType.equals(XmlList.class)) {
if(annotation instanceof XmlList) {
hasXmlList = true;
}
av = mv.visitAnnotation(L + annotationType.getName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON, true);
for (Method next : annotation.annotationType().getDeclaredMethods()) {
try {
Object nextValue = next.invoke(annotation, new Object[] {});
if (nextValue instanceof Class) {
nextValue = Type.getType(L + ((Class) nextValue).getName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON);
}
av.visit(next.getName(), nextValue);
} catch (InvocationTargetException ex) {
} catch (IllegalAccessException ex) {
}
}
av.visitEnd();
}
}
}
if(hasXmlList) {
// @XmlValue
av = mv.visitAnnotation("Ljavax/xml/bind/annotation/XmlValue;", true);
av.visitEnd();
} else {
// @XmlElement(name="item", nillable=true)
av = mv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true);
av.visit("name", ITEM);
av.visit("nillable", true);
av.visitEnd();
}
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(superType), "getAdaptedValue", "()Ljava/util/Collection;");
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
// public void setAdaptedValue(Collection<COMPONENT_TYPE> adaptedValue) {
// super.setAdaptedValue(adaptedValue);
// }
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setAdaptedValue", "(Ljava/util/Collection;)V", "(Ljava/util/Collection<L" + componentClassNameSeparatedBySlash + ";>;)V", null);
mv.visitCode();
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(superType), "setAdaptedValue", "(Ljava/util/Collection;)V");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
// public Class<?> containerClass() {
// return CONTAINER_TYPE.class;
// }
mv = cw.visitMethod(Opcodes.ACC_PROTECTED, "containerClass", "()Ljava/lang/Class;", "()Ljava/lang/Class<*>;", null);
mv.visitCode();
if(componentType.isPrimitive()) {
mv.visitFieldInsn(Opcodes.GETSTATIC, getObjectType(componentType).getQualifiedName().replace(DOT_CHR, SLASH_CHR), "TYPE", "Ljava/lang/Class;");
} else {
if(containerClassNameSeperatedBySlash.contains(";")) {
mv.visitLdcInsn(Type.getType(containerClassNameSeperatedBySlash));
} else {
mv.visitLdcInsn(Type.getType("L" + containerClassNameSeperatedBySlash + ";"));
}
}
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}