use of com.google.api.tools.framework.model.SymbolTable 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;
}
use of com.google.api.tools.framework.model.SymbolTable in project toolkit by googleapis.
the class ProtoInterfaceModel method getMethods.
@Override
public List<MethodModel> getMethods() {
ImmutableList.Builder<MethodModel> methods = ImmutableList.builder();
for (Method method : protoInterface.getMethods()) {
methods.add(new ProtoMethodModel(method));
}
SymbolTable symbolTable = protoInterface.getModel().getSymbolTable();
Api protoInterfaceConfig = protoInterface.getConfig();
if (protoInterfaceConfig != null) {
for (Mixin mixin : protoInterface.getConfig().getMixinsList()) {
Interface mixinInterface = symbolTable.lookupInterface(mixin.getName());
for (Method method : mixinInterface.getMethods()) {
methods.add(new ProtoMethodModel(method));
}
}
}
return methods.build();
}
Aggregations