Java Code Examples for com.google.protobuf.DescriptorProtos.FileDescriptorProto#Builder

The following examples show how to use com.google.protobuf.DescriptorProtos.FileDescriptorProto#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DescriptorGenerator.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
private FileDescriptorProto generateFile(String name, FileContents contents) {
  FileDescriptorProto.Builder fileBuilder = FileDescriptorProto.newBuilder();
  fileBuilder.setName(name);
  if (!Strings.isNullOrEmpty(contents.packageName)) {
    fileBuilder.setPackage(contents.packageName);
  }
  for (Api api : contents.apis) {
    fileBuilder.addService(generateApi(api));
  }
  for (Type type : contents.types.values()) {
    fileBuilder.addMessageType(generateType(type, contents));
  }
  for (Enum e : contents.enums) {
    fileBuilder.addEnumType(generateEnum(e));
  }
  if (imports.containsKey(name)) {
    for (String imported : imports.get(name)) {
      fileBuilder.addDependency(imported);
    }
  }
  return fileBuilder.build();
}
 
Example 2
Source File: AvroToProtoSchema.java    From metastore with Apache License 2.0 5 votes vote down vote up
public ProtoDomain get() {
  rootNamespace = root.path("namespace").asText();

  protoMessageOf(root);

  Map<String, FileDescriptorProto.Builder> fileMap = new HashMap<>();

  messageMap.forEach(
      (fullName, message) -> {
        String packageName =
            fullName.substring(0, fullName.length() - message.getName().length() - 1);
        FileDescriptorProto.Builder fdp = fileMap.get(packageName);
        if (fdp == null) {
          fdp =
              DescriptorProtos.FileDescriptorProto.newBuilder()
                  .setName(packageNameToFileName(packageName))
                  .setPackage(packageName)
                  .setSyntax("proto3");
          fileMap.put(packageName, fdp);
        }
        fdp.addMessageType(message);
      });

  DescriptorProtos.FileDescriptorSet.Builder fds =
      DescriptorProtos.FileDescriptorSet.newBuilder();
  fileMap.forEach(
      (name, fdp) -> {
        Set<String> imports = importMap.get(fdp.getPackage());
        if (imports != null) {
          imports.forEach(im -> fdp.addDependency(im));
        }

        fds.addFile(fdp);
      });
  fds.addFile(Int64Value.getDescriptor().getFile().toProto());

  return ProtoDomain.buildFrom(fds.build());
}
 
Example 3
Source File: BuilderVisitor.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
@Accepts
protected void accept(final FileDescriptorProto.Builder file) {
  pushParent(BuilderVisitorNodeInfo.create(file));
  currentFile.setManageSourceCodeInfo(manageSourceCodeInfo);

  visitRepeated(FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
  visitRepeated(FileDescriptorProto.ENUM_TYPE_FIELD_NUMBER);
  visitRepeated(FileDescriptorProto.EXTENSION_FIELD_NUMBER);
  visitRepeated(FileDescriptorProto.SERVICE_FIELD_NUMBER);

  visit(file.getOptionsBuilder());

  popExpectedParent(file);
}
 
Example 4
Source File: FileNodeInfo.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void setupPathsForFile(FileDescriptorProto.Builder file) {
  // Populate location map
  if (file.hasSourceCodeInfo() && manageSourceCodeInfo) {
    for (SourceCodeInfo.Location location : file.getSourceCodeInfo().getLocationList()) {
      pathToLocation.addDataElement(new ProtoPathWrapper(location.getPathList()), location);
    }
  } else {
    // Turn off SourceCodeInfo management if there is none.
    manageSourceCodeInfo = false;
  }
}
 
Example 5
Source File: FileNodeInfo.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void resetPathsForFile(FileDescriptorProto.Builder file) {
  if (modifiedSourceCodeInfo) {
    SourceCodeInfo.Builder sourceCodeInfo = file.getSourceCodeInfoBuilder();
    sourceCodeInfo.clearLocation();

    new LocationInfoUpdater(sourceCodeInfo).visit(pathToLocation);

    modifiedSourceCodeInfo = false;
  }

  elementToOriginalPath.clear();
  pathToLocation.clear();
}
 
Example 6
Source File: BuilderVisitor.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
public FileDescriptorProto.Builder getCurrentFile() {
  if (currentFile != null) {
    return (FileDescriptorProto.Builder) currentFile.node();
  }
  return null;
}
 
Example 7
Source File: BuilderVisitorNodeInfo.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
public static BuilderVisitorNodeInfo create(FileDescriptorProto.Builder node) {
  return new FileNodeInfo(node);
}