Search in sources :

Example 46 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 ClassLoadingStrategyDefaultTest method setUp.

@Before
public void setUp() throws Exception {
    classLoader = new URLClassLoader(new URL[0], null);
    binaryRepresentations = new LinkedHashMap<TypeDescription, byte[]>();
    typeDescription = new TypeDescription.ForLoadedType(Foo.class);
    binaryRepresentations.put(typeDescription, ClassFileExtraction.extract(Foo.class));
    protectionDomain = getClass().getProtectionDomain();
    when(packageDefinitionStrategy.define(any(ClassLoader.class), any(String.class), any(String.class))).thenReturn(PackageDefinitionStrategy.Definition.Undefined.INSTANCE);
}
Also used : URLClassLoader(java.net.URLClassLoader) TypeDescription(net.bytebuddy.description.type.TypeDescription) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) Before(org.junit.Before)

Example 47 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 TransformerForFieldTest method testNoChangesUnlessSpecified.

@Test
public void testNoChangesUnlessSpecified() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    FieldDescription fieldDescription = typeDescription.getSuperClass().getDeclaredFields().filter(named(FOO)).getOnly();
    FieldDescription transformed = Transformer.ForField.withModifiers().transform(typeDescription, fieldDescription);
    assertThat(transformed, is(fieldDescription));
    assertThat(transformed.getModifiers(), is(fieldDescription.getModifiers()));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) FieldDescription(net.bytebuddy.description.field.FieldDescription) Test(org.junit.Test)

Example 48 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 TransformerForFieldTest method testRetainsInstrumentedType.

@Test
public void testRetainsInstrumentedType() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    FieldDescription fieldDescription = typeDescription.getSuperClass().getDeclaredFields().filter(named(BAR)).getOnly();
    FieldDescription transformed = Transformer.ForField.withModifiers().transform(typeDescription, fieldDescription);
    assertThat(transformed, is(fieldDescription));
    assertThat(transformed.getModifiers(), is(fieldDescription.getModifiers()));
    assertThat(transformed.getType().asErasure(), is(typeDescription));
    assertThat(transformed.getType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(transformed.getType().getTypeArguments().size(), is(1));
    assertThat(transformed.getType().getTypeArguments().getOnly(), is(typeDescription.getSuperClass().getDeclaredFields().filter(named(FOO)).getOnly().getType()));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) FieldDescription(net.bytebuddy.description.field.FieldDescription) Test(org.junit.Test)

Example 49 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 TransformerForMethodTest method testNoChangesUnlessSpecified.

@Test
public void testNoChangesUnlessSpecified() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 50 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 TransformerForMethodTest method testRetainsInstrumentedType.

@Test
public void testRetainsInstrumentedType() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(BAR)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
    assertThat(transformed.getReturnType().asErasure(), is(typeDescription));
    assertThat(transformed.getReturnType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(transformed.getReturnType().getTypeArguments().size(), is(1));
    assertThat(transformed.getReturnType().getTypeArguments().getOnly(), is(typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly().getReturnType()));
}
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