本文整理汇总了Java中javassist.bytecode.AnnotationsAttribute.visibleTag方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationsAttribute.visibleTag方法的具体用法?Java AnnotationsAttribute.visibleTag怎么用?Java AnnotationsAttribute.visibleTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.AnnotationsAttribute
的用法示例。
在下文中一共展示了AnnotationsAttribute.visibleTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Reflections reflections = new Reflections();
LukkitPlus.BUKKIT_EVENTS = reflections.getSubTypesOf(Event.class);
ClassPool classpath = ClassPool.getDefault();
CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
".EventCallback");
for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
(), new CtClass[] { classpath.get(event.getName()) }, new CtClass[0], "online" +
".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
eventClass.addMethod(eventMethod);
AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
.getConstPool(), AnnotationsAttribute.visibleTag);
Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
.getClassFile().getConstPool());
attribute.addAnnotation(eventHandlerAnnt);
eventMethod.getMethodInfo().addAttribute(attribute);
}
System.out.println("Done!");
eventClass.writeFile();
}
示例2: generateClass
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static Class<?> generateClass() throws NotFoundException, CannotCompileException {
ClassPool classpath = ClassPool.getDefault();
classpath.insertClassPath(new ClassClassPath(EventCallbackGenerator.class));
CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
".EventCallback");
eventClass.addInterface(classpath.get(Listener.class.getName()));
for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
if (containsStaticHandlerList(event)) {
CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
(), new CtClass[]{classpath.get(event.getName())}, new CtClass[0], "online" +
".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
eventClass.addMethod(eventMethod);
AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
.getConstPool(), AnnotationsAttribute.visibleTag);
Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
.getClassFile().getConstPool());
attribute.addAnnotation(eventHandlerAnnt);
eventMethod.getMethodInfo().addAttribute(attribute);
}
}
return eventClass.toClass(LukkitPlus.class.getClassLoader());
}
示例3: instrumentMethod
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
protected void instrumentMethod(final CtMethod ctm, final ConstPool constpool) {
try {
if(ctm.getAnnotation(susAnn)==null) {
AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation annot = new javassist.bytecode.annotation.Annotation(susAnn.getName(), constpool);
attr.addAnnotation(annot);
ctm.getMethodInfo().addAttribute(attr);
}
/*
* Install latch. Needs to be accessible in finally block, so we need a singleton registry.
* Spin up fiber and invoke this method in fiber
* -- static method
* -- non static method
* Fiber execution: accumulate all pending sub-fibers
* finally block:
* -- if running in thread, skip.
* -- send batch
* -- wait for all sub-fibers to complete
* -- drop thread latch
*
*/
} catch (Exception ex) {
ex.printStackTrace(System.err);
throw new RuntimeException(ex);
}
}
示例4: 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();
}
示例5: addAnnotation
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void addAnnotation(IClass cls, Class<? extends Annotation> ann,
HashMap<String, Object> values)
throws InstrumenterException {
CtClass cl = ((JAClass) cls).getCtClass();
ClassFile ccFile = cl.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation marker
= new javassist.bytecode.annotation.Annotation(
ann.getName(), constpool);
setValues(marker, constpool, values);
attr.addAnnotation(marker);
cl.getClassFile().addAttribute(attr);
}
示例6: addEndpointMapping
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
@Override
protected void addEndpointMapping(CtMethod ctMethod, String method, String request) {
MethodInfo methodInfo = ctMethod.getMethodInfo();
ConstPool constPool = methodInfo.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation requestMapping = new Annotation(RequestMapping.class.getName(), constPool);
ArrayMemberValue valueVals = new ArrayMemberValue(constPool);
StringMemberValue valueVal = new StringMemberValue(constPool);
valueVal.setValue(request);
valueVals.setValue(new MemberValue[]{valueVal});
requestMapping.addMemberValue("value", valueVals);
ArrayMemberValue methodVals = new ArrayMemberValue(constPool);
EnumMemberValue methodVal = new EnumMemberValue(constPool);
methodVal.setType(RequestMethod.class.getName());
methodVal.setValue(method);
methodVals.setValue(new MemberValue[]{methodVal});
requestMapping.addMemberValue("method", methodVals);
attr.addAnnotation(requestMapping);
methodInfo.addAttribute(attr);
}
示例7: addMethodAnnotations
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static void addMethodAnnotations(CtMethod ctMethod, Method method) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
if (method != null) {
MethodInfo methodInfo = ctMethod.getMethodInfo();
ConstPool constPool = methodInfo.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
methodInfo.addAttribute(attr);
for(java.lang.annotation.Annotation anno : method.getAnnotations()) {
// If it's a Transition skip
// TODO : Make this a parameterized set of Filters instead of hardcoding
//
Annotation clone = null;
if (anno instanceof Transitions || anno instanceof Transition) {
// skip
} else {
clone = cloneAnnotation(constPool, anno);
attr.addAnnotation(clone);
}
}
}
}
示例8: annotateMethod
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private AnnotationsAttribute annotateMethod(
CtMethod ctmethod,
String annotationName,
int annotationValue ) {
AnnotationsAttribute attr = new AnnotationsAttribute(
ctmethod.getMethodInfo().getConstPool(),
AnnotationsAttribute.visibleTag);
Annotation anno = new Annotation(
"java.lang.Integer",
ctmethod.getMethodInfo().getConstPool());
anno.addMemberValue(
annotationName,
new IntegerMemberValue(
ctmethod.getMethodInfo().getConstPool(),
annotationValue));
attr.addAnnotation(anno);
ctmethod.getMethodInfo().addAttribute(
attr);
return attr;
}
示例9: annotateField
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void annotateField(
CtField ctfield,
String annotationName,
int annotationValue ) {
AnnotationsAttribute attr = new AnnotationsAttribute(
ctfield.getFieldInfo().getConstPool(),
AnnotationsAttribute.visibleTag);
Annotation anno = new Annotation(
"java.lang.Integer",
ctfield.getFieldInfo().getConstPool());
anno.addMemberValue(
annotationName,
new IntegerMemberValue(
ctfield.getFieldInfo().getConstPool(),
annotationValue));
attr.addAnnotation(anno);
ctfield.getFieldInfo().addAttribute(
attr);
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
}
示例13: 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);
}
}
示例14: makeAnnotationAttribute
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
protected AnnotationsAttribute makeAnnotationAttribute(ClassPool classPool, ConstPool pool, Class<?> klass) {
AnnotationsAttribute result = new AnnotationsAttribute(pool, AnnotationsAttribute.visibleTag);
for (Annotation annotation : klass.getAnnotations()) {
result.addAnnotation(makeBytecodeAnnotation(classPool, pool, annotation));
}
return result;
}
示例15: JavassistDynamicField
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public JavassistDynamicField(DynamicBean dynamicBean, CtClass clazz, ConstPool cpool, String fieldName) {
try {
this.dynamicBean = dynamicBean;
this.cpool = cpool;
this.cfield = clazz.getField(fieldName);
attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag);
} catch (NotFoundException e) {
log.error(fieldName + " not found");
}
}