use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class GoGapicSurfaceTransformer method addXExampleImports.
@VisibleForTesting
void addXExampleImports(InterfaceContext context, Iterable<MethodModel> methods) {
ImportTypeTable typeTable = context.getImportTypeTable();
typeTable.saveNicknameFor("golang.org/x/net/context;;;");
typeTable.saveNicknameFor(context.getProductConfig().getPackageName() + ";;;");
for (MethodModel method : methods) {
method.getAndSaveRequestTypeName(context.getImportTypeTable(), context.getNamer());
}
addContextImports(context, ImportContext.EXAMPLE, methods);
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateApiMethods.
private List<StaticLangApiMethodView> generateApiMethods(InterfaceContext context) {
List<StaticLangApiMethodView> apiMethods = new ArrayList<>();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
MethodContext requestMethodContext = context.asRequestMethodContext(method);
if (methodConfig.isPageStreaming()) {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generatePagedFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generatePagedRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generatePagedCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateUnpagedListCallableMethod(requestMethodContext));
} else if (methodConfig.isGrpcStreaming()) {
ImportTypeTable typeTable = context.getImportTypeTable();
switch(methodConfig.getGrpcStreamingType()) {
case BidiStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.BidiStreamingCallable");
break;
case ClientStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable");
break;
case ServerStreaming:
typeTable.saveNicknameFor("com.google.api.gax.rpc.ServerStreamingCallable");
break;
default:
throw new IllegalArgumentException("Invalid streaming type: " + methodConfig.getGrpcStreamingType());
}
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else if (methodConfig.isLongRunningOperation()) {
context.getImportTypeTable().saveNicknameFor("com.google.api.gax.rpc.OperationCallable");
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateAsyncOperationFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateAsyncOperationRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateOperationCallableMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
} else {
if (methodConfig.isFlattening()) {
for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) {
MethodContext flattenedMethodContext = context.asFlattenedMethodContext(method, flatteningGroup);
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext));
if (hasAnyResourceNameParameter(flatteningGroup)) {
apiMethods.add(apiMethodTransformer.generateFlattenedMethod(flattenedMethodContext.withResourceNamesInSamplesOnly()));
}
}
}
apiMethods.add(apiMethodTransformer.generateRequestObjectMethod(requestMethodContext));
apiMethods.add(apiMethodTransformer.generateCallableMethod(requestMethodContext));
}
}
return apiMethods;
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceNamer method getAndSavePagedResponseTypeName.
@Override
public String getAndSavePagedResponseTypeName(MethodContext methodContext, FieldConfig resourceFieldConfig) {
// TODO(michaelbausor) make sure this uses the typeTable correctly
ImportTypeTable typeTable = methodContext.getTypeTable();
String fullPackageWrapperName = typeTable.getImplicitPackageFullNameFor(getApiWrapperClassName(methodContext.getInterfaceConfig()));
String pagedResponseShortName = getPagedResponseTypeInnerName(methodContext.getMethodModel(), typeTable, resourceFieldConfig.getField());
return typeTable.getAndSaveNicknameForInnerType(fullPackageWrapperName, pagedResponseShortName);
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceNamer method getResourceTypeParentParseMethod.
/**
* The name of the create method for the resource one-of for the given field config
*/
public String getResourceTypeParentParseMethod(MethodContext context, FieldConfig fieldConfig) {
ImportTypeTable typeTable = context.getTypeTable();
String resourceClass = context.getFeatureConfig().useStaticCreateMethodForOneofs() ? getAndSaveResourceTypeName(typeTable, fieldConfig.getMessageFieldConfig()) : getAndSaveResourceTypeFactoryName(typeTable, fieldConfig.getMessageFieldConfig());
return resourceClass + "." + publicMethodName(Name.from("parse"));
}
use of com.google.api.codegen.transformer.ImportTypeTable in project toolkit by googleapis.
the class JavaSurfaceTransformer method getAndSaveNicknameForRootType.
private String getAndSaveNicknameForRootType(InterfaceContext context, String nickname) {
SurfaceNamer namer = context.getNamer();
ImportTypeTable typeTable = context.getImportTypeTable();
String fullyQualifiedTypeName = namer.getRootPackageName() + "." + nickname;
return typeTable.getAndSaveNicknameFor(fullyQualifiedTypeName);
}
Aggregations