-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathnode.go
102 lines (87 loc) · 2.26 KB
/
node.go
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
package main
import (
"strings"
//"log"
)
type Node struct {
name string
space string
spaceTag string
parent *Node
parents []*Node
children map[string]*Node
childCount map[string]int
repeats bool
nodeTypeInfo *NodeTypeInfo
hasCharData bool
tempCharData string
charDataCount int64
discoveredOrder int
ignoredTag bool
}
type NodeVisitor interface {
Visit(n *Node) bool
AlreadyVisited(n *Node) bool
SetAlreadyVisited(n *Node)
}
func (n *Node) initialize(name string, space string, spaceTag string, parent *Node) {
n.parent = parent
n.parents = make([]*Node, 0, 0)
n.pushParent(parent)
n.name = name
n.space = space
n.spaceTag = spaceTag
n.children = make(map[string]*Node)
n.childCount = make(map[string]int)
n.nodeTypeInfo = new(NodeTypeInfo)
n.nodeTypeInfo.initialize()
n.hasCharData = false
n.ignoredTag = false
}
func (n *Node) makeName() string {
spaceTag := ""
if n.spaceTag != "" {
spaceTag = "_" + n.spaceTag
}
//return capitalizeFirstLetter(cleanName(n.name)) + spaceTag
return cleanName(n.name) + spaceTag
}
func (n *Node) makeType(prefix string, suffix string) string {
return goVariableNameSanitize(capitalizeFirstLetter(makeTypeGeneric(n.name, n.spaceTag, prefix, suffix, !keepXmlFirstLetterCase)) + n.renderSpaceTag())
}
func (n *Node) renderSpaceTag() string {
if len(strings.TrimSpace(n.spaceTag)) == 0 {
return ""
} else {
return "__" + n.spaceTag
}
}
func (n *Node) makeJavaType(prefix string, suffix string) string {
return capitalizeFirstLetter(makeTypeGeneric(n.name, n.spaceTag, prefix, suffix, !keepXmlFirstLetterCase))
}
func (n *Node) peekParent() *Node {
if len(n.parents) == 0 {
return nil
}
a := n.parents
return a[len(a)-1]
}
func (n *Node) pushParent(parent *Node) {
n.parents = append(n.parents, parent)
}
func (n *Node) popParent() *Node {
if len(n.parents) == 0 {
return nil
}
var poppedNode *Node
a := n.parents
poppedNode, n.parents = a[len(a)-1], a[:len(a)-1]
return poppedNode
}
func makeTypeGeneric(name string, space string, prefix string, suffix string, capitalizeName bool) string {
spaceTag := ""
if capitalizeName {
name = capitalizeFirstLetter(name)
}
return prefix + spaceTag + cleanName(name) + suffix
}