use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldConstantTest method testCached.
@Test
public void testCached() throws Exception {
StackManipulation stackManipulation = new FieldConstant(fieldDescription).cached();
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(implementationContext).cache(new FieldConstant(fieldDescription), new TypeDescription.ForLoadedType(Field.class));
verifyNoMoreInteractions(implementationContext);
verify(methodVisitor).visitFieldInsn(Opcodes.GETSTATIC, BAZ, FOO + BAR, QUX + BAZ);
verifyNoMoreInteractions(methodVisitor);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class IntegerConstantOpcodeTest method testConstant.
@Test
public void testConstant() throws Exception {
StackManipulation loading = IntegerConstant.forValue(value);
if (value == 0 || value == 1) {
assertThat(loading, is(IntegerConstant.forValue(value == 1)));
}
assertThat(loading.isValid(), is(true));
StackManipulation.Size size = loading.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(methodVisitor).visitInsn(opcode);
verifyNoMoreInteractions(methodVisitor);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class IntegerConstantTest method testBiPush.
@Test
public void testBiPush() throws Exception {
StackManipulation integerConstant = IntegerConstant.forValue(value);
assertThat(integerConstant.isValid(), is(true));
StackManipulation.Size size = integerConstant.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
pushType.verifyInstruction(methodVisitor, value);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldAccessOtherTest method testGenericFieldAccessPutterEqualErasure.
@Test
public void testGenericFieldAccessPutterEqualErasure() throws Exception {
TypeDescription declaredErasure = mock(TypeDescription.class);
when(genericType.asErasure()).thenReturn(declaredErasure);
when(declaredType.asErasure()).thenReturn(declaredErasure);
StackManipulation stackManipulation = FieldAccess.forField(genericField).write();
assertThat(stackManipulation.isValid(), is(true));
assertThat(stackManipulation, is(FieldAccess.forField(fieldDescription).write()));
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldAccessOtherTest method testEnumerationDescriptionNonEnumeration.
@Test
public void testEnumerationDescriptionNonEnumeration() throws Exception {
when(fieldDescription.isPublic()).thenReturn(true);
when(fieldDescription.isStatic()).thenReturn(true);
when(fieldDescription.isEnum()).thenReturn(false);
when(fieldDescription.getActualName()).thenReturn(FOO);
StackManipulation stackManipulation = FieldAccess.forEnumeration(enumerationDescription);
assertThat(stackManipulation.isValid(), is(false));
}
Aggregations