use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class DefaultMethodCallTest method testObjectProperties.
@Test
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(DefaultMethodCall.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {
@Override
public List<?> create() {
TypeDescription typeDescription = mock(TypeDescription.class);
when(typeDescription.isInterface()).thenReturn(true);
when(typeDescription.asErasure()).thenReturn(typeDescription);
when(typeDescription.getSort()).thenReturn(TypeDefinition.Sort.NON_GENERIC);
return Collections.singletonList(typeDescription);
}
}).apply();
final TypeDescription removalType = mock(TypeDescription.class);
final TypeDescription.Generic genericRemovalType = mock(TypeDescription.Generic.class);
when(genericRemovalType.asGenericType()).thenReturn(genericRemovalType);
when(genericRemovalType.asErasure()).thenReturn(removalType);
ObjectPropertyAssertion.of(DefaultMethodCall.Appender.class).refine(new ObjectPropertyAssertion.Refinement<Implementation.Target>() {
@Override
public void apply(Implementation.Target mock) {
TypeDescription typeDescription = mock(TypeDescription.class), otherType = mock(TypeDescription.class);
TypeDescription.Generic otherGenericType = mock(TypeDescription.Generic.class);
when(otherGenericType.asErasure()).thenReturn(otherType);
when(otherGenericType.asGenericType()).thenReturn(otherGenericType);
when(typeDescription.getInterfaces()).thenReturn(new TypeList.Generic.Explicit(genericRemovalType, otherGenericType));
when(mock.getInstrumentedType()).thenReturn(typeDescription);
}
}).create(new ObjectPropertyAssertion.Creator<List<?>>() {
@Override
public List<?> create() {
TypeDescription typeDescription = mock(TypeDescription.class);
when(typeDescription.asErasure()).thenReturn(typeDescription);
return Arrays.asList(removalType, typeDescription);
}
}).apply();
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testOrphanedBridge.
@Test
public void testOrphanedBridge() throws Exception {
MethodDescription.SignatureToken bridgeMethod = new MethodDescription.SignatureToken("foo", TypeDescription.VOID, Collections.<TypeDescription>emptyList());
TypeDescription typeDescription = new InstrumentedType.Default("foo", Opcodes.ACC_PUBLIC, TypeDescription.Generic.OBJECT, Collections.<TypeVariableToken>emptyList(), Collections.<TypeDescription.Generic>emptyList(), Collections.<FieldDescription.Token>emptyList(), Collections.singletonList(new MethodDescription.Token("foo", Opcodes.ACC_BRIDGE, TypeDescription.Generic.VOID, Collections.<TypeDescription.Generic>emptyList())), Collections.<AnnotationDescription>emptyList(), TypeInitializer.None.INSTANCE, LoadedTypeInitializer.NoOp.INSTANCE, TypeDescription.UNDEFINED, MethodDescription.UNDEFINED, TypeDescription.UNDEFINED, Collections.<TypeDescription>emptyList(), false, false, false);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.listNodes().size(), is(1 + TypeDescription.OBJECT.getDeclaredMethods().filter(ElementMatchers.isVirtual()).size()));
MethodGraph.Node node = methodGraph.locate(bridgeMethod);
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
assertThat(node.getRepresentative().asSignatureToken(), is(bridgeMethod));
assertThat(node.getMethodTypes().size(), is(1));
assertThat(node.getMethodTypes(), hasItem(bridgeMethod.asTypeToken()));
assertThat(node.getVisibility(), is(Visibility.PACKAGE_PRIVATE));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testDuplicateNameGenericClassExtension.
@Test
public void testDuplicateNameGenericClassExtension() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameGenericClass.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(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.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));
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.type.TypeDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testRawType.
@Test
public void testRawType() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(RawType.Raw.class);
MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
assertThat(methodGraph.getSuperClassGraph().listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
MethodDescription method = typeDescription.getSuperClass().getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly();
MethodGraph.Node node = methodGraph.locate(method.asSignatureToken());
assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
assertThat(methodGraph.locate(method.asDefined().asSignatureToken()), is(node));
assertThat(node.getMethodTypes().size(), is(2));
assertThat(node.getMethodTypes().contains(method.asTypeToken()), is(true));
assertThat(node.getMethodTypes().contains(method.asDefined().asTypeToken()), is(true));
assertThat(node.getVisibility(), is(method.getVisibility()));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class MethodGraphCompilerDefaultTest method testDuplicateNameInterface.
@Test
public void testDuplicateNameInterface() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(DuplicateNameInterface.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()));
}
Aggregations