use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class TypeConstantAdjustmentTest method testInstrumentationModernClassFile.
@Test
public void testInstrumentationModernClassFile() throws Exception {
ClassVisitor classVisitor = TypeConstantAdjustment.INSTANCE.wrap(mock(TypeDescription.class), this.classVisitor, mock(Implementation.Context.class), mock(TypePool.class), new FieldList.Empty<FieldDescription.InDefinedShape>(), new MethodList.Empty<MethodDescription>(), IGNORED, IGNORED);
classVisitor.visit(ClassFileVersion.JAVA_V5.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
assertThat(classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ }), is(methodVisitor));
verify(this.classVisitor).visit(ClassFileVersion.JAVA_V5.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verifyNoMoreInteractions(this.classVisitor);
verifyZeroInteractions(methodVisitor);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class TypeConstantAdjustmentTest method testInstrumentationLegacyClassFileArrayType.
@Test
public void testInstrumentationLegacyClassFileArrayType() throws Exception {
ClassVisitor classVisitor = TypeConstantAdjustment.INSTANCE.wrap(mock(TypeDescription.class), this.classVisitor, mock(Implementation.Context.class), mock(TypePool.class), new FieldList.Empty<FieldDescription.InDefinedShape>(), new MethodList.Empty<MethodDescription>(), IGNORED, IGNORED);
classVisitor.visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
MethodVisitor methodVisitor = classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
assertThat(methodVisitor, not(this.methodVisitor));
methodVisitor.visitLdcInsn(Type.getType(Object[].class));
verify(this.classVisitor).visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[] { BAZ });
verifyNoMoreInteractions(this.classVisitor);
verify(this.methodVisitor).visitLdcInsn(Type.getType(Object[].class).getInternalName().replace('/', '.'));
verify(this.methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getType(Class.class).getInternalName(), "forName", Type.getType(Class.class.getDeclaredMethod("forName", String.class)).getDescriptor(), false);
verifyNoMoreInteractions(this.methodVisitor);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class InstrumentedTypeDefaultTest method testWithTypeInitializerDouble.
@Test
public void testWithTypeInitializerDouble() throws Exception {
InstrumentedType instrumentedType = makePlainInstrumentedType();
assertThat(instrumentedType.getDeclaredFields().size(), is(0));
ByteCodeAppender first = mock(ByteCodeAppender.class), second = mock(ByteCodeAppender.class);
MethodDescription methodDescription = mock(MethodDescription.class);
when(first.apply(methodVisitor, implementationContext, methodDescription)).thenReturn(new ByteCodeAppender.Size(0, 0));
when(second.apply(methodVisitor, implementationContext, methodDescription)).thenReturn(new ByteCodeAppender.Size(0, 0));
instrumentedType = instrumentedType.withInitializer(first).withInitializer(second);
TypeInitializer typeInitializer = instrumentedType.getTypeInitializer();
assertThat(typeInitializer.isDefined(), is(true));
typeInitializer.apply(methodVisitor, implementationContext, methodDescription);
verify(first).apply(methodVisitor, implementationContext, methodDescription);
verify(second).apply(methodVisitor, implementationContext, methodDescription);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class AbstractTypeDescriptionGenericTest method testMethodTypeVariableWithExtensionIsRetained.
@Test
public void testMethodTypeVariableWithExtensionIsRetained() throws Exception {
TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(FOO));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getTypeArguments().size(), is(2));
assertThat(typeDescription.getTypeArguments().get(0).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(typeDescription.getTypeArguments().get(0).asErasure().represents(Number.class), is(true));
assertThat(typeDescription.getTypeArguments().get(1).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(typeDescription.getTypeArguments().get(1).asErasure().represents(Integer.class), is(true));
MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(QUX)).getOnly();
assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(methodDescription.getReturnType().getSymbol(), is("S"));
assertThat(methodDescription.getReturnType().getTypeVariableSource(), is((TypeVariableSource) methodDescription.asDefined()));
assertThat(methodDescription.getReturnType().getUpperBounds().size(), is(1));
assertThat(methodDescription.getReturnType().getUpperBounds().getOnly().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(methodDescription.getReturnType().getUpperBounds().getOnly().asErasure().represents(Number.class), is(true));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class AbstractTypeDescriptionGenericTest method testNestedInnerType.
@Test
public void testNestedInnerType() throws Exception {
TypeDescription.Generic foo = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(FOO));
assertThat(foo.getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(foo.getSymbol(), is(T));
assertThat(foo.getUpperBounds().size(), is(1));
assertThat(foo.getUpperBounds().getOnly(), is(TypeDescription.Generic.OBJECT));
assertThat(foo.getTypeVariableSource(), is((TypeVariableSource) new TypeDescription.ForLoadedType(NestedInnerType.class)));
TypeDescription.Generic bar = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(BAR));
assertThat(bar.getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(bar.getSymbol(), is(S));
assertThat(bar.getUpperBounds().size(), is(1));
assertThat(bar.getUpperBounds().getOnly(), is(foo));
assertThat(bar.getTypeVariableSource(), is((TypeVariableSource) new TypeDescription.ForLoadedType(NestedInnerType.InnerType.class)));
TypeDescription.Generic qux = describeReturnType(NestedInnerType.InnerType.class.getDeclaredMethod(QUX));
assertThat(qux.getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(qux.getSymbol(), is(U));
assertThat(qux.getUpperBounds().size(), is(1));
assertThat(qux.getUpperBounds().getOnly(), is(bar));
MethodDescription quxMethod = new MethodDescription.ForLoadedMethod(NestedInnerType.InnerType.class.getDeclaredMethod(QUX));
assertThat(qux.getTypeVariableSource(), is((TypeVariableSource) quxMethod));
}
Aggregations