Note that there are some explanatory texts on larger screens.

plurals
  1. POCode generation: create interface for class
    primarykey
    data
    text
    <p>I'm writing a util to generate interface for class using Apache Velocity. Currently it uses the following dtos:</p> <pre><code>public class ClassDescriptor { private String name; private List&lt;MethodDescriptor&gt; methods; // getters/setters } public class MethodDescriptor { private String name; private String returnType; private List&lt;ParamDescriptor&gt; parameters; // getters/setters } public class ParamDescriptor { public String name; public String type; public List&lt;String&gt; generics; // getters/setters } </code></pre> <p>Here is the code used at the moment:</p> <pre><code>final Class&lt;?&gt; clazz; final ClassDescriptor classDescriptor = new ClassDescriptor(); final List&lt;MethodDescriptor&gt; methodDescriptors = new ArrayList&lt;MethodDescriptor&gt;(); for (Method method : clazz.getDeclaredMethods()) { final MethodDescriptor methodDescriptor = new MethodDescriptor(); final Paranamer paranamer = new AdaptiveParanamer(); final String[] parameterNames = paranamer.lookupParameterNames(method, false); final List&lt;ParamDescriptor&gt; paramDescriptors = new ArrayList&lt;ParamDescriptor&gt;(); for (int i = 0; i &lt; method.getParameterTypes().length; i++) { final ParamDescriptor paramDescriptor = new ParamDescriptor(); paramDescriptor.setName(parameterNames[i]); paramDescriptors.add(paramDescriptor); paramDescriptor.setType(method.getGenericParameterTypes()[i].toString().replace("class ", "")); } methodDescriptor.setParameters(paramDescriptors); methodDescriptor.setName(method.getName()); methodDescriptor.setReturnType(method.getGenericReturnType().toString()); methodDescriptors.add(methodDescriptor); } classDescriptor.setMethods(methodDescriptors); classDescriptor.setName(simpleName); </code></pre> <p>The ????? should contain code to get a list of generics for the parameter and that is the problem, I still can't find a way to do that. I'm using the following test class:</p> <pre><code>public class TestDto { public void test(Map&lt;Double, Integer&gt; test) { } } </code></pre> <p>How can I get this information? I've already tried <code>ParameterizedType</code> with no luck. </p> <p><strong>Update:</strong> the code above is now working.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload