private static GetterCall getGetterCall(Class<?> propertyType, Class<? extends Getter> getterClass) { if (TypeHelper.isPrimitive(propertyType)) { Class<?> primitiveGetter = BiInstantiatorBuilder.getPrimitiveGetter(propertyType); if (primitiveGetter == null) { throw new IllegalStateException("No primitive getter for primitive " + propertyType); } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, primitiveGetter); if (publicGetterClass != null) { return new GetterCall("get" + getPrimitiveMethodSuffix(propertyType), publicGetterClass, true); } } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, Getter.class); return new GetterCall("get", publicGetterClass, false); }
private static GetterCall getGetterCall(Class<?> propertyType, Class<? extends Getter> getterClass) { if (TypeHelper.isPrimitive(propertyType)) { Class<?> primitiveGetter = BiInstantiatorBuilder.getPrimitiveGetter(propertyType); if (primitiveGetter == null) { throw new IllegalStateException("No primitive getter for primitive " + propertyType); } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, primitiveGetter); if (publicGetterClass != null) { return new GetterCall("get" + getPrimitiveMethodSuffix(propertyType), publicGetterClass, true); } } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, Getter.class); return new GetterCall("get", publicGetterClass, false); }
private static InjectionPoint getFunctionCall(Parameter parameter, BiFunction biFunction) { if (biFunction.getClass().equals(BiFunctionGetter.class)) { Getter getter = ((BiFunctionGetter)biFunction).getGetter(); Class<?> getterClass = getter.getClass(); if (TypeHelper.isPrimitive(parameter.getType())) { Class<?> primitiveGetter = getPrimitiveGetter(parameter.getType()); if (primitiveGetter == null) { throw new IllegalStateException("No primitive getter for primitive " + parameter.getType()); } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, primitiveGetter); if (publicGetterClass != null) { return new InjectionPoint(parameter, biFunction, true, "get" + getPrimitiveMethodSuffix(parameter.getType()), publicGetterClass, true); } } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, Getter.class); return new InjectionPoint(parameter, biFunction, true, "get", publicGetterClass, false); } else { return new InjectionPoint(parameter, biFunction, false, "apply", biFunction.getClass(), false); } }
private static InjectionPoint getFunctionCall(Parameter parameter, BiFunction biFunction) { if (biFunction.getClass().equals(BiFunctionGetter.class)) { Getter getter = ((BiFunctionGetter)biFunction).getGetter(); Class<?> getterClass = getter.getClass(); if (TypeHelper.isPrimitive(parameter.getType())) { Class<?> primitiveGetter = getPrimitiveGetter(parameter.getType()); if (primitiveGetter == null) { throw new IllegalStateException("No primitive getter for primitive " + parameter.getType()); } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, primitiveGetter); if (publicGetterClass != null) { return new InjectionPoint(parameter, biFunction, true, "get" + getPrimitiveMethodSuffix(parameter.getType()), publicGetterClass, true); } } Type publicGetterClass = AsmUtils.findClosestPublicTypeExposing(getterClass, Getter.class); return new InjectionPoint(parameter, biFunction, true, "get", publicGetterClass, false); } else { return new InjectionPoint(parameter, biFunction, false, "apply", biFunction.getClass(), false); } }
@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(); } }
@Test public void testGetClosestPublicImpl() { assertEquals(HashMap.class, TypeHelper.toClass(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Map.class))); assertNull(AsmUtils.findClosestPublicTypeExposing(new HashMap<Object, Object>() {}.getClass(), Getter.class)); }
@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 addMappingCall(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, mapperClassType, prefix + index, "L" + AsmUtils.toAsmType(mapperClass) + ";"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); Method m = getMapToMethod(TypeHelper.toClass(mapperClass)); AsmUtils.invoke(mv, m); }
@Override public void addMappingCall(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, mapperClassType, prefix + index, "L" + AsmUtils.toAsmType(mapperClass) + ";"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); Method m = getMapToMethod(TypeHelper.toClass(mapperClass)); AsmUtils.invoke(mv, m); }
@Override public void addInit(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, prefix == CONSTRUCTOR_MAPPER_PREFIX ? 2 : 1); AsmUtils.addIndex(mv, index); mv.visitInsn(AALOAD); mv.visitTypeInsn(CHECKCAST, AsmUtils.toAsmType(mapperClass)); mv.visitFieldInsn(PUTFIELD, mapperClassType, prefix + index, toTargetTypeDeclaration(AsmUtils.toAsmType(mapperClass))); }
@Override public void addInit(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, prefix == CONSTRUCTOR_MAPPER_PREFIX ? 2 : 1); AsmUtils.addIndex(mv, index); mv.visitInsn(AALOAD); mv.visitTypeInsn(CHECKCAST, AsmUtils.toAsmType(mapperClass)); mv.visitFieldInsn(PUTFIELD, mapperClassType, prefix + index, toTargetTypeDeclaration(AsmUtils.toAsmType(mapperClass))); }