Java Code Examples for com.google.protobuf.Descriptors.Descriptor#getNestedTypes()

The following examples show how to use com.google.protobuf.Descriptors.Descriptor#getNestedTypes() . 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: ProtoGenerator.java    From fuchsia with Apache License 2.0 6 votes vote down vote up
private void generateProtoFromDescriptor(Descriptor descriptor,
                                         Appendable out, String indent, Map<Descriptor, Boolean> descriptors)
        throws IOException {
    descriptors.put(descriptor, true);

    out.append(indent + "message " + descriptor.getName() + " {\n");

    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
        generateProtoFromDescriptor(fieldDescriptor, out, indent + "    ",
                descriptors);
    }

    for (Descriptor nested : descriptor.getNestedTypes()) {
        generateProtoFromDescriptor(nested, out, indent + "    ",
                descriptors);
    }

    for (EnumDescriptor enumDescriptor : descriptor.getEnumTypes()) {
        generateProtoFromDescriptor(enumDescriptor, out, indent + "    ");
    }

    out.append(indent + "}\n");
}
 
Example 2
Source File: ProtoReflectionService.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
private void processType(Descriptor type, FileDescriptor fd) {
  String typeName = type.getFullName();
  checkState(
      !fileDescriptorsBySymbol.containsKey(typeName), "Type already defined: %s", typeName);
  fileDescriptorsBySymbol.put(typeName, fd);
  for (FieldDescriptor extension : type.getExtensions()) {
    processExtension(extension, fd);
  }
  for (Descriptor nestedType : type.getNestedTypes()) {
    processType(nestedType, fd);
  }
}
 
Example 3
Source File: DynamicSchema.java    From protobuf-dynamic with Apache License 2.0 5 votes vote down vote up
private void addMessageType(Descriptor msgType, String scope, Set<String> msgDupes, Set<String> enumDupes) {
	String msgTypeNameFull = msgType.getFullName();
	String msgTypeNameShort = (scope == null ? msgType.getName() : scope + "." + msgType.getName());
	
	if (mMsgDescriptorMapFull.containsKey(msgTypeNameFull)) throw new IllegalArgumentException("duplicate name: " + msgTypeNameFull);
	if (mMsgDescriptorMapShort.containsKey(msgTypeNameShort)) msgDupes.add(msgTypeNameShort);
	
	mMsgDescriptorMapFull.put(msgTypeNameFull, msgType);
	mMsgDescriptorMapShort.put(msgTypeNameShort, msgType);
	
	for (Descriptor nestedType : msgType.getNestedTypes()) addMessageType(nestedType, msgTypeNameShort, msgDupes, enumDupes);
	for (EnumDescriptor enumType : msgType.getEnumTypes()) addEnumType(enumType, msgTypeNameShort, enumDupes);
}
 
Example 4
Source File: Message.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Collects messages referred to by a message and its nested messages.
 *
 * @return {@code referenced}
 */
private static Collection<Descriptor> collectMessages(
    Descriptor message, Collection<Descriptor> referenced) {
  for (FieldDescriptor fd : message.getFields()) {
    if (fd.getJavaType() == JavaType.MESSAGE) {
      referenced.add(fd.getMessageType());
    }
  }
  for (Descriptor nd : message.getNestedTypes()) {
    collectMessages(nd, referenced);
  }
  return referenced;
}
 
Example 5
Source File: Message.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Collects enums referred to by a message and its nested messages.
 *
 * @return {@code referenced}
 */
private static Collection<EnumDescriptor> collectEnums(
    Descriptor d, Collection<EnumDescriptor> referenced) {
  for (FieldDescriptor fd : d.getFields()) {
    if (fd.getJavaType() == JavaType.ENUM) {
      referenced.add(fd.getEnumType());
    }
  }
  for (Descriptor nd : d.getNestedTypes()) {
    collectEnums(nd, referenced);
  }
  return referenced;
}
 
Example 6
Source File: ProtoReflectionService.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void processType(Descriptor type, FileDescriptor fd) {
  String typeName = type.getFullName();
  checkState(
      !fileDescriptorsBySymbol.containsKey(typeName), "Type already defined: %s", typeName);
  fileDescriptorsBySymbol.put(typeName, fd);
  for (FieldDescriptor extension : type.getExtensions()) {
    processExtension(extension, fd);
  }
  for (Descriptor nestedType : type.getNestedTypes()) {
    processType(nestedType, fd);
  }
}
 
Example 7
Source File: Message.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Collects messages referred to by a message and its nested messages.
 *
 * @return {@code referenced}
 */
private static Collection<Descriptor> collectMessages(
    Descriptor message, Collection<Descriptor> referenced) {
  for (FieldDescriptor fd : message.getFields()) {
    if (fd.getJavaType() == JavaType.MESSAGE) {
      referenced.add(fd.getMessageType());
    }
  }
  for (Descriptor nd : message.getNestedTypes()) {
    collectMessages(nd, referenced);
  }
  return referenced;
}
 
Example 8
Source File: Message.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Collects enums referred to by a message and its nested messages.
 *
 * @return {@code referenced}
 */
private static Collection<EnumDescriptor> collectEnums(
    Descriptor d, Collection<EnumDescriptor> referenced) {
  for (FieldDescriptor fd : d.getFields()) {
    if (fd.getJavaType() == JavaType.ENUM) {
      referenced.add(fd.getEnumType());
    }
  }
  for (Descriptor nd : d.getNestedTypes()) {
    collectEnums(nd, referenced);
  }
  return referenced;
}