astpkg

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrImportNotFound = errors.New("import not found")

Functions

func CastToType

func CastToType[T Type](val any) (*T, bool)

func GetFuncDeclAllImportPath

func GetFuncDeclAllImportPath(funcDecl *FuncDecl) ([]string, error)

func GetPackagePath

func GetPackagePath(pkgDir string) (string, error)

func GetTypeDeclAllImportPath

func GetTypeDeclAllImportPath(typeDecl *TypeDecl) ([]string, error)

func InitSelfPackageImports

func InitSelfPackageImports(targetPackage string, packageList ...*Package) error

func InspectFields

func InspectFields(fieldList []*Field, fn func(*Field) error) error

func InspectFuncDeclFields

func InspectFuncDeclFields(funcDecl *FuncDecl, fn func(*Field) error) error

func InspectType

func InspectType(t Type, fn func(Type) error) error

func InspectTypeDeclTypes

func InspectTypeDeclTypes(typeDecl *TypeDecl, fn func(Type) error) error

func IsExported

func IsExported(name string) bool

func ReplaceImportAliasByImportPath

func ReplaceImportAliasByImportPath(t Type, importList ImportList) error

func SetPackageInformation

func SetPackageInformation(t Type, imports ImportList) error

func SetPackagePathForAllDecl

func SetPackagePathForAllDecl(pkg *Package) error

Types

type ArrayType

type ArrayType struct {
	Type Type
}

func (ArrayType) ExprString

func (t ArrayType) ExprString() string

func (ArrayType) Imports added in v1.0.2

func (t ArrayType) Imports() ImportList

func (ArrayType) String

func (t ArrayType) String() string

type ChanType

type ChanType struct {
	Type      Type
	Direction ast.ChanDir
}

func (ChanType) ExprString

func (t ChanType) ExprString() string

func (ChanType) Imports added in v1.0.2

func (t ChanType) Imports() ImportList

func (ChanType) String

func (t ChanType) String() string

type EllipsisType

type EllipsisType struct {
	Type Type
}

func (EllipsisType) ExprString

func (t EllipsisType) ExprString() string

func (EllipsisType) Imports added in v1.0.2

func (t EllipsisType) Imports() ImportList

func (EllipsisType) String

func (t EllipsisType) String() string

type Field

type Field struct {
	Name string
	Type Type
}

func NewField

func NewField(field *ast.Field) []*Field

func NewFieldList

func NewFieldList(fieldList *ast.FieldList) []*Field

func (Field) String

func (f Field) String() string

type FuncDecl

type FuncDecl struct {
	Receiver string
	Name     string
	Comment  string
	Params   []*Field
	Results  []*Field
}

func NewFuncDecl

func NewFuncDecl(spec *ast.FuncDecl) *FuncDecl

func (FuncDecl) GetSignatureImports added in v1.0.2

func (t FuncDecl) GetSignatureImports() ImportList

func (FuncDecl) String

func (t FuncDecl) String() string

type FuncDeclList

type FuncDeclList []*FuncDecl

func (FuncDeclList) GetByReceiverName

func (l FuncDeclList) GetByReceiverName(name string) FuncDeclList

type FuncType

type FuncType struct {
	Params  []*Field
	Results []*Field
}

func (FuncType) ExprString

func (t FuncType) ExprString() string

func (FuncType) Imports added in v1.0.2

func (t FuncType) Imports() ImportList

func (FuncType) String

func (t FuncType) String() string

type Ident

type Ident struct {
	Package     string
	PackagePath string
	Name        string
	Type        Type
}

func (Ident) ExprString

func (t Ident) ExprString() string

func (Ident) GetPackage

func (t Ident) GetPackage() string

func (Ident) GetPackagePath

func (t Ident) GetPackagePath() string

func (Ident) Imports added in v1.0.2

func (t Ident) Imports() ImportList

func (*Ident) SetPackage

func (t *Ident) SetPackage(i Import)

func (Ident) String

func (t Ident) String() string

type Import

type Import struct {
	Alias string
	Path  string
}

func NewImport

func NewImport(alias, path string) Import

func NewImportWithAlias

func NewImportWithAlias(path string) Import

func (Import) AliasFromPath added in v1.0.2

func (i Import) AliasFromPath() string

func (Import) String

func (i Import) String() string

type ImportList

type ImportList []Import

func GetAllPackagesImports

func GetAllPackagesImports(baseImportPath []string, packageList ...*Package) (ImportList, error)

func NewImportList

func NewImportList(imports []*ast.ImportSpec) ImportList

func NewImportListWithUniqAlias

func NewImportListWithUniqAlias(importPathList []string) (ImportList, error)

func (ImportList) Get

func (l ImportList) Get(key string) (Import, error)

func (ImportList) GetByPath

func (l ImportList) GetByPath(path string) (Import, bool)

type IndexExpr added in v1.0.1

type IndexExpr struct {
	Index Type
	X     Type
}

func (IndexExpr) ExprString added in v1.0.1

func (t IndexExpr) ExprString() string

func (IndexExpr) Imports added in v1.0.2

func (t IndexExpr) Imports() ImportList

func (IndexExpr) String added in v1.0.1

func (t IndexExpr) String() string

type InterfaceType

type InterfaceType struct {
	Methods []*Field
}

func (InterfaceType) ExprString

func (t InterfaceType) ExprString() string

func (InterfaceType) Imports added in v1.0.2

func (t InterfaceType) Imports() ImportList

func (InterfaceType) String

func (t InterfaceType) String() string

type MapType

type MapType struct {
	Key   Type
	Value Type
}

func (MapType) ExprString

func (t MapType) ExprString() string

func (MapType) Imports added in v1.0.2

func (t MapType) Imports() ImportList

func (MapType) String

func (t MapType) String() string

type Package

type Package struct {
	Path         string
	Dir          string
	TypeDeclList TypeDeclList
	FuncDeclList FuncDeclList
}

func ParsePackage

func ParsePackage(pkgName string) (*Package, error)

type PackageCarrierType

type PackageCarrierType interface {
	PackageGetterType
	PackageSetterType
}

type PackageGetterType

type PackageGetterType interface {
	GetPackage() string
	GetPackagePath() string
}

type PackageSetterType

type PackageSetterType interface {
	SetPackage(Import)
}

type SelectorExpr

type SelectorExpr struct {
	Package     string
	PackagePath string
	Name        string
	Type        Type
}

func (SelectorExpr) ExprString

func (t SelectorExpr) ExprString() string

func (SelectorExpr) GetPackage

func (t SelectorExpr) GetPackage() string

func (SelectorExpr) GetPackagePath

func (t SelectorExpr) GetPackagePath() string

func (SelectorExpr) Imports added in v1.0.2

func (t SelectorExpr) Imports() ImportList

func (*SelectorExpr) SetPackage

func (t *SelectorExpr) SetPackage(i Import)

func (SelectorExpr) String

func (t SelectorExpr) String() string

type StarExpr

type StarExpr struct {
	Type Type
}

func (StarExpr) ExprString

func (t StarExpr) ExprString() string

func (StarExpr) Imports added in v1.0.2

func (t StarExpr) Imports() ImportList

func (StarExpr) String

func (t StarExpr) String() string

type StructType

type StructType struct {
	Fields []*Field
}

func (StructType) ExprString

func (t StructType) ExprString() string

func (StructType) Imports added in v1.0.2

func (t StructType) Imports() ImportList

func (StructType) String

func (t StructType) String() string

type Type

type Type interface {
	String() string
	ExprString() string
	Imports() ImportList
}

func NewType

func NewType(expr ast.Expr) Type

type TypeDecl

type TypeDecl struct {
	Package     string
	PackagePath string
	Name        string
	Comment     string
	Type        Type
}

func NewTypeDecl

func NewTypeDecl(imp Import, generalDecl *ast.GenDecl, spec ast.Spec) (*TypeDecl, bool)

func (TypeDecl) GetFieldsImports added in v1.0.2

func (t TypeDecl) GetFieldsImports() ImportList

func (TypeDecl) String

func (t TypeDecl) String() string

type TypeDeclList

type TypeDeclList []*TypeDecl

func NewTypeDeclList

func NewTypeDeclList(pkg string, generalDecl *ast.GenDecl) TypeDeclList

func (TypeDeclList) GetByName

func (l TypeDeclList) GetByName(name string) (*TypeDecl, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL