use of com.google.api.codegen.util.testing.TestValueGenerator in project toolkit by googleapis.
the class InitCodeNode method resolveNamesAndTypes.
private void resolveNamesAndTypes(InitCodeContext context, TypeModel type, Name suggestedName, FieldConfig fieldConfig) {
for (InitCodeNode child : children.values()) {
validateKeyValue(type, child.key);
child.resolveNamesAndTypes(context, getChildType(type, child.key), getChildSuggestedName(suggestedName, lineType, child), getChildFieldConfig(context.fieldConfigMap(), fieldConfig, type, child.key));
if (type.isMessage()) {
child.oneofConfig = type.getOneOfConfig(child.getKey());
}
}
SymbolTable table = context.symbolTable();
TestValueGenerator valueGenerator = context.valueGenerator();
validateType(lineType, type, children.keySet());
typeRef = type;
nodeFieldConfig = fieldConfig;
identifier = table.getNewSymbol(suggestedName);
if (children.size() == 0) {
// Set the lineType of childless nodes to SimpleInitLine
lineType = InitCodeLineType.SimpleInitLine;
// Validate initValueConfig, or generate random value
if (initValueConfig.hasSimpleInitialValue()) {
validateValue(type, initValueConfig.getInitialValue().getValue());
} else if (initValueConfig.isEmpty() && type.isPrimitive() && !type.isRepeated() && valueGenerator != null) {
String newValue = valueGenerator.getAndStoreValue(type, identifier);
initValueConfig = InitValueConfig.createWithValue(InitValue.createLiteral(newValue));
}
}
}
Aggregations