I am playing with the Doclets, and I am running into the next problem. I want to get the attributes from a class, and I thought the parameter method would help. My code looks like the next one(I am doing that for the return type of a method):
ClassDoc retType = pMethod.returnType().asClassDoc();
if(retType == null) {
System.out.println("No returnType for method " + pMethod.name());
return false;
} else {
System.out.println("returnType for method "
+ pMethod.name() + " is from type " + pMethod.returnType().typeName());
}
FieldDoc[] fields = retType.fields();
System.out.println("fields length for type " +
retType.name() + " is " + fields.length);
What I am getting is
returnType for method myMethod is from type MyMethodResponse
fields length for type MyMethodResponse is 0
Maybe I am missing something. Would not the ClassDoc.fields() method bring me all the list of attributes? Is there any way to do that? Thank you very much.
Ok, searching on the web, I have not found a lot of explanations/examples. There is one web page: use doclet to extract class, field, method information from java source code in which, in order to extract the attributes, they use the ClassDoc.fields() method in the next way:
Using that in that way, I get all the attributes that I wanted, because I am disabling the access modifier filter that comes enabled by default. In the API, that boolean parameter from the fields method, is used to use enable/dissable the access modifier filter declared while calling javaDoc (-public, -protected, -package, and -private). So if we just want to get all attributes from that class, we need to disable it setting it to false.