use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class SubclassImplementationTargetTest method testSuperConstructorIsInvokable.
@Test
public void testSuperConstructorIsInvokable() throws Exception {
when(invokableMethod.isConstructor()).thenReturn(true);
when(definedSuperClassConstructor.isSpecializableFor(rawSuperClass)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(superConstructorToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) superClassConstructor));
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, QUX, BAZ, 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 AbstractImplementationTargetTest method testDefaultMethodInvocation.
@Test
public void testDefaultMethodInvocation() throws Exception {
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeDefault(defaultToken, defaultMethodDeclaringType);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) defaultMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(defaultMethodDeclaringType));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), is(0));
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZBAR, QUXBAZ, FOOBAZ, true);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
}
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 testAccessorMethodRegistrationWritesSecond.
@Test
public void testAccessorMethodRegistrationWritesSecond() throws Exception {
when(secondSpecialMethod.isStatic()).thenReturn(true);
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription secondMethodDescription = implementationContext.registerAccessorFor(secondSpecialInvocation, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(implementationContext.registerAccessorFor(secondSpecialInvocation, MethodAccessorFactory.AccessType.DEFAULT), is(secondMethodDescription));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("(" + BAR + ")" + FOO), isNull(String.class), aryEq(new String[] { BAZ }));
verify(methodVisitor).visitCode();
verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
verify(secondSpecialInvocation).apply(methodVisitor, implementationContext);
verify(methodVisitor).visitInsn(Opcodes.ARETURN);
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 testFieldGetterRegistration.
@Test
public void testFieldGetterRegistration() throws Exception {
Implementation.Context.Default implementationContext = new Implementation.Context.Default(instrumentedType, classFileVersion, auxiliaryTypeNamingStrategy, typeInitializer, auxiliaryClassFileVersion);
MethodDescription firstFieldGetter = implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(firstFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
assertThat(firstFieldGetter.getReturnType(), is(firstFieldType));
assertThat(firstFieldGetter.getInternalName(), startsWith(FOO));
assertThat(firstFieldGetter.getModifiers(), is(accessorMethodModifiers));
assertThat(firstFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
when(secondField.isStatic()).thenReturn(true);
MethodDescription secondFieldGetter = implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT);
assertThat(secondFieldGetter.getParameters(), is((ParameterList) new ParameterList.Empty<ParameterDescription>()));
assertThat(secondFieldGetter.getReturnType(), is(secondFieldType));
assertThat(secondFieldGetter.getInternalName(), startsWith(BAR));
assertThat(secondFieldGetter.getModifiers(), is(accessorMethodModifiers | Opcodes.ACC_STATIC));
assertThat(secondFieldGetter.getExceptionTypes(), is((TypeList.Generic) new TypeList.Generic.Empty()));
assertThat(implementationContext.registerGetterFor(firstField, MethodAccessorFactory.AccessType.DEFAULT), is(firstFieldGetter));
assertThat(implementationContext.registerGetterFor(secondField, MethodAccessorFactory.AccessType.DEFAULT), is(secondFieldGetter));
implementationContext.drain(drain, classVisitor, annotationValueFilterFactory);
verify(classVisitor).visitMethod(eq(accessorMethodModifiers), Matchers.startsWith(FOO), eq("()" + BAR), isNull(String.class), isNull(String[].class));
verify(classVisitor).visitMethod(eq(accessorMethodModifiers | Opcodes.ACC_STATIC), Matchers.startsWith(BAR), eq("()" + QUX), isNull(String.class), isNull(String[].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 testCompilationInvisible.
@Test
public void testCompilationInvisible() 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.isBridge()).thenReturn(false);
when(methodDescription.isVisibleTo(typeDescription)).thenReturn(false);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.ForDeclaredMethods.INSTANCE.compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(0));
}
Aggregations