net.bytebuddy.implementation.SuperMethodCall Java Examples
The following examples show how to use
net.bytebuddy.implementation.SuperMethodCall.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteBuddyProxyHelper.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public 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 byteBuddyState.loadProxy( persistentClass, new TypeCache.SimpleKey(key), byteBuddy -> byteBuddy .ignore( byteBuddyState.getProxyDefinitionHelpers().getGroovyGetMetaClassFilter() ) .with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getName() ) ) ) .subclass( interfaces.length == 1 ? persistentClass : Object.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING ) .implement( (Type[]) interfaces ) .method( byteBuddyState.getProxyDefinitionHelpers().getVirtualNotFinalizerFilter() ) .intercept( byteBuddyState.getProxyDefinitionHelpers().getDelegateToInterceptorDispatcherMethodDelegation() ) .method( byteBuddyState.getProxyDefinitionHelpers().getHibernateGeneratedMethodFilter() ) .intercept( SuperMethodCall.INSTANCE ) .defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE ) .implement( ProxyConfiguration.class ) .intercept( byteBuddyState.getProxyDefinitionHelpers().getInterceptorFieldAccessor() ) ); }
Example #2
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
Example #3
Source File: ClassByExtensionBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark of a class extension using Byte Buddy. This benchmark uses a specialized interception * strategy which is easier to inline by the compiler. * * @return The created instance, in order to avoid JIT removal. * @throws java.lang.Exception If the invocation causes an exception. */ @Benchmark public ExampleClass benchmarkByteBuddySpecialized() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(SuperMethodCall.INSTANCE) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
Example #4
Source File: ClassByExtensionBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark of a class extension using Byte Buddy. This benchmark uses delegation but completes with a * hard-coded super method call. This benchmark reuses a precomputed delegator. This benchmark uses a type pool to * compare against usage of the reflection API. * * @return The created instance, in order to avoid JIT removal. * @throws Exception If the invocation causes an exception. */ @Benchmark public ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegatorWithTypePool() throws Exception { return (ExampleClass) new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClassDescription) .method(isDeclaredBy(baseClassDescription)).intercept(prefixInterceptorDescription.andThen(SuperMethodCall.INSTANCE)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
Example #5
Source File: ClassByExtensionBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark of a class extension using Byte Buddy. This benchmark uses delegation but completes with a * hard-coded super method call. This benchmark uses a type pool to compare against usage of the reflection API. * * @return The created instance, in order to avoid JIT removal. * @throws Exception If the invocation causes an exception. */ @Benchmark public ExampleClass benchmarkByteBuddyWithPrefixWithTypePool() throws Exception { return (ExampleClass) new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClassDescription) .method(isDeclaredBy(baseClassDescription)).intercept(MethodDelegation.to(prefixClassDescription).andThen(SuperMethodCall.INSTANCE)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
Example #6
Source File: ClassByExtensionBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark of a class extension using Byte Buddy. This benchmark uses delegation but completes with a * hard-coded super method call. This benchmark reuses a precomputed delegator. * * @return The created instance, in order to avoid JIT removal. * @throws Exception If the invocation causes an exception. */ @Benchmark public ExampleClass benchmarkByteBuddyWithPrefixAndReusedDelegator() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(prefixInterceptor.andThen(SuperMethodCall.INSTANCE)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
Example #7
Source File: ClassByExtensionBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark of a class extension using Byte Buddy. This benchmark uses delegation but completes with a * hard-coded super method call. * * @return The created instance, in order to avoid JIT removal. * @throws Exception If the invocation causes an exception. */ @Benchmark public ExampleClass benchmarkByteBuddyWithPrefix() throws Exception { return new ByteBuddy() .with(TypeValidation.DISABLED) .ignore(none()) .subclass(baseClass) .method(isDeclaredBy(baseClass)).intercept(MethodDelegation.to(ByteBuddyPrefixInterceptor.class).andThen(SuperMethodCall.INSTANCE)) .make() .load(newClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .getDeclaredConstructor() .newInstance(); }
Example #8
Source File: TypeWriterDefaultTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) @JavaVersionRule.Enforce(8) public void testDefaultMethodCallFromLegacyType() throws Exception { new ByteBuddy(ClassFileVersion.JAVA_V7) .subclass(Class.forName("net.bytebuddy.test.precompiled.SingleDefaultMethodInterface")) .method(isDefaultMethod()) .intercept(SuperMethodCall.INSTANCE) .make(); }
Example #9
Source File: TypeWriterDefaultTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testConstructorOnAnnotationAssertion() throws Exception { new ByteBuddy() .makeAnnotation() .defineConstructor(Visibility.PUBLIC) .intercept(SuperMethodCall.INSTANCE) .make(); }
Example #10
Source File: TypeWriterDefaultTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testConstructorOnInterfaceAssertion() throws Exception { new ByteBuddy() .makeInterface() .defineConstructor(Visibility.PUBLIC) .intercept(SuperMethodCall.INSTANCE) .make(); }
Example #11
Source File: RebaseDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testCannotRebaseDefinedMethod() throws Exception { new ByteBuddy() .rebase(Foo.class) .defineMethod(FOO, void.class).intercept(SuperMethodCall.INSTANCE) .make(); }
Example #12
Source File: RebaseDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testRebaseOfRenamedType() throws Exception { Class<?> rebased = new ByteBuddy() .rebase(Sample.class) .name(Sample.class.getName() + FOO) .constructor(ElementMatchers.any()) .intercept(SuperMethodCall.INSTANCE) .make() .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER) .getLoaded(); assertThat(rebased.getName(), is(Sample.class.getName() + FOO)); assertThat(rebased.getDeclaredConstructors().length, is(2)); }
Example #13
Source File: RebaseDynamicTypeBuilderTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testConstructorRebaseSingleAuxiliaryType() throws Exception { DynamicType.Unloaded<?> dynamicType = new ByteBuddy() .rebase(Bar.class) .constructor(any()).intercept(SuperMethodCall.INSTANCE) .make(); assertThat(dynamicType.getAuxiliaryTypes().size(), is(1)); Class<?> type = dynamicType.load(new URLClassLoader(new URL[0], null), ClassLoadingStrategy.Default.WRAPPER).getLoaded(); assertThat(type.getDeclaredConstructors().length, is(2)); assertThat(type.getDeclaredMethods().length, is(0)); Field field = type.getDeclaredField(BAR); assertThat(field.get(type.getDeclaredConstructor(String.class).newInstance(FOO)), is((Object) FOO)); }
Example #14
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
Example #15
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
Example #16
Source File: ConstructorStrategy.java From byte-buddy with Apache License 2.0 | 5 votes |
@Override protected MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
Example #17
Source File: ByteBuddy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * <p> * Creates a new {@link Enum} type. * </p> * <p> * <b>Note</b>: Byte Buddy does not cache previous subclasses but will attempt the generation of a new subclass. For caching * types, a external cache or {@link TypeCache} should be used. * </p> * * @param values The names of the type's enumeration constants * @return A type builder for creating an enumeration type. */ public DynamicType.Builder<? extends Enum<?>> makeEnumeration(Collection<? extends String> values) { if (values.isEmpty()) { throw new IllegalArgumentException("Require at least one enumeration constant"); } TypeDescription.Generic enumType = TypeDescription.Generic.Builder.parameterizedType(Enum.class, TargetType.class).build(); return new SubclassDynamicTypeBuilder<Enum<?>>(instrumentedTypeFactory.subclass(namingStrategy.subclass(enumType), ModifierContributor.Resolver.of(Visibility.PUBLIC, TypeManifestation.FINAL, EnumerationState.ENUMERATION).resolve(), enumType), classFileVersion, auxiliaryTypeNamingStrategy, annotationValueFilterFactory, annotationRetention, implementationContextFactory, methodGraphCompiler, typeValidation, visibilityBridgeStrategy, classWriterStrategy, ignoredMethods, ConstructorStrategy.Default.NO_CONSTRUCTORS) .defineConstructor(Visibility.PRIVATE).withParameters(String.class, int.class) .intercept(SuperMethodCall.INSTANCE) .defineMethod(EnumerationImplementation.ENUM_VALUE_OF_METHOD_NAME, TargetType.class, Visibility.PUBLIC, Ownership.STATIC).withParameters(String.class) .intercept(MethodCall.invoke(enumType.getDeclaredMethods() .filter(named(EnumerationImplementation.ENUM_VALUE_OF_METHOD_NAME).and(takesArguments(Class.class, String.class))).getOnly()) .withOwnType().withArgument(0) .withAssigner(Assigner.DEFAULT, Assigner.Typing.DYNAMIC)) .defineMethod(EnumerationImplementation.ENUM_VALUES_METHOD_NAME, TargetType[].class, Visibility.PUBLIC, Ownership.STATIC) .intercept(new EnumerationImplementation(new ArrayList<String>(values))); }
Example #18
Source File: ContainerResourceMonitoringTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(MemorySizeTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #19
Source File: AgentBuilderDefaultApplicationTest.java From byte-buddy with Apache License 2.0 | 4 votes |
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { return builder.constructor(ElementMatchers.any()).intercept(SuperMethodCall.INSTANCE); }
Example #20
Source File: LuaGeneration.java From Cubes with MIT License | 4 votes |
public static Class extendClass(Class<?> extend, final LuaTable delegations, Class<?>... inherit) { long startTime = System.nanoTime(); ArrayDeque<Class> toCheck = new ArrayDeque<Class>(); toCheck.add(extend); toCheck.addAll(Arrays.asList(inherit)); while (!toCheck.isEmpty()) { Class check = toCheck.pop(); for (Method method : check.getDeclaredMethods()) { if (Modifier.isAbstract(method.getModifiers())) { if (delegations.get(method.getName()).isnil()) throw new DynamicDelegationError("No delegation for abstract method " + method); } } check = check.getSuperclass(); if (check != null && check != Object.class) toCheck.add(check); } try { ReceiverTypeDefinition<?> build = b.subclass(extend).implement(inherit) .method(not(isConstructor()).and(isAbstract())).intercept(MethodDelegation.to(new AbstractInterceptor(delegations))); if (!delegations.get("__new__").isnil()) { build = build.constructor(isConstructor()).intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(new ConstructorInterceptor(delegations)))); } Junction<MethodDescription> publicMethods = not(isConstructor().or(isAbstract())).and(isPublic()).and(new ElementMatcher<MethodDescription>() { @Override public boolean matches(MethodDescription target) { return !delegations.get(target.getName()).isnil(); } }); build = build.method(publicMethods).intercept(MethodDelegation.to(new PublicInterceptor(delegations))); Unloaded unloaded = build.make(); Loaded loaded = Compatibility.get().load(unloaded); Class c = loaded.getLoaded(); Log.debug("Created dynamic class " + c.getName() + " in " + ((System.nanoTime() - startTime) / 1000000) + "ms"); return c; } catch (Exception e) { Log.error("Failed to create dynamic class " + extend.getName() + " " + Arrays.toString(inherit)); throw new CubesException("Failed to make dynamic class", e); } }
Example #21
Source File: MapReduceTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(DeprecatedOutputFormatTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #22
Source File: MapReduceTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(DeprecatedInputFormatTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #23
Source File: MapReduceTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(OutputFormatTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #24
Source File: MapReduceTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(InputFormatTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #25
Source File: RMContainerTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return SuperMethodCall.INSTANCE.andThen(to(RMContainerImplTracer.class)); }
Example #26
Source File: RMAppTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(RMAppImplTracer.class).andThen(SuperMethodCall.INSTANCE); }
Example #27
Source File: ContainerResourceMonitoringTracer.java From garmadon with Apache License 2.0 | 4 votes |
@Override protected Implementation newImplementation() { return to(VcoreUsageTracer.class).andThen(SuperMethodCall.INSTANCE); }