Search in sources :

Example 66 with MethodDescription

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

the class MethodGraphCompilerDefaultTest method testDuplicateNameInterfaceExtension.

@Test
public void testDuplicateNameInterfaceExtension() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameInterface.InnerInterface.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(3));
    MethodDescription objectMethod = typeDescription.getInterfaces().getOnly().getDeclaredMethods().filter(takesArguments(Object.class)).getOnly();
    MethodGraph.Node objectNode = methodGraph.locate(objectMethod.asSignatureToken());
    assertThat(objectNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(objectNode.getRepresentative(), is(objectMethod));
    assertThat(objectNode.getMethodTypes().size(), is(1));
    assertThat(objectNode.getMethodTypes().contains(objectMethod.asTypeToken()), is(true));
    assertThat(objectNode.getVisibility(), is(objectMethod.getVisibility()));
    MethodDescription integerMethod = typeDescription.getInterfaces().getOnly().getDeclaredMethods().filter(takesArguments(Integer.class)).getOnly();
    MethodGraph.Node integerNode = methodGraph.locate(integerMethod.asSignatureToken());
    assertThat(integerNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(integerNode.getRepresentative(), is(integerMethod));
    assertThat(integerNode.getMethodTypes().size(), is(1));
    assertThat(integerNode.getMethodTypes().contains(integerMethod.asTypeToken()), is(true));
    assertThat(integerMethod.getVisibility(), is(integerNode.getVisibility()));
    MethodDescription voidMethod = typeDescription.getDeclaredMethods().filter(takesArguments(Void.class)).getOnly();
    MethodGraph.Node voidNode = methodGraph.locate(voidMethod.asSignatureToken());
    assertThat(voidNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(voidNode.getRepresentative(), is(voidMethod));
    assertThat(voidNode.getMethodTypes().size(), is(1));
    assertThat(voidNode.getMethodTypes().contains(voidMethod.asTypeToken()), is(true));
    assertThat(voidNode.getVisibility(), is(voidMethod.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 67 with MethodDescription

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

the class MethodGraphCompilerDefaultTest method testNonDominantInterfaceInheritanceRight.

@Test
public void testNonDominantInterfaceInheritanceRight() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.NonDominantTargetRight.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.AMBIGUOUS));
    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 68 with MethodDescription

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

the class MethodGraphCompilerDefaultTest method testMethodInterfaceConvergence.

@Test
public void testMethodInterfaceConvergence() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(MethodInterfaceConvergenceTarget.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription genericMethod = typeDescription.getInterfaces().filter(erasure(MethodInterfaceConvergenceFirstBase.class)).getOnly().getDeclaredMethods().filter(isMethod()).getOnly();
    MethodDescription nonGenericMethod = typeDescription.getInterfaces().filter(erasure(MethodInterfaceConvergenceSecondBase.class)).getOnly().getDeclaredMethods().filter(isMethod()).getOnly();
    assertThat(methodGraph.getSuperClassGraph().locate(genericMethod.asSignatureToken()).getSort(), is(MethodGraph.Node.Sort.UNRESOLVED));
    assertThat(methodGraph.getSuperClassGraph().locate(nonGenericMethod.asSignatureToken()).getSort(), is(MethodGraph.Node.Sort.UNRESOLVED));
    MethodGraph.Node node = methodGraph.locate(genericMethod.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.AMBIGUOUS));
    assertThat(node, is(methodGraph.locate(genericMethod.asDefined().asSignatureToken())));
    assertThat(node, is(methodGraph.locate(nonGenericMethod.asDefined().asSignatureToken())));
    assertThat(node.getMethodTypes().size(), is(2));
    assertThat(node.getMethodTypes().contains(genericMethod.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(genericMethod.asDefined().asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(genericMethod));
    assertThat(node.getRepresentative(), not(nonGenericMethod));
    assertThat(node.getVisibility(), is(genericMethod.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 69 with MethodDescription

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

the class MethodGraphCompilerDefaultTest method testDuplicateNameGenericInterfaceExtension.

@Test
public void testDuplicateNameGenericInterfaceExtension() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameGenericInterface.InnerInterface.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(3));
    MethodDescription objectMethod = typeDescription.getInterfaces().getOnly().getDeclaredMethods().filter(takesArguments(String.class)).getOnly();
    MethodGraph.Node objectNode = methodGraph.locate(objectMethod.asSignatureToken());
    assertThat(objectNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(objectNode.getRepresentative(), is(objectMethod));
    assertThat(objectNode.getMethodTypes().size(), is(2));
    assertThat(objectNode.getMethodTypes().contains(objectMethod.asTypeToken()), is(true));
    assertThat(objectNode.getMethodTypes().contains(objectMethod.asDefined().asTypeToken()), is(true));
    assertThat(objectNode.getVisibility(), is(objectMethod.getVisibility()));
    MethodDescription integerMethod = typeDescription.getInterfaces().getOnly().getDeclaredMethods().filter(takesArguments(Integer.class)).getOnly();
    MethodGraph.Node integerNode = methodGraph.locate(integerMethod.asSignatureToken());
    assertThat(integerNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(integerNode.getRepresentative(), is(integerMethod));
    assertThat(integerNode.getMethodTypes().size(), is(1));
    assertThat(integerNode.getMethodTypes().contains(integerMethod.asTypeToken()), is(true));
    assertThat(integerNode.getMethodTypes().contains(integerMethod.asDefined().asTypeToken()), is(true));
    assertThat(integerNode.getVisibility(), is(integerMethod.getVisibility()));
    MethodDescription voidMethod = typeDescription.getDeclaredMethods().filter(takesArguments(Void.class)).getOnly();
    MethodGraph.Node voidNode = methodGraph.locate(voidMethod.asSignatureToken());
    assertThat(voidNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(voidNode.getRepresentative(), is(voidMethod));
    assertThat(voidNode.getMethodTypes().size(), is(1));
    assertThat(voidNode.getMethodTypes().contains(voidMethod.asTypeToken()), is(true));
    assertThat(voidNode.getVisibility(), is(voidMethod.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 70 with MethodDescription

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

the class MethodGraphCompilerDefaultTest method testDuplicateNameGenericClass.

@Test
public void testDuplicateNameGenericClass() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameGenericClass.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 2));
    MethodDescription objectMethod = typeDescription.getDeclaredMethods().filter(takesArguments(Object.class)).getOnly();
    MethodGraph.Node objectNode = methodGraph.locate(objectMethod.asSignatureToken());
    assertThat(objectNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(objectNode.getRepresentative(), is(objectMethod));
    assertThat(objectNode.getMethodTypes().size(), is(1));
    assertThat(objectNode.getMethodTypes().contains(objectMethod.asTypeToken()), is(true));
    assertThat(objectNode.getVisibility(), is(objectMethod.getVisibility()));
    MethodDescription voidMethod = typeDescription.getDeclaredMethods().filter(takesArguments(Integer.class)).getOnly();
    MethodGraph.Node voidNode = methodGraph.locate(voidMethod.asSignatureToken());
    assertThat(voidNode.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(voidNode.getRepresentative(), is(voidMethod));
    assertThat(voidNode.getMethodTypes().size(), is(1));
    assertThat(voidNode.getMethodTypes().contains(voidMethod.asTypeToken()), is(true));
    assertThat(voidNode.getVisibility(), is(voidMethod.getVisibility()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)105 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 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)2 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)2 ByteCodeAppender (net.bytebuddy.implementation.bytecode.ByteCodeAppender)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1