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


Java ClassFile.addAttribute方法代码示例

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


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

示例1: addMimicAnnotation

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void addMimicAnnotation(CtClass dst, String sourceClassName,
        boolean isMimicingInterfaces, boolean isMimicingFields,
        boolean isMimicingConstructors, boolean isMimicingMethods) {
    ClassFile cf = dst.getClassFile();
    ConstPool cp = cf.getConstPool();
    AnnotationsAttribute attr = new AnnotationsAttribute(cp,
            AnnotationsAttribute.visibleTag);

    Annotation a = new Annotation(Mimic.class.getName(), cp);
    a.addMemberValue("sourceClass", new ClassMemberValue(sourceClassName,
            cp));
    a.addMemberValue("isMimicingInterfaces", new BooleanMemberValue(
            isMimicingInterfaces, cp));
    a.addMemberValue("isMimicingFields", new BooleanMemberValue(
            isMimicingFields, cp));
    a.addMemberValue("isMimicingConstructors", new BooleanMemberValue(
            isMimicingConstructors, cp));
    a.addMemberValue("isMimicingMethods", new BooleanMemberValue(
            isMimicingMethods, cp));
    attr.setAnnotation(a);
    cf.addAttribute(attr);
    cf.setVersionToJava5();
}
 
开发者ID:stephanenicolas,项目名称:mimic,代码行数:24,代码来源:MimicProcessorTest.java

示例2: generate

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
Class<? extends T> generate(Class<? extends Repository> baseImpl) {
    try {
        CtClass cc = createClass(
                getClassName(baseImpl, getCounter(repositoryInterface).incrementAndGet()),
                baseImpl
        );
        ClassFile cf = cc.getClassFile();
        ConstPool constPool = cf.getConstPool();

        cc.setModifiers(Modifier.PUBLIC);

        cc.setInterfaces(new CtClass[]{classPool.getCtClass(repositoryInterface.getName())});

        if (hasGenericConstructor(baseImpl)) {
            cc.addConstructor(createConstructor(constPool, cc));
        } else {
            cc.addConstructor(createDefaultConstructor(cc));
        }

        cf.addAttribute(createQualifierAttribute(constPool, getQualifier(baseImpl)
                .orElseThrow(() -> new NotFoundException("Qualifier annotation not found"))));

        return cc.toClass(
                classLoader,
                DefaultRepositoryCollector.class.getProtectionDomain()
        );
    } catch (NoSuchMethodException | CannotCompileException | NotFoundException e) {
        throw BusinessException.wrap(e, BusinessErrorCode.UNABLE_TO_CREATE_DEFAULT_IMPLEMENTATION)
                .put("interface", repositoryInterface)
                .put("base", baseImpl);
    }
}
 
开发者ID:seedstack,项目名称:business,代码行数:34,代码来源:DefaultRepositoryGenerator.java

示例3: setAttribute

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public void setAttribute(String name, byte[] data) {
    checkModify();
    ClassFile cf = getClassFile2();
    cf.addAttribute(new AttributeInfo(cf.getConstPool(), name, data));
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:6,代码来源:CtClassType.java

示例4: copyAnnotations

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
protected void copyAnnotations(ClassPool pool, Class<?> runnerClass, CtClass newRunnerCtClass) {
    ClassFile classFile = newRunnerCtClass.getClassFile();
    classFile.addAttribute(makeAnnotationAttribute(pool, classFile.getConstPool(), runnerClass));
}
 
开发者ID:diosmosis,项目名称:junit-composite-runner,代码行数:5,代码来源:BaseClassExtender.java

示例5: createMixInAnnotation

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
/**
 * 创建jackson的代理注解接口类 <br>
 * 2013-10-25 上午11:59:50
 *
 * @param names 要生成的字段
 * @return 代理接口类
 */
private Class<?> createMixInAnnotation(String[] names) {
    Class<?> clazz = null;
    clazz = proxyMixInAnnotationMap.get(StringHelper.hashCodeOfStringArray(names));
    if (clazz != null) {
        return clazz;
    }

    ClassPool pool = ClassPool.getDefault();

    // 创建代理接口
    CtClass cc = pool.makeInterface("ProxyMixInAnnotation" + System.currentTimeMillis()
            + proxyIndex++);

    ClassFile ccFile = cc.getClassFile();
    ConstPool constpool = ccFile.getConstPool();

    // create the annotation
    AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
            AnnotationsAttribute.visibleTag);
    // 创建JsonIgnoreProperties注解
    Annotation jsonIgnorePropertiesAnnotation = new Annotation(
            JsonIgnoreProperties.class.getName(), constpool);

    BooleanMemberValue ignoreUnknownMemberValue = new BooleanMemberValue(false, constpool);

    ArrayMemberValue arrayMemberValue = new ArrayMemberValue(constpool);// value的数组成员

    Collection<MemberValue> memberValues = new HashSet<MemberValue>();
    for (int i = 0; i < names.length; i++) {
        String name = names[i];
        StringMemberValue memberValue = new StringMemberValue(constpool);// 将name值设入注解内
        memberValue.setValue(name);
        memberValues.add(memberValue);
    }
    arrayMemberValue.setValue(memberValues.toArray(new MemberValue[]{}));

    jsonIgnorePropertiesAnnotation.addMemberValue("value", arrayMemberValue);
    jsonIgnorePropertiesAnnotation.addMemberValue("ignoreUnknown", ignoreUnknownMemberValue);

    attr.addAnnotation(jsonIgnorePropertiesAnnotation);
    ccFile.addAttribute(attr);

    // generate the class
    try {
        clazz = cc.toClass();
        proxyMixInAnnotationMap.put(StringHelper.hashCodeOfStringArray(names), clazz);
        // JsonIgnoreProperties ignoreProperties = (JsonIgnoreProperties)
        // clazz
        // .getAnnotation(JsonIgnoreProperties.class);

        // EntityHelper.print(ignoreProperties);
        //
        // EntityHelper.print(clazz);

        // try {
        // Object instance = clazz.newInstance();
        // EntityHelper.print(instance);
        //
        // } catch (InstantiationException e) {
        // e.printStackTrace();
        // } catch (IllegalAccessException e) {
        // e.printStackTrace();
        // }
    } catch (CannotCompileException e) {
        e.printStackTrace();
    }

    // right
    // mthd.getMethodInfo().addAttribute(attr);

    return clazz;

}
 
开发者ID:blademainer,项目名称:common_utils,代码行数:81,代码来源:JavassistFilterPropertyHandler.java

示例6: setGenericSignature

import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public void setGenericSignature(String sig) {
    ClassFile cf = getClassFile();
    SignatureAttribute sa = new SignatureAttribute(cf.getConstPool(), sig);
    cf.addAttribute(sa);
}
 
开发者ID:MeRPG2,项目名称:EndHQ-Libraries,代码行数:6,代码来源:CtClassType.java


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