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

The following examples show how to use com.google.protobuf.DescriptorProtos.DescriptorProto#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: BuilderVisitor.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
@Accepts
protected void accept(DescriptorProto.Builder message) {
  MessageNodeInfo messageInfo =
      (MessageNodeInfo) pushParent(BuilderVisitorNodeInfo.create(message, currentFile));

  visitRepeated(DescriptorProto.FIELD_FIELD_NUMBER);
  visitRepeated(DescriptorProto.NESTED_TYPE_FIELD_NUMBER);
  visitRepeated(DescriptorProto.ENUM_TYPE_FIELD_NUMBER);
  visitRepeated(DescriptorProto.EXTENSION_FIELD_NUMBER);

  visit(message.getOptionsBuilder());

  popExpectedParent(message);
}
 
Example 2
Source File: FileNodeInfo.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
public void processAddedFields(DescriptorProto.Builder message, Iterable<FieldLocation> fields) {
  if (manageSourceCodeInfo) {
    ProtoPathWrapper messagePath = pathFromElement(message);
    if (messagePath == null) {
      throw new RuntimeException(
          String.format(
              "Internal error - couldn't find path for proto message %s",
              ProtoHelpers.getName(message)));
    }
    ProtoPathWrapper fieldsPath =
        ProtoHelpers.buildPath(messagePath, DescriptorProto.FIELD_FIELD_NUMBER);
    ProtoPathTree<SourceCodeInfo.Location> fieldsPathTree =
        pathToLocation.getSubtree(fieldsPath, true);
    for (FieldLocation field : fields) {
      Integer fieldIndex = fieldsPathTree.size();
      if (fieldIndex > 0
          && (fieldsPathTree.firstKey() != 0 || fieldsPathTree.lastKey() != (fieldIndex - 1))) {
        throw new RuntimeException(
            String.format(
                "BuilderVisitor internal error - non-contiguous field indexes found [%d..%d]\n",
                fieldsPathTree.firstKey(), fieldsPathTree.lastKey()));
      }
      fieldsPathTree.addDataElement(
          new ProtoPathWrapper(fieldIndex), // relative path of field within this message
          field.location());
      elementToOriginalPath.put(
          field.fieldDescriptor(), ProtoHelpers.buildPath(fieldsPath, fieldIndex));
    }
  }
}
 
Example 3
Source File: MessageNodeInfo.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void processAddedFields(FileNodeInfo currentFile) {
  if (!toBeAddedFields().isEmpty()) {
    DescriptorProto.Builder message = (DescriptorProto.Builder) node();

    if (currentFile != null) {
      currentFile.processAddedFields(message, toBeAddedFields());
    }

    for (FieldLocation fieldInfo : toBeAddedFields()) {
      message.addField(fieldInfo.fieldDescriptor());
    }
  }
}
 
Example 4
Source File: BuilderVisitorNodeInfo.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
public static BuilderVisitorNodeInfo create(
    DescriptorProto.Builder node, FileNodeInfo parentFile) {
  return new MessageNodeInfo(node, parentFile);
}