@@ -33,6 +33,13 @@ type (
3333 isPathStep ()
3434 }
3535
36+ // StructField represents a struct field access on a field called Name.
37+ StructField interface {
38+ PathStep
39+ Name () string
40+ Index () int
41+ isStructField ()
42+ }
3643 // SliceIndex is an index operation on a slice or array at some index Key.
3744 SliceIndex interface {
3845 PathStep
@@ -57,23 +64,16 @@ type (
5764 Key () reflect.Value
5865 isMapIndex ()
5966 }
60- // TypeAssertion represents a type assertion on an interface.
61- TypeAssertion interface {
62- PathStep
63- isTypeAssertion ()
64- }
65- // StructField represents a struct field access on a field called Name.
66- StructField interface {
67- PathStep
68- Name () string
69- Index () int
70- isStructField ()
71- }
7267 // Indirect represents pointer indirection on the parent type.
7368 Indirect interface {
7469 PathStep
7570 isIndirect ()
7671 }
72+ // TypeAssertion represents a type assertion on an interface.
73+ TypeAssertion interface {
74+ PathStep
75+ isTypeAssertion ()
76+ }
7777 // Transform is a transformation from the parent type to the current type.
7878 Transform interface {
7979 PathStep
@@ -188,17 +188,6 @@ type (
188188 typ reflect.Type
189189 }
190190
191- sliceIndex struct {
192- pathStep
193- xkey , ykey int
194- }
195- mapIndex struct {
196- pathStep
197- key reflect.Value
198- }
199- typeAssertion struct {
200- pathStep
201- }
202191 structField struct {
203192 pathStep
204193 name string
@@ -211,9 +200,20 @@ type (
211200 pvx , pvy reflect.Value // Parent values
212201 field reflect.StructField // Field information
213202 }
203+ sliceIndex struct {
204+ pathStep
205+ xkey , ykey int
206+ }
207+ mapIndex struct {
208+ pathStep
209+ key reflect.Value
210+ }
214211 indirect struct {
215212 pathStep
216213 }
214+ typeAssertion struct {
215+ pathStep
216+ }
217217 transform struct {
218218 pathStep
219219 trans * transformer
@@ -231,6 +231,12 @@ func (ps pathStep) String() string {
231231 }
232232 return fmt .Sprintf ("{%s}" , s )
233233}
234+ func (ps pathStep ) isPathStep () {}
235+
236+ func (sf structField ) String () string { return fmt .Sprintf (".%s" , sf .name ) }
237+ func (sf structField ) Name () string { return sf .name }
238+ func (sf structField ) Index () int { return sf .idx }
239+ func (sf structField ) isStructField () {}
234240
235241func (si sliceIndex ) String () string {
236242 switch {
@@ -247,48 +253,38 @@ func (si sliceIndex) String() string {
247253 return fmt .Sprintf ("[%d->%d]" , si .xkey , si .ykey )
248254 }
249255}
250- func (mi mapIndex ) String () string { return fmt .Sprintf ("[%#v]" , mi .key ) }
251- func (ta typeAssertion ) String () string { return fmt .Sprintf (".(%v)" , ta .typ ) }
252- func (sf structField ) String () string { return fmt .Sprintf (".%s" , sf .name ) }
253- func (in indirect ) String () string { return "*" }
254- func (tf transform ) String () string { return fmt .Sprintf ("%s()" , tf .trans .name ) }
255-
256256func (si sliceIndex ) Key () int {
257257 if si .xkey != si .ykey {
258258 return - 1
259259 }
260260 return si .xkey
261261}
262262func (si sliceIndex ) SplitKeys () (x , y int ) { return si .xkey , si .ykey }
263- func (mi mapIndex ) Key () reflect.Value { return mi .key }
264- func (sf structField ) Name () string { return sf .name }
265- func (sf structField ) Index () int { return sf .idx }
266- func (tf transform ) Name () string { return tf .trans .name }
267- func (tf transform ) Func () reflect.Value { return tf .trans .fnc }
268- func (tf transform ) Option () Option { return tf .trans }
263+ func (si sliceIndex ) isSliceIndex () {}
269264
270- func (pathStep ) isPathStep () {}
271- func (sliceIndex ) isSliceIndex () {}
272- func (mapIndex ) isMapIndex () {}
273- func (typeAssertion ) isTypeAssertion () {}
274- func (structField ) isStructField () {}
275- func (indirect ) isIndirect () {}
276- func (transform ) isTransform () {}
265+ func (mi mapIndex ) String () string { return fmt .Sprintf ("[%#v]" , mi .key ) }
266+ func (mi mapIndex ) Key () reflect.Value { return mi .key }
267+ func (mi mapIndex ) isMapIndex () {}
277268
278- var (
279- _ SliceIndex = sliceIndex {}
280- _ MapIndex = mapIndex {}
281- _ TypeAssertion = typeAssertion {}
282- _ StructField = structField {}
283- _ Indirect = indirect {}
284- _ Transform = transform {}
269+ func (in indirect ) String () string { return "*" }
270+ func (in indirect ) isIndirect () {}
285271
286- _ PathStep = sliceIndex {}
287- _ PathStep = mapIndex {}
288- _ PathStep = typeAssertion {}
289- _ PathStep = structField {}
290- _ PathStep = indirect {}
291- _ PathStep = transform {}
272+ func (ta typeAssertion ) String () string { return fmt .Sprintf (".(%v)" , ta .typ ) }
273+ func (ta typeAssertion ) isTypeAssertion () {}
274+
275+ func (tf transform ) String () string { return fmt .Sprintf ("%s()" , tf .trans .name ) }
276+ func (tf transform ) Name () string { return tf .trans .name }
277+ func (tf transform ) Func () reflect.Value { return tf .trans .fnc }
278+ func (tf transform ) Option () Option { return tf .trans }
279+ func (tf transform ) isTransform () {}
280+
281+ var (
282+ _ PathStep = StructField (structField {})
283+ _ PathStep = SliceIndex (sliceIndex {})
284+ _ PathStep = MapIndex (mapIndex {})
285+ _ PathStep = Indirect (indirect {})
286+ _ PathStep = TypeAssertion (typeAssertion {})
287+ _ PathStep = Transform (transform {})
292288)
293289
294290// isExported reports whether the identifier is exported.
0 commit comments