mirror of https://github.com/fluffle/goirc
Fix copypasta and add a comment about fail.
This commit is contained in:
parent
2e4623676d
commit
de94609749
20
fix/goirc.go
20
fix/goirc.go
|
@ -23,6 +23,11 @@ var goircFix = fix{
|
||||||
`Update code that uses goirc/client to new API.`,
|
`Update code that uses goirc/client to new API.`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
clientPath = "github.com/fluffle/goirc/client"
|
||||||
|
statePath = "github.com/fluffle/goirc/state"
|
||||||
|
)
|
||||||
|
|
||||||
var goircConstants = map[string]string{
|
var goircConstants = map[string]string{
|
||||||
`"REGISTER"`: "REGISTER",
|
`"REGISTER"`: "REGISTER",
|
||||||
`"CONNECTED"`: "CONNECTED",
|
`"CONNECTED"`: "CONNECTED",
|
||||||
|
@ -89,7 +94,7 @@ func goircNewApi(f *ast.File) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func stateApi(f *ast.File) bool {
|
func stateApi(f *ast.File) bool {
|
||||||
spec := importSpec(f, "github.com/fluffle/goirc/state")
|
spec := importSpec(f, statePath)
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -106,7 +111,7 @@ func stateApi(f *ast.File) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func clientApi(f *ast.File) bool {
|
func clientApi(f *ast.File) bool {
|
||||||
spec := importSpec(f, "github.com/fluffle/goirc/client")
|
spec := importSpec(f, clientPath)
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -165,6 +170,15 @@ func clientApi(f *ast.File) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isClientConn(t ast.Expr, pkg string) bool {
|
func isClientConn(t ast.Expr, pkg string) bool {
|
||||||
|
// TODO(fluffle): when Conn is a struct member and we're looking for e.g.
|
||||||
|
// struct.Conn.AddHandler()
|
||||||
|
// we will pass in the *ast.SelectorExpr{X: struct, Sel: Conn} to this.
|
||||||
|
// Unfortunately the *ast.Ident{Conn} in this case often has no *ast.Object
|
||||||
|
// associated with it, so to divine it's type we need to recurse down until
|
||||||
|
// X is an *ast.Ident instead of another *ast.SelectorExpr, then look for
|
||||||
|
// the struct member types all the way back up until we get to "Conn".
|
||||||
|
// This is a massive pain-in-the-arse; I can see why type checking of this
|
||||||
|
// sort is often not done, s/AddHandler/HandleFunc/g is much simpler.
|
||||||
id, ok := t.(*ast.Ident)
|
id, ok := t.(*ast.Ident)
|
||||||
if !ok || id.Obj == nil { return false }
|
if !ok || id.Obj == nil { return false }
|
||||||
switch dec := id.Obj.Decl.(type) {
|
switch dec := id.Obj.Decl.(type) {
|
||||||
|
@ -185,7 +199,7 @@ func isClientConn(t ast.Expr, pkg string) bool {
|
||||||
return ok && isPkgDot(lit.Type, pkg, "Conn")
|
return ok && isPkgDot(lit.Type, pkg, "Conn")
|
||||||
case *ast.CompositeLit:
|
case *ast.CompositeLit:
|
||||||
// X := client.Conn{}
|
// X := client.Conn{}
|
||||||
return isPkgDot(lit.Type, pkg, "Conn")
|
return isPkgDot(rhs.Type, pkg, "Conn")
|
||||||
default:
|
default:
|
||||||
fmt.Printf("rhs: %#v\n", rhs)
|
fmt.Printf("rhs: %#v\n", rhs)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue