Debian Codegraph @

internal/typesinternal/isnamed.go

raw symbols SCIP
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package typesinternalscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/
6
7 import (
8 "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/"
9 "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/"
10 )
11
12 // IsTypeNamed reports whether t is (or is an alias for) a
13 // package-level defined type with the given package path and one of
14 // the given names. It returns false if t is nil.
15 //
16 // This function avoids allocating the concatenation of "pkg.Name",
17 // which is important for the performance of syntax matching.
18 func IsTypeNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsTypeNamed().(t typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Typescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Type#, pkgPath string, names ...string) bool {
19 if named, ok := typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Unaliasscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Unalias().(t).(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Namedscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Named#); ok {
20 tname := named.Objscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Named#Obj().()
21 return tname != nil &&
22 IsPackageLevelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsPackageLevel().(tname) &&
23 tname.Pkgscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/object#Pkg().().Pathscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Package#Path().() == pkgPath &&
24 slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(names, tname.Namescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/object#Name().())
25 }
26 return false
27 }
28
29 // IsPointerToNamed reports whether t is (or is an alias for) a pointer to a
30 // package-level defined type with the given package path and one of the given
31 // names. It returns false if t is not a pointer type.
32 func IsPointerToNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsPointerToNamed().(t typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Typescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Type#, pkgPath string, names ...string) bool {
33 r := Unpointerscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/Unpointer().(t)
34 if r == t {
35 return false
36 }
37 return IsTypeNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsTypeNamed().(r, pkgPath, names...)
38 }
39
40 // IsFunctionNamed reports whether obj is a package-level function
41 // defined in the given package and has one of the given names.
42 // It returns false if obj is nil.
43 //
44 // This function avoids allocating the concatenation of "pkg.Name",
45 // which is important for the performance of syntax matching.
46 func IsFunctionNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsFunctionNamed().(obj typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Objectscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Object#, pkgPath string, names ...string) bool {
47 f, ok := obj.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Funcscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#)
48 return ok &&
49 IsPackageLevelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsPackageLevel().(obj) &&
50 f.Pkgscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#Pkg().().Pathscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Package#Path().() == pkgPath &&
51 f.Signaturescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#Signature().().Recvscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Signature#Recv().() == nil &&
52 slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(names, f.Namescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/object#Name().())
53 }
54
55 // IsMethodNamed reports whether obj is a method defined on a
56 // package-level type with the given package and type name, and has
57 // one of the given names. It returns false if obj is nil.
58 //
59 // This function avoids allocating the concatenation of "pkg.TypeName.Name",
60 // which is important for the performance of syntax matching.
61 func IsMethodNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsMethodNamed().(obj typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Objectscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Object#, pkgPath string, typeName string, names ...string) bool {
62 if fn, ok := obj.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Funcscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#); ok {
63 if recv := fn.Signaturescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#Signature().().Recvscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Signature#Recv().(); recv != nil {
64 _, T := ReceiverNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/ReceiverNamed().(recv)
65 return T != nil &&
66 IsTypeNamedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/typesinternal`/IsTypeNamed().(T, pkgPath, typeName) &&
67 slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.0 slices/Contains().(names, fn.Namescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/object#Name().())
68 }
69 }
70 return false
71 }