mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 00:15:24 +00:00
ref[protocol]: refactor field method
This commit is contained in:
1 parent
0983e66f95
commit
4f3c2119e5
15 files changed
+18
-16
No files matched your search
+4
-2
@@ -253,8 +253,10 @@ public class CodeGenerateEcmaScript implements ICodeGenerate {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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, "[]");
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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()), "[]");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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()");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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);
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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()");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
*/
|
||||
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", "\"\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user