use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testClassInheritance.
@Test
public void testClassInheritance() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(ClassBase.Inner.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription method = typeDescription.getDeclaredMethods().filter(isMethod()).getOnly();
MethodGraph.Node node = methodGraph.locate(method.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
assertThat(node.getMethodTypes().size(), is(1));
assertThat(node.getMethodTypes().contains(method.asTypeToken()), is(true));
assertThat(node.getRepresentative(), is(method));
assertThat(node.getVisibility(), is(method.getVisibility()));
assertThat(methodGraph.listNodes().contains(node), is(true));
MethodGraph.Node baseNode = methodGraph.getSuperClassGraph().locate(method.asSignatureToken());
assertThat(node, not(baseNode));
assertThat(typeDescription.getSuperClass().getDeclaredMethods().filter(ElementMatchers.is(baseNode.getRepresentative())).getOnly(), is(baseNode.getRepresentative()));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerForDeclaredMethodsTest method testCompilationNonBridge.
@Test
public void testCompilationNonBridge() throws Exception {
TypeDescription typeDescription = mock(TypeDescription.class);
MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InDefinedShape>(methodDescription));
when(methodDescription.isVirtual()).thenReturn(true);
when(methodDescription.getModifiers()).thenReturn(Opcodes.ACC_BRIDGE);
when(methodDescription.isVisibleTo(typeDescription)).thenReturn(true);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.ForDeclaredMethods.INSTANCE.compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(0));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ImplementationContextDefaultTest method testFieldGetterRegistrationWritesFirst.
@Test
public void testFieldGetterRegistrationWritesFirst() throws Exception {
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription firstMethodDescription = implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("()" + BAR), isNull(String.class), isNull(String[].class));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
verify(methodVisitor).visitFieldInsn(Opcodes.GETFIELD, QUX, FOO, BAR);
verify(methodVisitor).visitInsn(Opcodes.ARETURN);
verify(methodVisitor).visitMaxs(1, 1);
verify(methodVisitor).visitEnd();
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ImplementationContextDefaultTest method testFieldSetterRegistrationWritesSecond.
@Test
public void testFieldSetterRegistrationWritesSecond() throws Exception {
when(secondField.isStatic()).thenReturn(true);
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription secondMethodDescription = implementationContext.registerSetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerSetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT), is(secondMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("(" + QUX + ")V"), isNull(String.class), isNull(String[].class));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
verify(methodVisitor).visitFieldInsn(Opcodes.PUTSTATIC, BAZ, BAR, FOO);
verify(methodVisitor).visitInsn(Opcodes.RETURN);
verify(methodVisitor).visitMaxs(1, 0);
verify(methodVisitor).visitEnd();
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ImplementationContextDefaultTest method testFieldSetterRegistrationWritesFirst.
@Test
public void testFieldSetterRegistrationWritesFirst() throws Exception {
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription firstMethodDescription = implementationContext.registerSetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerSetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("(" + BAR + ")V"), isNull(String.class), isNull(String[].class));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 1);
verify(methodVisitor).visitFieldInsn(Opcodes.PUTFIELD, QUX, FOO, BAR);
verify(methodVisitor).visitInsn(Opcodes.RETURN);
verify(methodVisitor).visitMaxs(2, 1);
verify(methodVisitor).visitEnd();
}
Aggregations