use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class JavaSampleImportTransformer method addOutputImports.
@Override
protected void addOutputImports(MethodContext context, OutputContext outputContext) {
ImportTypeTable typeTable = context.getTypeTable();
OutputTransformer.ScopeTable scopeTable = outputContext.scopeTable();
for (TypeModel type : scopeTable.allTypes()) {
if (type == null) {
saveResourceTypeName(context);
} else {
typeTable.getAndSaveNicknameFor(type);
}
}
if (outputContext.hasMaps()) {
typeTable.getAndSaveNicknameFor("java.util.Map");
}
if (outputContext.hasBytesFileOutput()) {
typeTable.getAndSaveNicknameFor("java.io.FileOutputStream");
typeTable.getAndSaveNicknameFor("java.io.OutputStream");
}
if (outputContext.hasStringFileOutput()) {
typeTable.getAndSaveNicknameFor("java.io.FileWriter");
}
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class StaticLangApiMethodTransformer method generateAsyncOperationRequestObjectMethod.
// Used by: C# (and indirectly by Java via the overload above)
public StaticLangApiMethodView generateAsyncOperationRequestObjectMethod(MethodContext context, List<ParamWithSimpleDoc> additionalParams, boolean requiresOperationMethod, SampleContext sampleContext) {
MethodModel method = context.getMethodModel();
SurfaceNamer namer = context.getNamer();
StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder();
setCommonFields(context, methodViewBuilder);
methodViewBuilder.name(namer.getAsyncApiMethodName(context.getMethodModel(), context.getMethodConfig().getVisibility()));
methodViewBuilder.exampleName(namer.getAsyncApiMethodExampleName(method));
setRequestObjectMethodFields(context, namer.getOperationCallableMethodName(method), Synchronicity.Async, additionalParams, methodViewBuilder, context.getCallingForms(), sampleContext);
if (requiresOperationMethod) {
// Only for protobuf-based APIs.
methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
}
if (context.isLongRunningMethodContext()) {
// Only for protobuf-based APIs.
TypeModel returnType = context.getLongRunningConfig().getReturnType();
methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType));
methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
} else {
throw new IllegalArgumentException("Discovery-based APIs do not have LongRunning operations.");
}
return methodViewBuilder.type(ClientMethodType.AsyncOperationRequestObjectMethod).build();
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformer method mapLoopView.
private OutputView.MapLoopView mapLoopView(ResponseStatementProto.LoopStatement loop, MethodContext methodContext, SampleContext sampleContext, OutputContext outputContext) {
outputContext.mapSpecs().add(loop);
ScopeTable scope = outputContext.scopeTable();
String key = loop.getKey();
String value = loop.getValue();
OutputView.VariableView mapVar = accessor(new Scanner(loop.getMap()), methodContext, sampleContext, scope);
TypeModel keyType = mapVar.type().getMapKeyType();
TypeModel valueType = mapVar.type().getMapValueType();
String keyTypeName = methodContext.getTypeTable().getNicknameFor(keyType);
String valueTypeName = methodContext.getTypeTable().getNicknameFor(valueType);
if (!key.isEmpty()) {
assertIdentifierNotUsed(key, methodContext, sampleContext);
scope.put(key, keyType, keyTypeName);
}
if (!value.isEmpty()) {
assertIdentifierNotUsed(value, methodContext, sampleContext);
scope.put(value, valueType, valueTypeName);
}
return OutputView.MapLoopView.newBuilder().keyVariableName(methodContext.getNamer().localVarName(Name.anyLower(key))).keyType(keyTypeName).valueVariableName(methodContext.getNamer().localVarName(Name.anyLower(value))).valueType(valueTypeName).map(mapVar).body(loop.getBodyList().stream().map(body -> toView(body, methodContext, sampleContext, outputContext)).collect(ImmutableList.toImmutableList())).build();
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class InitCodeNode method validateKeyValue.
private static void validateKeyValue(TypeModel parentType, String key) {
if (parentType.isMap()) {
TypeModel keyType = parentType.getMapKeyType();
validateValue(keyType, key);
} else if (parentType.isRepeated()) {
validateValue(INT_TYPE, key);
} else {
// Don't validate message types, field will be missing for a bad key
}
}
use of com.google.api.codegen.config.TypeModel in project toolkit by googleapis.
the class OutputTransformerTest method testScopeTablePut.
@Test
public void testScopeTablePut() {
TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string"));
assertThat(parent.put("str", stringTypeModel, "String")).isTrue();
}
Aggregations