]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/api.go
go/types, types2: implement Info.PkgNameOf
[gostls13.git] / src / go / types / api.go
index 38cde80085897f61bb6413ba70a090a083242566..0dc06af53843361a813a1fbe92614f4b4461e904 100644 (file)
@@ -331,6 +331,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 {