当前位置: 首页>>代码示例>>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;未经允许,请勿转载。