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

The following examples show how to use com.google.protobuf.Descriptors.Descriptor#getFullName() . 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: 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 2
Source File: OpenApiDefinitionHandler.java    From grpc-swagger with MIT License 5 votes vote down vote up
@Nullable
private String findRefByType(Descriptor typeDescriptor) {
    String fullName = typeDescriptor.getFullName();
    DefinitionType definitionType = typeLookupTable.get(fullName);
    if (definitionType != null) {
        return DEFINITION_REF_PREFIX + fullName;
    }
    return null;
}
 
Example 3
Source File: OpenApiDefinitionHandler.java    From grpc-swagger with MIT License 5 votes vote down vote up
@Nullable
private String findRefByType(Descriptor typeDescriptor) {
    String fullName = typeDescriptor.getFullName();
    DefinitionType definitionType = typeLookupTable.get(fullName);
    if (definitionType != null) {
        return DEFINITION_REF_PREFIX + fullName;
    }
    return null;
}
 
Example 4
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 5
Source File: GrpcDocServicePlugin.java    From armeria with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
StructInfo newStructInfo(Descriptor descriptor) {
    return new StructInfo(
            descriptor.getFullName(),
            descriptor.getFields().stream()
                      .map(GrpcDocServicePlugin::newFieldInfo)
                      .collect(toImmutableList()));
}
 
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: JsonJacksonFormat.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a single field from {@code parser} and merge it into {@code builder}. If a ',' is
 * detected after the field ends, the next field will be parsed automatically
 * @throws IOException
 * @throws JsonParseException
 */
protected void mergeField(JsonParser parser,
                               ExtensionRegistry extensionRegistry,
                               Message.Builder builder) throws JsonParseException, IOException {
    FieldDescriptor field = null;
    Descriptor type = builder.getDescriptorForType();
    boolean unknown = false;
    ExtensionRegistry.ExtensionInfo extension = null;
    JsonToken token = parser.getCurrentToken();

    if (token != null) {
        String name = parser.getCurrentName();

        if (name.contains(".")) {
        	// should be an extension
        	extension = extensionRegistry.findExtensionByName(name);
            if (extension == null) {
                throw new RuntimeException("Extension \""
                		+ name + "\" not found in the ExtensionRegistry.");
            } else if (extension.descriptor.getContainingType() != type) {
                throw new RuntimeException("Extension \"" + name
                		+ "\" does not extend message type \""
                		+ type.getFullName() + "\".");
            }

        	field = extension.descriptor;
        } else {
        	field = type.findFieldByName(name);
        }

        // Group names are expected to be capitalized as they appear in the
        // .proto file, which actually matches their type names, not their field
        // names.
        if (field == null) {
            // Explicitly specify US locale so that this code does not break when
            // executing in Turkey.
            String lowerName = name.toLowerCase(Locale.US);
            field = type.findFieldByName(lowerName);
            // If the case-insensitive match worked but the field is NOT a group,
            if ((field != null) && (field.getType() != FieldDescriptor.Type.GROUP)) {
                field = null;
            }
        }
        // Again, special-case group names as described above.
        if ((field != null) && (field.getType() == FieldDescriptor.Type.GROUP)
            && !field.getMessageType().getName().equals(name)
            && !field.getMessageType().getFullName().equalsIgnoreCase(name) /* extension */) {
            field = null;
        }

        // Last try to lookup by field-index if 'name' is numeric,
        // which indicates a possible unknown field
        if (field == null && TextUtils.isDigits(name)) {
            field = type.findFieldByNumber(Integer.parseInt(name));
            unknown = true;
        }

        // no throwing exceptions if field not found, since it could be a different version.
        if (field == null) {
        	UnknownFieldSet.Builder unknownsBuilder = UnknownFieldSet.newBuilder();
        	handleMissingField(name, parser, extensionRegistry, unknownsBuilder);
        	builder.setUnknownFields(unknownsBuilder.build());
        }
    }

    if (field != null) {
    	token = parser.nextToken();

        boolean array = token.equals(JsonToken.START_ARRAY);

        if (array) {
        	token = parser.nextToken();
            while (!token.equals(JsonToken.END_ARRAY)) {
                handleValue(parser, extensionRegistry, builder, field, extension, unknown);
                token = parser.nextToken();
            }
        } else {
            handleValue(parser, extensionRegistry, builder, field, extension, unknown);
        }
    }
}