Source File
idents.go
Belonging Package
golang.org/x/pkgsite/internal/godoc/dochtml/internal/render
package render
import (
)
func ( *doc.Package, func( ast.Decl)) {
for , := range .Consts {
(.Decl)
}
for , := range .Vars {
(.Decl)
}
for , := range .Funcs {
(.Decl)
}
for , := range .Types {
(.Decl)
for , := range .Consts {
(.Decl)
}
for , := range .Vars {
(.Decl)
}
for , := range .Funcs {
(.Decl)
}
for , := range .Methods {
(.Decl)
}
}
}
topLevelDecls map[interface{}]bool // map[T]bool where T is *ast.FuncDecl | *ast.GenDecl | *ast.TypeSpec | *ast.ValueSpec
}
for , := range append([]*doc.Package{}, ...) {
if , := .pkgIDs[.Name]; {
continue // package name conflicts, ignore this package
}
.impPaths[.Name] = .ImportPath
.pkgIDs[.Name] = make(map[string]bool)
forEachPackageDecl(, func( ast.Decl) {
for , := range generateAnchorPoints() {
.pkgIDs[.Name][.ID.String()] = true // E.g., ["io"]["Reader.Read"]
}
})
}
forEachPackageDecl(, func( ast.Decl) {
.topLevelDecls[] = true
if , := .(*ast.GenDecl); != nil {
for , := range .Specs {
.topLevelDecls[] = true
}
}
})
return
}
for , := range []*ast.FieldList{.Type.Params, .Type.Results} {
if == nil {
continue
}
for , := range .List {
, := nodeName(.Type) // E.g., "context.Context"
if == "" {
continue
}
for , := range .Names {
, := nodeName() // E.g., "ctx"
if != "" {
.paramTypes[] =
}
}
}
}
}
return
}
type identifierResolver struct {
*packageIDs
*declIDs
packageURL func(string) string
}
func ( identifierResolver) (, string) ( string) {
if != "" {
= "/" +
if .packageURL != nil {
= .packageURL()
}
}
if != "" {
+= "#" +
}
return
}
if !isExported() && len() == 1 {
return safehtml.HTMLEscaped()
}
var []string
if , := .paramTypes[[0]]; {
= append(, +[len([0]):]) // E.g., "r.Read" => "io.Reader.Read"
} else if .recvType != "" {
= append(, .recvType+"."+) // E.g., "Read" => "Reader.Read"
}
= append(, )
var string
for , := range {
if , , := .lookup(); {
= // direct match
goto
}
if , , := .lookup(strings.TrimSuffix(, "s")); {
= [:len()-len("s")] // E.g., "Caches" => "Cache"
goto
}
if , , := .lookup(strings.TrimSuffix(, "es")); {
= [:len()-len("es")] // E.g., "Boxes" => "Box"
goto
}
, := len(), len()
for >= 0 && >= 0 {
:= isExported([:]) || strings.Contains([:], ".")
if , , := .lookup([:]); && {
= [:]
= strings.Split([:], ".")
= safehtml.HTMLEscaped([:])
goto
}
= strings.LastIndexByte([:], '.')
= strings.LastIndexByte([:], '.')
}
}
return safehtml.HTMLEscaped() // no match found
if := strings.IndexByte([+1:], '.'); >= 0 {
+= 1 +
} else {
= len()
}
, , := .lookup([:])
:= .toURL(, )
, := LinkTemplate.ExecuteToHTML(Link{Href: , Text: })
if != nil {
= safehtml.HTMLEscaped("[" + .Error() + "]")
}
= append(, )
= append(, safehtml.HTMLEscaped("."))
}
if len() == 0 {
return
[len()-1] =
return safehtml.HTMLConcat(...)
}
func ( identifierResolver) ( string) (, string, bool) {
if .pkgIDs[.name][] {
return "", , true // ID refers to local top-level declaration
}
if := .impPaths[]; != "" {
return , "", true // ID refers to a package
}
if := strings.IndexByte(, '.'); >= 0 {
, := [:], [+1:]
if .pkgIDs[][] {
if == .name {
= ""
}
return .impPaths[], , true // ID refers to a different package's top-level declaration
}
}
return "", "", false // not found
}
func ( ast.Node) (string, *ast.Ident) {
switch n := .(type) {
case *ast.Ident:
return .String(),
case *ast.StarExpr:
return (.X)
case *ast.SelectorExpr:
if , := (.X); != "" {
return + "." + .Sel.String(), .Sel
}
return .Sel.String(), .Sel
default:
return "", nil
}
}
func ( string) bool {
, := utf8.DecodeRuneInString()
return unicode.IsUpper()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |