You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Type.String method and TypeString function are thin wrappers around a complex set of pretty-printing functions. Object.String and ObjectString are part of the same strongly connected component.
These functions are useful, but some clients need variants that differ in their treatment of named types. For example, when printing results about a particular place in a program, it's best to use the locally appropriate name for each imported package, as determined by the ast.File Scope.
If we changed TypeString and ObjectString so that they accept a func(*Named)string parameter that formats the named types, then all three of these variants could be easily expressed, and any future ones too.
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
go/types: need a generalization of the Type.String method and TypeString function
x/tools/go/types: need a generalization of the Type.String method and TypeString function
Jun 30, 2015
…function
The optional Qualifier function determines what prefix to attach to
package-level names, enabling clients to qualify packages in different
ways, for example, using only the package name instead of its complete
path, or using the locally appropriate name for package given a set of
(possibly renaming) imports.
Prior to this change, clients wanting this behavior had to copy
hundreds of lines of complex printing logic.
Fun fact: (*types.Package).Path and (*types.Package).Name are valid
Qualifier functions.
We provide the RelativeTo helper function to create Qualifiers so that
the old behavior remains a one-liner.
Fixes#11133
This CL is a copy of https://go-review.googlesource.com/#/c/11692/
to the golang.org/x/tools repository.
Change-Id: I26d0f3644d077a26bfe350989f9c545f018eefbf
Reviewed-on: https://go-review.googlesource.com/11790
Reviewed-by: Robert Griesemer <[email protected]>
Run-TryBot: Robert Griesemer <[email protected]>
The Type.String method and TypeString function are thin wrappers around a complex set of pretty-printing functions. Object.String and ObjectString are part of the same strongly connected component.
These functions are useful, but some clients need variants that differ in their treatment of named types. For example, when printing results about a particular place in a program, it's best to use the locally appropriate name for each imported package, as determined by the ast.File Scope.
If we changed TypeString and ObjectString so that they accept a func(*Named)string parameter that formats the named types, then all three of these variants could be easily expressed, and any future ones too.
The text was updated successfully, but these errors were encountered: