• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FieldAccessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.bytebuddy.implementation.FieldAccessor的典型用法代码示例。如果您正苦于以下问题:Java FieldAccessor类的具体用法?Java FieldAccessor怎么用?Java FieldAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FieldAccessor类属于net.bytebuddy.implementation包,在下文中一共展示了FieldAccessor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createLazyClass

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Class<? extends T> createLazyClass(Class<T> type) {
	Class<? extends Element> lazyType = byteBuddy
			.subclass(AbstractElement.class)
			.implement(type)
			.defineField("handler", InvocationHandler.class, Visibility.PUBLIC)
			.implement(HandlerSetter.class)
			.intercept(FieldAccessor.ofField("handler"))
			.method(ElementMatchers.not(ElementMatchers.isDeclaredBy(HandlerSetter.class)))
			.intercept(InvocationHandlerAdapter.toField("handler"))
			.make()
			.load(type.getClassLoader())
			.getLoaded();
	lazyTypes.put(type, lazyType);
	return (Class<? extends T>) lazyType;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:17,代码来源:LazyLoader.java


示例2: defineProperty

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
@Override
public FieldDefinition.Optional<S> defineProperty(String name, TypeDefinition type, boolean readOnly) {
    if (name.isEmpty()) {
        throw new IllegalArgumentException("A bean property cannot have an empty name");
    } else if (type.represents(void.class)) {
        throw new IllegalArgumentException("A bean property cannot have a void type");
    }
    DynamicType.Builder<S> builder = this;
    FieldManifestation fieldManifestation;
    if (!readOnly) {
        builder = builder
                .defineMethod("set" + Character.toUpperCase(name.charAt(0)) + name.substring(1), void.class, Visibility.PUBLIC)
                .withParameters(type)
                .intercept(FieldAccessor.ofField(name));
        fieldManifestation = FieldManifestation.PLAIN;
    } else {
        fieldManifestation = FieldManifestation.FINAL;
    }
    return builder
            .defineMethod((type.represents(boolean.class) || type.represents(Boolean.class)
                    ? "is"
                    : "get") + Character.toUpperCase(name.charAt(0)) + name.substring(1), type, Visibility.PUBLIC)
            .intercept(FieldAccessor.ofField(name))
            .defineField(name, type, Visibility.PRIVATE, fieldManifestation);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:26,代码来源:DynamicType.java


示例3: createInstance

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
public static <T> T createInstance(Context ctx, Class<T> clazz, Name ident, JCIdent jcIdent, Class<?>[] requiredConstructor, Object[] params) {
    try {
        Class<?> fake = baseClass2Impl.get(clazz);

        if (fake == null) {
            Method visitIdent = Visitor.class.getDeclaredMethod("visitIdent", JCIdent.class);
            Method visitIdentifier = TreeVisitor.class.getDeclaredMethod("visitIdentifier", IdentifierTree.class, Object.class);
            Method toString = Object.class.getDeclaredMethod("toString");
            fake = new ByteBuddy()
                    .subclass(clazz)
                    .implement(IdentifierTree.class)
                    .defineField("ident", Name.class, Visibility.PUBLIC)
                    .defineField("jcIdent", JCIdent.class, Visibility.PUBLIC)
                    .method(ElementMatchers.named("getName")).intercept(FieldAccessor.ofField("ident"))
                    .method(ElementMatchers.named("getKind")).intercept(FixedValue.value(Kind.IDENTIFIER))
                    .method(ElementMatchers.named("accept").and(ElementMatchers.takesArguments(Visitor.class))).intercept(MethodCall.invoke(visitIdent).onArgument(0).withField("jcIdent"))
                    .method(ElementMatchers.named("accept").and(ElementMatchers.takesArgument(0, TreeVisitor.class))).intercept(MethodCall.invoke(visitIdentifier).onArgument(0).withThis().withArgument(1))
                    .method(ElementMatchers.named("toString")).intercept(MethodCall.invoke(toString).onField("ident"))
                    .make()
                    .load(JackpotTrees.class.getClassLoader())
                    .getLoaded();
            baseClass2Impl.put(clazz, fake);
        }

        NEXT: for (Constructor c : fake.getDeclaredConstructors()) {
            if (c.getParameterCount() < requiredConstructor.length)
                continue;
            for (int e = 0; e < requiredConstructor.length; e++) {
                if (!c.getParameterTypes()[e].equals(requiredConstructor[e])) {
                    continue NEXT;
                }
            }
            java.util.List<Object> instances = new ArrayList<>();
            instances.addAll(Arrays.asList(params));
            for (int i = instances.size(); i < c.getParameterCount(); i++) {
                instances.add(null);
            }

            JCTree tree = (JCTree) c.newInstance(instances.toArray(new Object[0]));

            Field identField = fake.getDeclaredField("ident");

            identField.set(tree, ident);

            Field jcIdentField = fake.getDeclaredField("jcIdent");

            jcIdentField.set(tree, jcIdent);

            return clazz.cast(tree);
        }

        throw new IllegalStateException();
    } catch (IllegalAccessException | IllegalArgumentException | IllegalStateException | InstantiationException | NoSuchFieldException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:JackpotTrees.java


示例4: constructClass

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
private <E> Class<? extends E> constructClass(final Element element, final Class<E> clazz) {
    Class constructedClass = constructedClassCache.get(clazz);
    if (constructedClass != null)
        return constructedClass;

    DynamicType.Builder<? extends E> classBuilder;
    if (clazz.isInterface())
        if (element instanceof Vertex)
            classBuilder = (DynamicType.Builder<? extends E>) new ByteBuddy().subclass(AbstractVertexFrame.class).implement(clazz);
        else if (element instanceof Edge)
            classBuilder = (DynamicType.Builder<? extends E>) new ByteBuddy().subclass(AbstractEdgeFrame.class).implement(clazz);
        else
            throw new IllegalStateException("class is neither an Edge or a vertex!");
    else {
        if( !(element instanceof Vertex || element instanceof Edge) )
            throw new IllegalStateException("element is neither an edge nor a vertex");
        else if (element instanceof Vertex && !VertexFrame.class.isAssignableFrom(clazz))
            throw new IllegalStateException(clazz.getName() + " Class is not a type of VertexFrame");
        else if (element instanceof Edge && !EdgeFrame.class.isAssignableFrom(clazz))
            throw new IllegalStateException(clazz.getName() + " Class is not a type of EdgeFrame");
        classBuilder = new ByteBuddy().subclass(clazz);
    }

    classBuilder = classBuilder.defineField("reflectionCache", ReflectionCache.class, Visibility.PRIVATE, FieldManifestation.PLAIN).implement(CachesReflection.class).intercept(FieldAccessor.
          ofBeanProperty());

    //try and construct any abstract methods that are left
    for (final Method method : clazz.getMethods())
        if (isAbstract(method))
            annotation_loop:
            for (final Annotation annotation : method.getAnnotations()) {
                final MethodHandler handler = methodHandlers.get(annotation.annotationType());
                if (handler != null) {
                    classBuilder = handler.processMethod(classBuilder, method, annotation);
                    break;
                }
            }

    constructedClass = classBuilder.make().load(AnnotationFrameFactory.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    this.constructedClassCache.put(clazz, constructedClass);
    return constructedClass;
}
 
开发者ID:Syncleus,项目名称:Ferma,代码行数:43,代码来源:AbstractAnnotationFrameFactory.java


示例5: constructClass

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
private <E> Class<? extends E> constructClass(final Element element, final Class<E> clazz)
{
    Class constructedClass = constructedClassCache.get(clazz);
    if (constructedClass != null)
        return constructedClass;

    DynamicType.Builder<? extends E> classBuilder;
    if (clazz.isInterface())
    {
        if (element instanceof Vertex)
            classBuilder = (DynamicType.Builder<? extends E>) new ByteBuddy().subclass(AbstractVertexFrame.class);
        else if (element instanceof Edge)
            classBuilder = (DynamicType.Builder<? extends E>) new ByteBuddy().subclass(AbstractEdgeFrame.class);
        else
            throw new IllegalStateException("class is neither an Edge or a vertex!");

        if (clazz.getCanonicalName().contains("ByteBuddy"))
        {
            // if the input class is itself a bytebuddy class, only take its interfaces
            classBuilder = classBuilder.implement(clazz.getInterfaces());
        }
        else
        {
            classBuilder = classBuilder.implement(clazz);
        }
    }
    else
    {
        if (!(element instanceof Vertex || element instanceof Edge))
            throw new IllegalStateException("element is neither an edge nor a vertex");
        else if (element instanceof Vertex && !VertexFrame.class.isAssignableFrom(clazz))
            throw new IllegalStateException(clazz.getName() + " Class is not a type of VertexFrame");
        else if (element instanceof Edge && !EdgeFrame.class.isAssignableFrom(clazz))
            throw new IllegalStateException(clazz.getName() + " Class is not a type of EdgeFrame");
        classBuilder = new ByteBuddy().subclass(clazz);
    }

    classBuilder = classBuilder.defineField("reflectionCache", ReflectionCache.class, Visibility.PRIVATE, FieldManifestation.PLAIN)
                .implement(CachesReflection.class).intercept(FieldAccessor.ofBeanProperty());

    /*
     * Just a hack so that our generified frame types can work.
     *
     * This information will not really be used by the generated class.
     */
    classBuilder = classBuilder.typeVariable("T");

    // try and construct any abstract methods that are left
    for (final Method method : clazz.getMethods())
        if (isAbstract(method))
            annotation_loop: for (final Annotation annotation : method.getAnnotations())
            {
                final MethodHandler handler = methodHandlers.get(annotation.annotationType());
                if (handler != null)
                {
                    classBuilder = handler.processMethod(classBuilder, method, annotation);
                    break;
                }
            }

    DynamicType.Unloaded unloadedClass = classBuilder.make();
    constructedClass = unloadedClass.load(this.classLoader, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    this.constructedClassCache.put(clazz, constructedClass);
    return constructedClass;
}
 
开发者ID:windup,项目名称:windup,代码行数:66,代码来源:AbstractAnnotationFrameFactory.java


示例6: getCreator

import net.bytebuddy.implementation.FieldAccessor; //导入依赖的package包/类
/**
 * Get robust web element factory for this context.
 * 
 * @param context target context
 * @return robust web element factory
 */
private static synchronized InstanceCreator getCreator(WrapsContext context) {
    WebDriver driver = context.getWrappedDriver();
    String driverName = driver.getClass().getName();
    if (creatorMap.containsKey(driverName)) {
        return creatorMap.get(driverName);
    }
    
    WebElement reference = driver.findElement(By.tagName("*"));
    Class<? extends WebElement> refClass = reference.getClass();
    
    Class<? extends WebElement> wrapperClass = new ByteBuddy()
                    .subclass(refClass)
                    .name(refClass.getPackage().getName() + ".Robust" + refClass.getSimpleName())
                    .method(not(isDeclaredBy(Object.class)))
                    .intercept(MethodDelegation.withEmptyConfiguration()
                            .withBinders(TargetMethodAnnotationDrivenBinder.ParameterBinder.DEFAULTS)
                            .withResolvers(MethodNameEqualityResolver.INSTANCE, BindingPriority.Resolver.INSTANCE)
                            .filter(not(isDeclaredBy(Object.class)))
                            .toField("interceptor"))
                    .implement(RobustWebElement.class)
                    .defineField("interceptor", RobustElementWrapper.class, Visibility.PRIVATE)
                    .implement(InterceptionAccessor.class).intercept(FieldAccessor.ofBeanProperty())
                    .make()
                    .load(refClass.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                    .getLoaded();
    
    InstanceCreator creator;
    
    try {
        creator = new ByteBuddy()
                        .subclass(InstanceCreator.class)
                        .method(not(isDeclaredBy(Object.class)))
                        .intercept(MethodDelegation.toConstructor(wrapperClass))
                        .make()
                        .load(wrapperClass.getClassLoader())
                        .getLoaded().newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw UncheckedThrow.throwUnchecked(e);
    }
    
    creatorMap.put(driverName, creator);
    return creator;
}
 
开发者ID:Nordstrom,项目名称:Selenium-Foundation,代码行数:50,代码来源:RobustElementFactory.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ProspectiveSearchServiceFactory类代码示例发布时间:2022-05-22
下一篇:
Java NavbarComponents类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap