Merge branch 'master' of ssh://nickel.broadinstitute.org/humgen/gsa-scr1/gsa-engineering/git/unstable

This commit is contained in:
Ryan Poplin 2011-08-11 09:59:20 -04:00
commit 79c86e211f
7 changed files with 34 additions and 16 deletions

View File

@ -185,7 +185,7 @@ public class ArgumentSource {
* @return A default value for the given type. * @return A default value for the given type.
*/ */
public Object createTypeDefault(ParsingEngine parsingEngine) { public Object createTypeDefault(ParsingEngine parsingEngine) {
return typeDescriptor.createTypeDefault(parsingEngine,this,field.getType()); return typeDescriptor.createTypeDefault(parsingEngine,this,field.getGenericType());
} }
/** /**

View File

@ -96,12 +96,13 @@ public abstract class ArgumentTypeDescriptor {
/** /**
* Generates a default for the given type. * Generates a default for the given type.
*
* @param parsingEngine the parsing engine used to validate this argument type descriptor. * @param parsingEngine the parsing engine used to validate this argument type descriptor.
* @param source Source of the command-line argument. * @param source Source of the command-line argument.
* @param type Type of value to create, in case the command-line argument system wants influence. * @param type Type of value to create, in case the command-line argument system wants influence.
* @return A default value for the given type. * @return A default value for the given type.
*/ */
public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class<?> type) { throw new UnsupportedOperationException("Unable to create default for type " + getClass()); } public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) { throw new UnsupportedOperationException("Unable to create default for type " + getClass()); }
/** /**
* Given the given argument source and attributes, synthesize argument definitions for command-line arguments. * Given the given argument source and attributes, synthesize argument definitions for command-line arguments.
@ -323,8 +324,9 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor {
public boolean createsTypeDefault(ArgumentSource source) { return ! source.isRequired(); } public boolean createsTypeDefault(ArgumentSource source) { return ! source.isRequired(); }
@Override @Override
public Object createTypeDefault(ParsingEngine parsingEngine, ArgumentSource source, Class<?> type) { public Object createTypeDefault(ParsingEngine parsingEngine, ArgumentSource source, Type type) {
return RodBinding.makeUnbound((Class<? extends Feature>)type); Class parameterType = getParameterizedTypeClass(type);
return RodBinding.makeUnbound((Class<? extends Feature>)parameterType);
} }
@Override @Override
@ -646,7 +648,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor {
} }
@Override @Override
public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class<?> type) { public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) {
if(multiplexer == null || multiplexedIds == null) if(multiplexer == null || multiplexedIds == null)
throw new ReviewedStingException("No multiplexed ids available"); throw new ReviewedStingException("No multiplexed ids available");

View File

@ -364,7 +364,7 @@ public class ParsingEngine {
*/ */
private void loadValueIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) { private void loadValueIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) {
// Nothing to load // Nothing to load
if( argumentMatches.size() == 0 && !(source.createsTypeDefault() && source.isRequired())) if( argumentMatches.size() == 0 && ! source.createsTypeDefault() )
return; return;
// Target instance into which to inject the value. // Target instance into which to inject the value.

View File

@ -75,12 +75,12 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor {
} }
@Override @Override
public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) {
if(!source.isRequired()) if(!source.isRequired())
throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default.");
OutputStreamStub stub = new OutputStreamStub(defaultOutputStream); OutputStreamStub stub = new OutputStreamStub(defaultOutputStream);
engine.addOutput(stub); engine.addOutput(stub);
return createInstanceOfClass(type,stub); return createInstanceOfClass((Class)type,stub);
} }
@Override @Override

View File

@ -99,7 +99,7 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
} }
@Override @Override
public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class<?> type) { public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) {
if(!source.isRequired()) if(!source.isRequired())
throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default.");
SAMFileWriterStub stub = new SAMFileWriterStub(engine,defaultOutputStream); SAMFileWriterStub stub = new SAMFileWriterStub(engine,defaultOutputStream);

View File

@ -114,7 +114,7 @@ public class VCFWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor {
} }
@Override @Override
public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class<?> type) { public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source, Type type) {
if(!source.isRequired()) if(!source.isRequired())
throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default.");
VCFWriterStub stub = new VCFWriterStub(engine, defaultOutputStream, false, argumentSources, false, false); VCFWriterStub stub = new VCFWriterStub(engine, defaultOutputStream, false, argumentSources, false, false);

View File

@ -632,8 +632,8 @@ public class ParsingEngineUnitTest extends BaseTest {
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
private class SingleRodBindingArgProvider { private class SingleRodBindingArgProvider {
@Input(fullName="binding", shortName="V", required=false) @Input(fullName="binding", shortName="V", required=true)
public RodBinding<Feature> binding = RodBinding.makeUnbound(Feature.class); public RodBinding<Feature> binding;
} }
@Test @Test
@ -656,7 +656,7 @@ public class ParsingEngineUnitTest extends BaseTest {
private class ShortNameOnlyRodBindingArgProvider { private class ShortNameOnlyRodBindingArgProvider {
@Input(shortName="short", required=false) @Input(shortName="short", required=false)
public RodBinding<Feature> binding = RodBinding.makeUnbound(Feature.class); public RodBinding<Feature> binding; // = RodBinding.makeUnbound(Feature.class);
} }
@Test @Test
@ -677,22 +677,38 @@ public class ParsingEngineUnitTest extends BaseTest {
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 1, "Tags aren't correctly set"); Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 1, "Tags aren't correctly set");
} }
private class OptionalRodBindingArgProvider {
@Input(fullName="binding", shortName="V", required=false)
public RodBinding<Feature> binding;
@Input(fullName="bindingNull", shortName="VN", required=false)
public RodBinding<VariantContext> bindingNull = null;
}
@Test @Test
public void unbasicRodBindingArgumentTest() { public void optionalRodBindingArgumentTest() {
final String[] commandLine = new String[] {}; final String[] commandLine = new String[] {};
parsingEngine.addArgumentSource( SingleRodBindingArgProvider.class ); parsingEngine.addArgumentSource( OptionalRodBindingArgProvider.class );
parsingEngine.parse( commandLine ); parsingEngine.parse( commandLine );
parsingEngine.validate(); parsingEngine.validate();
SingleRodBindingArgProvider argProvider = new SingleRodBindingArgProvider(); OptionalRodBindingArgProvider argProvider = new OptionalRodBindingArgProvider();
parsingEngine.loadArgumentsIntoObject( argProvider ); parsingEngine.loadArgumentsIntoObject( argProvider );
Assert.assertNotNull(argProvider.binding, "Default value not applied corrected to RodBinding");
Assert.assertEquals(argProvider.binding.getName(), RodBinding.UNBOUND_VARIABLE_NAME, "Name isn't set properly"); Assert.assertEquals(argProvider.binding.getName(), RodBinding.UNBOUND_VARIABLE_NAME, "Name isn't set properly");
Assert.assertEquals(argProvider.binding.getSource(), RodBinding.UNBOUND_SOURCE, "Source isn't set to its expected value"); Assert.assertEquals(argProvider.binding.getSource(), RodBinding.UNBOUND_SOURCE, "Source isn't set to its expected value");
Assert.assertEquals(argProvider.binding.getType(), Feature.class, "Type isn't set to its expected value"); Assert.assertEquals(argProvider.binding.getType(), Feature.class, "Type isn't set to its expected value");
Assert.assertEquals(argProvider.binding.isBound(), false, "Bound() isn't returning its expected value"); Assert.assertEquals(argProvider.binding.isBound(), false, "Bound() isn't returning its expected value");
Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 0, "Tags aren't correctly set"); Assert.assertEquals(argProvider.binding.getTags().getPositionalTags().size(), 0, "Tags aren't correctly set");
Assert.assertNotNull(argProvider.bindingNull, "Default value not applied corrected to RodBinding");
Assert.assertEquals(argProvider.bindingNull.getName(), RodBinding.UNBOUND_VARIABLE_NAME, "Name isn't set properly");
Assert.assertEquals(argProvider.bindingNull.getSource(), RodBinding.UNBOUND_SOURCE, "Source isn't set to its expected value");
Assert.assertEquals(argProvider.bindingNull.getType(), VariantContext.class, "Type isn't set to its expected value");
Assert.assertEquals(argProvider.bindingNull.isBound(), false, "Bound() isn't returning its expected value");
Assert.assertEquals(argProvider.bindingNull.getTags().getPositionalTags().size(), 0, "Tags aren't correctly set");
} }
@Test(expectedExceptions = UserException.class) @Test(expectedExceptions = UserException.class)