* This parses the api declarations from the resource classes of the api
* @param declarations The map of resource name to declaration which will be added to
*/
public void parse(Map<String, ApiDeclaration> declarations) {
ClassDoc currentClassDoc = this.classDoc;
while (currentClassDoc != null) {
// read default error type for class
String defaultErrorTypeClass = ParserHelper.getTagValue(currentClassDoc, this.options.getDefaultErrorTypeTags());
Type defaultErrorType = ParserHelper.findModel(this.classes, defaultErrorTypeClass);
Set<Model> classModels = new HashSet<Model>();
if (this.options.isParseModels() && defaultErrorType != null) {
classModels.addAll(new ApiModelParser(this.options, this.options.getTranslator(), defaultErrorType).parse());
}
// read class level resource path, priority and description
String classResourcePath = ParserHelper.getTagValue(currentClassDoc, this.options.getResourceTags());
String classResourcePriority = ParserHelper.getTagValue(currentClassDoc, this.options.getResourcePriorityTags());
String classResourceDescription = ParserHelper.getTagValue(currentClassDoc, this.options.getResourceDescriptionTags());
// check if its a sub resource
// TODO: be more deterministic e.g. build map of sub resource types that are explicitly referenced
boolean isSubResourceClass = (getRootPath() == null || getRootPath().isEmpty()) && !currentClassDoc.isAbstract();
// dont process a subresource outside the context of its parent method
if (isSubResourceClass && this.parentMethod == null) {
// skip
} else {
for (MethodDoc method : currentClassDoc.methods()) {
ApiMethodParser methodParser = this.parentMethod == null ? new ApiMethodParser(this.options, this.rootPath, method, this.classes,
defaultErrorTypeClass) : new ApiMethodParser(this.options, this.parentMethod, method, this.classes, defaultErrorTypeClass);
Method parsedMethod = methodParser.parse();
if (parsedMethod == null) {
continue;
}
// see which resource path to use for the method, if its got a resourceTag then use that
// otherwise use the root path
String resourcePath = buildResourcePath(classResourcePath, method);
if (parsedMethod.isSubResource()) {
ClassDoc subResourceClassDoc = lookUpClassDoc(method.returnType());
if (subResourceClassDoc != null) {
// delete class from the dictionary to handle recursive sub-resources
Collection<ClassDoc> shrunkClasses = new ArrayList<ClassDoc>(this.classes);
shrunkClasses.remove(currentClassDoc);
// recursively parse the sub-resource class