perf[protobuf]: recreate get and set method

This commit is contained in:
godotg
2023-12-03 16:26:35 +08:00
parent e76dd3ab81
commit 6624e5b053
6 changed files with 32 additions and 158 deletions
@@ -107,7 +107,8 @@ public class ProtoParser {
ProtoValue pv = readValueUtilSemicolon();
String optionValue = pv.getValue();
Option option = new Option();
option.setName(optionLabel).setValue(optionValue);
option.setName(optionLabel);
option.setValue(optionValue);
proto.addOption(option);
comments.clear();
break;
@@ -176,10 +177,10 @@ public class ProtoParser {
notSupportInnerMessage();
} else if (Cardinality.cardinalityOf(token) != null) {
PbField field = parseField(Cardinality.cardinalityOf(token), null);
msg.addField(field);
msg.getFields().add(field);
} else {
PbField field = parseField(Cardinality.OPTIONAL, token);
msg.addField(field);
msg.getFields().add(field);
}
boolean isEnd = blockEnd();
if (isEnd) {
@@ -405,14 +406,17 @@ public class ProtoParser {
PbField field;
if (gType != null) {
TypeProtobuf type = TypeProtobuf.valueOf(gType.getKeyType().toUpperCase(Locale.ENGLISH));
field = new MapField().setKey(type).setValue(gType.getValueType());
var mapField = new MapField();
mapField.setKey(type);
mapField.setValue(gType.getValueType());
field = mapField;
} else {
field = new PbField();
}
field.setCardinality(cardinality)
.setName(fieldName)
.setTag(tag)
.setType(fieldType);
field.setCardinality(cardinality);
field.setName(fieldName);
field.setTag(tag);
field.setType(fieldType);
field.getComments().addAll(comments);
comments.clear();
return field;
@@ -798,7 +802,8 @@ public class ProtoParser {
readValueSeparator('=');
String value = readOptionValue();
Option option = new Option();
option.setName(name).setValue(value);
option.setName(name);
option.setValue(value);
options.add(option);
trim();
}
@@ -23,35 +23,19 @@ public class MapField extends PbField {
private TypeProtobuf key;
private String value;
/**
* @return the key
*/
public TypeProtobuf getKey() {
return key;
}
/**
* @param key the key to set
* @return
*/
public MapField setKey(TypeProtobuf key) {
public void setKey(TypeProtobuf key) {
this.key = key;
return this;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @param value the value to set
* @return
*/
public MapField setValue(String value) {
public void setValue(String value) {
this.value = value;
return this;
}
}
@@ -27,28 +27,19 @@ public class Option {
*/
private String value;
public Option setValue(String value) {
this.value = value;
return this;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public Option setName(String name) {
this.name = name;
return this;
}
public String getName() {
return name;
}
public static boolean getBoolean(String value) {
if (value == null || value.isEmpty()) {
return false;
}
return "true".equalsIgnoreCase(value) || "t".equalsIgnoreCase(value);
public void setValue(String value) {
this.value = value;
}
}
@@ -89,84 +89,36 @@ public class PbField {
private List<String> comments = new ArrayList<>();
/**
* 消息属性的规则
*
* @return the cardinality
*/
public Cardinality getCardinality() {
return cardinality;
}
/**
* 消息属性的规则
*
* @param cardinality the cardinality to set
* @return
*/
public PbField setCardinality(Cardinality cardinality) {
public void setCardinality(Cardinality cardinality) {
this.cardinality = cardinality;
return this;
}
/**
* 消息属性名称
*
* @return the name
*/
public String getName() {
return name;
}
/**
* 消息属性名称
*
* @param name the name to set
* @return
*/
public PbField setName(String name) {
public void setName(String name) {
this.name = name;
return this;
}
/**
* 消息属性值的类型
*
* @return the type
*/
public String getType() {
return type;
}
/**
* 消息属性值的类型
*
* @param type the type to set
* @return
*/
public PbField setType(String type) {
public void setType(String type) {
this.type = type;
return this;
}
/**
* 属性的顺序标记一个消息内不允许重复
*
* @return the tag
*/
public int getTag() {
return tag;
}
/**
* 属性的顺序标记一个消息内不允许重复
*
* @param tag the tag to set
* @return
*/
public PbField setTag(int tag) {
public void setTag(int tag) {
this.tag = tag;
return this;
}
public List<String> getComments() {
@@ -37,77 +37,29 @@ public class ProtoMessage {
*/
private List<String> comments = new ArrayList<>();
public ProtoMessage addMessage(ProtoMessage child) {
if (child == null) {
return this;
}
getMessages().add(child);
return this;
}
public ProtoMessage addField(PbField field) {
if (field == null) {
return this;
}
getFields().add(field);
return this;
}
/**
* 消息的名称
*
* @return the name
*/
public String getName() {
return name;
}
/**
* 消息的名称
*
* @param name the name to set
*/
public ProtoMessage setName(String name) {
public void setName(String name) {
this.name = name;
return this;
}
/**
* 消息包含的Fields列表
*
* @return the fields
*/
public List<PbField> getFields() {
return fields;
}
/**
* 消息包含的Fields列表
*
* @param fields the fields to set
*/
public ProtoMessage setFields(List<PbField> fields) {
public void setFields(List<PbField> fields) {
this.fields = fields;
return this;
}
/**
* 消息内嵌的Message列表
*
* @return the messages
*/
public List<ProtoMessage> getMessages() {
public List<ProtoMessage> getProtoMessages() {
return protoMessages;
}
/**
* 消息内嵌的Message列表
*
* @param protoMessages the messages to set
*/
public ProtoMessage setMessages(List<ProtoMessage> protoMessages) {
public void setProtoMessages(List<ProtoMessage> protoMessages) {
this.protoMessages = protoMessages;
return this;
}
public List<String> getComments() {
@@ -31,14 +31,4 @@ public enum Syntax {
return value;
}
public static Syntax fromValue(String value) {
switch (value) {
case "proto2":
return Syntax.PROTO_2;
case "proto3":
return Syntax.PROTO_3;
default:
throw new IllegalArgumentException("no enum value Syntax " + value);
}
}
}