meta

package
v0.0.0-...-0b6a355 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package meta provides functionalities for parsing Go files ASTs.

Index

Constants

This section is empty.

Variables

View Source
var ErrMethodNotFound = errors.New("method not found in ASTs")
View Source
var PackagesASTsMap map[string]PackageASTs = map[string]PackageASTs{}

Packages ASTs map built on embedded Go source files. It's built on init.

Functions

func MethodBodySource

func MethodBodySource(
	astMap map[string]PackageASTs, typeName, methodName string,
) (*ast.BlockStmt, string, error)

MethodBodySource finds given method for given type in the AST and return it's body AST and source code as string. If given type or method does not exist in given ASTs map, then non nil error would be returned.

func ParseASTs

func ParseASTs(fs embed.FS) error

ParseASTs parses ASTs for packages and its Go files based on given FS. Parsed object is assigned to PackagesASTsMap. It's enough to call this function just once at the program start.

func ParsePackagesASTs

func ParsePackagesASTs(fs embed.FS) (map[string]PackageASTs, error)

ParsePackagesASTs parses all packages under ./src/ in this project in form of map from package ID to PackageASTs (metadata plus mapping file -> AST).

func TypeName

func TypeName(t any) string

TypeName returns string with type name of given object. For pointers (*T) underlying type name is returned.

Types

type PackageASTs

type PackageASTs struct {
	Name       string
	Fset       *token.FileSet
	FileToASTs map[string]*ast.File
}

PackageASTs represents single Go package metadata with FileToAST field which is a mapping from package file name to its parsed AST.

type PointTest

type PointTest struct {
	X int
	Y int
}

func (*PointTest) EmptyMethod

func (pt *PointTest) EmptyMethod()

func (PointTest) String

func (pt PointTest) String() string

Jump to

Keyboard shortcuts

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