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 4f3c211 commit 8dd5ddb
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ private String protocol_field_definition(ProtocolRegistration registration) {
for (var fieldNote : fieldNotes) {
fieldDefinitionBuilder.append(fieldNote).append(LS);
}
var pair = jsSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
fieldDefinitionBuilder.append(StringUtils.format("this.{} = {}; // {}", fieldName, pair.getValue(), pair.getKey()))
.append(LS);

var fieldTypeDefaultValue = jsSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration);
var fieldType = fieldTypeDefaultValue.getKey();
var fieldDefaultValue = fieldTypeDefaultValue.getValue();
fieldDefinitionBuilder.append(StringUtils.format("this.{} = {}; // {}", fieldName, fieldDefaultValue, fieldType)).append(LS);
}
return fieldDefinitionBuilder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
public interface IJsSerializer {

/**
* 获取属性的类型,名称,默认值
* 获取属性的类型,默认值
*/
Pair<String, String> field(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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class JsArraySerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsBoolSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsByteSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsDoubleSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsFloatSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsIntSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsListSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsLongSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsMapSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 @@ -30,7 +30,7 @@
*/
public class JsObjectProtocolSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsSetSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsShortSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(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 JsStringSerializer implements IJsSerializer {
@Override
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
return new Pair<>("string", "\"\"");
}

Expand Down

0 comments on commit 8dd5ddb

Please sign in to comment.