ast_extend

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 2 Imported by: 2

README

Ast Extend

easy use *ast.File.

Catalog

Const

FindConstByTypeName

Struct

FindStructByName

Function

FindFuncByName

Const

FindConstByTypeName
FindConstByTypeName find all const in *ast.File

Parameter
TypeName    : try to find the const by value type

Return
[]*ast.ValueSpec : return all found const value

Example

type Type byte

const (
	TypeCA Type = iota
	TypeCB
	NotTypeCA = 2
	NotTypeCB = iota
	TypeCC    = Type(iota)
	TypeCD
	NotTypeCC      = int(iota)
	NotTypeCD      = byte(7)
	TypeCE    Type = 8
	TypeCF    Type = 9
)

Struct

FindStructByName
FindStructByName find struct in *ast.File

Parameter
StructName: try to find the struct name

Return
*ast.TypeSpec  : struct declaration
*ast.StructType: struct content declaration
bool           : is found struct

Example

func F() {}
FindStructByName(f,"F")

Function

FindFuncByName
FindFuncByName(f *ast.File, ReceiverType, FuncName string) (*ast.FuncDecl, bool)

Parameter
ReceiverType : method pass the receiver type if there is a receiver or empty string
FuncName     : try to find the function name


Return
*ast.FuncDecl : return the found the function or nil
bool          : return true if found function or false

Example Function Without Receiver

func F() {}
func FindFuncByName(f,"","F")

Example Function With Receiver

type idea struct{}
func (idea) F(){}
func (*idea) F(){}
func (i idea) F(){}
func (i *idea) F(){}
func FindFuncByName(f,"idea","F")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindConstByTypeName

func FindConstByTypeName(f *ast.File, typeName string) []*ast.ValueSpec

FindConstByTypeName find all const in *ast.File

Parameter TypeName : find the const value

Return []*ast.ValueSpec : return all found const value

Example type Type byte

const (

TypeCA Type = iota
TypeCB
NotTypeCA = 2
NotTypeCB = iota
TypeCC    = Type(iota)
TypeCD
NotTypeCC      = int(iota)
NotTypeCD      = byte(7)
TypeCE    Type = 8
TypeCF    Type = 9

) */

func FindFuncByName

func FindFuncByName(f *ast.File, ReceiverType, FuncName string) (*ast.FuncDecl, bool)

FindFuncByName find function in *ast.File

Parameter ReceiverType: pass the receiver type if there is a receiver or empty string FuncName : try to find the function name

Return *ast.FuncDecl: return the found the function or nil bool : return true if found function or false

Example function without receiver: func F() {} FindFuncByName(f,"","F") function with receiver: type idea struct{} func (idea) F(){} FindFuncByName(f,"idea","F") */

func FindStructByName

func FindStructByName(f *ast.File, StructName string) (*ast.TypeSpec, *ast.StructType, bool)

FindStructByName find struct in *ast.File

Parameter StructName: try to find the struct name

Return *ast.TypeSpec : struct declaration *ast.StructType: struct content declaration bool : is found struct

Example func F() {} FindStructByName(f,"F")

Types

This section is empty.

Jump to

Keyboard shortcuts

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