use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceTransformer method addApiImports.
private void addApiImports(InterfaceContext context) {
ImportTypeTable typeTable = context.getImportTypeTable();
typeTable.saveNicknameFor("com.google.api.core.BetaApi");
typeTable.saveNicknameFor("com.google.api.gax.core.BackgroundResource");
typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable");
typeTable.saveNicknameFor("com.google.api.pathtemplate.PathTemplate");
typeTable.saveNicknameFor("java.io.Closeable");
typeTable.saveNicknameFor("java.io.IOException");
typeTable.saveNicknameFor("java.util.concurrent.TimeUnit");
typeTable.saveNicknameFor("javax.annotation.Generated");
if (context.getInterfaceConfig().hasLongRunningOperations()) {
typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationFuture");
typeTable.saveNicknameFor("com.google.longrunning.Operation");
typeTable.saveNicknameFor("com.google.longrunning.OperationsClient");
}
switch(context.getProductConfig().getTransportProtocol()) {
case HTTP:
typeTable.saveNicknameFor("java.util.List");
typeTable.saveNicknameFor("java.util.ArrayList");
typeTable.saveNicknameFor("java.util.concurrent.ScheduledExecutorService");
}
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSampleImportTransformer method addInitCodeImports.
@Override
protected void addInitCodeImports(MethodContext context, ImportTypeTable initCodeTypeTable, Iterable<InitCodeNode> nodes) {
super.addInitCodeImports(context, initCodeTypeTable, nodes);
ImportTypeTable typeTable = context.getTypeTable();
for (InitCodeNode node : nodes) {
switch(node.getLineType()) {
case ListInitLine:
typeTable.saveNicknameFor("java.util.List");
typeTable.saveNicknameFor("java.util.Arrays");
break;
case MapInitLine:
typeTable.saveNicknameFor("java.util.Map");
typeTable.saveNicknameFor("java.util.HashMap");
break;
case ReadFileInitLine:
typeTable.saveNicknameFor("java.nio.file.Files");
typeTable.saveNicknameFor("java.nio.file.Path");
typeTable.saveNicknameFor("java.nio.file.Paths");
break;
case SimpleInitLine:
case StructureInitLine:
// fall through
break;
default:
throw new IllegalArgumentException("Unrecognized line type: " + node.getLineType());
}
}
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method transform.
@Override
public List<ViewModel> transform(ApiModelT model, GapicProductConfig productConfig) {
SurfaceNamer namer = surfaceTransformer.createSurfaceNamer(productConfig);
List<ViewModel> views = new ArrayList<>();
for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
if (!productConfig.hasInterfaceConfig(apiInterface)) {
continue;
}
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createUnitTestFileView(context));
if (context.getInterfaceConfig().getSmokeTestConfig() != null) {
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createSmokeTestClassView(context));
}
}
for (InterfaceModel apiInterface : mockServiceTransformer.getGrpcInterfacesToMock(model, productConfig)) {
ImportTypeTable typeTable = surfaceTransformer.createTypeTable(productConfig.getPackageName());
InterfaceContext context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable);
views.add(createMockServiceImplFileView(context));
context = surfaceTransformer.createInterfaceContext(apiInterface, productConfig, namer, typeTable.cloneEmpty());
views.add(createMockServiceView(context));
}
return views;
}
Aggregations