github.com/AndrienkoAleksandr/go@v0.0.19/src/go/types/package.go (about)

     1  // Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
     2  
     3  // Copyright 2013 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package types
     8  
     9  import (
    10  	"fmt"
    11  )
    12  
    13  // A Package describes a Go package.
    14  type Package struct {
    15  	path     string
    16  	name     string
    17  	scope    *Scope
    18  	imports  []*Package
    19  	complete bool
    20  	fake     bool // scope lookup errors are silently dropped if package is fake (internal use only)
    21  	cgo      bool // uses of this package will be rewritten into uses of declarations from _cgo_gotypes.go
    22  }
    23  
    24  // NewPackage returns a new Package for the given package path and name.
    25  // The package is not complete and contains no explicit imports.
    26  func NewPackage(path, name string) *Package {
    27  	scope := NewScope(Universe, nopos, nopos, fmt.Sprintf("package %q", path))
    28  	return &Package{path: path, name: name, scope: scope}
    29  }
    30  
    31  // Path returns the package path.
    32  func (pkg *Package) Path() string { return pkg.path }
    33  
    34  // Name returns the package name.
    35  func (pkg *Package) Name() string { return pkg.name }
    36  
    37  // SetName sets the package name.
    38  func (pkg *Package) SetName(name string) { pkg.name = name }
    39  
    40  // Scope returns the (complete or incomplete) package scope
    41  // holding the objects declared at package level (TypeNames,
    42  // Consts, Vars, and Funcs).
    43  // For a nil pkg receiver, Scope returns the Universe scope.
    44  func (pkg *Package) Scope() *Scope {
    45  	if pkg != nil {
    46  		return pkg.scope
    47  	}
    48  	return Universe
    49  }
    50  
    51  // A package is complete if its scope contains (at least) all
    52  // exported objects; otherwise it is incomplete.
    53  func (pkg *Package) Complete() bool { return pkg.complete }
    54  
    55  // MarkComplete marks a package as complete.
    56  func (pkg *Package) MarkComplete() { pkg.complete = true }
    57  
    58  // Imports returns the list of packages directly imported by
    59  // pkg; the list is in source order.
    60  //
    61  // If pkg was loaded from export data, Imports includes packages that
    62  // provide package-level objects referenced by pkg. This may be more or
    63  // less than the set of packages directly imported by pkg's source code.
    64  //
    65  // If pkg uses cgo and the FakeImportC configuration option
    66  // was enabled, the imports list may contain a fake "C" package.
    67  func (pkg *Package) Imports() []*Package { return pkg.imports }
    68  
    69  // SetImports sets the list of explicitly imported packages to list.
    70  // It is the caller's responsibility to make sure list elements are unique.
    71  func (pkg *Package) SetImports(list []*Package) { pkg.imports = list }
    72  
    73  func (pkg *Package) String() string {
    74  	return fmt.Sprintf("package %s (%q)", pkg.name, pkg.path)
    75  }