use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testDominantInterfaceInheritanceLeft.
@Test
public void testDominantInterfaceInheritanceLeft() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.DominantInterfaceTargetLeft.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()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testInterfaceImplementation.
@Test
public void testInterfaceImplementation() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(InterfaceBase.InnerClass.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription method = typeDescription.getInterfaces().getOnly().getDeclaredMethods().getOnly();
MethodGraph.Node node = methodGraph.locate(method.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
assertThat(node.getMethodTypes().size(), is(1));
assertThat(node.getMethodTypes().contains(method.asTypeToken()), is(true));
assertThat(node.getRepresentative(), is(method));
assertThat(node.getVisibility(), is(method.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 testReturnTypeInterfaceBridge.
@Test
@JavaVersionRule.Enforce(8)
public void testReturnTypeInterfaceBridge() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(RETURN_TYPE_INTERFACE_BRIDGE));
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(1));
MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(returns(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(returns(Object.class)).getOnly().asTypeToken()), is(true));
assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testClassAndInterfaceDominantInheritance.
@Test
public void testClassAndInterfaceDominantInheritance() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(ClassAndInterfaceInheritance.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription method = typeDescription.getSuperClass().getDeclaredMethods().filter(isMethod()).getOnly();
MethodGraph.Node node = methodGraph.locate(method.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
assertThat(node.getMethodTypes().size(), is(1));
assertThat(node.getMethodTypes().contains(method.asTypeToken()), is(true));
assertThat(node.getRepresentative(), is(method));
assertThat(node.getVisibility(), is(method.getVisibility()));
MethodGraph.Node baseNode = methodGraph.getInterfaceGraph(new TypeDescription.ForLoadedType(InterfaceBase.class)).locate(method.asSignatureToken());
assertThat(node, not(baseNode));
assertThat(baseNode.getRepresentative(), is((MethodDescription) typeDescription.getInterfaces().getOnly().getDeclaredMethods().getOnly()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class JavaConstantMethodHandleTest method testStaticMethodNotSpecial.
@Test(expected = IllegalArgumentException.class)
public void testStaticMethodNotSpecial() throws Exception {
MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
TypeDescription typeDescription = mock(TypeDescription.class);
when(methodDescription.isStatic()).thenReturn(true);
when(methodDescription.isSpecializableFor(typeDescription)).thenReturn(true);
JavaConstant.MethodHandle.ofSpecial(methodDescription, typeDescription);
}
Aggregations