-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodekind.go
More file actions
131 lines (122 loc) · 2.38 KB
/
Copy pathnodekind.go
File metadata and controls
131 lines (122 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package model
import (
"encoding/json"
"fmt"
)
// NodeKind enumerates the 34 node types in the codeiq graph.
// String values MUST match the Java NodeKind enum 1:1 (see
// src/main/java/io/github/randomcodespace/iq/model/NodeKind.java).
type NodeKind int
const (
NodeModule NodeKind = iota
NodePackage
NodeClass
NodeMethod
NodeEndpoint
NodeEntity
NodeRepository
NodeQuery
NodeMigration
NodeTopic
NodeQueue
NodeEvent
NodeRMIInterface
NodeConfigFile
NodeConfigKey
NodeWebSocketEndpoint
NodeInterface
NodeAbstractClass
NodeEnum
NodeAnnotationType
NodeProtocolMessage
NodeConfigDefinition
NodeDatabaseConnection
NodeAzureResource
NodeAzureFunction
NodeMessageQueue
NodeInfraResource
NodeComponent
NodeGuard
NodeMiddleware
NodeHook
NodeService
NodeExternal
NodeSQLEntity
)
var nodeKindNames = [...]string{
"module",
"package",
"class",
"method",
"endpoint",
"entity",
"repository",
"query",
"migration",
"topic",
"queue",
"event",
"rmi_interface",
"config_file",
"config_key",
"websocket_endpoint",
"interface",
"abstract_class",
"enum",
"annotation_type",
"protocol_message",
"config_definition",
"database_connection",
"azure_resource",
"azure_function",
"message_queue",
"infra_resource",
"component",
"guard",
"middleware",
"hook",
"service",
"external",
"sql_entity",
}
// String returns the canonical lowercase value.
func (k NodeKind) String() string {
if int(k) < 0 || int(k) >= len(nodeKindNames) {
return fmt.Sprintf("nodekind(%d)", int(k))
}
return nodeKindNames[k]
}
// AllNodeKinds returns every NodeKind in declaration order.
func AllNodeKinds() []NodeKind {
out := make([]NodeKind, len(nodeKindNames))
for i := range nodeKindNames {
out[i] = NodeKind(i)
}
return out
}
// ParseNodeKind looks up a NodeKind by its canonical string value.
func ParseNodeKind(s string) (NodeKind, error) {
for i, name := range nodeKindNames {
if name == s {
return NodeKind(i), nil
}
}
return 0, fmt.Errorf("unknown NodeKind: %q", s)
}
// MarshalJSON emits the canonical string value.
func (k NodeKind) MarshalJSON() ([]byte, error) {
return json.Marshal(k.String())
}
// UnmarshalJSON parses the canonical string value.
func (k *NodeKind) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
parsed, err := ParseNodeKind(s)
if err != nil {
return err
}
*k = parsed
return nil
}