use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testTrivialDelegation.
@Test
public void testTrivialDelegation() throws Exception {
Class<?> type = new ByteBuddy().redefine(EmptyDelegationAdvice.class).visit(Advice.to(EmptyDelegationAdvice.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), nullValue(Object.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceOnConstructorExitAdviceWithSuppression.
@Test
public void testAdviceOnConstructorExitAdviceWithSuppression() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(TrivialAdviceSkipExceptionWithSuppression.class).on(isConstructor())).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredConstructor().newInstance(), notNullValue(Object.class));
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testVariableMappingAdviceLarger.
@Test
public void testVariableMappingAdviceLarger() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(AdviceWithVariableValues.class).on(named(BAR))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(BAR, String.class).invoke(type.getDeclaredConstructor().newInstance(), FOO + BAR + QUX + BAZ), is((Object) (FOO + BAR + QUX + BAZ)));
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project hibernate-orm by hibernate.
the class ByteBuddyProxyFactory method buildProxy.
public static Class buildProxy(final Class persistentClass, final Class[] interfaces) {
Set<Class<?>> key = new HashSet<Class<?>>();
if (interfaces.length == 1) {
key.add(persistentClass);
}
key.addAll(Arrays.<Class<?>>asList(interfaces));
return CACHE.findOrInsert(persistentClass.getClassLoader(), new TypeCache.SimpleKey(key), new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return new ByteBuddy().with(TypeValidation.DISABLED).with(new NamingStrategy.SuffixingRandom("HibernateProxy")).subclass(interfaces.length == 1 ? persistentClass : Object.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING).implement((Type[]) interfaces).method(ElementMatchers.isVirtual().and(ElementMatchers.not(ElementMatchers.isFinalizer()))).intercept(MethodDelegation.to(ProxyConfiguration.InterceptorDispatcher.class)).method(ElementMatchers.nameStartsWith("$$_hibernate_").and(ElementMatchers.isVirtual())).intercept(SuperMethodCall.INSTANCE).defineField(ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE).implement(ProxyConfiguration.class).intercept(FieldAccessor.ofField(ProxyConfiguration.INTERCEPTOR_FIELD_NAME).withAssigner(Assigner.DEFAULT, Assigner.Typing.DYNAMIC)).make().load(persistentClass.getClassLoader()).getLoaded();
}
}, CACHE);
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class EntryPointDefaultTest method testRedefineLocal.
@Test
@SuppressWarnings("unchecked")
public void testRedefineLocal() throws Exception {
assertThat(EntryPoint.Default.REDEFINE_LOCAL.getByteBuddy(), is(new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE)));
when(byteBuddy.redefine(typeDescription, classFileLocator)).thenReturn((DynamicType.Builder) builder);
when(builder.ignoreAlso(not(isDeclaredBy(typeDescription)))).thenReturn((DynamicType.Builder) otherBuilder);
assertThat(EntryPoint.Default.REDEFINE_LOCAL.transform(typeDescription, byteBuddy, classFileLocator, methodNameTransformer), is((DynamicType.Builder) otherBuilder));
}
Aggregations