Parag Phadtare
Parag Phadtare

Reputation: 117

Paranamer does not return parameter names

I am using paranamer.jar to get the parameter names of a method. But it does not get any parameter names.

    Class c = Class.forName("com.soa1.MyClass");
    Class[] argTypes = { java.lang.String.class };
    Method method=ABC.class.getMethod("getData",argTypes);
Paranamer paranamer = new CachingParanamer();
    String[] parameterNames = paranamer.lookupParameterNames(method,false);

Upvotes: 0

Views: 766

Answers (3)

Bilel Boulifa
Bilel Boulifa

Reputation: 216

keep the debug information when compiling

if you are compiling with eclipse so check the option keep debug information in project-properties-java compiler

if you are compiling with javac add -g option

and in your code use Paranamer paranamer = new AdaptiveParanamer();

Upvotes: 0

Valmir Moraes Pereira
Valmir Moraes Pereira

Reputation: 61

Use this:

Paranamer paranamer = new AdaptiveParanamer();

Instead this:

Paranamer paranamer = new CachingParanamer();

If are not working yet, tell me, cause I have trouble with paranamer too - after help of a brazilian friend I've learned how it works. See ya!

Upvotes: 0

C. K. Young
C. K. Young

Reputation: 223083

Did the parameter names come from somewhere? According to ParaNamer's documentation, it uses several ways to obtain parameter names:

  1. Via a __PARANAMER_DATA field. Obviously, this only works if your class has such a field.
  2. Via debug information in your .class file. Obviously, this only works if your class was compiled with debugging information.
  3. Via a @Named annotation. Obviously, this only works if your method parameters contain such an annotation.

If none of these apply to your class, then sorry, parameter names will not be available.

Upvotes: 3

Related Questions