@Test void getDefaultValue_message() { Proto proto = new Proto(); proto.setPackage(new Package(proto, "package")); Message message = new Message(proto); message.setName("Message"); message.setProto(proto); Field field = new Field(null); field.setType(message); assertEquals("package.Message.getDefaultInstance()", MessageFieldUtil.getDefaultValue(field)); }
public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); }
MessageFieldUtil { public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); } }
MessageFieldUtil { public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); } private  MessageFieldUtil(); }
MessageFieldUtil { public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); } private  MessageFieldUtil(); static String getFieldType(Field field); static String getFieldName(Field field); static String getJsonFieldName(Field field); static String getFieldGetterName(Field field); static String getFieldSetterName(Field field); static String getFieldWitherName(Field field); static String getEnumFieldValueGetterName(Field field); static String getEnumFieldValueSetterName(Field field); static String getFieldCleanerName(Field field); static boolean isMessage(Field field); static String getHasMethodName(Field field); static String getBuilderSetterName(Field field); static String getDefaultValue(Field field); static boolean isScalarNullableType(Field field); static String getRepeatedFieldType(Field field); static String getIterableFieldType(Field field); static String getWrapperFieldType(Field field); static String getRepeatedFieldGetterName(Field field); static String getRepeatedEnumFieldValueGetterName(Field field); static String javaRepeatedEnumValueGetterByIndexName(Field field); static String getRepeatedEnumConverterName(Field field); static String getRepeatedFieldSetterName(Field field); static String getRepeatedEnumValueSetterName(Field field); static String repeatedGetCountMethodName(Field field); static String repeatedGetByIndexMethodName(Field field); static String getRepeatedBuilderSetterName(Field field); static String getBuilderGetterName(Field field); static String getRepeatedFieldAdderName(Field field); static String getRepeatedFieldAddAllName(Field field); static String getRepeatedEnumValueAdderName(Field field); static String getRepeatedEnumValueAddAllName(Field field); static String toStringPart(Field field); static String protostuffReadMethod(Field field); static String protostuffWriteMethod(Field field); static String bitFieldName(Field field); static int bitFieldIndex(Field field); static int bitFieldMask(Field field); static String getMapFieldType(Field field); static String getMapFieldKeyType(Field field); static String getMapFieldValueType(Field field); static String getMapGetterName(Field field); static String getMapSetterName(Field field); static String mapGetByKeyMethodName(Field field); static String getMapFieldAdderName(Field field); static String getMapFieldAddAllName(Field field); static String javaOneofConstantName(Field field); static boolean isNumericType(Field field); static boolean isBooleanType(Field field); }
MessageFieldUtil { public static String getDefaultValue(Field field) { FieldType type = field.getType(); if (type instanceof ScalarFieldType) { return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type); } if (type instanceof Message) { Message m = (Message) type; return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()"; } if (type instanceof Enum) { Enum anEnum = (Enum) type; String defaultValue; List<EnumConstant> constants = anEnum.getConstants(); if (constants.isEmpty()) { defaultValue = "UNRECOGNIZED"; } else { DynamicMessage options = field.getOptions(); defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName(); } return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue; } throw new IllegalArgumentException(String.valueOf(type)); } private  MessageFieldUtil(); static String getFieldType(Field field); static String getFieldName(Field field); static String getJsonFieldName(Field field); static String getFieldGetterName(Field field); static String getFieldSetterName(Field field); static String getFieldWitherName(Field field); static String getEnumFieldValueGetterName(Field field); static String getEnumFieldValueSetterName(Field field); static String getFieldCleanerName(Field field); static boolean isMessage(Field field); static String getHasMethodName(Field field); static String getBuilderSetterName(Field field); static String getDefaultValue(Field field); static boolean isScalarNullableType(Field field); static String getRepeatedFieldType(Field field); static String getIterableFieldType(Field field); static String getWrapperFieldType(Field field); static String getRepeatedFieldGetterName(Field field); static String getRepeatedEnumFieldValueGetterName(Field field); static String javaRepeatedEnumValueGetterByIndexName(Field field); static String getRepeatedEnumConverterName(Field field); static String getRepeatedFieldSetterName(Field field); static String getRepeatedEnumValueSetterName(Field field); static String repeatedGetCountMethodName(Field field); static String repeatedGetByIndexMethodName(Field field); static String getRepeatedBuilderSetterName(Field field); static String getBuilderGetterName(Field field); static String getRepeatedFieldAdderName(Field field); static String getRepeatedFieldAddAllName(Field field); static String getRepeatedEnumValueAdderName(Field field); static String getRepeatedEnumValueAddAllName(Field field); static String toStringPart(Field field); static String protostuffReadMethod(Field field); static String protostuffWriteMethod(Field field); static String bitFieldName(Field field); static int bitFieldIndex(Field field); static int bitFieldMask(Field field); static String getMapFieldType(Field field); static String getMapFieldKeyType(Field field); static String getMapFieldValueType(Field field); static String getMapGetterName(Field field); static String getMapSetterName(Field field); static String mapGetByKeyMethodName(Field field); static String getMapFieldAdderName(Field field); static String getMapFieldAddAllName(Field field); static String javaOneofConstantName(Field field); static boolean isNumericType(Field field); static boolean isBooleanType(Field field);  }