Documentation
¶
Index ¶
- Variables
- func AutoNaming(ft *ast.FuncType) *ast.FuncType
- func ExportFields(pkg *ast.Package, fields *ast.FieldList) *ast.FieldList
- func ExportFunc(pkg *ast.Package, fn *ast.FuncDecl) *ast.FuncDecl
- func ExportType(pkg *ast.Package, expr ast.Expr) ast.Expr
- func FindInterface(pkg *ast.Package, name string) *ast.InterfaceType
- func FindStruct(pkg *ast.Package, name string) *ast.StructType
- func FindTypeByName(pkg *ast.Package, name string) ast.Expr
- func GetMethods(pkg *ast.Package, name string) []*ast.FuncDecl
- func GetMethodsDeep(pkg *ast.Package, name string) ([]*ast.FuncDecl, error)
- func GetRequires(it *ast.InterfaceType) []*ast.Field
- func ImportPackage(importPath string) (*ast.Package, error)
- func ResolvePackage(f *ast.File, name string) (*ast.Package, error)
- func ResolveType(f *ast.File, expr ast.Expr) (*ast.Package, string, error)
- func ScanDecl(pkg *ast.Package, f func(ast.Decl) bool)
- func TypeName(expr ast.Expr) string
- type Importer
- func (i *Importer) GetMethodsDeep(pkg *ast.Package, name string) ([]*ast.FuncDecl, error)
- func (i *Importer) ImportPackage(importPath string) (*ast.Package, error)
- func (i *Importer) Load(pkgs map[string]*ast.Package)
- func (i *Importer) Loaded() []string
- func (i *Importer) ResolvePackage(f *ast.File, name string) (*ast.Package, error)
- func (i *Importer) ResolveType(f *ast.File, expr ast.Expr) (*ast.Package, string, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PackageNotFound = errors.New("package not found") TypeNotFound = errors.New("type not found") )
Functions ¶
func FindInterface ¶
func FindInterface(pkg *ast.Package, name string) *ast.InterfaceType
func FindStruct ¶
func FindStruct(pkg *ast.Package, name string) *ast.StructType
func GetRequires ¶
func GetRequires(it *ast.InterfaceType) []*ast.Field
func ImportPackage ¶
Example ¶
package main
import (
"fmt"
"log"
"github.com/urbantriump/impast"
)
func main() {
pkg, err := impast.ImportPackage("io")
if err != nil {
log.Fatal(err)
}
it := impast.FindInterface(pkg, "Writer")
if it == nil {
log.Fatalf("io.Writer not found")
}
methods := impast.GetRequires(it)
for _, method := range methods {
fmt.Println(method.Names[0].Name)
}
}
Output: Write
Types ¶
type Importer ¶
type Importer struct {
EnableCache bool
// contains filtered or unexported fields
}
var DefaultImporter Importer
func (*Importer) GetMethodsDeep ¶
func (*Importer) ImportPackage ¶
func (*Importer) ResolvePackage ¶
Click to show internal directories.
Click to hide internal directories.