diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java index b40f08324..cd7a27032 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java @@ -270,15 +270,21 @@ class ArgumentDefinition { * Creates a new argument definition. * @param source Source information for defining the argument. */ - public ArgumentDefinition( ArgumentSource source ) { + public ArgumentDefinition( ArgumentSource source, + String fullName, + String shortName, + String doc, + boolean required, + String exclusiveOf, + String validation ) { this.source = source; - fullName = source.getFullName(); - shortName = source.getShortName(); - doc = source.getDoc(); - required = source.isRequired(); - exclusiveOf = source.getExclusiveOf(); - validation = source.getValidationRegex(); + this.fullName = fullName; + this.shortName = shortName; + this.doc = doc; + this.required = required; + this.exclusiveOf = exclusiveOf; + this.validation = validation; } } diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java index c8b3adeb8..78d016b90 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java @@ -29,6 +29,8 @@ import org.broadinstitute.sting.utils.StingException; import java.lang.reflect.Field; import java.util.Collection; +import java.util.List; +import java.util.Collections; /** * Describes the source field which defines a command-line argument. @@ -94,53 +96,26 @@ public class ArgumentSource { } /** - * Retrieves the full name of the argument, specifiable with the '--' prefix. The full name can be - * either specified explicitly with the fullName annotation parameter or implied by the field name. - * @return full name of the argument. Never null. + * Generate a list of all argument definitions to which this argument source maps. + * @return A non-null, non-empty list of argument definitions. */ - public String getFullName() { - return descriptor.fullName().trim().length() > 0 ? descriptor.fullName().trim() : field.getName().toLowerCase(); - } + public List createArgumentDefinitions() { + String fullName = descriptor.fullName().trim().length() > 0 ? descriptor.fullName().trim() : field.getName().toLowerCase(); + String shortName = descriptor.shortName().trim().length() > 0 ? descriptor.shortName().trim() : null; + String doc = descriptor.doc(); + boolean required = descriptor.required() && !isFlag(); + String exclusiveOf = descriptor.exclusiveOf().trim().length() > 0 ? descriptor.exclusiveOf().trim() : null; + String validation = descriptor.validation().trim().length() > 0 ? descriptor.validation().trim() : null; - /** - * Retrieves the short name of the argument, specifiable with the '-' prefix. The short name can - * be specified or not; if left unspecified, no short name will be present. - * @return short name of the argument. Null if no short name exists. - */ - public String getShortName() { - return descriptor.shortName().trim().length() > 0 ? descriptor.shortName().trim() : null; - } - - /** - * Documentation for this argument. Mandatory field. - * @return Documentation for this argument. - */ - public String getDoc() { - return descriptor.doc(); - } - - /** - * Returns whether this field is required. Note that flag fields are always forced to 'not required'. - * @return True if the field is mandatory and not a boolean flag. False otherwise. - */ - public boolean isRequired() { - return descriptor.required() && !isFlag(); - } - - /** - * Specifies other arguments which cannot be used in conjunction with tihs argument. Comma-separated list. - * @return A comma-separated list of exclusive arguments, or null if none are present. - */ - public String getExclusiveOf() { - return descriptor.exclusiveOf().trim().length() > 0 ? descriptor.exclusiveOf().trim() : null; - } - - /** - * A regular expression which can be used for validation. - * @return a JVM regex-compatible regular expression, or null to permit any possible value. - */ - public String getValidationRegex() { - return descriptor.validation().trim().length() > 0 ? descriptor.validation().trim() : null; + ArgumentDefinition argumentDefinition = new ArgumentDefinition( this, + fullName, + shortName, + doc, + required, + exclusiveOf, + validation ); + + return Collections.singletonList(argumentDefinition); } /** diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/FieldParser.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java similarity index 86% rename from java/src/org/broadinstitute/sting/utils/cmdLine/FieldParser.java rename to java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java index 617bcca4c..f1f227441 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/FieldParser.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java @@ -38,54 +38,54 @@ import java.util.*; * @author mhanna * @version 0.1 */ -public abstract class FieldParser { +public abstract class ArgumentTypeDescriptor { /** * our log, which we want to capture anything from org.broadinstitute.sting */ - protected static Logger logger = Logger.getLogger(FieldParser.class); + protected static Logger logger = Logger.getLogger(ArgumentTypeDescriptor.class); /** * Name of the field which should be parsed by this argument. */ protected final String fieldName; - public static FieldParser create( Field field ) { + public static ArgumentTypeDescriptor create( Field field ) { Class type = field.getType(); if( Collection.class.isAssignableFrom(type) || type.isArray() ) - return new JRECompoundFieldParser( field ); + return new CompoundArgumentTypeDescriptor( field ); else - return new JRESimpleFieldParser( field ); + return new SimpleArgumentTypeDescriptor( field ); } - static FieldParser create( String fieldName, Class type ) { + static ArgumentTypeDescriptor create( String fieldName, Class type ) { if( Collection.class.isAssignableFrom(type) || type.isArray() ) - return new JRECompoundFieldParser( fieldName, type ); + return new CompoundArgumentTypeDescriptor( fieldName, type ); else - return new JRESimpleFieldParser( fieldName, type ); + return new SimpleArgumentTypeDescriptor( fieldName, type ); } - protected FieldParser( Field field ) { + protected ArgumentTypeDescriptor( Field field ) { fieldName = field.toString(); } - protected FieldParser( String fieldName ) { + protected ArgumentTypeDescriptor( String fieldName ) { this.fieldName = fieldName; } public abstract Object parse( String... values ); } -class JRESimpleFieldParser extends FieldParser { +class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor { private final Class type; - public JRESimpleFieldParser( Field field ) { + public SimpleArgumentTypeDescriptor( Field field ) { super( field ); this.type = field.getType(); } - public JRESimpleFieldParser( String fieldName, Class type ) { + public SimpleArgumentTypeDescriptor( String fieldName, Class type ) { super( fieldName ); this.type = type; } @@ -142,12 +142,12 @@ class JRESimpleFieldParser extends FieldParser { }; } -class JRECompoundFieldParser extends FieldParser { +class CompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor { private final Class type; private final Class componentType; - private final FieldParser componentArgumentParser; + private final ArgumentTypeDescriptor componentArgumentParser; - public JRECompoundFieldParser( Field field ) { + public CompoundArgumentTypeDescriptor( Field field ) { super( field ); Class candidateType = field.getType(); @@ -181,10 +181,10 @@ class JRECompoundFieldParser extends FieldParser { else throw new StingException("Unsupported compound argument type: " + candidateType); - componentArgumentParser = FieldParser.create( fieldName, componentType ); + componentArgumentParser = ArgumentTypeDescriptor.create( fieldName, componentType ); } - public JRECompoundFieldParser( String fieldName, Class type ) { + public CompoundArgumentTypeDescriptor( String fieldName, Class type ) { super(fieldName); this.type = type; @@ -198,7 +198,7 @@ class JRECompoundFieldParser extends FieldParser { else throw new StingException("Unsupported compound argument type: " + type); - componentArgumentParser = FieldParser.create( fieldName, componentType ); + componentArgumentParser = ArgumentTypeDescriptor.create( fieldName, componentType ); } @Override diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java index 2e843da53..1eeaa82ab 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java @@ -85,7 +85,7 @@ public class ParsingEngine { public void addArgumentSource( String sourceName, Class sourceClass ) { List argumentsFromSource = new ArrayList(); for( ArgumentSource argumentSource: extractArgumentSources(sourceClass,true) ) - argumentsFromSource.add( new ArgumentDefinition(argumentSource) ); + argumentsFromSource.addAll( argumentSource.createArgumentDefinitions() ); argumentDefinitions.add( new ArgumentDefinitionGroup(sourceName, argumentsFromSource) ); } @@ -280,7 +280,7 @@ public class ParsingEngine { if( !definition.source.isFlag() ) { String[] tokens = match.values().toArray(new String[0]); - FieldParser fieldParser = FieldParser.create(definition.source.field); + ArgumentTypeDescriptor fieldParser = ArgumentTypeDescriptor.create(definition.source.field); definition.source.setValue( object, fieldParser.parse(tokens) ); } else @@ -355,7 +355,7 @@ public class ParsingEngine { * @return Parsed object of the inferred type. */ private Object constructFromString(Field f, List strs) { - FieldParser fieldParser = FieldParser.create(f); + ArgumentTypeDescriptor fieldParser = ArgumentTypeDescriptor.create(f); return fieldParser.parse( strs.toArray(new String[0]) ); } } diff --git a/java/test/org/broadinstitute/sting/playground/gatk/walkers/indels/CleanedReadInjectorTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/indels/CleanedReadInjectorTest.java similarity index 99% rename from java/test/org/broadinstitute/sting/playground/gatk/walkers/indels/CleanedReadInjectorTest.java rename to java/test/org/broadinstitute/sting/gatk/walkers/indels/CleanedReadInjectorTest.java index ef1781380..4a91146e9 100644 --- a/java/test/org/broadinstitute/sting/playground/gatk/walkers/indels/CleanedReadInjectorTest.java +++ b/java/test/org/broadinstitute/sting/gatk/walkers/indels/CleanedReadInjectorTest.java @@ -1,4 +1,4 @@ -package org.broadinstitute.sting.playground.gatk.walkers.indels; +package org.broadinstitute.sting.gatk.walkers.indels; import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.gatk.OutputTracker; diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterTest.java index fc5e33922..d02bf8f45 100755 --- a/java/test/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterTest.java +++ b/java/test/org/broadinstitute/sting/gatk/walkers/recalibration/CovariateCounterTest.java @@ -11,7 +11,6 @@ import org.junit.Test; import org.junit.Before; import org.junit.BeforeClass; import org.broadinstitute.sting.BaseTest; -import org.broadinstitute.sting.playground.gatk.walkers.indels.CleanedReadInjector; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.GenomeLocParser;