mardi 27 septembre 2016

Get Parameter name of java component

I Have problem with get name of parameter from default java component.

I have try using reflection :

Class cls=Class.forName("javax.swing.JFrame");
Method[] met=cls.getDeclaredMethods();
for(Method m : met)
{
    Parameter[] par = m.getParameters();
    for(Parameter p : par)
    {
        System.out.println(p.getName);
    }
}

but I get result arg0, arg1, arg2, etc

I have try use paranamers :

Class cls=Class.forName("javax.swing.JFrame");
Method[] met=cls.getDeclaredMethods();
for(Method m : met)
{
    m = cls.getMethod(m.getName(), m.getParameterTypes());
    Paranamer paranamer = new AdaptiveParanamer();
    paranamerName=paranamer.lookupParameterNames(m, true);
    for(String getParam : paranamerName)
    {
        System.out.println(getParam);
    }
}

but I have get some errors :

SEVERE: null
com.thoughtworks.paranamer.ParameterNamesNotFoundException: One or more @Named annotations missing for class 'java.awt.Canvas', methodOrCtor update and parameter types java.awt.Graphics
        at com.thoughtworks.paranamer.AnnotationParanamer.lookupParameterNames(AnnotationParanamer.java:129)
        at com.thoughtworks.paranamer.CachingParanamer.lookupParameterNames(CachingParanamer.java:76)
        at com.thoughtworks.paranamer.CachingParanamer.lookupParameterNames(CachingParanamer.java:68)

I have change using :

Paranamer paranamer = new CachingParanamer(new AnnotationParanamer(new BytecodeReadingParanamer()));

But still doesn't work. or is any other way to fix it ?





Aucun commentaire:

Enregistrer un commentaire