1
0
mirror of https://github.com/fzipp/gocyclo.git synced 2025-02-06 10:23:54 +00:00

support method receivers with type parameters for Go 1.18

This commit is contained in:
fzipp 2021-10-30 10:51:11 +02:00
parent e117b7f7d5
commit 44804ba326
4 changed files with 51 additions and 13 deletions

View File

@ -138,15 +138,3 @@ func funcName(fn *ast.FuncDecl) string {
}
return fn.Name.Name
}
// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
}
return "BADRECV"
}

2
go.mod
View File

@ -1,3 +1,3 @@
module github.com/fzipp/gocyclo
go 1.16
go 1.18

26
recv.go Normal file
View File

@ -0,0 +1,26 @@
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package gocyclo
import "go/ast"
// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
case *ast.IndexExpr:
return recvString(t.X)
case *ast.IndexListExpr:
return recvString(t.X)
}
return "BADRECV"
}

24
recv_pre118.go Normal file
View File

@ -0,0 +1,24 @@
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.18
// +build !go1.18
package gocyclo
import "go/ast"
// recvString returns a string representation of recv of the
// form "T", "*T", or "BADRECV" (if not a proper receiver type).
func recvString(recv ast.Expr) string {
switch t := recv.(type) {
case *ast.Ident:
return t.Name
case *ast.StarExpr:
return "*" + recvString(t.X)
case *ast.IndexExpr:
return recvString(t.X)
}
return "BADRECV"
}