use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testMethodClassConvergence.
@Test
public void testMethodClassConvergence() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(MethodClassConvergence.Inner.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly();
MethodDescription genericMethod = typeDescription.getSuperClass().getDeclaredMethods().filter(isMethod().and(definedMethod(takesArguments(Object.class)))).getOnly();
MethodDescription nonGenericMethod = typeDescription.getSuperClass().getDeclaredMethods().filter(isMethod().and(definedMethod(takesArguments(Void.class)))).getOnly();
MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
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(methodDescription.asTypeToken()), is(true));
assertThat(node.getMethodTypes().contains(methodDescription.asDefined().asTypeToken()), is(true));
assertThat(node.getRepresentative(), is(methodDescription));
assertThat(node.getVisibility(), is(methodDescription.getVisibility()));
MethodGraph superGraph = methodGraph.getSuperClassGraph();
MethodGraph.Node superNode = superGraph.locate(methodDescription.asSignatureToken());
assertThat(superNode.getSort(), is(MethodGraph.Node.Sort.AMBIGUOUS));
assertThat(superNode.getMethodTypes().size(), is(2));
assertThat(superNode.getMethodTypes().contains(methodDescription.asTypeToken()), is(true));
assertThat(superNode.getMethodTypes().contains(methodDescription.asDefined().asTypeToken()), is(true));
assertThat(superNode.getRepresentative(), is(nonGenericMethod));
assertThat(superNode.getRepresentative(), is(genericMethod));
assertThat(superNode.getVisibility(), is(methodDescription.getVisibility()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testSimpleClass.
@Test
public void testSimpleClass() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(SimpleClass.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size()));
assertThat(methodGraph.getSuperClassGraph().listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size()));
assertThat(methodGraph.getInterfaceGraph(mock(TypeDescription.class)).listNodes().size(), is(0));
for (MethodDescription methodDescription : TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual())) {
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()));
assertThat(methodGraph.listNodes().contains(node), is(true));
}
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testDuplicateNameGenericInterface.
@Test
public void testDuplicateNameGenericInterface() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameGenericInterface.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(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()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testTrivialJVMHierarchy.
@Test
public void testTrivialJVMHierarchy() throws Exception {
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJVMHierarchy().compile(TypeDescription.OBJECT);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size()));
assertThat(methodGraph.getSuperClassGraph().listNodes().size(), is(0));
assertThat(methodGraph.getInterfaceGraph(mock(TypeDescription.class)).listNodes().size(), is(0));
for (MethodDescription methodDescription : TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual())) {
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()));
assertThat(methodGraph.listNodes().contains(node), is(true));
}
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testNonDominantInterfaceInheritanceLeft.
@Test
public void testNonDominantInterfaceInheritanceLeft() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.NonDominantTargetLeft.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()));
}
Aggregations