private Interface getService() { return proto.getInterfaces().get(0); }
public ProtoLocation(ProtoFile fileElement) { this.displayString = fileElement.getSimpleName(); this.element = fileElement; }
/** * Helper to get the documentation backed up by this proto file for the given * element. */ public String getDocumentation(ProtoElement element) { if (element instanceof ProtoFile) { // For files themselves, comments from multiple locations are composed. StringBuilder result = new StringBuilder(); for (String path : FILE_DOC_LOCATIONS) { String comment = getDocumentation(path); if (Strings.isNullOrEmpty(comment)) { continue; } if (result.length() > 0) { result.append('\n'); } result.append(comment); } return result.toString(); } else { return getDocumentation(element.getPath()); } }
private static String getPath(ProtoFile file) { return file.getFullName() + "." + file.getSimpleName(); } }
public static String getJavaPackage(ProtoFile file) { String packageName = file.getProto().getOptions().getJavaPackage(); if (Strings.isNullOrEmpty(packageName)) { return DEFAULT_JAVA_PACKAGE_PREFIX + "." + file.getFullName(); } return packageName; }
private boolean isSourceApiInterfaceFile(ProtoFile file) { List<Api> apis = file.getModel().getServiceConfig().getApisList(); for (Interface apiInterface : file.getReachableInterfaces()) { for (Api api : apis) { if (api.getName().equals(apiInterface.getFullName())) { return true; } } } return false; }
.getFiles() .stream() .filter(f -> f.getSimpleName().equals("library.proto")) .findFirst() .get(); libraryService = libraryProtoFile.getInterfaces().get(0); .getMessages() .stream() .filter(m -> m.getSimpleName().equals("Shelf")) .getMessages() .stream() .filter(m -> m.getSimpleName().equals("Book")) shelf.getFields().stream().filter(f -> f.getSimpleName().equals("name")).findFirst().get(); libraryService = libraryProtoFile.getInterfaces().get(0); deleteShelfMethod = libraryService.lookupMethod("DeleteShelf"); getBigBookMethod = libraryService.lookupMethod("GetBigBook");
private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) { ModelTypeTable typeTable = new ModelTypeTable( new RubyTypeTable(productConfig.getPackageName()), new RubyModelTypeNameConverter(productConfig.getPackageName())); // Use file path for package name to get file-specific package instead of package for the API. SurfaceNamer namer = new RubySurfaceNamer(typeTable.getFullNameFor(file)); String subPath = pathMapper.getOutputPath(file.getFullName(), productConfig); String baseFilename = namer.getProtoFileName(file.getSimpleName()); GrpcDocView.Builder doc = GrpcDocView.newBuilder(); doc.templateFileName(DOC_TEMPLATE_FILENAME); doc.outputPath(subPath + "/doc/" + baseFilename); doc.fileHeader( fileHeaderTransformer.generateFileHeader( productConfig, ImportSectionView.newBuilder().build(), namer)); doc.elementDocs( elementDocTransformer.generateElementDocs(productConfig, typeTable, namer, file)); doc.modules( generateModuleViews( new ProtoApiModel(file.getModel()), productConfig, namer, isSourceApiInterfaceFile(file) ? file : null)); return doc.build(); }
@Test public void smokeTestApiConstruction() { Assert.assertEquals(1, testModel.getFiles().size()); ProtoFile file = testModel.getFiles().get(0); Assert.assertEquals(2, file.getMessages().size()); Assert.assertEquals(1, file.getEnums().size()); Assert.assertEquals(3, file.getMessages().get(0).getFields().size()); Assert.assertEquals(1, file.getMessages().get(1).getMessages().size()); Assert.assertEquals(1, file.getInterfaces().size()); }
for (MessageType message : protoFile.getMessages()) { ResourceNameMessageConfig resourceNameMessageConfig = ResourceNameMessageConfig.createResourceNameMessageConfig( Set<String> seenProtoFiles = new HashSet<>(); for (ProtoFile protoFile : protoFiles) { if (!seenProtoFiles.contains(protoFile.getSimpleName())) { seenProtoFiles.add(protoFile.getSimpleName()); for (MessageType msg : protoFile.getMessages()) { ResourceNameMessageConfig messageConfig = messageResourceTypeConfigMap.get(msg.getFullName());
private static String getShortName(ProtoElement elem) { return elem.getFullName().substring(elem.getFile().getFullName().length() + 1); }
/** * For each ProtoFile dependency, put its TypeAlias in allTypeTable; and if it is a local import, * then put it in the given localImportNames, otherwise if it is a shared import, but it in the * given sharedImportNames. */ private void populateTypeTable( Iterable<ProtoFile> protoFileDependencies, ModelTypeTable allTypeTable, Set<String> localImportNames, Set<String> sharedImportNames, Collection<ProtoFile> localImportFiles) { for (ProtoFile protoFile : protoFileDependencies) { // For python, adding a single message from the proto file to the type table will populate // the type table with the correct imports. ImmutableList<MessageType> messages = protoFile.getMessages(); if (!messages.isEmpty()) { TypeRef typeRef = TypeRef.of(messages.get(0)); allTypeTable.getAndSaveNicknameFor(typeRef); if (localImportFiles .stream() .anyMatch(f -> f.getFullName().equals(protoFile.getFullName()))) { localImportNames.add(allTypeTable.getFullNameFor(typeRef)); } else { sharedImportNames.add(allTypeTable.getFullNameFor(typeRef)); } } } }
this.isSource = isSource; this.proto = proto; buildChildren(proto.getMessageTypeList(), proto.getEnumTypeList(), PATH, List<ServiceDescriptorProto> serviceProtos = proto.getServiceList(); for (int i = 0; i < serviceProtos.size(); i++) { String childPath = buildPath(null, FileDescriptorProto.SERVICE_FIELD_NUMBER, i); interfacesBuilder.add(Interface.create(this, serviceProtos.get(i), childPath)); syntax = getProtoSyntax(proto); protoToLocation.put(this, new ProtoLocation(this));
@Override public TypeName getTypeName(ProtoElement elem) { List<String> path = getClassNamePath(elem); if (elem instanceof EnumType) { path.add(0, "enums"); String shortName = Joiner.on(".").join(path); return getTypeNameInImplicitPackage(shortName); } boolean useGrpcName = elem instanceof Interface || elem instanceof Method; if (elem.getFile().getSimpleName().equals("google/iam/v1/iam_policy.proto")) { // IAM policy gRPC service isn't actually used; API producers implement this themselves. useGrpcName = false; } if (useGrpcName) { path.add(0, getGrpcPbFileName(elem.getFile().getSimpleName())); } else { path.add(0, getPbFileName(elem.getFile().getSimpleName())); } path.add(0, protoPackageToPythonPackage(elem.getFile().getProto().getPackage())); String fullName = Joiner.on(".").join(path); return typeNameConverter.getTypeName(fullName); }
protected MessageType getOuterMessage() { return proto.getMessages().get(0); }
RubyPackageMetadataNamer packageNamer = new RubyPackageMetadataNamer(productConfig.getPackageName()); String packageFilePath = file.getFullName().replace(".", File.separator); ImmutableList.Builder<TocContentView> tocContents = ImmutableList.builder(); for (Interface apiInterface : file.getReachableInterfaces()) { String description = RubyUtil.getSentence(namer.getDocLines(GapicParser.getDocString(apiInterface)));
/** * Returns the interfaces reachable with active scoper. */ public Iterable<Interface> getReachableInterfaces() { return getModel().reachable(interfaces); }
/** * Creates a new protocol file backed up by the given descriptor. */ public static ProtoFile create(Model model, FileDescriptorProto proto, boolean isSource, ExtensionPool extensionPool) { return new ProtoFile(model, proto, isSource, extensionPool); }
/** * Creates a field that represents an extension. */ public static Field createAsExtension(MessageType parent, Extension extension, String path, String name) { Field field = new Field(parent, extension.getProto(), path, null, name); field.getFile().addExtension(extension, field); return field; }