Search in sources :

Example 16 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 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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 17 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 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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 18 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 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()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 19 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 testGenericWithReturnTypeClassMultipleEvolution.

@Test
public void testGenericWithReturnTypeClassMultipleEvolution() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(GenericWithReturnTypeClassBase.Intermediate.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription.SignatureToken token = typeDescription.getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asSignatureToken();
    MethodGraph.Node node = methodGraph.locate(token);
    MethodDescription.SignatureToken firstBridgeToken = typeDescription.getSuperClass().getDeclaredMethods().filter(isMethod().and(ElementMatchers.not(isBridge()))).getOnly().asDefined().asSignatureToken();
    MethodDescription.SignatureToken secondBridgeToken = typeDescription.getSuperClass().getSuperClass().getDeclaredMethods().filter(isMethod()).getOnly().asDefined().asSignatureToken();
    assertThat(node, is(methodGraph.locate(firstBridgeToken)));
    assertThat(node, is(methodGraph.locate(secondBridgeToken)));
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(3));
    assertThat(node.getMethodTypes().contains(token.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(firstBridgeToken.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(secondBridgeToken.asTypeToken()), is(true));
    assertThat(node.getVisibility(), is(Visibility.PUBLIC));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 20 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 testMultipleAmbiguousInterfaceInheritance.

@Test
public void testMultipleAmbiguousInterfaceInheritance() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(AmbiguousInterfaceBase.InterfaceTarget.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(1));
    MethodDescription first = typeDescription.getInterfaces().filter(erasure(InterfaceBase.class)).getOnly().getDeclaredMethods().filter(isMethod()).getOnly();
    MethodDescription second = typeDescription.getInterfaces().filter(erasure(AmbiguousInterfaceBase.class)).getOnly().getDeclaredMethods().filter(isMethod()).getOnly();
    MethodGraph.Node node = methodGraph.locate(first.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.AMBIGUOUS));
    assertThat(node.getMethodTypes().size(), is(1));
    assertThat(node.getMethodTypes().contains(first.asTypeToken()), is(true));
    assertThat(node.getMethodTypes().contains(second.asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(first));
    assertThat(node.getRepresentative(), not(second));
    assertThat(node.getVisibility(), is(first.getVisibility()));
    assertThat(node, is(methodGraph.locate(second.asSignatureToken())));
    MethodGraph.Node firstBaseNode = methodGraph.getInterfaceGraph(new TypeDescription.ForLoadedType(InterfaceBase.class)).locate(first.asSignatureToken());
    assertThat(node, not(firstBaseNode));
    assertThat(firstBaseNode.getRepresentative(), is(first));
    MethodGraph.Node secondBaseNode = methodGraph.getInterfaceGraph(new TypeDescription.ForLoadedType(InterfaceBase.class)).locate(second.asSignatureToken());
    assertThat(node, not(secondBaseNode));
    assertThat(secondBaseNode.getRepresentative(), is(first));
}
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