Debian Codegraph @

spdxexp/node.go

raw symbols SCIP
1 package spdxexpscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/"
5 "sortscip-go gomod github.com/golang/go/src go1.24 sort/"
6 "stringsscip-go gomod github.com/golang/go/src go1.24 strings/"
7 )
8
9 type nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair# struct {
10 firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode. *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#
11 secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode. *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#
12 }
13
14 type nodeRolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodeRole# uint8
15
16 const (
17 expressionNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNode. nodeRolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodeRole# = iota
18 licenseRefNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefNode.
19 licenseNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNode.
20 )
21
22 type nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node# struct {
23 rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#role. nodeRolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodeRole#
24 expscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exp. *expressionNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#
25 licscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#lic. *licenseNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#
26 refscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#ref. *referenceNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#
27 }
28
29 type expressionNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial# struct {
30 leftscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#left. *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#
31 conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#conjunction. string
32 rightscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#right. *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#
33 }
34
35 type licenseNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial# struct {
36 licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#license. string
37 hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#hasPlus. bool
38 hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#hasException. bool
39 exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#exception. string
40 }
41
42 type referenceNodePartialscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial# struct {
43 hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#hasDocumentRef. bool
44 documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#documentRef. string
45 licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#licenseRef. string
46 }
47
48 // ---------------------- Helper Methods ----------------------
49
50 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() bool {
51 return n.rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#role. == expressionNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNode.
52 }
53
54 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) isOrExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isOrExpression().() bool {
55 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
56 return false
57 }
58 return *n.conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#conjunction().() == "or"
59 }
60
61 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) isAndExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isAndExpression().() bool {
62 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
63 return false
64 }
65 return *n.conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#conjunction().() == "and"
66 }
67
68 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) leftscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#left().() *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node# {
69 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
70 return nil
71 }
72 return n.expscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exp..leftscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#left.
73 }
74
75 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#conjunction().() *string {
76 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
77 return nil
78 }
79 return &(n.expscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exp..conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#conjunction.)
80 }
81
82 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) rightscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#right().() *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node# {
83 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
84 return nil
85 }
86 return n.expscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exp..rightscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNodePartial#right.
87 }
88
89 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() bool {
90 return n.rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#role. == licenseNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNode.
91 }
92
93 // license returns the value of the license field.
94 // See also reconstructedLicenseString()
95 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#license().() *string {
96 if !n.isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() {
97 return nil
98 }
99 return &(n.licscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#lic..licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#license.)
100 }
101
102 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exception().() *string {
103 if !n.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() {
104 return nil
105 }
106 return &(n.licscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#lic..exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#exception.)
107 }
108
109 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasPlus().() bool {
110 if !n.isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() {
111 return false
112 }
113 return n.licscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#lic..hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#hasPlus.
114 }
115
116 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() bool {
117 if !n.isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() {
118 return false
119 }
120 return n.licscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#lic..hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNodePartial#hasException.
121 }
122
123 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) isLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicenseRef().() bool {
124 return n.rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#role. == licenseRefNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefNode.
125 }
126
127 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#licenseRef().() *string {
128 if !n.isLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicenseRef().() {
129 return nil
130 }
131 return &(n.refscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#ref..licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#licenseRef.)
132 }
133
134 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#documentRef().() *string {
135 if !n.hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().() {
136 return nil
137 }
138 return &(n.refscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#ref..documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#documentRef.)
139 }
140
141 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().() bool {
142 if !n.isLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicenseRef().() {
143 return false
144 }
145 return n.refscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#ref..hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/referenceNodePartial#hasDocumentRef.
146 }
147
148 // reconstructedLicenseString returns the string representation of a license, license ref, or expression.
149 // TODO: Original had "NOASSERTION". Does that still apply?
150 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().() *string {
151 switch n.rolescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#role. {
152 case expressionNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/expressionNode.:
153 return n.reconstructedExpressionStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedExpressionString().()
154 case licenseNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseNode.:
155 license := *n.licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#license().()
156 if n.hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasPlus().() && !stringsscip-go gomod github.com/golang/go/src go1.24 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24 strings/HasSuffix().(stringsscip-go gomod github.com/golang/go/src go1.24 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.24 strings/ToLower().(license), "-or-later") {
157 license += "+"
158 }
159 if n.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() {
160 license += " WITH " + *n.exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exception().()
161 }
162 return &license
163 case licenseRefNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/licenseRefNode.:
164 license := "LicenseRef-" + *n.licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#licenseRef().()
165 if n.hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().() {
166 license = "DocumentRef-" + *n.documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#documentRef().() + ":" + license
167 }
168 return &license
169 }
170 return nil
171 }
172
173 func (n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) reconstructedExpressionStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedExpressionString().() *string {
174 if n == nil || !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
175 return nil
176 }
177
178 left := n.leftscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#left().()
179 right := n.rightscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#right().()
180 if left == nil || right == nil {
181 return nil
182 }
183
184 leftStr := left.reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().()
185 rightStr := right.reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().()
186 if leftStr == nil || rightStr == nil {
187 return nil
188 }
189
190 conj := n.conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#conjunction().()
191 if conj == nil {
192 return nil
193 }
194
195 operator := stringsscip-go gomod github.com/golang/go/src go1.24 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24 strings/ToUpper().(*conj)
196 if operator != "AND" && operator != "OR" {
197 return nil
198 }
199
200 parentPrec := nodePrecedencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePrecedence().(n)
201 leftRendered := *leftStr
202 if left.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() && nodePrecedencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePrecedence().(left) < parentPrec {
203 leftRendered = "(" + leftRendered + ")"
204 }
205 rightRendered := *rightStr
206 if right.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() && nodePrecedencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePrecedence().(right) < parentPrec {
207 rightRendered = "(" + rightRendered + ")"
208 }
209
210 s := fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24 fmt/Sprintf().("%s %s %s", leftRendered, operator, rightRendered)
211 return &s
212 }
213
214 func nodePrecedencescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePrecedence().(n *nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) int {
215 if n == nil {
216 return 0
217 }
218 if !n.isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
219 // atomic (license/licenseRef)
220 return 3
221 }
222 conj := n.conjunctionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#conjunction().()
223 if conj == nil {
224 return 0
225 }
226 switch stringsscip-go gomod github.com/golang/go/src go1.24 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.24 strings/ToLower().(*conj) {
227 case "and":
228 return 2
229 case "or":
230 return 1
231 default:
232 return 0
233 }
234 }
235
236 // sortLicenses sorts an array of license and license reference nodes alphabetically based
237 // on their reconstructedLicenseString() representation. The sort function does not expect
238 // expression nodes, but if one is in the nodes list, it will sort to the end.
239 func sortLicensesscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/sortLicenses().(nodes []*nodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#) {
240 sortscip-go gomod github.com/golang/go/src go1.24 sort/.Slicescip-go gomod github.com/golang/go/src go1.24 sort/Slice().(nodes, func(i, j int) bool {
241 if nodes[j].isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
242 // push second license toward end by saying first license is less than
243 return true
244 }
245 if nodes[i].isExpressionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isExpression().() {
246 // push first license toward end by saying second license is less than
247 return false
248 }
249 return *nodes[i].reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().() < *nodes[j].reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().()
250 })
251 }
252
253 // ---------------------- Comparator Methods ----------------------
254
255 // licensesAreCompatible returns true if two licenses are compatible; otherwise, false.
256 // Two licenses are compatible if they are the same license or if they are in the same
257 // license group and they meet one of the following rules:
258 //
259 // * both licenses have the `hasPlus` flag set to true
260 // * the first license has the `hasPlus` flag and the second license is in the first license's range or greater
261 // * the second license has the `hasPlus` flag and the first license is in the second license's range or greater
262 // * both licenses are in the same range
263 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) licensesAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#licensesAreCompatible().() bool {
264 // checking ranges is expensive, so check for simple cases first
265 if !nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() || !nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..isLicensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicense().() {
266 return false
267 }
268 if !nodes.exceptionsAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#exceptionsAreCompatible().() {
269 return false
270 }
271 if nodes.licensesExactlyEqualscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#licensesExactlyEqual().() {
272 return true
273 }
274
275 // simple cases don't apply, so check license ranges
276 // NOTE: Ranges are organized into groups (referred to as license groups) of the same base license (e.g. GPL).
277 // Groups have sub-groups of license versions (referred to as the range) where each member is considered
278 // to be the same version (e.g. {GPL-2.0, GPL-2.0-only}). The sub-groups are in ascending order within
279 // the license group, such that the first sub-group is considered to be less than the second sub-group,
280 // and so on. (e.g. {{GPL-1.0}, {GPL-2.0, GPL-2.0-only}} implies {GPL-1.0} < {GPL-2.0, GPL-2.0-only}).
281 if nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasPlus().() {
282 if nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasPlus().() {
283 // first+, second+ just need to be in same range group
284 return nodes.rangesAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#rangesAreCompatible().()
285 }
286 // first, second+ requires first to be in range of second
287 return nodes.identifierInRangescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#identifierInRange().()
288 }
289 // else secondNode does not have plus
290 if nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..hasPlusscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasPlus().() {
291 // first+, second requires second to be in range of first
292 revNodes := &nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#{firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode.: nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode., secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode.: nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode.}
293 return revNodes.identifierInRangescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#identifierInRange().()
294 }
295 // first, second requires both to be in same range group
296 return nodes.rangesEqualscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#rangesEqual().()
297 }
298
299 // licenseRefsAreCompatible returns true if two license references are compatible; otherwise, false.
300 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) licenseRefsAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#licenseRefsAreCompatible().() bool {
301 if !nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..isLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicenseRef().() || !nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..isLicenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#isLicenseRef().() {
302 return false
303 }
304
305 compatible := *nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#licenseRef().() == *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..licenseRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#licenseRef().()
306 compatible = compatible && (nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().() == nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().())
307 if compatible && nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..hasDocumentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasDocumentRef().() {
308 compatible = compatible && (*nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#documentRef().() == *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..documentRefscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#documentRef().())
309 }
310 return compatible
311 }
312
313 // licenseRefsAreCompatible returns true if two licenses are in the same license group (e.g. all "GPL" licenses are in the same
314 // license group); otherwise, false.
315 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) rangesAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#rangesAreCompatible().() bool {
316 firstNode := *nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode.
317 secondNode := *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode.
318
319 firstRange := getLicenseRangescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getLicenseRange().(*firstNode.licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#license().())
320 secondRange := getLicenseRangescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/getLicenseRange().(*secondNode.licensescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#license().())
321
322 // When both licenses allow later versions (i.e. hasPlus==true), being in the same license
323 // group is sufficient for compatibility, as long as, any exception is also compatible
324 // Example: All Apache licenses (e.g. Apache-1.0, Apache-2.0) are in the same license group
325 return sameLicenseGroupscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/sameLicenseGroup().(firstRange, secondRange)
326 }
327
328 // identifierInRange returns true if the (first) simple license is in range of the (second)
329 // ranged license; otherwise, false.
330 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) identifierInRangescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#identifierInRange().() bool {
331 simpleLicense := nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode.
332 plusLicense := nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode.
333
334 return compareGTscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/compareGT().(simpleLicense, plusLicense) || compareEQscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/compareEQ().(simpleLicense, plusLicense)
335 }
336
337 // exceptionsAreCompatible returns true if neither license has an exception or they have
338 // the same exception; otherwise, false
339 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) exceptionsAreCompatiblescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#exceptionsAreCompatible().() bool {
340 firstNode := *nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode.
341 secondNode := *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode.
342
343 if !firstNode.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() && !secondNode.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() {
344 // if neither has an exception, then licenses are compatible
345 return true
346 }
347
348 if firstNode.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() != secondNode.hasExceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#hasException().() {
349 // if one has and exception and the other does not, then the license are NOT compatible
350 return false
351 }
352
353 return *nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exception().() == *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..exceptionscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#exception().()
354 }
355
356 // rangesEqual returns true if the licenses are in the same range; otherwise, false
357 // (e.g. GPL-2.0-only == GPL-2.0)
358 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) rangesEqualscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#rangesEqual().() bool {
359 return compareEQscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/compareEQ().(nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode., nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode.)
360 }
361
362 // licensesExactlyEqual returns true if the licenses are the same; otherwise, false
363 func (nodes *nodePairscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#) licensesExactlyEqualscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#licensesExactlyEqual().() bool {
364 return stringsscip-go gomod github.com/golang/go/src go1.24 strings/.EqualFoldscip-go gomod github.com/golang/go/src go1.24 strings/EqualFold().(*nodes.firstNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#firstNode..reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().(), *nodes.secondNodescip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/nodePair#secondNode..reconstructedLicenseStringscip-go gomod github.com/github/go-spdx/v2 . `github.com/github/go-spdx/v2/spdxexp`/node#reconstructedLicenseString().())
365 }