0 Replies Latest reply on Nov 21, 2013 5:38 AM by Matthew Young

    Javassist adding annotation to method argument

    Matthew Young Newbie

      Read this answer (How to add parameter annotation to new Method ?) on the jboss community regarding adding an annotation to a parameter in a method. Stuck at getting the parameter or in Javassist terms the attribute.

      Given class XYZ:

      public class XYZ { public void changes(String whatever, Integer flag) { } } 

      With the following code: ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(XYZ.class.getName());

      CtMethod m = clazz.getDeclaredMethod("changes"); CtClass[] parameters = m.getParameterTypes(); // shows 2 parameter (one String, other Integer)

      AttributeInfo paramAtrributeInfo = m.getMethodInfo().getAttribute("whatever");

      paramAttributeInfo is null. I see 2 attributes when debugging but these have concrete calls LocalVariableAttribute and LineNumberAttribute.

      Can't get a handle (attribute) to add my parameter annotation to. Ideas?