Java Code Examples for io.protostuff.compiler.model.Field#getName()
The following examples show how to use
io.protostuff.compiler.model.Field#getName() .
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: OptionsPostProcessor.java From protostuff-compiler with Apache License 2.0 | 6 votes |
private void checkFieldValue(ProtoContext context, Descriptor descriptor, Field field, DynamicMessage.Value value) { String fieldName = field.getName(); FieldType fieldType = field.getType(); DynamicMessage.Value.Type valueType = value.getType(); if (fieldType instanceof ScalarFieldType) { ScalarFieldType scalarFieldType = (ScalarFieldType) fieldType; if (!isAssignableFrom(scalarFieldType, value)) { throw new ParserException(value, "Cannot set option '%s': expected %s value", fieldName, fieldType); } } else if (fieldType instanceof Enum) { Enum anEnum = (Enum) fieldType; Set<String> allowedNames = anEnum.getConstantNames(); if (valueType != DynamicMessage.Value.Type.ENUM || !allowedNames.contains(value.getEnumName())) { throw new ParserException(value, "Cannot set option '%s': expected enum = %s", fieldName, allowedNames); } } else if (fieldType instanceof Message) { if (valueType != DynamicMessage.Value.Type.MESSAGE) { throw new ParserException(value, "Cannot set option '%s': expected message value", fieldName); } Message message = (Message) fieldType; processOptions(context, message, descriptor, value.getMessage()); } else { throw new IllegalStateException("Unknown field type: " + fieldType); } }
Example 2
Source File: FieldSchema.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public FieldSchema(Field protoField, JavaType javaType) { this.protoField = protoField; this.name = protoField.getName(); this.fieldNumber = protoField.getTag(); this.packed = ProtoUtils.isPacked(protoField); int wireType = packed && protoField.isRepeated() ? WireFormat.WIRETYPE_LENGTH_DELIMITED : FieldTypeUtils.convert(protoField.getType()).wireType; this.tag = WireFormat.makeTag(fieldNumber, wireType); this.tagSize = ProtobufOutputEx.computeRawVarint32Size(tag); this.javaType = javaType; this.primitive = javaType.isPrimitive(); }
Example 3
Source File: ExtensionRegistratorPostProcessor.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private void checkRanges(Field field, List<Range> ranges) { int tag = field.getTag(); boolean inRange = false; for (Range range : ranges) { int from = range.getFrom(); int to = range.getTo(); if (tag >= from && tag <= to) { inRange = true; } } if (!inRange) { String format = "Extension field '%s' tag=%d is out of allowed range"; throw new ParserException(field, format, field.getName(), tag); } }
Example 4
Source File: UserTypeValidationPostProcessor.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private void checkReservedFieldNames(Message message, List<Field> fields) { Set<String> names = new HashSet<>(message.getReservedFieldNames()); for (Field field : fields) { String name = field.getName(); if (names.contains(name)) { throw new ParserException(field, "Reserved field name: '%s'", name); } } }
Example 5
Source File: UserTypeValidationPostProcessor.java From protostuff-compiler with Apache License 2.0 | 5 votes |
private void checkDuplicateFieldNames(List<Field> fields) { Map<String, Field> fieldByName = new HashMap<>(); for (Field field : fields) { String name = field.getName(); if (fieldByName.containsKey(name)) { throw new ParserException(field, "Duplicate field name: '%s'", name); } fieldByName.put(name, field); } }
Example 6
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a java field name for proto field. */ public static String getFieldName(Field field) { String name = field.getName(); String formattedName = Formatter.toCamelCase(name); if (isReservedKeyword(formattedName)) { return formattedName + '_'; } return formattedName; }
Example 7
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
/** * Returns a json field name for proto field. */ public static String getJsonFieldName(Field field) { String name = field.getName(); return Formatter.toCamelCase(name); }
Example 8
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 4 votes |
/** * Returns an one-of enum constant name for oneof field. */ public static String javaOneofConstantName(Field field) { String name = field.getName(); String underscored = Formatter.toUnderscoreCase(name); return Formatter.toUpperCase(underscored); }