jessiee white [
http://community.jboss.org/people/jesbo] created the discussion
"Re: How to add parameter annotation to new Method ?"
To view the discussion, visit:
http://community.jboss.org/message/639707#639707
--------------------------------------------------------------
if you want to add annotion to argo,you have to add @parameter(name = "arg0") to
the parameter.
String addAnnotiontion(@Pparameter(name = "arg0") String name,String card);
use javassist to add annotion .the main train like the below:
/**
* get constpool
*/
AttributeInfo paramAtrributeInfo =
methodInfo.getAttribute(ParameterAnnotationsAttribute.visibleTag); // or inVisibleTag
ConstPool parameterConstPool = paramAtrributeInfo.getConstPool();
/**
* param annotation
*/
Annotation parameterAnnotation = new Annotation("annotation name",
parameterConstPool);
ClassMemberValue parameterMemberValue = new ClassMemberValue("class full
name", parameterConstPool);
parameterAnnotation.addMemberValue("value", parameterMemberValue);
/**
* add annotation to dimensional array
*/
ParameterAnnotationsAttribute parameterAtrribute = ((ParameterAnnotationsAttribute)
paramAtrributeInfo);
Annotation[][] paramArrays = parameterAtrribute.getAnnotations();
int orderNum = position.getOrderNumber();
Annotation[] addAnno = paramArrays[orderNum];
Annotation[] newAnno = null;
if (addAnno.length == 0) {
newAnno = new Annotation[1];
} else {
newAnno = Arrays.copyOf(addAnno, addAnno.length + 1);
}
newAnno[addAnno.length] = parameterAnnotation;
paramArrays[orderNum] = newAnno;
parameterAtrribute.setAnnotations(paramArrays);
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/639707#639707]
Start a new discussion in Javassist at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]