TypeAnnotation 类型标注
用于标注数据结构属性、逻辑的输入参数、输出参数、局部变量等概念的类型。 可以是用户自行选择的,也可以是 LanguageServer 推断的。
1. 结构声明
- TS Declaration
- JSON Schema
class TypeAnnotation extends BaseNode {
typeKind: 'primitive' | 'reference' | 'generic' | 'typeParam' | 'function' | 'union' | 'anonymousStructure';
typeNamespace: string;
typeName: string;
typeArguments?: Array<TypeAnnotation>;
returnType?: Array<TypeAnnotation>;
inferred: boolean;
properties?: Array<StructureProperty>;
ruleMap: Map<string, int>;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"typeKind": {
"type": "string",
"enum": [
"primitive",
"reference",
"generic",
"typeParam",
"function",
"union",
"anonymousStructure"
]
},
"typeNamespace": {
"type": "string"
},
"typeName": {
"type": "string"
},
"typeArguments": {
"type": "array",
"items": {
"$ref": "#/definitions/TypeAnnotation"
}
},
"returnType": {
"type": "array",
"items": {
"$ref": "#/definitions/TypeAnnotation"
}
},
"inferred": {
"type": "boolean"
},
"properties": {
"type": "array",
"items": {
"$ref": "#/definitions/StructureProperty"
}
},
"ruleMap": {
"type": "object",
"properties": {
"size": {
"type": "number"
}
},
"required": [
"size"
],
"additionalProperties": false
}
},
"required": [
"typeKind",
"typeNamespace",
"typeName",
"inferred",
"ruleMap"
],
"additionalProperties": false
}
2. 节点示例
(1) Boolean 布尔值
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Boolean",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Boolean
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
Boolean
(2) Integer 整数
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
Integer
(3) Decimal 小数
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Decimal",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Decimal
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
Decimal
(4) String 字符串
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
String
(5) Date 日期
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Date",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Date
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
Date
(6) Time 时间
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Time",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Time
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
Time
(7) DateTime 日期时间
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "DateTime",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: DateTime
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
DateTime
(8) 引用实体
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "Product",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.dataSources.defaultDS.entities
typeName: Product
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
app::dataSources::defaultDS::entities::Product
(9) 引用数据结构
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.structures",
"typeName": "StudentInfo",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.structures
typeName: StudentInfo
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
app::structures::StudentInfo
(10) 引用枚举
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.enums",
"typeName": "Status",
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.enums
typeName: Status
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
app::enums::Status
(11) 引用泛型
AST 如下:
- JSON
- YAML
{
"concept": "TypeAnnotation",
"typeKind": "generic",
"typeNamespace": "nasl.collection",
"typeName": "List",
"typeArguments": [
{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Integer",
"inferred": false,
"ruleMap": {}
}
],
"inferred": false,
"ruleMap": {}
}
concept: TypeAnnotation
typeKind: generic
typeNamespace: nasl.collection
typeName: List
typeArguments:
- concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Integer
inferred: false
ruleMap: {}
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
List<Integer>