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()); }
@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.getType().isMessage() && !protoField.isMap() ? ProtoConst.LIST_TYPE : ProtoConst.MAP_TYPE; } javaType = TypeFactory.defaultInstance().constructParametricType(PropertyWrapper.class, javaType); } if (javaType.isJavaLangObject()) { javaType = ProtoConst.MAP_TYPE; } return new MessageReadSchema<>(protoMapper, message, javaType); }
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; }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
static BeanFactory createFactory(Field field) { // map also is repeated, so must determine first if (field.isMap()) { return BeanFactory::mapFactory; } if (field.isRepeated()) { return BeanFactory::listFactory; } if (field.getType().isScalar()) { // no need a factory return null; } return BeanFactory::mapFactory; }
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()); }
/** * 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 + "()"; }
/** * 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 + "()"; }
.oneof(field.isOneofPart() ? field.getOneof().getName() : null) .options(field.getOptions().toMap()); boolean isMap = field.isMap(); if (isMap) { builder.map(true);
protected FieldSchema createSchemaField(SchemaCreateContext context, Field protoField, boolean repeated) { if (protoField.isMap()) { Message entryMessage = (Message) protoField.getType(); FieldSchema keySchema = createSchemaField(context, entryMessage.getField(1), false);
protected FieldSchema createSchemaField(SchemaCreateContext context, JavaType javaType, Field protoField, boolean repeated) { if (protoField.isMap()) { Message entryMessage = (Message) protoField.getType(); FieldSchema keySchema = createSchemaField(context, javaType.getKeyType(), entryMessage.getField(1), false);