當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotationsAttribute.setAnnotation方法代碼示例

本文整理匯總了Java中javassist.bytecode.AnnotationsAttribute.setAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationsAttribute.setAnnotation方法的具體用法?Java AnnotationsAttribute.setAnnotation怎麽用?Java AnnotationsAttribute.setAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javassist.bytecode.AnnotationsAttribute的用法示例。


在下文中一共展示了AnnotationsAttribute.setAnnotation方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addMimicAnnotation

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的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: addToClass

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
public CtMethod addToClass(CtClass declaringClass) throws CannotCompileException {
	if (this.returnType == null) {
		this.returnType = declaringClass;
	}
	CtMethod ctMethod = CtNewMethod.make(this.modifier, this.returnType, this.name, this.parameters, this.exceptions, this.body, declaringClass);
	ctMethod.setModifiers(this.modifier);
	declaringClass.addMethod(ctMethod);
	for (String annotation : annotations) {
		ClassFile classFile = declaringClass.getClassFile();
		ConstPool constPool = classFile.getConstPool();
		AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
		Annotation annot = new Annotation(annotation, constPool);
		attr.setAnnotation(annot);
		ctMethod.getMethodInfo().addAttribute(attr);
	}
	return ctMethod;
}
 
開發者ID:siom79,項目名稱:japicmp,代碼行數:18,代碼來源:CtMethodBuilder.java

示例3: addToClassPool

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
public CtClass addToClassPool(ClassPool classPool) {
	CtClass ctClass;
	if (this.superclass.isPresent()) {
		ctClass = classPool.makeClass(this.name, this.superclass.get());
	} else {
		ctClass = classPool.makeClass(this.name);
	}
	ctClass.setModifiers(this.modifier);
	for (String annotation : annotations) {
		ClassFile classFile = ctClass.getClassFile();
		ConstPool constPool = classFile.getConstPool();
		AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
		Annotation annot = new Annotation(annotation, constPool);
		attr.setAnnotation(annot);
		ctClass.getClassFile2().addAttribute(attr);
	}
	for (CtClass interfaceCtClass : interfaces) {
		ctClass.addInterface(interfaceCtClass);
	}
	return ctClass;
}
 
開發者ID:siom79,項目名稱:japicmp,代碼行數:22,代碼來源:CtClassBuilder.java

示例4: checkRequest

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
private void checkRequest(CtClass cc, ClassPool pool) throws CannotCompileException, NotFoundException {
    try {
        // javassist won't let you check for the availability of a field and fetching the field throws
        // NotFoundException instead of returning null. So...ick.
        cc.getField("_sreq");
    } catch (NotFoundException nfe) {
        ConstPool constPool = cc.getClassFile().getConstPool();
        AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
        javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation("javax.ws.rs.core.Context", constPool);
        attr.setAnnotation(annotation);

        CtField request = new CtField(pool.get("javax.servlet.http.HttpServletRequest"), "_sreq", cc);
        request.getFieldInfo().addAttribute(attr);
        cc.addField(request);
    }
}
 
開發者ID:ryankennedy,項目名稱:telemetry,代碼行數:17,代碼來源:JaxRsMethodHandler.java

示例5: checkResponse

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
private void checkResponse(CtClass cc, ClassPool pool) throws CannotCompileException, NotFoundException {
    try {
        // javassist won't let you check for the availability of a field and fetching the field throws
        // NotFoundException instead of returning null. So...ick.
        cc.getField("_sres");
    } catch (NotFoundException nfe) {
        ConstPool constPool = cc.getClassFile().getConstPool();
        AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
        javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation("javax.ws.rs.core.Context", constPool);
        attr.setAnnotation(annotation);

        CtField response = new CtField(pool.get("javax.servlet.http.HttpServletResponse"), "_sres", cc);
        response.getFieldInfo().addAttribute(attr);
        cc.addField(response);
    }
}
 
開發者ID:ryankennedy,項目名稱:telemetry,代碼行數:17,代碼來源:JaxRsMethodHandler.java

示例6: applyTransformations

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
@Override
protected void applyTransformations(CtClass clazz) throws Exception {
    AnnotationsAttribute attribute = (AnnotationsAttribute) clazz.getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
    Annotation annotation = attribute.getAnnotation("org.spongepowered.api.plugin.Plugin");
    StringMemberValue version = (StringMemberValue) annotation.getMemberValue("version");
    version.setValue(this.version);
    attribute.setAnnotation(annotation);
}
 
開發者ID:BuycraftPlugin,項目名稱:BuycraftX,代碼行數:9,代碼來源:Transform.java

示例7: disableBooleanMember

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
/**
 * Iterate the annotations, look for a 'required' parameter, and set it to
 * false.
 * 
 * @param field
 * @param prefix
 */
private void disableBooleanMember(
		String booleanMemberName,
		CtField field ) {

	// This is the JCommander package name
	String packageName = JCommander.class.getPackage().getName();

	AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
			AnnotationsAttribute.visibleTag);

	// Look for annotations that have a 'names' attribute, and whose package
	// starts with the expected JCommander package.
	for (Annotation annotation : fieldAttributes.getAnnotations()) {
		if (annotation.getTypeName().startsWith(
				packageName)) {
			// See if it has a 'names' member variable.
			MemberValue requiredMember = annotation.getMemberValue(booleanMemberName);

			// We have a names member!!!
			if (requiredMember != null) {
				BooleanMemberValue booleanRequiredMember = (BooleanMemberValue) requiredMember;

				// Set it to not required.
				booleanRequiredMember.setValue(false);

				// This is KEY! For some reason, the existing annotation
				// will not be modified unless
				// you call 'setAnnotation' here. I'm guessing
				// 'getAnnotation()' creates a copy.
				fieldAttributes.setAnnotation(annotation);

				// Finished processing names.
				break;
			}
		}
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:45,代碼來源:JCommanderTranslationMap.java

示例8: addToClass

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
public CtField addToClass(CtClass ctClass) throws CannotCompileException {
	CtField ctField = new CtField(this.type, this.name, ctClass);
	ctField.setModifiers(this.modifier);
	if (constantValue != null) {
		if (constantValue instanceof Boolean) {
			ctClass.addField(ctField, CtField.Initializer.constant((Boolean) constantValue));
		} else if (constantValue instanceof Integer) {
			ctClass.addField(ctField, CtField.Initializer.constant((Integer) constantValue));
		} else if (constantValue instanceof Long) {
			ctClass.addField(ctField, CtField.Initializer.constant((Long) constantValue));
		} else if (constantValue instanceof String) {
			ctClass.addField(ctField, CtField.Initializer.constant((String) constantValue));
		} else {
			throw new IllegalArgumentException("Provided constant value for field is of unsupported type: " + constantValue.getClass().getName());
		}
	} else {
		ctClass.addField(ctField);
	}
	for (String annotation : annotations) {
		ClassFile classFile = ctClass.getClassFile();
		ConstPool constPool = classFile.getConstPool();
		AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
		Annotation annot = new Annotation(annotation, constPool);
		attr.setAnnotation(annot);
		ctField.getFieldInfo().addAttribute(attr);
	}
	return ctField;
}
 
開發者ID:siom79,項目名稱:japicmp,代碼行數:29,代碼來源:CtFieldBuilder.java

示例9: createQualifierAttribute

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
private AnnotationsAttribute createQualifierAttribute(ConstPool constPool,
        java.lang.annotation.Annotation qualifier) throws NotFoundException, NoSuchMethodException {
    AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    attr.setAnnotation(copyAnnotation(constPool, qualifier));
    return attr;
}
 
開發者ID:seedstack,項目名稱:business,代碼行數:7,代碼來源:DefaultRepositoryGenerator.java

示例10: addInjectAnnotation

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
private void addInjectAnnotation(ConstPool constPool, CtConstructor cc) {
    AnnotationsAttribute attribute = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    attribute.setAnnotation(createAnnotation(constPool, Inject.class));
    cc.getMethodInfo().addAttribute(attribute);
}
 
開發者ID:seedstack,項目名稱:business,代碼行數:6,代碼來源:DefaultRepositoryGenerator.java

示例11: overrideParameterPrefixes

import javassist.bytecode.AnnotationsAttribute; //導入方法依賴的package包/類
/**
 * Iterate the annotations, look for a 'names' parameter, and override it to
 * prepend the given prefix.
 * 
 * @param field
 * @param prefix
 */
private void overrideParameterPrefixes(
		CtField field,
		String[] names ) {

	// This is the JCommander package name
	String packageName = JCommander.class.getPackage().getName();

	AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
			AnnotationsAttribute.visibleTag);

	// Look for annotations that have a 'names' attribute, and whose package
	// starts with the expected JCommander package.
	for (Annotation annotation : fieldAttributes.getAnnotations()) {
		if (annotation.getTypeName().startsWith(
				packageName)) {
			// See if it has a 'names' member variable.
			MemberValue namesMember = annotation.getMemberValue(NAMES_MEMBER);

			// We have a names member!!!
			if (namesMember != null) {
				ArrayMemberValue arrayNamesMember = (ArrayMemberValue) namesMember;

				// Iterate and transform each item in 'names()' list and
				// transform it.
				MemberValue[] newMemberValues = new MemberValue[names.length];
				for (int i = 0; i < names.length; i++) {
					newMemberValues[i] = new StringMemberValue(
							names[i],
							field.getFieldInfo2().getConstPool());
				}

				// Override the member values in nameMember with the new
				// one's we've generated
				arrayNamesMember.setValue(newMemberValues);

				// This is KEY! For some reason, the existing annotation
				// will not be modified unless
				// you call 'setAnnotation' here. I'm guessing
				// 'getAnnotation()' creates a copy.
				fieldAttributes.setAnnotation(annotation);

				// Finished processing names.
				break;
			}
		}
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:55,代碼來源:JCommanderTranslationMap.java


注:本文中的javassist.bytecode.AnnotationsAttribute.setAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。