Java Code Examples for com.google.protobuf.DescriptorProtos.DescriptorProto#getNestedType()

The following examples show how to use com.google.protobuf.DescriptorProtos.DescriptorProto#getNestedType() . 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: GrpcDocStringExtractor.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String appendToFullName(
        DescriptorProto messageDescriptor, List<Integer> path, String fullNameSoFar) {
    switch (path.get(0)) {
        case DescriptorProto.NESTED_TYPE_FIELD_NUMBER:
            final DescriptorProto nestedMessage = messageDescriptor.getNestedType(path.get(1));
            return appendMessageToFullName(nestedMessage, path, fullNameSoFar);
        case DescriptorProto.ENUM_TYPE_FIELD_NUMBER:
            final EnumDescriptorProto enumDescriptor = messageDescriptor.getEnumType(path.get(1));
            return appendEnumToFullName(enumDescriptor, path, fullNameSoFar);
        case DescriptorProto.FIELD_FIELD_NUMBER:
            final FieldDescriptorProto fieldDescriptor = messageDescriptor.getField(path.get(1));
            return appendFieldComponent(fullNameSoFar, fieldDescriptor.getName());
        default:
            return null;
    }
}
 
Example 2
Source File: ExtensionPool.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void add(DescriptorProto message) {
  fullNameSegments.push(message.getName());
  pathSegments.push(DescriptorProto.EXTENSION_FIELD_NUMBER);
  add(message.getExtensionList());
  pathSegments.pop();
  pathSegments.push(DescriptorProto.NESTED_TYPE_FIELD_NUMBER);
  for (int i = 0; i < message.getNestedTypeCount(); i++) {
    pathSegments.push(i);
    DescriptorProto nested = message.getNestedType(i);
    add(nested);
    pathSegments.pop();
  }
  pathSegments.pop();
  fullNameSegments.pop();
}
 
Example 3
Source File: Descriptors.java    From play-store-api with GNU General Public License v3.0 4 votes vote down vote up
private Descriptor(final DescriptorProto proto,
                   final FileDescriptor file,
                   final Descriptor parent,
                   final int index)
            throws DescriptorValidationException {
  this.index = index;
  this.proto = proto;
  fullName = computeFullName(file, parent, proto.getName());
  this.file = file;
  containingType = parent;

  oneofs = new OneofDescriptor[proto.getOneofDeclCount()];
  for (int i = 0; i < proto.getOneofDeclCount(); i++) {
    oneofs[i] = new OneofDescriptor(
      proto.getOneofDecl(i), file, this, i);
  }

  nestedTypes = new Descriptor[proto.getNestedTypeCount()];
  for (int i = 0; i < proto.getNestedTypeCount(); i++) {
    nestedTypes[i] = new Descriptor(
      proto.getNestedType(i), file, this, i);
  }

  enumTypes = new EnumDescriptor[proto.getEnumTypeCount()];
  for (int i = 0; i < proto.getEnumTypeCount(); i++) {
    enumTypes[i] = new EnumDescriptor(
      proto.getEnumType(i), file, this, i);
  }

  fields = new FieldDescriptor[proto.getFieldCount()];
  for (int i = 0; i < proto.getFieldCount(); i++) {
    fields[i] = new FieldDescriptor(
      proto.getField(i), file, this, i, false);
  }

  extensions = new FieldDescriptor[proto.getExtensionCount()];
  for (int i = 0; i < proto.getExtensionCount(); i++) {
    extensions[i] = new FieldDescriptor(
      proto.getExtension(i), file, this, i, true);
  }

  for (int i = 0; i < proto.getOneofDeclCount(); i++) {
    oneofs[i].fields = new FieldDescriptor[oneofs[i].getFieldCount()];
    oneofs[i].fieldCount = 0;
  }
  for (int i = 0; i < proto.getFieldCount(); i++) {
    OneofDescriptor oneofDescriptor = fields[i].getContainingOneof();
    if (oneofDescriptor != null) {
      oneofDescriptor.fields[oneofDescriptor.fieldCount++] = fields[i];
    }
  }

  file.pool.addSymbol(this);
}