Search in sources :

Example 1 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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();
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) TypeList(net.bytebuddy.description.type.TypeList) ObjectPropertyAssertion(net.bytebuddy.test.utility.ObjectPropertyAssertion) Test(org.junit.Test)

Example 2 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) TypeVariableToken(net.bytebuddy.description.type.TypeVariableToken) FieldDescription(net.bytebuddy.description.field.FieldDescription) Test(org.junit.Test)

Example 3 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 4 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 5 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Aggregations

TypeDescription (net.bytebuddy.description.type.TypeDescription)178 Test (org.junit.Test)155 MethodDescription (net.bytebuddy.description.method.MethodDescription)75 ByteBuddy (net.bytebuddy.ByteBuddy)25 DynamicType (net.bytebuddy.dynamic.DynamicType)25 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)17 ClassFileLocator (net.bytebuddy.dynamic.ClassFileLocator)10 AnnotationList (net.bytebuddy.description.annotation.AnnotationList)9 AbstractTypeDescriptionTest (net.bytebuddy.description.type.AbstractTypeDescriptionTest)9 Map (java.util.Map)8 MethodList (net.bytebuddy.description.method.MethodList)8 Field (java.lang.reflect.Field)7 List (java.util.List)5 FieldDescription (net.bytebuddy.description.field.FieldDescription)5 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)5 Serializable (java.io.Serializable)4 URLClassLoader (java.net.URLClassLoader)4 TypeList (net.bytebuddy.description.type.TypeList)4 Before (org.junit.Before)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4