com.google.protobuf.Descriptors.EnumValueDescriptor Java Examples

The following examples show how to use com.google.protobuf.Descriptors.EnumValueDescriptor. 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: GeneratedMessage.java    From play-store-api with GNU General Public License v3.0 6 votes vote down vote up
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);
  }
}
 
Example #2
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example #3
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example #4
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
  }
}
 
Example #5
Source File: DataDstPbHelper.java    From xresloader with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
static public void dumpConstIntoHashMap(String package_name, HashMap<String, Object> parent,
        Descriptors.EnumDescriptor enum_desc) {
    String enum_seg = enum_desc.getName();
    HashMap<String, Object> enum_root;
    if (parent.containsKey(enum_seg)) {
        Object node = parent.get(enum_seg);
        if (node instanceof HashMap) {
            enum_root = (HashMap<String, Object>) node;
        } else {
            ProgramOptions.getLoger().error("enum name %s.%s conflict.", package_name, enum_seg);
            return;
        }
    } else {
        enum_root = new HashMap<String, Object>();
        parent.put(enum_seg, enum_root);
    }

    // 写出所有常量值
    for (Descriptors.EnumValueDescriptor enum_val : enum_desc.getValues()) {
        enum_root.put(enum_val.getName(), enum_val.getNumber());
    }
}
 
Example #6
Source File: ProtoTypeAdapter.java    From gson with Apache License 2.0 6 votes vote down vote up
/**
 * Finds an enum value in the given {@link EnumDescriptor} that matches the given JSON element,
 * either by name if the current adapter is using {@link EnumSerialization#NAME}, otherwise by
 * number. If matching by name, it uses the extension value if it is defined, otherwise it uses
 * its default value.
 *
 * @throws IllegalArgumentException if a matching name/number was not found
 */
private EnumValueDescriptor findValueByNameAndExtension(EnumDescriptor desc,
    JsonElement jsonElement) {
  if (enumSerialization == EnumSerialization.NAME) {
    // With enum name
    for (EnumValueDescriptor enumDesc : desc.getValues()) {
      String enumValue = getCustSerializedEnumValue(enumDesc.getOptions(), enumDesc.getName());
      if (enumValue.equals(jsonElement.getAsString())) {
        return enumDesc;
      }
    }
    throw new IllegalArgumentException(
        String.format("Unrecognized enum name: %s", jsonElement.getAsString()));
  } else {
    // With enum value
    EnumValueDescriptor fieldValue = desc.findValueByNumber(jsonElement.getAsInt());
    if (fieldValue == null) {
      throw new IllegalArgumentException(
          String.format("Unrecognized enum value: %s", jsonElement.getAsInt()));
    }
    return fieldValue;
  }
}
 
Example #7
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example #8
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
  }
}
 
Example #9
Source File: DataDstPbHelper.java    From xresloader with MIT License 6 votes vote down vote up
static public HashMap<String, Object> dumpOptionsIntoHashMap(Descriptors.EnumValueDescriptor msg_desc,
        com.google.protobuf.ExtensionRegistry custom_extensions) {
    HashMap<String, Object> msg_root = new HashMap<String, Object>();
    boolean has_data = false;

    HashMap<String, Object> options_data = dumpMessageExtensions(msg_desc.getOptions(),
            msg_desc.getOptions().getAllFields(), custom_extensions);
    if (options_data != null && !options_data.isEmpty()) {
        has_data = true;
        msg_root.put("options", options_data);
    }

    if (has_data) {
        msg_root.put("name", msg_desc.getName());
        msg_root.put("number", msg_desc.getNumber());
        return msg_root;
    }

    return null;
}
 
Example #10
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example #11
Source File: GeneratedMessage.java    From play-store-api with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example #13
Source File: JsonEncoder.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private JsonElement encodeValue(FieldDescriptor field, Object value) {
  switch (field.getJavaType()) {
    case ENUM:
      return new JsonPrimitive(((EnumValueDescriptor) value).getNumber());

    case MESSAGE:
      return encode((Message) value);

    case BOOLEAN:
      return !((boolean) value) ? new JsonPrimitive(0) : new JsonPrimitive(1);

    case INT:
    case LONG:
      return new JsonPrimitive((Number) value);

    case STRING:
      return isNullOrEmpty((String) value)
          ? JsonNull.INSTANCE
          : new JsonPrimitive((String) value);

    default:
      return JsonNull.INSTANCE;
  }
}
 
Example #14
Source File: ProtoFieldValueParser.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #16
Source File: MapEntry.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Builder<K, V> setField(FieldDescriptor field, Object value) {
    checkFieldDescriptor(field);
    if (field.getNumber() == 1) {
        setKey((K) value);
    } else {
        if (field.getType() == FieldDescriptor.Type.ENUM) {
            value = ((EnumValueDescriptor) value).getNumber();
        }
        setValue((V) value);
    }
    return this;
}
 
Example #17
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** 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.");
  }
  if (field.getEnumType() != ((EnumValueDescriptor) value).getType()) {
    throw new IllegalArgumentException(
      "EnumValueDescriptor doesn't much Enum Field.");
  }
}
 
Example #18
Source File: CompatibilityTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testGetUnsetField() throws Exception {
  TypicalData data = TypicalData.newBuilder().build();
  Descriptor descriptor = TypicalData.getDescriptor();
  assertEquals(0, data.getField(descriptor.findFieldByNumber(1)));
  Object result = data.getField(descriptor.findFieldByNumber(3));
  assertTrue(result instanceof EnumValueDescriptor);
  assertEquals(TypicalData.EnumType.VALUE1.getValueDescriptor().getNumber(),
               ((EnumValueDescriptor) result).getNumber());
  assertTrue(data.getField(descriptor.findFieldByNumber(11)) instanceof TypicalDataMessage);
}
 
Example #19
Source File: ProtoTypeAdapter.java    From gson with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the enum value to use for serialization, depending on the value of
 * {@link EnumSerialization} that was given to this adapter.
 */
private Object getEnumValue(EnumValueDescriptor enumDesc) {
  if (enumSerialization == EnumSerialization.NAME) {
    return getCustSerializedEnumValue(enumDesc.getOptions(), enumDesc.getName());
  } else {
    return enumDesc.getNumber();
  }
}
 
Example #20
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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);

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");
}
 
Example #21
Source File: DataDstPbHelper.java    From xresloader with MIT License 5 votes vote down vote up
static public HashMap<String, Object> dumpOptionsIntoHashMap(Descriptors.EnumDescriptor msg_desc,
        com.google.protobuf.ExtensionRegistry custom_extensions) {
    HashMap<String, Object> msg_root = new HashMap<String, Object>();
    boolean has_data = false;

    HashMap<String, Object> options_data = dumpMessageExtensions(msg_desc.getOptions(),
            msg_desc.getOptions().getAllFields(), custom_extensions);
    if (options_data != null && !options_data.isEmpty()) {
        has_data = true;
        msg_root.put("options", options_data);
    }

    // value
    HashMap<String, Object> child_message = null;
    for (Descriptors.EnumValueDescriptor sub_desc : msg_desc.getValues()) {
        HashMap<String, Object> subset = dumpOptionsIntoHashMap(sub_desc, custom_extensions);
        if (subset == null) {
            continue;
        }

        if (child_message == null) {
            child_message = new HashMap<String, Object>();
            msg_root.put("value", child_message);
        }

        has_data = true;
        child_message.put(sub_desc.getName(), subset);
    }

    if (has_data) {
        msg_root.put("name", msg_desc.getName());
        return msg_root;
    }

    return null;
}
 
Example #22
Source File: DetailedExitCode.java    From bazel with Apache License 2.0 5 votes vote down vote up
/** Returns the numeric exit code associated with a {@link FailureDetail} message. */
private static int getNumericExitCode(FailureDetail failureDetail) {
  MessageOrBuilder categoryMsg = getCategorySubmessage(failureDetail);
  EnumValueDescriptor subcategoryDescriptor =
      getSubcategoryDescriptor(failureDetail, categoryMsg);
  return getNumericExitCode(subcategoryDescriptor);
}
 
Example #23
Source File: DetailedExitCode.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the enum value descriptor for the enum field with field number 1 in the {@link
 * FailureDetail}'s category submessage.
 */
private static EnumValueDescriptor getSubcategoryDescriptor(
    FailureDetail failureDetail, MessageOrBuilder categoryMsg) {
  FieldDescriptor fieldNumberOne = categoryMsg.getDescriptorForType().findFieldByNumber(1);
  checkNotNull(
      fieldNumberOne, "FailureDetail category submessage has no field #1: %s", failureDetail);
  Object fieldNumberOneVal = categoryMsg.getField(fieldNumberOne);
  checkArgument(
      fieldNumberOneVal instanceof EnumValueDescriptor,
      "FailureDetail category submessage has non-enum field #1: %s",
      failureDetail);
  return (EnumValueDescriptor) fieldNumberOneVal;
}
 
Example #24
Source File: CompatibilityTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testEnumDescriptor() throws Exception {
  Descriptor descriptor = TypicalData.Builder.getDescriptor();
  FieldDescriptor fieldDescriptor = descriptor.findFieldByNumber(3);
  assertEquals(Type.ENUM, fieldDescriptor.getType());
  EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
  assertNotNull(enumDescriptor);

  EnumValueDescriptor enumValueDescriptor = enumDescriptor.findValueByNumber(1);
  assertEquals(1, enumValueDescriptor.getNumber());
  assertEquals("VALUE1", enumValueDescriptor.getName());
}
 
Example #25
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
RepeatedEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");
}
 
Example #26
Source File: DetailedExitCode.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the numeric exit code associated with a {@link FailureDetail} submessage's subcategory
 * enum value.
 */
private static int getNumericExitCode(EnumValueDescriptor subcategoryDescriptor) {
  checkArgument(
      subcategoryDescriptor.getOptions().hasExtension(FailureDetails.metadata),
      "Enum value %s has no FailureDetails.metadata",
      subcategoryDescriptor);
  return subcategoryDescriptor.getOptions().getExtension(FailureDetails.metadata).getExitCode();
}
 
Example #27
Source File: DescriptorsTest.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public void testEnumDescriptor() throws Exception {
  EnumDescriptor enumType = ForeignEnum.getDescriptor();
  EnumDescriptor nestedType = TestAllTypes.NestedEnum.getDescriptor();

  assertEquals("ForeignEnum", enumType.getName());
  assertEquals("protobuf_unittest.ForeignEnum", enumType.getFullName());
  assertEquals(UnittestProto.getDescriptor(), enumType.getFile());
  assertNull(enumType.getContainingType());
  assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(),
               enumType.getOptions());

  assertEquals("NestedEnum", nestedType.getName());
  assertEquals("protobuf_unittest.TestAllTypes.NestedEnum",
               nestedType.getFullName());
  assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
  assertEquals(TestAllTypes.getDescriptor(), nestedType.getContainingType());

  EnumValueDescriptor value = ForeignEnum.FOREIGN_FOO.getValueDescriptor();
  assertEquals(value, enumType.getValues().get(0));
  assertEquals("FOREIGN_FOO", value.getName());
  assertEquals(4, value.getNumber());
  assertEquals(value, enumType.findValueByName("FOREIGN_FOO"));
  assertEquals(value, enumType.findValueByNumber(4));
  assertNull(enumType.findValueByName("NO_SUCH_VALUE"));
  for (int i = 0; i < enumType.getValues().size(); i++) {
    assertEquals(i, enumType.getValues().get(i).getIndex());
  }
}
 
Example #28
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 5 votes vote down vote up
RepeatedEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");
}
 
Example #29
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 5 votes vote down vote up
SingularEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  valueOfMethod = getMethodOrDie(type, "valueOf",
                                 EnumValueDescriptor.class);
  getValueDescriptorMethod =
    getMethodOrDie(type, "getValueDescriptor");
}
 
Example #30
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
RepeatedEnumFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

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