Skip to main content
Version: Latest(3.11)

Logic 逻辑

1. 结构声明

class Logic extends Annotatable {
name: string = '';
title?: string;
description?: string;
triggerType?: string;
cron?: string;
overridable?: boolean;
transactional?: Transactional;
typeParams?: Array<TypeParam>;
params: Array<Param>;
returns: Array<Return>;
variables: Array<Variable>;
body: Array<LogicItem>;
playground: Array<LogicItem>;
}

2. 节点示例

(1) 示例

AST 如下:

{
"concept": "Logic",
"name": "logic1",
"title": "标题",
"description": "",
"triggerType": "",
"cron": "",
"overridable": false,
"transactional": {
"concept": "Transactional",
"enabled": false,
"propagation": "REQUIRED",
"isolation": "DEFAULT"
},
"params": [
{
"concept": "Param",
"name": "list",
"description": "",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeNamespace": "nasl.collection",
"typeKind": "generic",
"typeName": "List",
"typeArguments": [
{
"concept": "TypeAnnotation",
"typeNamespace": "nasl.core",
"typeKind": "primitive",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
],
"inferred": false,
"ruleMap": {}
}
}
],
"returns": [
{
"concept": "Return",
"name": "result",
"description": ""
}
],
"variables": [],
"body": [
{
"concept": "Start"
},
{
"concept": "Assignment",
"label": "赋值",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "result"
},
"right": {
"concept": "NullLiteral"
}
},
{
"concept": "IfStatement",
"test": {
"concept": "BinaryExpression",
"left": {
"concept": "MemberExpression",
"object": {
"concept": "Identifier",
"namespace": "",
"name": "list"
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "length"
}
},
"right": {
"concept": "NumericLiteral",
"value": "0",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
},
"operator": "=="
},
"consequent": [
{
"concept": "Assignment",
"label": "赋值",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "result"
},
"right": {
"concept": "NullLiteral"
}
}
],
"alternate": [
{
"concept": "Assignment",
"label": "赋值",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "result"
},
"right": {
"concept": "BinaryExpression",
"left": {
"concept": "CallFunction",
"label": "内置函数",
"calleeNamespace": "nasl.util",
"calleeName": "ListSum",
"typeArguments": [],
"arguments": [
{
"concept": "Argument",
"keyword": "list",
"expression": {
"concept": "Identifier",
"namespace": "",
"name": "list"
}
}
]
},
"right": {
"concept": "MemberExpression",
"object": {
"concept": "Identifier",
"namespace": "",
"name": "list"
},
"property": {
"concept": "Identifier",
"namespace": "",
"name": "length"
}
},
"operator": "/"
}
}
]
},
{
"concept": "End"
}
],
"playground": []
}

对应的代码如下:

@(
title = "标题",
description = "",
triggerType = "",
cron = "",
transactional = false,
overridable = false,
)
logic logic1(list: List&lt;Integer&gt;) => result {
result = null
if (list.length == 0) {
result = null
} else {
result = ListSum(list) / list.length
}
end
}