New uses DocumentedGATKFeatureObject instead of annotation directly

-- Step 1 on the way to creating a static list of additional classes that we want to document.
This commit is contained in:
Mark DePristo 2011-08-18 12:31:04 -04:00
parent d4511807ed
commit e03db30ca0
4 changed files with 66 additions and 24 deletions

View File

@ -39,6 +39,5 @@ public @interface DocumentedGATKFeature {
public boolean enable() default true; public boolean enable() default true;
public String groupName(); public String groupName();
public String summary() default ""; public String summary() default "";
public Class<? extends DocumentedGATKFeatureHandler> handler() default GenericDocumentationHandler.class;
public Class[] extraDocs() default {}; public Class[] extraDocs() default {};
} }

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2011, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.utils.help;
/**
* Documentation unit. Effectively a class version of the DocumentedGATKFeature
*
* @author depristo
*/
class DocumentedGATKFeatureObject {
final boolean enable;
final String groupName, summary;
final Class[] extraDocs;
public DocumentedGATKFeatureObject(final boolean enable, final String groupName, final String summary, final Class[] extraDocs) {
this.enable = enable;
this.groupName = groupName;
this.summary = summary;
this.extraDocs = extraDocs;
}
public boolean enable() { return enable; }
public String groupName() { return groupName; }
public String summary() { return summary; }
public Class[] extraDocs() { return extraDocs; }
}

View File

@ -51,7 +51,7 @@ class GATKDocWorkUnit implements Comparable<GATKDocWorkUnit> {
/** The javadoc documentation for clazz */ /** The javadoc documentation for clazz */
final ClassDoc classDoc; final ClassDoc classDoc;
/** The annotation that lead to this Class being in GATKDoc */ /** The annotation that lead to this Class being in GATKDoc */
final DocumentedGATKFeature annotation; final DocumentedGATKFeatureObject annotation;
/** When was this walker built, and what's the absolute version number */ /** When was this walker built, and what's the absolute version number */
final String buildTimestamp, absoluteVersion; final String buildTimestamp, absoluteVersion;
@ -60,7 +60,7 @@ class GATKDocWorkUnit implements Comparable<GATKDocWorkUnit> {
Map<String, Object> forTemplate; Map<String, Object> forTemplate;
public GATKDocWorkUnit(String name, String filename, String group, public GATKDocWorkUnit(String name, String filename, String group,
DocumentedGATKFeature annotation, DocumentedGATKFeatureHandler handler, DocumentedGATKFeatureObject annotation, DocumentedGATKFeatureHandler handler,
ClassDoc classDoc, Class clazz, ClassDoc classDoc, Class clazz,
String buildTimestamp, String absoluteVersion) { String buildTimestamp, String absoluteVersion) {
this.annotation = annotation; this.annotation = annotation;

View File

@ -99,7 +99,7 @@ public class GATKDoclet {
//if ( clazz != null && clazz.getName().equals("org.broadinstitute.sting.gatk.walkers.annotator.AlleleBalance")) //if ( clazz != null && clazz.getName().equals("org.broadinstitute.sting.gatk.walkers.annotator.AlleleBalance"))
// logger.debug("foo"); // logger.debug("foo");
DocumentedGATKFeature feature = getFeatureForClassDoc(doc); DocumentedGATKFeatureObject feature = getFeatureForClassDoc(doc);
DocumentedGATKFeatureHandler handler = createHandler(doc, feature); DocumentedGATKFeatureHandler handler = createHandler(doc, feature);
if ( handler != null && handler.includeInDocs(doc) ) { if ( handler != null && handler.includeInDocs(doc) ) {
logger.info("Generating documentation for class " + doc); logger.info("Generating documentation for class " + doc);
@ -146,31 +146,26 @@ public class GATKDoclet {
} }
} }
private DocumentedGATKFeatureHandler createHandler(ClassDoc doc, DocumentedGATKFeature feature) { private DocumentedGATKFeatureHandler createHandler(ClassDoc doc, DocumentedGATKFeatureObject feature) {
try {
if ( feature != null ) { if ( feature != null ) {
if ( feature.enable() ) { if ( feature.enable() ) {
DocumentedGATKFeatureHandler handler = feature.handler().newInstance(); DocumentedGATKFeatureHandler handler = new GenericDocumentationHandler();
handler.setDoclet(this); handler.setDoclet(this);
return handler; return handler;
} else { } else {
logger.info("Skipping disabled Documentation for " + doc); logger.info("Skipping disabled Documentation for " + doc);
} }
} }
} catch ( IllegalAccessException e) {
throw new RuntimeException(e); // the constructor is now private -- this is an error
} catch ( InstantiationException e) {
throw new RuntimeException(e); // the constructor is now private -- this is an error
}
return null; return null;
} }
private DocumentedGATKFeature getFeatureForClassDoc(ClassDoc doc) { private DocumentedGATKFeatureObject getFeatureForClassDoc(ClassDoc doc) {
// todo -- what do I need the ? extends Object to pass the compiler?
Class<? extends Object> docClass = getClassForClassDoc(doc); Class<? extends Object> docClass = getClassForClassDoc(doc);
// todo -- add looked here to static TO DOC collection as well
if ( docClass != null && docClass.isAnnotationPresent(DocumentedGATKFeature.class) ) { if ( docClass != null && docClass.isAnnotationPresent(DocumentedGATKFeature.class) ) {
return docClass.getAnnotation(DocumentedGATKFeature.class); DocumentedGATKFeature f = docClass.getAnnotation(DocumentedGATKFeature.class);
return new DocumentedGATKFeatureObject(f.enable(), f.groupName(), f.summary(), f.extraDocs());
} else { } else {
return null; // not annotated so it shouldn't be documented return null; // not annotated so it shouldn't be documented
} }
@ -217,7 +212,7 @@ public class GATKDoclet {
Collections.sort(indexData); Collections.sort(indexData);
Set<DocumentedGATKFeature> docFeatures = new HashSet<DocumentedGATKFeature>(); Set<DocumentedGATKFeatureObject> docFeatures = new HashSet<DocumentedGATKFeatureObject>();
List<Map<String, String>> data = new ArrayList<Map<String, String>>(); List<Map<String, String>> data = new ArrayList<Map<String, String>>();
for ( GATKDocWorkUnit workUnit : indexData ) { for ( GATKDocWorkUnit workUnit : indexData ) {
data.add(workUnit.indexDataMap()); data.add(workUnit.indexDataMap());
@ -225,7 +220,7 @@ public class GATKDoclet {
} }
List<Map<String, String>> groups = new ArrayList<Map<String, String>>(); List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
for ( DocumentedGATKFeature feature : docFeatures ) { for ( DocumentedGATKFeatureObject feature : docFeatures ) {
groups.add(toMap(feature)); groups.add(toMap(feature));
} }
@ -237,7 +232,7 @@ public class GATKDoclet {
return root; return root;
} }
private static final Map<String, String> toMap(DocumentedGATKFeature annotation) { private static final Map<String, String> toMap(DocumentedGATKFeatureObject annotation) {
Map<String, String> root = new HashMap<String, String>(); Map<String, String> root = new HashMap<String, String>();
root.put("name", annotation.groupName()); root.put("name", annotation.groupName());
root.put("summary", annotation.summary()); root.put("summary", annotation.summary());