use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class RebaseImplementationTargetTest method testSuperTypeMethodIsInvokable.
@Test
public void testSuperTypeMethodIsInvokable() throws Exception {
when(invokableMethod.isSpecializableFor(rawSuperClass)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(invokableToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(rawSuperClass));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAR, FOO, QUX, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), 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 testAccessorMethodRegistrationWritesFirst.
@Test
public void testAccessorMethodRegistrationWritesFirst() throws Exception {
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription firstMethodDescription = implementationContext.registerAccessorFor(firstSpecialInvocation, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerAccessorFor(firstSpecialInvocation, MethodAccessorFactory.AccessType.DEFAULT), is(firstMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("(" + BAZ + ")" + QUX), isNull(String.class), aryEq(new String[] { FOO }));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 1);
verify(firstSpecialInvocation).apply(methodVisitor, implementationContext);
verify(methodVisitor).visitInsn(Opcodes.ARETURN);
verify(methodVisitor).visitMaxs(2, 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 testFieldGetterRegistrationWritesSecond.
@Test
public void testFieldGetterRegistrationWritesSecond() throws Exception {
when(secondField.isStatic()).thenReturn(true);
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription secondMethodDescription = implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT), is(secondMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("()" + QUX), isNull(String.class), isNull(String[].class));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitFieldInsn(Opcodes.GETSTATIC, BAZ, BAR, FOO);
verify(methodVisitor).visitInsn(Opcodes.ARETURN);
verify(methodVisitor).visitMaxs(0, 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 ImplementationSpecialMethodInvocationSimpleTest method testEquality.
@Test
public void testEquality() throws Exception {
MethodDescription firstMethod = mock(MethodDescription.class), secondMethod = mock(MethodDescription.class);
MethodDescription.SignatureToken firstToken = mock(MethodDescription.SignatureToken.class), secondToken = mock(MethodDescription.SignatureToken.class);
when(firstMethod.asSignatureToken()).thenReturn(firstToken);
when(secondMethod.asSignatureToken()).thenReturn(secondToken);
TypeDescription firstType = mock(TypeDescription.class), secondType = mock(TypeDescription.class);
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), is(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class))));
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(secondMethod, firstType, mock(StackManipulation.class))));
assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(firstMethod, secondType, mock(StackManipulation.class))));
}
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 testCompilationNonVirtual.
@Test
public void testCompilationNonVirtual() 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(false);
when(methodDescription.isBridge()).thenReturn(false);
when(methodDescription.isVisibleTo(typeDescription)).thenReturn(true);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.ForDeclaredMethods.INSTANCE.compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(0));
}
Aggregations