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:
parent
e117b7f7d5
commit
44804ba326
12
analyze.go
12
analyze.go
@ -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"
|
||||
}
|
||||
|
26
recv.go
Normal file
26
recv.go
Normal 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
24
recv_pre118.go
Normal 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"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user