I am in need to add an annotation to a method parameter. The method is previously created with javassist like:
CtClass cc2 = pool.makeClass("Dummy");
CtMethod method = CtNewMethod.make("public java.lang.String dummyMethod( java.lang.String oneparam){ return null; }", cc2);
The annotation I want to add is quite simple:
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Param {
/** Name of the parameter */
String name() default "";
}
1) writting the annotation in the method creation throws
javassist.CannotCompileException: [source error] syntax error near "myMethod(@Param
2) found this solution but it is based on a line which in my case returns null:
AttributeInfo paramAtrributeInfo = methodInfo.getAttribute(ParameterAnnotationsAttribute.visibleTag); // or inVisibleTag
I am getting lost on how to accomplish this; has anyone found a way to create a new method and add any annotation to its parameters?
Thanks in advance.