use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testGenericVisibilityBridge.
@Test
public void testGenericVisibilityBridge() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericVisibilityBridgeTarget.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.getSuperClass().getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly();
MethodDescription.SignatureToken bridgeToken = typeDescription.getSuperClass().getSuperClass().getDeclaredMethods().filter(isMethod()).getOnly().asSignatureToken();
MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.VISIBLE));
assertThat(node, is(methodGraph.locate(bridgeToken)));
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()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testInterfaceDuplicateInHierarchyImplementation.
@Test
public void testInterfaceDuplicateInHierarchyImplementation() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(InterfaceBase.InterfaceDuplicate.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(1));
MethodDescription method = typeDescription.getInterfaces().filter(ElementMatchers.is(InterfaceBase.class)).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 testDiamondInheritanceClass.
@Test
public void testDiamondInheritanceClass() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericDiamondClassBase.Inner.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription diamondOverride = typeDescription.getInterfaces().getOnly().getDeclaredMethods().getOnly();
MethodDescription explicitOverride = typeDescription.getSuperClass().getDeclaredMethods().filter(isVirtual()).getOnly();
MethodGraph.Node node = methodGraph.locate(diamondOverride.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
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()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testDuplicateNameClassExtension.
@Test
public void testDuplicateNameClassExtension() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameClass.Inner.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 3));
MethodDescription objectMethod = typeDescription.getSuperClass().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.getSuperClass().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.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()));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testVisibilityBridge.
@Test
public void testVisibilityBridge() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(VisibilityBridgeTarget.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.getSuperClass().getDeclaredMethods().filter(isMethod()).getOnly();
MethodGraph.Node node = methodGraph.locate(methodDescription.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.VISIBLE));
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