null_exception.go 1.1 KB
Newer Older
P
Phodal Huang 已提交
1
	package evaluator
2 3

import (
4
	"github.com/phodal/coca/pkg/domain/core_domain"
5 6
)

P
Phodal Huang 已提交
7
type NullPointException struct {
8 9
}

10
func (NullPointException) Evaluate(*EvaluateModel, core_domain.CodeDataStruct) {
11 12 13

}

14
func (n NullPointException) EvaluateList(evaluateModel *EvaluateModel, nodes []core_domain.CodeDataStruct, nodeMap map[string]core_domain.CodeDataStruct, identifiers []core_domain.JIdentifier) {
P
Phodal Huang 已提交
15
	var nullableList []string = nil
P
Phodal Huang 已提交
16
	var nullableMap = make(map[string]string)
17
	for _, ident := range identifiers {
P
Phodal Huang 已提交
18
		for _, method := range ident.Functions {
P
Phodal Huang 已提交
19
			methodName := buildMethodPath(ident, method)
P
Phodal Huang 已提交
20
			if method.IsReturnNull {
P
Phodal Huang 已提交
21
				nullableMap[methodName] = methodName
P
Phodal Huang 已提交
22 23
			} else {
				for _, annotation := range method.Annotations {
P
Phodal Huang 已提交
24
					if annotation.Name == "Nullable" || annotation.Name == "CheckForNull"  {
P
Phodal Huang 已提交
25
						nullableMap[methodName] = methodName
P
Phodal Huang 已提交
26
					}
27 28 29 30
				}
			}
		}
	}
31

P
Phodal Huang 已提交
32 33 34 35
	for _, value := range nullableMap {
		nullableList = append(nullableList, value)
	}

36
	evaluateModel.Nullable.Items = nullableList
37
}
P
Phodal Huang 已提交
38

P
Phodal Huang 已提交
39
func buildMethodPath(ident core_domain.JIdentifier, method core_domain.CodeFunction) string {
P
Phodal Huang 已提交
40
	return ident.Package + "." + ident.NodeName + "." + method.Name
P
Phodal Huang 已提交
41
}