Skip to main content
Version: 3.8

Enum 枚举

1. 结构声明

class Enum extends BaseNode {
name: string = '';
label?: string;
description?: string;
enumItems: Array<EnumItem>;
valueType: TypeAnnotation;
}

2. 节点示例

(1) 示例

AST 如下:

{
"concept": "Enum",
"name": "ProductStatus",
"label": "",
"description": "",
"valueType": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
},
"enumItems": [
{
"concept": "EnumItem",
"value": "Listing",
"label": {
"concept": "StaticString",
"value": "上架"
}
},
{
"concept": "EnumItem",
"value": "Delisting",
"label": {
"concept": "StaticString",
"value": "下架"
}
}
]
}

对应的代码如下:

@(
label = "",
description = "",
)
enum ProductStatus {
@(label = '上架')
case Listing;

@(label = '下架')
case Delisting;
}

(2) 带描述的示例

AST 如下:

{
"concept": "Enum",
"name": "ProductStatus",
"label": "商品状态",
"description": "表示商品状态的枚举",
"valueType": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
},
"enumItems": [
{
"concept": "EnumItem",
"value": "Listing",
"label": {
"concept": "StaticString",
"value": "上架"
}
},
{
"concept": "EnumItem",
"value": "Delisting",
"label": {
"concept": "StaticString",
"value": "下架"
}
}
]
}

对应的代码如下:

@(
label = "商品状态",
description = "表示商品状态的枚举",
)
enum ProductStatus {
@(label = '上架')
case Listing;

@(label = '下架')
case Delisting;
}