public static String toGenericAsmType(final Type type) { StringBuilder sb = new StringBuilder(); sb.append(toAsmType(type)); Type[] typeParameters = null; if (type instanceof ParameterizedType) { typeParameters = ((ParameterizedType) type).getActualTypeArguments(); } if (typeParameters != null && typeParameters.length > 0) { sb.append("<"); for(Type t : typeParameters) { sb.append(toTargetTypeDeclaration(toGenericAsmType(t))); } sb.append(">"); } return sb.toString(); }
public static String toGenericAsmType(final Type type) { StringBuilder sb = new StringBuilder(); sb.append(toAsmType(type)); Type[] typeParameters = null; if (type instanceof ParameterizedType) { typeParameters = ((ParameterizedType) type).getActualTypeArguments(); } if (typeParameters != null && typeParameters.length > 0) { sb.append("<"); for(Type t : typeParameters) { sb.append(toTargetTypeDeclaration(toGenericAsmType(t))); } sb.append(">"); } return sb.toString(); }
@Override public void addDeclaration(ClassWriter cw) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index, toTargetTypeDeclaration(AsmUtils.toAsmType(mapperClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(mapperClass)), null); fv.visitEnd(); } }
@Override public void addDeclaration(ClassWriter cw) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index, toTargetTypeDeclaration(AsmUtils.toAsmType(mapperClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(mapperClass)), null); fv.visitEnd(); } }
@Override public void addDeclaration(ClassWriter cw) { { FieldVisitor fvSetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index+ "Setter", toTargetTypeDeclaration(AsmUtils.toAsmType(setterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(setterClass)), null); fvSetter.visitEnd(); } }
@Override public void addDeclaration(ClassWriter cw) { { FieldVisitor fvSetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index+ "Setter", toTargetTypeDeclaration(AsmUtils.toAsmType(setterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(setterClass)), null); fvSetter.visitEnd(); } }
@Override public void addDeclaration(ClassWriter cw) { { FieldVisitor fvGetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index + "Getter", toTargetTypeDeclaration(AsmUtils.toAsmType(getterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(getterClass)), null); fvGetter.visitEnd(); } { FieldVisitor fvSetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index+ "Setter", toTargetTypeDeclaration(AsmUtils.toAsmType(setterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(setterClass)), null); fvSetter.visitEnd(); } } }
@Override public void addDeclaration(ClassWriter cw) { { FieldVisitor fvGetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index + "Getter", toTargetTypeDeclaration(AsmUtils.toAsmType(getterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(getterClass)), null); fvGetter.visitEnd(); } { FieldVisitor fvSetter = cw.visitField(ACC_PRIVATE + ACC_FINAL, prefix + index+ "Setter", toTargetTypeDeclaration(AsmUtils.toAsmType(setterClass)), toTargetTypeDeclaration(AsmUtils.toGenericAsmType(setterClass)), null); fvSetter.visitEnd(); } } }
@Test public void testToAsmType() { assertEquals("java/lang/String", AsmUtils.toAsmType(String.class)); assertEquals("java/lang/String", AsmUtils.toGenericAsmType(String.class)); assertEquals("java/util/HashMap", AsmUtils.toAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass())); assertEquals("java/util/HashMap<Ljava/lang/String;Ljava/lang/Long;>", AsmUtils.toGenericAsmType(new HashMap<String, Long>() {}.getClass().getGenericSuperclass())); }