@Test @JavaVersionRule.Enforce(7) public void testMethodTypeConstantPool() throws Exception { Class<? extends Qux> qux = new ByteBuddy() .subclass(Qux.class) .method(isDeclaredBy(Qux.class)) .intercept(FixedValue.value(JavaConstant.MethodType.of(void.class, Object.class))) .make() .load(Qux.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER) .getLoaded(); assertThat(qux.getDeclaredFields().length, is(0)); assertThat(qux.getDeclaredConstructor().newInstance().bar(), is(makeMethodType(void.class, Object.class))); }
public static AssignerConfigurable value(Object fixedValue) { Class<?> type = fixedValue.getClass(); if (type == String.class) { return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class); } else if (type == Byte.class) { return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class); } else if (type == Short.class) { return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class); } else if (type == Character.class) { return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class); } else if (type == Integer.class) { return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class); } else if (type == Long.class) { return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class); } else if (type == Float.class) { return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class); } else if (type == Double.class) { return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type); } else { return reference(fixedValue); } }
FixedValue implements Implementation { public static AssignerConfigurable value(Object fixedValue) { Class<?> type = fixedValue.getClass(); if (type == String.class) { return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class); } else if (type == Byte.class) { return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class); } else if (type == Short.class) { return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class); } else if (type == Character.class) { return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class); } else if (type == Integer.class) { return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class); } else if (type == Long.class) { return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class); } else if (type == Float.class) { return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class); } else if (type == Double.class) { return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type); } else { return reference(fixedValue); } } }
FixedValue implements Implementation { public static AssignerConfigurable value(Object fixedValue) { Class<?> type = fixedValue.getClass(); if (type == String.class) { return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class); } else if (type == Byte.class) { return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class); } else if (type == Short.class) { return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class); } else if (type == Character.class) { return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class); } else if (type == Integer.class) { return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class); } else if (type == Long.class) { return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class); } else if (type == Float.class) { return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class); } else if (type == Double.class) { return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type); } else { return reference(fixedValue); } } protected  FixedValue(Assigner assigner, Assigner.Typing typing); }
FixedValue implements Implementation { public static AssignerConfigurable value(Object fixedValue) { Class<?> type = fixedValue.getClass(); if (type == String.class) { return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class); } else if (type == Byte.class) { return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class); } else if (type == Short.class) { return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class); } else if (type == Character.class) { return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class); } else if (type == Integer.class) { return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class); } else if (type == Long.class) { return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class); } else if (type == Float.class) { return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class); } else if (type == Double.class) { return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type); } else { return reference(fixedValue); } } protected  FixedValue(Assigner assigner, Assigner.Typing typing); static AssignerConfigurable value(Object fixedValue); static AssignerConfigurable reference(Object fixedValue); static AssignerConfigurable reference(Object fixedValue, String fieldName); static AssignerConfigurable value(TypeDescription fixedValue); static AssignerConfigurable value(JavaConstant fixedValue); static AssignerConfigurable argument(int index); static AssignerConfigurable self(); static Implementation nullValue(); static AssignerConfigurable originType(); }
FixedValue implements Implementation { public static AssignerConfigurable value(Object fixedValue) { Class<?> type = fixedValue.getClass(); if (type == String.class) { return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING); } else if (type == Class.class) { return new ForPoolValue(ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) fixedValue)), TypeDescription.CLASS); } else if (type == Boolean.class) { return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class); } else if (type == Byte.class) { return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class); } else if (type == Short.class) { return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class); } else if (type == Character.class) { return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class); } else if (type == Integer.class) { return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class); } else if (type == Long.class) { return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class); } else if (type == Float.class) { return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class); } else if (type == Double.class) { return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type); } else { return reference(fixedValue); } } protected  FixedValue(Assigner assigner, Assigner.Typing typing); static AssignerConfigurable value(Object fixedValue); static AssignerConfigurable reference(Object fixedValue); static AssignerConfigurable reference(Object fixedValue, String fieldName); static AssignerConfigurable value(TypeDescription fixedValue); static AssignerConfigurable value(JavaConstant fixedValue); static AssignerConfigurable argument(int index); static AssignerConfigurable self(); static Implementation nullValue(); static AssignerConfigurable originType();  }