)
// A Qualifier controls how named package-level objects are printed in
-// calls to TypeString, ObjectString, and SelectionString.
+// calls to [TypeString], [ObjectString], and [SelectionString].
//
// These three formatting routines call the Qualifier for each
// package-level object O, and if the Qualifier returns a non-empty
// string p, the object is printed in the form p.O.
// If it returns an empty string, only the object name O is printed.
//
-// Using a nil Qualifier is equivalent to using (*Package).Path: the
+// Using a nil Qualifier is equivalent to using (*[Package]).Path: the
// object is qualified by the import path, e.g., "encoding/json.Marshal".
type Qualifier func(*Package) string
-// RelativeTo returns a Qualifier that fully qualifies members of
+// RelativeTo returns a [Qualifier] that fully qualifies members of
// all packages other than pkg.
func RelativeTo(pkg *Package) Qualifier {
if pkg == nil {
}
// TypeString returns the string representation of typ.
-// The Qualifier controls the printing of
+// The [Qualifier] controls the printing of
// package-level objects, and may be nil.
func TypeString(typ Type, qf Qualifier) string {
var buf bytes.Buffer
}
// WriteType writes the string representation of typ to buf.
-// The Qualifier controls the printing of
+// The [Qualifier] controls the printing of
// package-level objects, and may be nil.
func WriteType(buf *bytes.Buffer, typ Type, qf Qualifier) {
newTypeWriter(buf, qf).typ(typ)
}
// WriteSignature writes the representation of the signature sig to buf,
-// without a leading "func" keyword. The Qualifier controls the printing
+// without a leading "func" keyword. The [Qualifier] controls the printing
// of package-level objects, and may be nil.
func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier) {
newTypeWriter(buf, qf).signature(sig)
// error messages. This doesn't need to be super-elegant; we just
// need a clear indication that this is not a predeclared name.
if w.ctxt == nil && Universe.Lookup(t.obj.name) != nil {
- w.string(fmt.Sprintf(" /* with %s declared at %s */", t.obj.name, t.obj.Pos()))
+ if isTypes2 {
+ w.string(fmt.Sprintf(" /* with %s declared at %v */", t.obj.name, t.obj.Pos()))
+ } else {
+ // Can't print position information because
+ // we don't have a token.FileSet accessible.
+ w.string("/* type parameter */")
+ }
}
}
+// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
+
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import (
"bytes"
"fmt"
- "go/token"
"sort"
"strconv"
"strings"
case *Basic:
// exported basic types go into package unsafe
// (currently this is just unsafe.Pointer)
- if token.IsExported(t.name) {
+ if isExported(t.name) {
if obj, _ := Unsafe.scope.Lookup(t.name).(*TypeName); obj != nil {
w.typeName(obj)
break
// If disambiguating one struct for another, look for the first unexported field.
// Do this first in case of nested structs; tag the first-outermost field.
pkgAnnotate := false
- if w.qf == nil && w.pkgInfo && !token.IsExported(f.name) {
+ if w.qf == nil && w.pkgInfo && !isExported(f.name) {
// note for embedded types, type name is field name, and "string" etc are lower case hence unexported.
pkgAnnotate = true
w.pkgInfo = false // only tag once
}
if tag := t.Tag(i); tag != "" {
w.byte(' ')
- // TODO(rfindley) If tag contains blanks, replacing them with '#'
- // in Context.TypeHash may produce another tag
- // accidentally.
+ // TODO(gri) If tag contains blanks, replacing them with '#'
+ // in Context.TypeHash may produce another tag
+ // accidentally.
w.string(strconv.Quote(tag))
}
}
// (say int), point out where it is declared to avoid confusing
// error messages. This doesn't need to be super-elegant; we just
// need a clear indication that this is not a predeclared name.
- // Note: types2 prints position information here - we can't do
- // that because we don't have a token.FileSet accessible.
if w.ctxt == nil && Universe.Lookup(t.obj.name) != nil {
- w.string("/* type parameter */")
+ if isTypes2 {
+ w.string(fmt.Sprintf(" /* with %s declared at %v */", t.obj.name, t.obj.Pos()))
+ } else {
+ // Can't print position information because
+ // we don't have a token.FileSet accessible.
+ w.string("/* type parameter */")
+ }
}
}