Search in sources :

Example 21 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class MethodGraphCompilerDefaultTest method testTypeVariableInterfaceBridge.

@Test
@JavaVersionRule.Enforce(8)
public void testTypeVariableInterfaceBridge() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(TYPE_VARIABLE_INTERFACE_BRIDGE));
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(takesArguments(String.class)).getOnly();
    MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getRepresentative(), is(methodDescription));
    assertThat(node.getMethodTypes().size(), is(2));
    assertThat(node.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(typeDescription.getDeclaredMethods().filter(takesArguments(Object.class)).getOnly().asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 22 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class MethodGraphCompilerDefaultTest method testDominantInterfaceInheritanceRight.

@Test
public void testDominantInterfaceInheritanceRight() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.DominantInterfaceTargetRight.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.DominantIntermediate.class).getDeclaredMethods().getOnly();
    MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(1));
    assertThat(node.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(methodDescription));
    assertThat(node.getVisibility(), is(methodDescription.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 23 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class MethodGraphCompilerDefaultTest method testDominantClassInheritance.

@Test
public void testDominantClassInheritance() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.DominantClassTarget.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription methodDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.DominantIntermediate.class).getDeclaredMethods().getOnly();
    MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(1));
    assertThat(node.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(methodDescription));
    assertThat(node.getVisibility(), is(methodDescription.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 24 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class MethodGraphCompilerDefaultTest method testDiamondInheritanceInterface.

@Test
public void testDiamondInheritanceInterface() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericDiamondInterfaceBase.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription diamondOverride = typeDescription.getInterfaces().get(0).getDeclaredMethods().getOnly();
    MethodDescription explicitOverride = typeDescription.getInterfaces().get(1).getDeclaredMethods().getOnly();
    MethodGraph.Node node = methodGraph.locate(diamondOverride.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.AMBIGUOUS));
    assertThat(methodGraph.locate(explicitOverride.asDefined().asSignatureToken()), is(node));
    assertThat(node.getMethodTypes().size(), is(2));
    assertThat(node.getMethodTypes().contains(diamondOverride.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(explicitOverride.asDefined().asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(explicitOverride.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 25 with MethodDescription

use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.

the class InstrumentedTypeDefaultTest method testWithTypeInitializerSingle.

@Test
public void testWithTypeInitializerSingle() throws Exception {
    InstrumentedType instrumentedType = makePlainInstrumentedType();
    assertThat(instrumentedType.getDeclaredFields().size(), is(0));
    ByteCodeAppender byteCodeAppender = mock(ByteCodeAppender.class);
    instrumentedType = instrumentedType.withInitializer(byteCodeAppender);
    TypeInitializer typeInitializer = instrumentedType.getTypeInitializer();
    assertThat(typeInitializer.isDefined(), is(true));
    MethodDescription methodDescription = mock(MethodDescription.class);
    typeInitializer.apply(methodVisitor, implementationContext, methodDescription);
    verify(byteCodeAppender).apply(methodVisitor, implementationContext, methodDescription);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) LoadedTypeInitializer(net.bytebuddy.implementation.LoadedTypeInitializer) ByteCodeAppender(net.bytebuddy.implementation.bytecode.ByteCodeAppender) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)104 Test (org.junit.Test)102 TypeDescription (net.bytebuddy.description.type.TypeDescription)62 MethodVisitor (org.objectweb.asm.MethodVisitor)15 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)12 MethodList (net.bytebuddy.description.method.MethodList)9 Implementation (net.bytebuddy.implementation.Implementation)8 AbstractImplementationTargetTest (net.bytebuddy.implementation.AbstractImplementationTargetTest)6 Serializable (java.io.Serializable)4 TypeVariableSource (net.bytebuddy.description.TypeVariableSource)4 FieldList (net.bytebuddy.description.field.FieldList)4 TypePool (net.bytebuddy.pool.TypePool)4 ClassVisitor (org.objectweb.asm.ClassVisitor)4 ByteBuddy (net.bytebuddy.ByteBuddy)3 DynamicType (net.bytebuddy.dynamic.DynamicType)3 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)2 ByteCodeAppender (net.bytebuddy.implementation.bytecode.ByteCodeAppender)2 Annotation (java.lang.annotation.Annotation)1 Callable (java.util.concurrent.Callable)1 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)1