Skip to content

Commit

Permalink
ref[protocol]: refactor field method
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 15, 2024
1 parent 0983e66 commit 4f3c211
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ private String protocol_field_definition(ProtocolRegistration registration) {
for (var fieldNote : fieldNotes) {
fieldDefinitionBuilder.append(fieldNote).append(LS);
}
var fieldTypeValue = esSerializer(fieldRegistration.serializer()).fieldTypeValue(field, fieldRegistration);
fieldDefinitionBuilder.append(StringUtils.format("{} = {}; // {}", fieldName, fieldTypeValue.getValue(), fieldTypeValue.getKey()))
var fieldTypeDefaultValue = esSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration);
var fieldType = fieldTypeDefaultValue.getKey();
var fieldDefaultValue = fieldTypeDefaultValue.getValue();
fieldDefinitionBuilder.append(StringUtils.format("{} = {}; // {}", fieldName, fieldDefaultValue, fieldType))
.append(LS);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class EsArraySerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
var type = StringUtils.format("Array<{}>", CodeGenerateTypeScript.toTsClassName(field.getType().getComponentType().getSimpleName()));
return new Pair<>(type, "[]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsBoolSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("boolean", "false");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsByteSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsDoubleSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsFloatSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsIntSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class EsListSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "[]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsLongSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class EsMapSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "new Map()");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class EsObjectProtocolSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
var type = StringUtils.format("{} | null", protocolSimpleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class EsSetSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "new Set()");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsShortSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("number", "0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class EsStringSerializer implements IEsSerializer {
@Override
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("string", "\"\"");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IEsSerializer {
/**
* 获取属性的类型,默认值
*/
Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration);
Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration);

void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);

Expand Down

0 comments on commit 4f3c211

Please sign in to comment.