当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationsAttribute.addAnnotation方法代码示例

本文整理汇总了Java中javassist.bytecode.AnnotationsAttribute.addAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationsAttribute.addAnnotation方法的具体用法?Java AnnotationsAttribute.addAnnotation怎么用?Java AnnotationsAttribute.addAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javassist.bytecode.AnnotationsAttribute的用法示例。


在下文中一共展示了AnnotationsAttribute.addAnnotation方法的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();
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:22,代码来源:EventCallbackGenerator.java

示例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());
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:23,代码来源:EventCallbackGenerator.java

示例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);
	}
}
 
开发者ID:nickman,项目名称:JMXMPAgent,代码行数:27,代码来源:FibonnoitreClassFileTransformer.java

示例4: 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;
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:23,代码来源:JavassistUtilsTest.java

示例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);
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:20,代码来源:CodeModifier.java

示例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);
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:26,代码来源:SpringMVCBinder.java

示例7: addClassAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static void addClassAnnotation(CtClass clazz, Class<?> annotationClass, Object... values) {
	ClassFile ccFile = clazz.getClassFile();
	ConstPool constPool = ccFile.getConstPool();
	AnnotationsAttribute attr = getAnnotationsAttribute(ccFile);
	Annotation annot = new Annotation(annotationClass.getName(), constPool);
	
	for(int i = 0; i < values.length; i = i + 2) {
		String valueName = (String)values[i];
		Object value = values[i+1];
		if (valueName != null && value != null) {
			MemberValue memberValue = createMemberValue(constPool, value);
			annot.addMemberValue(valueName, memberValue);
		}
	}
	
	attr.addAnnotation(annot);
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:18,代码来源:JavassistUtils.java

示例8: 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);
			}
		}
	}
}
 
开发者ID:statefulj,项目名称:statefulj,代码行数:22,代码来源:JavassistUtils.java

示例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);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:21,代码来源:JavassistUtilsTest.java

示例10: addField

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private CtField addField(CtClass targetClass, CtClass fieldType, String fieldName, boolean makeTransient) {
	final ConstPool constPool = targetClass.getClassFile().getConstPool();

	final CtField theField;
	try {
		theField = new CtField( fieldType, fieldName, targetClass );
		targetClass.addField( theField );
	}
	catch (CannotCompileException e) {
		throw new EnhancementException(
				String.format(
						"Could not enhance class [%s] to add field [%s]",
						targetClass.getName(),
						fieldName
				),
				e
		);
	}

	// make that new field (1) private, (2) transient and (3) @Transient
	if ( makeTransient ) {
		theField.setModifiers( theField.getModifiers() | Modifier.TRANSIENT );
	}
	theField.setModifiers( Modifier.setPrivate( theField.getModifiers() ) );

	final AnnotationsAttribute annotationsAttribute = getVisibleAnnotations( theField.getFieldInfo() );
	annotationsAttribute.addAnnotation( new Annotation( Transient.class.getName(), constPool ) );
	return theField;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:Enhancer.java

示例11: 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;
}
 
开发者ID:diosmosis,项目名称:junit-composite-runner,代码行数:8,代码来源:BaseClassExtender.java

示例12: gecco

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
@Override
public JavassistDynamicBean gecco(String[] matchUrl, String downloader, int timeout, String... pipelines) {
	AnnotationsAttribute attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag);

	Annotation annot = new Annotation(Gecco.class.getName(), cpool);
	// matchUrl
	//annot.addMemberValue("matchUrl", new StringMemberValue(matchUrl, cpool));
	ArrayMemberValue arrayMemberValueMatchUrl = new ArrayMemberValue(cpool);
	MemberValue[] elementMatchUrls = new StringMemberValue[matchUrl.length];
	for (int i = 0; i < matchUrl.length; i++) {
		elementMatchUrls[i] = new StringMemberValue(matchUrl[i], cpool);
	}
	arrayMemberValueMatchUrl.setValue(elementMatchUrls);
	annot.addMemberValue("matchUrl", arrayMemberValueMatchUrl);
	
	
	// downloader
	annot.addMemberValue("downloader", new StringMemberValue(downloader, cpool));
	// timeout
	annot.addMemberValue("timeout", new IntegerMemberValue(cpool, timeout));
	// pipelines
	ArrayMemberValue arrayMemberValue = new ArrayMemberValue(cpool);
	MemberValue[] elements = new StringMemberValue[pipelines.length];
	for (int i = 0; i < pipelines.length; i++) {
		elements[i] = new StringMemberValue(pipelines[i], cpool);
	}
	arrayMemberValue.setValue(elements);
	annot.addMemberValue("pipelines", arrayMemberValue);

	attr.addAnnotation(annot);
	cfile.addAttribute(attr);
	return this;
}
 
开发者ID:xtuhcy,项目名称:gecco,代码行数:34,代码来源:JavassistDynamicBean.java

示例13: addClassAnnotations

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void addClassAnnotations(DTODescription description, CtClass hyalineProxyClass, ConstPool constpool)
		throws CannotBuildClassException {
	if (description.getAnnotations() != null) {
		AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
		for (java.lang.annotation.Annotation annotation : description.getAnnotations()) {
			Annotation annotationCopy = JavassistUtils.createJavassistAnnotation(constpool, annotation);
			attr.addAnnotation(annotationCopy);
		}
		hyalineProxyClass.getClassFile().addAttribute(attr);
	}
}
 
开发者ID:qzagarese,项目名称:hyaline-dto,代码行数:12,代码来源:JavassistBasedClassBuilder.java

示例14: createFieldFromDescription

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private CtField createFieldFromDescription(ClassPool classPool, ConstPool constpool, FieldDescription field,
		CtClass hyalineProxyClass) throws CannotCompileException, CannotBuildClassException {
	String fieldTypeName = field.getField().getType().getCanonicalName();
	CtField ctField = CtField.make("private " + fieldTypeName + " " + field.getField().getName() + ";",
			hyalineProxyClass);
	if (field.getAnnotations() != null && field.getAnnotations().size() > 0) {
		AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
		for (java.lang.annotation.Annotation annotation : field.getAnnotations()) {
			Annotation annotationCopy = JavassistUtils.createJavassistAnnotation(constpool, annotation);
			attr.addAnnotation(annotationCopy);
		}
		ctField.getFieldInfo().addAttribute(attr);
	}
	return ctField;
}
 
开发者ID:qzagarese,项目名称:hyaline-dto,代码行数:16,代码来源:JavassistBasedClassBuilder.java

示例15: addAnnotation

import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
 * Create a new annotation to be dynamically inserted in the byte code.
 *
 * @param attribute      attribute
 * @param annotationType annotation type
 * @param members        members
 */
public static void addAnnotation(AnnotationsAttribute attribute, String annotationType, Map<String, MemberValue> members) {
    javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation(annotationType, attribute.getConstPool());
    for (Map.Entry<String, MemberValue> member : members.entrySet()) {
        annotation.addMemberValue(member.getKey(), member.getValue());
    }
    attribute.addAnnotation(annotation);
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:15,代码来源:Enhancer.java


注:本文中的javassist.bytecode.AnnotationsAttribute.addAnnotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。