use of com.google.api.codegen.util.TypeAlias in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateRpcStubClass.
private StaticLangRpcStubView generateRpcStubClass(InterfaceContext context, GapicProductConfig productConfig) {
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addRpcStubImports(context);
// Stub class has different default package name from method, request, and resource classes.
InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
List<StaticLangApiMethodView> methods = javaApiMethodTransformer.generateApiMethods(apiMethodsContext);
StaticLangRpcStubView.Builder stubClass = StaticLangRpcStubView.newBuilder();
stubClass.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
String name = namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol());
stubClass.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
stubClass.name(name);
stubClass.parentName(namer.getApiStubInterfaceName(interfaceConfig));
stubClass.settingsClassName(getAndSaveNicknameForRootType(apiMethodsContext, namer.getApiSettingsClassName(interfaceConfig)));
stubClass.stubSettingsClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getApiStubSettingsClassName(interfaceConfig)));
stubClass.callableFactoryClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol())));
stubClass.methodDescriptors(apiCallableTransformer.generateMethodDescriptors(apiMethodsContext));
stubClass.apiCallables(apiCallableTransformer.generateStaticLangApiCallables(apiMethodsContext));
stubClass.callableMethods(filterIncludeCallableMethods(methods));
stubClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
stubClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
stubClass.transportProtocol(productConfig.getTransportProtocol());
if (productConfig.getTransportProtocol() == TransportProtocol.HTTP) {
stubClass.callSettingsClassName("HttpJsonCallSettings");
stubClass.stubCallableFactoryClassName("HttpJsonStubCallableFactory");
} else {
stubClass.callSettingsClassName("GrpcCallSettings");
stubClass.stubCallableFactoryClassName("GrpcStubCallableFactory");
}
for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
context.getImportTypeTable().getAndSaveNicknameFor(alias);
}
return stubClass.build();
}
use of com.google.api.codegen.util.TypeAlias in project toolkit by googleapis.
the class StandardImportSectionTransformer method generateImportSection.
public ImportSectionView generateImportSection(Map<String, TypeAlias> typeImports, String className) {
HashSet<String> allFullNames = new HashSet<>();
ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
for (TypeAlias alias : typeImports.values()) {
if (excludeAppImport(alias, className)) {
continue;
}
ImportTypeView.Builder imp = ImportTypeView.newBuilder();
String fullName;
switch(alias.getImportType()) {
case OuterImport:
fullName = alias.getParentFullName();
break;
default:
fullName = alias.getFullName();
break;
}
if (allFullNames.contains(fullName)) {
continue;
}
allFullNames.add(fullName);
imp.fullName(fullName);
imp.nickname(alias.getNickname());
imp.type(alias.getImportType());
appImports.add(ImportFileView.newBuilder().types(ImmutableList.of(imp.build())).build());
}
return ImportSectionView.newBuilder().appImports(appImports.build()).build();
}
use of com.google.api.codegen.util.TypeAlias in project toolkit by googleapis.
the class PythonTypeTable method updateOldImports.
private void updateOldImports(String shortName, Collection<TypeAlias> aliases) {
for (TypeAlias alias : aliases) {
String className = alias.getNickname().substring(alias.getNickname().indexOf(".") + 1);
getAndSaveNicknameFor(TypeAlias.createAliasedImport(alias.getFullName(), shortName + "." + className));
}
}
use of com.google.api.codegen.util.TypeAlias in project toolkit by googleapis.
the class PhpImportSectionTransformer method generateImportSection.
/**
* Package-private for use in PhpGapicSurfaceTestTransformer
*/
ImportSectionView generateImportSection(Map<String, TypeAlias> typeImports) {
ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
for (Map.Entry<String, TypeAlias> entry : typeImports.entrySet()) {
String key = entry.getKey();
TypeAlias alias = entry.getValue();
// Remove leading backslash because it is not required by PHP use statements
String fullName = key.startsWith("\\") ? key.substring(1) : key;
ImportTypeView.Builder imp = ImportTypeView.newBuilder();
imp.fullName(fullName);
imp.nickname(alias.getNickname());
imp.type(alias.getImportType());
appImports.add(ImportFileView.newBuilder().types(ImmutableList.of(imp.build())).build());
}
return ImportSectionView.newBuilder().appImports(appImports.build()).build();
}
use of com.google.api.codegen.util.TypeAlias in project toolkit by googleapis.
the class PythonImportSectionTransformer method generateTypesProtoImports.
private ImportSectionView.Builder generateTypesProtoImports(Model model, GapicProductConfig productConfig) {
ImportSectionView.Builder importView = ImportSectionView.newBuilder();
ModelTypeTable allTypeTable = emptyTypeTable(productConfig);
// Imports from the same API client library package.
Set<ImportFileView> localImports = new TreeSet<>(importFileViewComparator());
// Shared imports, e.g. protobuf imports.
Set<ImportFileView> sharedImports = new TreeSet<>(importFileViewComparator());
// All imports.
Set<ImportFileView> appImports = new TreeSet<>(importFileViewComparator());
Set<String> localImportNames = new HashSet<>();
Set<String> sharedImportNames = new HashSet<>();
SymbolTable symbolTable = model.getSymbolTable();
Collection<ProtoFile> localImportFiles = productConfig.getInterfaceConfigMap().keySet().stream().map(symbolTable::lookupInterface).filter(Objects::nonNull).map(Interface::getFile).collect(ImmutableSet.toImmutableSet());
Iterable<ProtoFile> allFiles = model.reachable(model.getFiles());
// Skip API interfaces excluded from interface configs.
Collection<ProtoFile> skippedFiles = Streams.stream(allFiles).filter(ProtoFile::isSource).flatMap(f -> f.getInterfaces().stream()).filter(Interface::isReachable).filter(i -> productConfig.getInterfaceConfig(i) == null).map(Interface::getFile).collect(ImmutableSet.toImmutableSet());
// Can't use Collection#removeAll since allFiles is an Iterable.
Iterable<ProtoFile> protoFileDependencies = Streams.stream(allFiles).filter(f -> !skippedFiles.contains(f)).collect(ImmutableSet.toImmutableSet());
// Save proto file import names to the type table for disambiguation.
populateTypeTable(protoFileDependencies, allTypeTable, localImportNames, sharedImportNames, localImportFiles);
// Get disambiguated imports.
for (Map.Entry<String, TypeAlias> entry : allTypeTable.getImports().entrySet()) {
String importFullName = entry.getKey();
String nickName = entry.getValue().getNickname();
appImports.add(generateAppImport(importFullName, nickName));
if (localImportNames.contains(importFullName)) {
localImports.add(generateAppImport(importFullName, nickName));
} else if (sharedImportNames.contains(importFullName)) {
sharedImports.add(generateAppImport(importFullName, nickName));
}
}
importView.localImports(ImmutableList.copyOf(localImports));
importView.sharedImports(ImmutableList.copyOf(sharedImports));
importView.appImports(ImmutableList.copyOf(appImports));
return importView;
}
Aggregations