Skip to content

Instantly share code, notes, and snippets.

@creativepsyco
Created January 6, 2014 17:47
Show Gist options
  • Save creativepsyco/8286534 to your computer and use it in GitHub Desktop.
Save creativepsyco/8286534 to your computer and use it in GitHub Desktop.
--- i/wire-compiler/src/main/java/com/squareup/wire/MessageWriter.java
+++ w/wire-compiler/src/main/java/com/squareup/wire/MessageWriter.java
@@ -94,10 +94,20 @@ public class MessageWriter {
} else if (type instanceof EnumType) {
EnumType enumType = (EnumType) type;
writer.beginType(enumType.getName(), "enum", EnumSet.of(PUBLIC));
+ int index = 0;
for (EnumType.Value value : enumType.getValues()) {
MessageWriter.emitDocumentation(writer, value.getDocumentation());
writer.emitAnnotation(ProtoEnum.class, value.getTag());
- writer.emitEnumValue(value.getName());
+ writer.emitEnumValue(value.getName(), (index == enumType.getValues().size() - 1));
+ index++;
+ }
+
+ // Output Enum Integer Value
+ for (EnumType.Value value : enumType.getValues()) {
+ String fieldName = value.getName();
+ String initialValue = Integer.toString(value.getTag());
+ writer.emitField("Integer", fieldName.toUpperCase(Locale.US) + "_VALUE",
+ EnumSet.of(PUBLIC, STATIC, FINAL), initialValue);
}
writer.endType();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment