本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
}
}