public static SampleValueSetView of(SampleValueSet config) { SampleValueSetView.Builder builder = new AutoValue_SampleValueSetView.Builder(); return builder .id(config.getId()) .title(config.getTitle()) .description(config.getDescription()) .parameters(config.getParameters().getDefaultsList()) .build(); }
SampleValueSet.newBuilder() .setParameters( SampleParameters.newBuilder() fieldConfigs, initCodeOutputType, valueSet.getParameters().getDefaultsList(), valueSet .getParameters() .getAttributesList() .stream() List<OutputSpec> outputs = valueSet.getOnSuccessList(); if (outputs.isEmpty()) { outputs = OutputTransformer.defaultOutputSpecs(methodContext.getMethodModel()); methodContext.getMethodModel().getSimpleName(), form, valueSet.getId())) .sampleFunctionName( methodContext.getNamer().getSampleFunctionName(methodContext.getMethodModel()))
@Before public void setUp() { valueSet = SampleValueSet.newBuilder().setId("test-sample-value-set-id").build(); parent = new OutputTransformer.ScopeTable(); child = new OutputTransformer.ScopeTable(parent); MockitoAnnotations.initMocks(this); when(context.getFeatureConfig()).thenReturn(featureConfig); when(context.getMethodConfig()).thenReturn(config); when(context.getMethodModel()).thenReturn(model); when(context.getNamer()).thenReturn(namer); when(context.getTypeTable()).thenReturn(typeTable); when(model.getSimpleName()).thenReturn("methodSimpleName"); when(namer.getSampleResponseVarName(context)).thenReturn("sampleResponseVarName"); }
@Override public void run() { Preconditions.checkArgument( !ran, "%s:%s: only one field of OutputSpec may be set", context.getMethodModel().getSimpleName(), valueSet.getId()); ran = true; } };
@Test(expected = IllegalArgumentException.class) public void storingDuplicateValueSets() { final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder() .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .addSampleValueSets(SampleValueSet.newBuilder().setId("bob")) .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .setSamples( SampleConfiguration.newBuilder() .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("bob") .addCallingForms(".*"))) .build(); SampleSpec sampleSpec = new SampleSpec(methodConfigProto); }
public SampleSpec(MethodConfigProto methodConfigProto) { specified = methodConfigProto.hasSamples(); sampleConfiguration = methodConfigProto.getSamples(); valueSets = methodConfigProto.getSampleValueSetsList(); HashSet<String> ids = new HashSet<>(); for (SampleValueSet valueSet : valueSets) { String id = valueSet.getId(); if (!ids.add(id)) { throw new IllegalArgumentException( String.format( "in method \"%s\": duplicate value set id: \"%s\"", methodConfigProto.getName(), id)); } } }
@Test public void valueSetsMatching() { SampleValueSet valueSetAlice = SampleValueSet.newBuilder() .setId("alice") .setParameters(SampleParameters.newBuilder().addDefaults("apple").build()) .build(); SampleValueSet valueSetBob = SampleValueSet.newBuilder() .setId("bob") .setParameters(SampleParameters.newBuilder().addDefaults("banana").build()) .build(); SampleValueSet valueSetAlison = SampleValueSet.newBuilder() .setId("alison") .setParameters(SampleParameters.newBuilder().addDefaults("apricot").build())
private OutputView.PrintView printView( List<String> config, MethodContext context, SampleValueSet valueSet, ScopeTable localVars) { Preconditions.checkArgument( !config.isEmpty(), "%s:%s: print spec cannot be empty", context.getMethodModel().getSimpleName(), valueSet.getId()); return OutputView.PrintView.newBuilder() .format(context.getNamer().getPrintSpec(config.get(0))) .args( config .subList(1, config.size()) .stream() .map( a -> printArgTransformer.generatePrintArg( context, accessor(new Scanner(a), context, valueSet, localVars))) .collect(ImmutableList.toImmutableList())) .build(); }
@Test public void valueSetsReferencedMultipleTimes() { final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder() .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .addSampleValueSets(SampleValueSet.newBuilder().setId("bob")) .setSamples( SampleConfiguration.newBuilder() .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("bob") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*"))) .build(); SampleSpec sampleSpec = new SampleSpec(methodConfigProto); assertThat(sampleSpec.getMatchingValueSets(CallingForm.Request, SampleType.STANDALONE)) .hasSize(3); } }
for (SampleTypeConfiguration sample : matchingSamples) { for (String valueSetExpression : sample.getValueSetsList()) { if (expressionMatchesId(valueSetExpression, vset.getId())) { result.add( ValueSetAndTags.newBuilder().values(vset).regionTag(sample.getRegionTag()).build());
"%s:%s: one field of OutputSpec must be set", context.getMethodModel().getSimpleName(), valueSet.getId());
private OutputView.DefineView defineView( Scanner definition, MethodContext context, SampleValueSet valueSet, ScopeTable localVars) { Preconditions.checkArgument( definition.scan() == Scanner.IDENT, "%s:%s: expected identifier: %s", context.getMethodModel().getSimpleName(), valueSet.getId(), definition.input()); String identifier = definition.tokenStr(); assertIdentifierNotReserved( identifier, context.getMethodModel().getSimpleName(), valueSet.getId()); Preconditions.checkArgument( definition.scan() == '=', "%s:%s invalid definition, expecting '=': %s", context.getMethodModel().getSimpleName(), valueSet.getId(), definition.input()); OutputView.VariableView reference = accessorNewVariable(definition, context, valueSet, localVars, identifier, false); return OutputView.DefineView.newBuilder() .variableType(localVars.getTypeName(identifier)) .variableName(context.getNamer().localVarName(Name.from(identifier))) .reference(reference) .build(); }
"%s:%s: expected identifier: %s", context.getMethodModel().getSimpleName(), valueSet.getId(), config.input()); String baseIdentifier = config.tokenStr(); "%s:%s: variable not defined: %s", context.getMethodModel().getSimpleName(), valueSet.getId(), baseIdentifier); "%s:%s: accessing a field of a resource name is not currently supported", context.getMethodModel().getSimpleName(), valueSet.getId()); Preconditions.checkArgument( type.isMessage(), "%s:%s: %s is not a message", context.getMethodModel().getSimpleName(), valueSet.getId(), config.input()); Preconditions.checkArgument( "%s:%s: %s is not scalar", context.getMethodModel().getSimpleName(), valueSet.getId(), config.input()); "%s:%s: expected identifier: %s", context.getMethodModel().getSimpleName(),
private OutputView.LoopView loopView( OutputSpec.LoopStatement loop, MethodContext context, SampleValueSet valueSet, ScopeTable localVars) { ScopeTable scope = localVars.newChild(); String loopVariable = loop.getVariable(); assertIdentifierNotReserved( loopVariable, context.getMethodModel().getSimpleName(), valueSet.getId()); OutputView.VariableView accessor = accessorNewVariable( new Scanner(loop.getCollection()), context, valueSet, scope, loopVariable, true); OutputView.LoopView ret = OutputView.LoopView.newBuilder() .variableType(scope.getTypeName(loopVariable)) .variableName(context.getNamer().localVarName(Name.from(loopVariable))) .collection(accessor) .body( loop.getBodyList() .stream() .map(body -> toView(body, context, valueSet, scope)) .collect(ImmutableList.toImmutableList())) .build(); return ret; }