當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。