Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dgunay committed Oct 16, 2022
1 parent 13d132f commit 5bbeaf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ifacecapture/captured_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func (c *CallViaReceiver) ProcessSelExpr(expr *ast.SelectorExpr) error {
return nil
}

// Receiver returns the receiver for this call, which is the last element in
// the chain. Will panic if the chain is empty.
func (c CallViaReceiver) Receiver() *ast.Ident {
// last of the chain
return c.Chain[len(c.Chain)-1]
}

Expand Down
9 changes: 5 additions & 4 deletions ifacecapture/type_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type TypeChain struct {
}

func NewTypeChain() TypeChain {
return TypeChain{
Types: []*ast.Ident{},
}
return TypeChain{Types: []*ast.Ident{}}
}

// ProcessTypeChain traverses a chain of selector expressions like
// mypkg.MyInterface and collects the idents of the types in the chain.
func (t *TypeChain) ProcessTypeChain(expr ast.Expr) error {
switch expr.(type) {
case *ast.Ident:
Expand Down Expand Up @@ -53,7 +53,7 @@ func traverseSelChain(idents *[]*ast.Ident, selExpr *ast.SelectorExpr) error {
}
}

// True if the last element of the chain is an interface.
// IsInterface returns true if the last element of the chain is an interface.
func (t TypeChain) IsInterface() bool {
// last in the chain is an interface
last := t.Last()
Expand All @@ -71,6 +71,7 @@ func (t TypeChain) IsInterface() bool {
return ok
}

// Last returns the last element in the chain. Panics if the chain is empty.
func (t TypeChain) Last() *ast.Ident {
return t.Types[len(t.Types)-1]
}
1 change: 1 addition & 0 deletions ifacecapture/util/collections.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package util

// Any returns true if the given slice contains an element satisfying the predicate.
func Any[T any](elems []T, pred func(T) bool) bool {
for _, elem := range elems {
if pred(elem) {
Expand Down

0 comments on commit 5bbeaf4

Please sign in to comment.