当前位置: 首页>>代码示例>>Java>>正文


Java DynamicType.Builder方法代码示例

本文整理汇总了Java中net.bytebuddy.dynamic.DynamicType.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java DynamicType.Builder方法的具体用法?Java DynamicType.Builder怎么用?Java DynamicType.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.bytebuddy.dynamic.DynamicType的用法示例。


在下文中一共展示了DynamicType.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
        final DynamicType.Builder<?> builder,
        final TypeDescription typeDescription,
        final ClassLoader classLoader,
        final JavaModule module) {

    final AsmVisitorWrapper methodsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceMethods.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isMethod()));

    final AsmVisitorWrapper constructorsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceConstructors.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isConstructor()));

    return builder.visit(methodsVisitor).visit(constructorsVisitor);
}
 
开发者ID:ivanyu,项目名称:java-agents-demo,代码行数:20,代码来源:MetricsCollectionByteBuddyAgent.java

示例2: build

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
public static <T> Class<?> build(Class<T> origin, String name, MethodInclusion methodInclusion, Object interceptor) {
    DynamicType.Builder<T> builder = new ByteBuddy()
            .subclass(origin).name(proxyClassName(name));
    Class<?> cachedClass = classCache.get(origin);
    if (cachedClass != null) {
        return cachedClass;
    }
    Class<? extends T> proxied = builder
            .method(methodInclusion.getIncludes())
            .intercept(MethodDelegation.to(interceptor))
            .make()
            .load(ProxyClassBuilder.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    classCache.putIfAbsent(origin, proxied);
    return proxied;
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:17,代码来源:ProxyClassBuilder.java

示例3: buildApiListingEndpoint

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
/**
 * Build a Swagger API listing JAX-RS endpoint class, binding it to given <code>path</code> using standard JAX-RS
 * {@link Path} annotation.
 * @param classLoader ClassLoader to use to create the class proxy
 * @param apiGroupId API group id
 * @param path Endpoint path
 * @param authSchemes Authenticatiob schemes
 * @param rolesAllowed Optional security roles for endpoint authorization
 * @return The Swagger API listing JAX-RS endpoint class proxy
 */
public static Class<?> buildApiListingEndpoint(ClassLoader classLoader, String apiGroupId, String path,
		String[] authSchemes, String[] rolesAllowed) {
	String configId = (apiGroupId != null && !apiGroupId.trim().equals("")) ? apiGroupId
			: ApiGroupId.DEFAULT_GROUP_ID;
	final ClassLoader cl = (classLoader != null) ? classLoader : ClassUtils.getDefaultClassLoader();
	DynamicType.Builder<SwaggerApiListingResource> builder = new ByteBuddy()
			.subclass(SwaggerApiListingResource.class)
			.annotateType(AnnotationDescription.Builder.ofType(Path.class).define("value", path).build())
			.annotateType(AnnotationDescription.Builder.ofType(ApiGroupId.class).define("value", configId).build());
	if (authSchemes != null && authSchemes.length > 0) {
		if (authSchemes.length == 1 && authSchemes[0] != null && authSchemes[0].trim().equals("*")) {
			builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class).build());
		} else {
			builder = builder.annotateType(AnnotationDescription.Builder.ofType(Authenticate.class)
					.defineArray("schemes", authSchemes).build());
		}
	}
	if (rolesAllowed != null && rolesAllowed.length > 0) {
		builder = builder.annotateType(AnnotationDescription.Builder.ofType(RolesAllowed.class)
				.defineArray("value", rolesAllowed).build());
	}
	return builder.make().load(cl, ClassLoadingStrategy.Default.INJECTION).getLoaded();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:34,代码来源:SwaggerJaxrsUtils.java

示例4: check

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final void check() throws Exception {
    final TypeDescription typeDescription = new TypeDescription.ForLoadedType(clazz);
    final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(clazz);
    final DynamicType.Unloaded<?> make = bt
            .transitionResult(subclass, typeDescription)
            .value()
            .get()
            .make();
    final Class<?> newClazz = make.load(new AnonymousClassLoader()).getLoaded();
    assertThat(
        List.of(newClazz.getDeclaredMethods()).map(Method::getName)
    ).containsOnlyElementsOf(
        methodNames
    );
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:17,代码来源:AssertClassToHaveCertainMethodsAfterBuilderTransition.java

示例5: createMethodIdProxy

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
private static <C> C createMethodIdProxy(final Class<C> interfaceToProxy, final Optional<String> scopeNameOpt)
{
    final List<ConfigDescriptor> configDescList = ConfigSystem.descriptorFactory.buildDescriptors(interfaceToProxy, scopeNameOpt);

    DynamicType.Builder<C> typeBuilder = new ByteBuddy().subclass(interfaceToProxy);
    for (ConfigDescriptor desc : configDescList) {
        typeBuilder = typeBuilder.method(ElementMatchers.is(desc.getMethod())).intercept(InvocationHandlerAdapter.of((Object proxy, Method method1, Object[] args) -> {
            log.trace("BB InvocationHandler identifying method {} proxy {}, argCount {}", method1.getName(), proxy.toString(), args.length);
            lastIdentifiedMethodAndScope.set(new MethodAndScope(method1, scopeNameOpt));
            return defaultForType(desc.getMethod().getReturnType());
        }));
    }

    Class<? extends C> configImpl = typeBuilder.make()
        .load(interfaceToProxy.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
        .getLoaded();
    try {
        return configImpl.newInstance();
    }
    catch (InstantiationException | IllegalAccessException ex) {
        throw new ConfigException("Failed to instantiate identification implementation of Config {} scope {}",
            interfaceToProxy.getName(), scopeNameOpt.orElse("<empty>"), ex);
    }
}
 
开发者ID:kikinteractive,项目名称:ice,代码行数:25,代码来源:MethodIdProxyFactory.java

示例6: createInstanceWithFields

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
private Object createInstanceWithFields(Parameter[] parameters)
{
    DynamicType.Builder<Object> objectBuilder = new ByteBuddy().subclass(Object.class)
            .modifiers(PUBLIC);
    for (Parameter parameter : parameters) {
        objectBuilder = objectBuilder.defineField(parameter.getName(), parameter.getType(), PUBLIC)
                .annotateField(ArrayUtils.add(parameter.getAnnotations(), INJECT_ANNOTATION));
    }
    try {
        Class<?> createdClass = objectBuilder.make()
                .load(getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
                .getLoaded();
        return createdClass
                .getConstructor()
                .newInstance();
    }
    catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:prestodb,项目名称:tempto,代码行数:21,代码来源:ReflectionInjectorHelper.java

示例7: processMethod

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public <E> DynamicType.Builder<E> processMethod(final DynamicType.Builder<E> builder, final Method method, final Annotation annotation) {
    final java.lang.reflect.Parameter[] arguments = method.getParameters();

    if (ReflectionUtility.isSetMethod(method))
        if (arguments == null || arguments.length == 0)
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had no arguments.");
        else if (arguments.length == 1)
            return this.setProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had more than 1 arguments.");
    else if (ReflectionUtility.isGetMethod(method))
        if (arguments == null || arguments.length == 0)
            return this.getProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had arguments.");
    else if (ReflectionUtility.isRemoveMethod(method))
        if (arguments == null || arguments.length == 0)
            return this.removeProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had some arguments.");
    else
        throw new IllegalStateException(method.getName() + " was annotated with @Property but did not begin with either of the following keywords: add, get");
}
 
开发者ID:Syncleus,项目名称:Ferma,代码行数:25,代码来源:PropertyMethodHandler.java

示例8: processMethod

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public <E> DynamicType.Builder<E> processMethod(final DynamicType.Builder<E> builder, final Method method, final Annotation annotation)
{
    final java.lang.reflect.Parameter[] arguments = method.getParameters();

    if (ReflectionUtility.isSetMethod(method))
        if (arguments == null || arguments.length == 0)
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had no arguments.");
        else if (arguments.length == 1)
            return this.setProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had more than 1 arguments.");
    else if (ReflectionUtility.isGetMethod(method))
        if (arguments == null || arguments.length == 0)
            return this.getProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had arguments.");
    else if (ReflectionUtility.isRemoveMethod(method))
        if (arguments == null || arguments.length == 0)
            return this.removeProperty(builder, method, annotation);
        else
            throw new IllegalStateException(method.getName() + " was annotated with @Property but had some arguments.");
    else
        throw new IllegalStateException(
                    method.getName() + " was annotated with @Property but did not begin with either of the following keywords: add, get");
}
 
开发者ID:windup,项目名称:windup,代码行数:27,代码来源:WindupPropertyMethodHandler.java

示例9: make

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public DynamicType make(String auxiliaryTypeName,
                        ClassFileVersion classFileVersion,
                        MethodAccessorFactory methodAccessorFactory) {
    MethodDescription accessorMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
    LinkedHashMap<String, TypeDescription> parameterFields = extractFields(accessorMethod);
    DynamicType.Builder<?> builder = new ByteBuddy(classFileVersion)
            .with(PrecomputedMethodGraph.INSTANCE)
            .subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS)
            .name(auxiliaryTypeName)
            .modifiers(DEFAULT_TYPE_MODIFIER)
            .implement(Runnable.class, Callable.class).intercept(new MethodCall(accessorMethod, assigner))
            .implement(serializableProxy ? new Class<?>[]{Serializable.class} : new Class<?>[0])
            .defineConstructor().withParameters(parameterFields.values())
            .intercept(ConstructorCall.INSTANCE);
    for (Map.Entry<String, TypeDescription> field : parameterFields.entrySet()) {
        builder = builder.defineField(field.getKey(), field.getValue(), Visibility.PRIVATE);
    }
    return builder.make();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodCallProxy.java

示例10: processMethod

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
/**
 * The handling method.
 */
@Override
public <E> DynamicType.Builder<E> processMethod(final DynamicType.Builder<E> builder, final Method method, final Annotation annotation)
{
    String methodName = method.getName();
    if (ReflectionUtility.isGetMethod(method))
        return createInterceptor(builder, method);
    else if (ReflectionUtility.isSetMethod(method))
        return createInterceptor(builder, method);
    else if (methodName.startsWith("addAll"))
        return createInterceptor(builder, method);
    else if (methodName.startsWith("add"))
        return createInterceptor(builder, method);
    else
        throw new WindupException("Only get*, set*, add*, and addAll* method names are supported for @"
                    + SetInProperties.class.getSimpleName() + ", found at: " + method.getName());
}
 
开发者ID:windup,项目名称:windup,代码行数:20,代码来源:SetInPropertiesHandler.java

示例11: getPropertyNameExtractor

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
public static <T> T getPropertyNameExtractor(Class<T> type) {
    DynamicType.Builder<?> builder = new ByteBuddy(ClassFileVersion.JAVA_V8)
            .subclass(type.isInterface() ? Object.class : type);

    if (type.isInterface()) {
        builder = builder.implement(type);
    }

    Class<?> proxyType = builder
            .method(ElementMatchers.any())
                .intercept(MethodDelegation.to(PropertyNameExtractorInterceptor.class))
            .make()
            .load(
                    PropertyNames.class.getClassLoader(),
                    ClassLoadingStrategy.Default.WRAPPER
            )
            .getLoaded();

    try {
        @SuppressWarnings("unchecked")
        Class<T> typed = (Class<T>) proxyType;
        return typed.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(
                "Couldn't instantiate proxy for method name retrieval", e
        );
    }
}
 
开发者ID:strangeway-org,项目名称:nameof,代码行数:29,代码来源:PropertyNames.java

示例12: transitionResult

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final Result<DynamicType.Builder<?>> transitionResult(DynamicType.Builder<?> source, TypeDescription typeDescription) {
    Result<DynamicType.Builder<?>> result = mainTransition.transitionResult(source, typeDescription);
    if(result.issues().nonEmpty()) {
        result = fallbackTransition.transitionResult(source, typeDescription);
    }
    return result;
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:9,代码来源:BtFallback.java

示例13: transitionResult

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final Result<DynamicType.Builder<?>> transitionResult(DynamicType.Builder<?> source, TypeDescription typeDescription) {
    if(matcher.matches(typeDescription)) {
        return matchBranch.transitionResult(source, typeDescription);
    } else {
        return mismatchBranch.transitionResult(source, typeDescription);
    }
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:9,代码来源:BtConditional.java

示例14: transitionResult

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final Result<DynamicType.Builder<?>> transitionResult(DynamicType.Builder<?> source, TypeDescription typeDescription) {
    final Result<TypeDescription> validateResult = validator.transitionResult(typeDescription);
    final List<String> issues = validateResult.issues();
    if(issues.isEmpty()) {
        return delegate.transitionResult(source, typeDescription);
    } else {
        return new RFailure<>(issues);
    }
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:11,代码来源:BtValidated.java

示例15: check

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Override
public final void check() throws Exception {
    final DynamicType.Builder<?> subclass = new ByteBuddy().redefine(type);
    final TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
    assertThatCode(() -> {
        final DynamicType.Unloaded<?> make = bt
                .transitionResult(subclass, typeDescription)
                .value()
                .get().make();
        final Class<?> clazz = make.load(new AnonymousClassLoader()).getLoaded();
        clazz.getMethods(); // Initiate validation.
    }).doesNotThrowAnyException();
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:14,代码来源:AssertBuilderTransitionIsNotCorruptingClass.java


注:本文中的net.bytebuddy.dynamic.DynamicType.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。