perf[ts]: remove null type of ts variable

This commit is contained in:
godotg
2023-04-14 22:13:20 +08:00
parent 8c8291174c
commit 4f51f8b103
7 changed files with 18 additions and 15 deletions
@@ -481,6 +481,13 @@ public class ProtocolAnalysis {
}
/**
* 此方法仅在生成协议的时候调用,一旦运行,不能调用
*/
public static Set<Short> getFirstSubProtocolIds(short protocolId) {
return subProtocolIdMap.get(protocolId);
}
/**
* 此方法仅在生成协议的时候调用,一旦运行,不能调用
*/
@@ -137,7 +137,7 @@ public abstract class GenerateTsUtils {
private static String importSubProtocol(ProtocolRegistration registration) {
var protocolId = registration.getId();
var subProtocols = ProtocolAnalysis.getAllSubProtocolIds(protocolId);
var subProtocols = ProtocolAnalysis.getFirstSubProtocolIds(protocolId);
if (CollectionUtils.isEmpty(subProtocols)) {
return StringUtils.EMPTY;
@@ -33,8 +33,8 @@ public class TsArraySerializer implements ITsSerializer {
@Override
public Triple<String, String, String> field(Field field, IFieldRegistration fieldRegistration) {
var type = StringUtils.format(": Array<{}> | null", GenerateTsUtils.toTsClassName(field.getType().getComponentType().getSimpleName()));
return new Triple<>(type, field.getName(), "null");
var type = StringUtils.format(": Array<{}>", GenerateTsUtils.toTsClassName(field.getType().getComponentType().getSimpleName()));
return new Triple<>(type, field.getName(), "[]");
}
@Override
@@ -33,8 +33,8 @@ public class TsListSerializer implements ITsSerializer {
@Override
public Triple<String, String, String> field(Field field, IFieldRegistration fieldRegistration) {
var type = StringUtils.format(": {} | null", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "null");
var type = StringUtils.format(": {}", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "[]");
}
@Override
@@ -33,8 +33,8 @@ public class TsMapSerializer implements ITsSerializer {
@Override
public Triple<String, String, String> field(Field field, IFieldRegistration fieldRegistration) {
var type = StringUtils.format(": {} | null", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "null");
var type = StringUtils.format(": {}", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "new Map()");
}
@Override
@@ -33,8 +33,8 @@ public class TsSetSerializer implements ITsSerializer {
@Override
public Triple<String, String, String> field(Field field, IFieldRegistration fieldRegistration) {
var type = StringUtils.format(": {} | null", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "null");
var type = StringUtils.format(": {}", GenerateTsUtils.toTsClassName(field.getGenericType().toString()));
return new Triple<>(type, field.getName(), "new Set()");
}
@Override
@@ -4,20 +4,16 @@ class {} {
{}
static PROTOCOL_ID: number = {}
static PROTOCOL_ID: number = {};
protocolId(): number {
return {}.PROTOCOL_ID;
}
static write(buffer: any, packet: {} | null) {
if (buffer.writePacketFlag(packet)) {
if (buffer.writePacketFlag(packet) || packet == null) {
return;
}
if (packet === null) {
return;
}
{}
}