Java Code Examples for io.protostuff.compiler.model.Field#isRepeated()
The following examples show how to use
io.protostuff.compiler.model.Field#isRepeated() .
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: DeserializerSchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Override protected <T> SchemaEx<T> newMessageSchema(Message message, JavaType javaType) { if (ProtoUtils.isWrapProperty(message) && javaType.getRawClass() != PropertyWrapper.class) { Field protoField = message.getField(1); if (javaType.isJavaLangObject()) { javaType = protoField.isRepeated() && !protoField.isMap() ? ProtoConst.LIST_TYPE : ProtoConst.MAP_TYPE; } if (javaType.isPrimitive()) { javaType = TypeFactory.defaultInstance() .constructParametricType(PropertyWrapper.class, TypesUtil.primitiveJavaTypeToWrapper(javaType)); } else { javaType = TypeFactory.defaultInstance().constructParametricType(PropertyWrapper.class, javaType); } } if (javaType.isJavaLangObject()) { javaType = ProtoConst.MAP_TYPE; } return new MessageReadSchema<>(protoMapper, message, javaType); }
Example 2
Source File: AbstractWriters.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public AbstractWriters(Field protoField, Class<T[]> arrayClass) { this.protoField = protoField; int wireType = ProtoUtils.isPacked(protoField) && protoField.isRepeated() ? WireFormat.WIRETYPE_LENGTH_DELIMITED : FieldTypeUtils.convert(protoField.getType()).wireType; this.tag = WireFormat.makeTag(protoField.getTag(), wireType); this.tagSize = ProtobufOutputEx.computeRawVarint32Size(tag); if (arrayClass == null) { arrayClass = getFieldArgument(this.getClass(), "arrayWriter"); } this.arrayClass = arrayClass; }
Example 3
Source File: SchemaManager.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public <T> FieldSchema<T> createSchemaField(Field protoField, PropertyDescriptor propertyDescriptor) { // map is a special repeated if (protoField.isMap()) { return createMapFieldSchema(protoField, propertyDescriptor); } if (protoField.isRepeated()) { return createRepeatedSchema(protoField, propertyDescriptor); } if (isAnyField(protoField)) { return new AnySchema<>(protoMapper, protoField, propertyDescriptor); } if (protoField.getType().isScalar()) { return createScalarField(protoField, propertyDescriptor); } // message if (protoField.getType().isMessage()) { SchemaEx<Object> messageSchema = getOrCreateMessageSchema((Message) protoField.getType(), propertyDescriptor.getJavaType()); if (isWrapProperty((Message) protoField.getType())) { return new PropertyWrapperAsFieldSchema<>(protoField, propertyDescriptor, messageSchema); } return new MessageAsFieldSchema<>(protoField, propertyDescriptor, messageSchema); } if (protoField.isOneofPart()) { throw new IllegalStateException("not IMPL oneof now."); } ProtoUtils.throwNotSupportWrite(protoField, propertyDescriptor.getJavaType().getRawClass()); return null; }
Example 4
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 5
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a java field getter name for proto repeated field. */ public static String getRepeatedFieldGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + GETTER_REPEATED_SUFFIX; } throw new IllegalArgumentException(field.toString()); }
Example 6
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field value getter name for proto repeated enum field. */ public static String getRepeatedEnumFieldValueGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "ValueList"; } throw new IllegalArgumentException(field.toString()); }
Example 7
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field value getter by index name for proto repeated enum field. */ public static String javaRepeatedEnumValueGetterByIndexName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE; } throw new IllegalArgumentException(field.toString()); }
Example 8
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field converter class name for proto repeated enum field. */ public static String getRepeatedEnumConverterName(Field field) { if (field.isRepeated()) { return "__" + Formatter.toCamelCase(field.getName()) + "Converter"; } throw new IllegalArgumentException(field.toString()); }
Example 9
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field setter name for proto repeated field. */ public static String getRepeatedFieldSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
Example 10
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field value setter name for proto repeated enum field. */ public static String getRepeatedEnumValueSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE; } throw new IllegalArgumentException(field.toString()); }
Example 11
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a element count getter name for proto repeated field. */ public static String repeatedGetCountMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "Count"; } throw new IllegalArgumentException(field.toString()); }
Example 12
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns a field getter by index name for proto repeated field. */ public static String repeatedGetByIndexMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
Example 13
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Generate part of toString method for a single field. */ public static String toStringPart(Field field) { String getterName; if (field.isMap()) { getterName = getMapGetterName(field); } else if (field.isRepeated()) { getterName = getRepeatedFieldGetterName(field); } else { getterName = getFieldGetterName(field); } if (field.getType().isEnum() && !field.isRepeated()) { return "\"" + getFieldName(field) + "=\" + " + getterName + "() + '(' + " + getEnumFieldValueGetterName(field) + "() + ')'"; } return "\"" + getFieldName(field) + "=\" + " + getterName + "()"; }