Java Code Examples for io.protostuff.compiler.model.Field#isMap()
The following examples show how to use
io.protostuff.compiler.model.Field#isMap() .
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: 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 3
Source File: ProtoToStringGenerator.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void fieldToString(Field field, boolean repeated, StringBuilder sb) { if (field.isMap()) { fieldMapToString(field, sb); return; } if (repeated) { fieldRepeatedToString(field, sb); return; } appendLine(sb, "%s %s = %d;", field.getTypeName(), field.getName(), field.getTag()); }
Example 4
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 + "()"; }
Example 5
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns map field getter name. */ public static String getMapGetterName(Field field) { if (field.isMap()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX; } throw new IllegalArgumentException(field.toString()); }
Example 6
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns map field setter name. */ public static String getMapSetterName(Field field) { if (field.isMap()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX; } throw new IllegalArgumentException(field.toString()); }
Example 7
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns map field getter for particular key method name. */ public static String mapGetByKeyMethodName(Field field) { if (field.isMap()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
Example 8
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns map field "put" method name. */ public static String getMapFieldAdderName(Field field) { if (field.isMap()) { return PUT_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
Example 9
Source File: MessageFieldUtil.java From protostuff-compiler with Apache License 2.0 | 5 votes |
/** * Returns "putAll" method name for map field. */ public static String getMapFieldAddAllName(Field field) { if (field.isMap()) { return "putAll" + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }