Skip to main content
Version: 3.10

TypeAnnotation 类型标注

用于标注数据结构属性、逻辑的输入参数、输出参数、局部变量等概念的类型。 可以是用户自行选择的,也可以是 LanguageServer 推断的。

1. 结构声明

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>;
}

2. 节点示例

(1) Boolean 布尔值

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Boolean",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

Boolean

(2) Integer 整数

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

Integer

(3) Decimal 小数

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Decimal",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

Decimal

(4) String 字符串

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

String

(5) Date 日期

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Date",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

Date

(6) Time 时间

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Time",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

Time

(7) DateTime 日期时间

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "DateTime",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

DateTime

(8) 引用实体

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "Product",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

app::dataSources::defaultDS::entities::Product

(9) 引用数据结构

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.structures",
"typeName": "StudentInfo",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

app::structures::StudentInfo

(10) 引用枚举

AST 如下:

{
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.enums",
"typeName": "Status",
"inferred": false,
"ruleMap": {}
}

对应的代码如下:

app::enums::Status

(11) 引用泛型

AST 如下:

{
"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": {}
}

对应的代码如下:

List<Integer>