Java 类com.google.protobuf.Descriptors.EnumValueDescriptor 实例源码

项目:sstore-soft    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (type.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:s-store    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (type.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:seldon-core    文件:JsonFormat.java   
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
项目:seldon-core    文件:JsonFormat.java   
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
项目:seldon-core    文件:JsonFormat.java   
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
项目:api-compiler    文件:ProtoFieldValueParser.java   
/**
 * Parse Enum value {@link EnumValueDescriptor} associated with given {@link EnumDescriptor} from
 * given text if found. Otherwise, throw a {@link ParseException}.
 *
 * <p>The text could be either enum value name or enum value number.
 */
static EnumValueDescriptor parseEnum(EnumDescriptor enumType, String text) {
  EnumValueDescriptor value = null;
  if (lookingAtNumber(text)) {
    int number = parseUInt32(text);
    value = enumType.findValueByNumber(number);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with number %d", enumType.getFullName(), number));
    }
  } else {
    value = enumType.findValueByName(text);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with name '%s'", enumType.getFullName(), text));
    }
  }
  return value;
}
项目:cfapi    文件:DynamicMessage.java   
/** Verifies that the value is EnumValueDescriptor and matches Enum Type. */
private void ensureSingularEnumValueDescriptor(
    FieldDescriptor field, Object value) {
  if (value == null) {
    throw new NullPointerException();
  }
  if (!(value instanceof EnumValueDescriptor)) {
    throw new IllegalArgumentException(
      "DynamicMessage should use EnumValueDescriptor to set Enum Value.");
  }
  // TODO(xiaofeng): Re-enable this check after Orgstore is fixed to not
  // set incorrect EnumValueDescriptors.
  // EnumDescriptor fieldType = field.getEnumType();
  // EnumDescriptor fieldValueType = ((EnumValueDescriptor) value).getType();
  // if (fieldType != fieldValueType) {
  //  throw new IllegalArgumentException(String.format(
  //      "EnumDescriptor %s of field doesn't match EnumDescriptor %s of field value",
  //      fieldType.getFullName(), fieldValueType.getFullName()));
  // }
}
项目:cfapi    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:cfapi    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:cfapi    文件:GeneratedMessage.java   
SingularEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass,
    final String containingOneofCamelCaseName) {
  super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);

  enumDescriptor = descriptor.getEnumType();

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");

  supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
  if (supportUnknownEnumValue) {
    getValueMethod =
        getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
    getValueMethodBuilder =
        getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
    setValueMethod =
        getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
  }
}
项目:cfapi    文件:GeneratedMessage.java   
RepeatedEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  enumDescriptor = descriptor.getEnumType();

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");

  supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
  if (supportUnknownEnumValue) {
    getRepeatedValueMethod =
        getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class);
    getRepeatedValueMethodBuilder =
        getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class);
    setRepeatedValueMethod =
        getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class);
    addRepeatedValueMethod =
        getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
  }
}
项目:play-store-api    文件:DynamicMessage.java   
/** Verifies that the value is EnumValueDescriptor and matches Enum Type. */
private void ensureSingularEnumValueDescriptor(
    FieldDescriptor field, Object value) {
  if (value == null) {
    throw new NullPointerException();
  }
  if (!(value instanceof EnumValueDescriptor)) {
    throw new IllegalArgumentException(
      "DynamicMessage should use EnumValueDescriptor to set Enum Value.");
  }
  // TODO(xiaofeng): Re-enable this check after Orgstore is fixed to not
  // set incorrect EnumValueDescriptors.
  // EnumDescriptor fieldType = field.getEnumType();
  // EnumDescriptor fieldValueType = ((EnumValueDescriptor) value).getType();
  // if (fieldType != fieldValueType) {
  //  throw new IllegalArgumentException(String.format(
  //      "EnumDescriptor %s of field doesn't match EnumDescriptor %s of field value",
  //      fieldType.getFullName(), fieldValueType.getFullName()));
  // }
}
项目:play-store-api    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:play-store-api    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
@Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:play-store-api    文件:GeneratedMessage.java   
SingularEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass,
    final String containingOneofCamelCaseName) {
  super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);

  enumDescriptor = descriptor.getEnumType();

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");

  supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
  if (supportUnknownEnumValue) {
    getValueMethod =
        getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
    getValueMethodBuilder =
        getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
    setValueMethod =
        getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
  }
}
项目:play-store-api    文件:GeneratedMessage.java   
RepeatedEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  enumDescriptor = descriptor.getEnumType();

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");

  supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
  if (supportUnknownEnumValue) {
    getRepeatedValueMethod =
        getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class);
    getRepeatedValueMethodBuilder =
        getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class);
    setRepeatedValueMethod =
        getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class);
    addRepeatedValueMethod =
        getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
  }
}
项目:bd-codes    文件:GeneratedMessage.java   
private GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
                           Class singularType,
                           Message messageDefaultInstance) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
}
项目:bd-codes    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:protoc-gen-as3    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:protoc-gen-as3    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:dotalys-cli    文件:GeneratedMessage.java   
private GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
                           Class singularType,
                           Message messageDefaultInstance) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
}
项目:dotalys-cli    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:TayzGrid    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (type.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:TayzGrid    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (type.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:protobuffer    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:protobuffer    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:protobuffer    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:protobuffer    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:GetThere    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:GetThere    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:365browser    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:365browser    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:hpcourse    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:hpcourse    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:vsminecraft    文件:GeneratedMessage.java   
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
    Class singularType,
    Message messageDefaultInstance,
    ExtensionType extensionType) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
  this.extensionType = extensionType;
}
项目:vsminecraft    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
// @Override
protected Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        return messageDefaultInstance.newBuilderForType()
            .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:nfc-smart-tag    文件:GeneratedMessage.java   
private GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
                           Class singularType,
                           Message messageDefaultInstance) {
  if (Message.class.isAssignableFrom(singularType) &&
      !singularType.isInstance(messageDefaultInstance)) {
    throw new IllegalArgumentException(
        "Bad messageDefaultInstance for " + singularType.getName());
  }
  this.descriptorRetriever = descriptorRetriever;
  this.singularType = singularType;
  this.messageDefaultInstance = messageDefaultInstance;

  if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
    this.enumValueOf = getMethodOrDie(singularType, "valueOf",
                                      EnumValueDescriptor.class);
    this.enumGetValueDescriptor =
        getMethodOrDie(singularType, "getValueDescriptor");
  } else {
    this.enumValueOf = null;
    this.enumGetValueDescriptor = null;
  }
}
项目:nfc-smart-tag    文件:GeneratedMessage.java   
/**
 * Like {@link #fromReflectionType(Object)}, but if the type is a repeated
 * type, this converts a single element.
 */
private Object singularFromReflectionType(final Object value) {
  FieldDescriptor descriptor = getDescriptor();
  switch (descriptor.getJavaType()) {
    case MESSAGE:
      if (singularType.isInstance(value)) {
        return value;
      } else {
        // It seems the copy of the embedded message stored inside the
        // extended message is not of the exact type the user was
        // expecting.  This can happen if a user defines a
        // GeneratedExtension manually and gives it a different type.
        // This should not happen in normal use.  But, to be nice, we'll
        // copy the message to whatever type the caller was expecting.
        return messageDefaultInstance.newBuilderForType()
                       .mergeFrom((Message) value).build();
      }
    case ENUM:
      return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
    default:
      return value;
  }
}
项目:protobuf-utils    文件:Converter.java   
private static Object toMap(FieldDescriptor descr, Object value) {
    if (value == null) {
        return null;
    }

    final Object result;
    switch(descr.getJavaType()) {
        case MESSAGE:
            result = toMap((Message )value);
            break;

        case ENUM:
            result = ((EnumValueDescriptor )value).getName();
            break;

        default:
            result = value;
            break;                        
    }

    return result;
}
项目:Beam    文件:GeneratedMessage.java   
GeneratedExtension (ExtensionDescriptorRetriever descriptorRetriever,
        Class singularType,
        Message messageDefaultInstance,
        ExtensionType extensionType) {
    if (Message.class.isAssignableFrom (singularType)
            && !singularType.isInstance (messageDefaultInstance)) {
        throw new IllegalArgumentException (
                "Bad messageDefaultInstance for " + singularType.getName ());
    }
    this.descriptorRetriever = descriptorRetriever;
    this.singularType = singularType;
    this.messageDefaultInstance = messageDefaultInstance;

    if (ProtocolMessageEnum.class.isAssignableFrom (singularType)) {
        this.enumValueOf = getMethodOrDie (singularType, "valueOf",
                EnumValueDescriptor.class);
        this.enumGetValueDescriptor
                = getMethodOrDie (singularType, "getValueDescriptor");
    } else {
        this.enumValueOf = null;
        this.enumGetValueDescriptor = null;
    }
    this.extensionType = extensionType;
}