ArgumentSource no longer comparable. Arguments sorted by GATKDoclet

This commit is contained in:
Mark DePristo 2011-08-18 22:20:14 -04:00
parent 1d3799ddf7
commit 5fbdf968f7
2 changed files with 35 additions and 14 deletions

View File

@ -39,7 +39,7 @@ import java.util.List;
* @author mhanna * @author mhanna
* @version 0.1 * @version 0.1
*/ */
public class ArgumentSource implements Comparable<ArgumentSource> { public class ArgumentSource {
/** /**
* Field into which to inject command-line arguments. * Field into which to inject command-line arguments.
*/ */
@ -216,9 +216,4 @@ public class ArgumentSource implements Comparable<ArgumentSource> {
public String toString() { public String toString() {
return field.getDeclaringClass().getSimpleName() + ": " + field.getName(); return field.getDeclaringClass().getSimpleName() + ": " + field.getName();
} }
@Override
public int compareTo(final ArgumentSource argumentSource) {
return field.getName().toLowerCase().compareTo(argumentSource.field.getName().toLowerCase());
}
} }

View File

@ -111,16 +111,16 @@ public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
// attempt to instantiate the class // attempt to instantiate the class
Object instance = makeInstanceIfPossible(toProcess.clazz); Object instance = makeInstanceIfPossible(toProcess.clazz);
Map<String, List<Object>> args = new HashMap<String, List<Object>>(); Map<String, List<Map<String, Object>>> args = new HashMap<String, List<Map<String, Object>>>();
root.put("arguments", args); root.put("arguments", args);
args.put("all", new ArrayList<Object>()); args.put("all", new ArrayList<Map<String, Object>>());
args.put("required", new ArrayList<Object>()); args.put("required", new ArrayList<Map<String, Object>>());
args.put("optional", new ArrayList<Object>()); args.put("optional", new ArrayList<Map<String, Object>>());
args.put("advanced", new ArrayList<Object>()); args.put("advanced", new ArrayList<Map<String, Object>>());
args.put("hidden", new ArrayList<Object>()); args.put("hidden", new ArrayList<Map<String, Object>>());
args.put("depreciated", new ArrayList<Object>()); args.put("depreciated", new ArrayList<Map<String, Object>>());
try { try {
for ( ArgumentSource argumentSource : new TreeSet<ArgumentSource>(parsingEngine.extractArgumentSources(HelpUtils.getClassForDoc(classdoc))) ) { for ( ArgumentSource argumentSource : parsingEngine.extractArgumentSources(HelpUtils.getClassForDoc(classdoc)) ) {
ArgumentDefinition argDef = argumentSource.createArgumentDefinitions().get(0); ArgumentDefinition argDef = argumentSource.createArgumentDefinitions().get(0);
FieldDoc fieldDoc = getFieldDoc(classdoc, argumentSource.field.getName()); FieldDoc fieldDoc = getFieldDoc(classdoc, argumentSource.field.getName());
Map<String, Object> argBindings = docForArgument(fieldDoc, argumentSource, argDef); // todo -- why can you have multiple ones? Map<String, Object> argBindings = docForArgument(fieldDoc, argumentSource, argDef); // todo -- why can you have multiple ones?
@ -155,11 +155,37 @@ public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
logger.debug(String.format("Skipping hidden feature %s", argumentSource)); logger.debug(String.format("Skipping hidden feature %s", argumentSource));
} }
} }
// sort the arguments
for (Map.Entry<String,List<Map<String, Object>>> entry : args.entrySet()) {
entry.setValue(sortArguments(entry.getValue()));
}
} catch ( ClassNotFoundException e ) { } catch ( ClassNotFoundException e ) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private List<Map<String, Object>> sortArguments(List<Map<String, Object>> unsorted) {
Collections.sort(unsorted, new CompareArgumentsByName());
return unsorted;
}
private class CompareArgumentsByName implements Comparator<Map<String, Object>> {
public int compare(Map<String, Object> x, Map<String, Object> y) {
return elt(x).compareTo(elt(y));
}
private String elt(Map<String, Object> m) {
String v = m.get("name").toString().toLowerCase();
if ( v.startsWith("--") )
return v.substring(2);
else if ( v.startsWith("-") )
return v.substring(1);
else
throw new RuntimeException("Expect to see arguments beginning with at least one -, but found " + v);
}
}
private Object getFieldValue(Class c, Object instance, String fieldName) { private Object getFieldValue(Class c, Object instance, String fieldName) {
Field field = JVMUtils.findField(c, fieldName); Field field = JVMUtils.findField(c, fieldName);
if ( field != null ) { if ( field != null ) {