]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/api.go
go/types, types2: implement Alias proposal (export API)
[gostls13.git] / src / go / types / api.go
index 81a98f7e663882e17938176b6797b0eb63d5d568..6635253fdfdd37f07a5f97293be36bad2b282bd8 100644 (file)
@@ -326,6 +326,23 @@ func (info *Info) ObjectOf(id *ast.Ident) Object {
        return info.Uses[id]
 }
 
+// PkgNameOf returns the local package name defined by the import,
+// or nil if not found.
+//
+// For dot-imports, the package name is ".".
+//
+// Precondition: the Defs and Implicts maps are populated.
+func (info *Info) PkgNameOf(imp *ast.ImportSpec) *PkgName {
+       var obj Object
+       if imp.Name != nil {
+               obj = info.Defs[imp.Name]
+       } else {
+               obj = info.Implicits[imp]
+       }
+       pkgname, _ := obj.(*PkgName)
+       return pkgname
+}
+
 // TypeAndValue reports the type and value (for constants)
 // of the corresponding expression.
 type TypeAndValue struct {