extractor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package extractor is a package, that extracts type specs and methods from given ast tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractMethodsFromPackage

func ExtractMethodsFromPackage(pkg Package) []*ast.FuncDecl

ExtractMethodsFromPackage is a function to extract methods from package.

func ExtractRecvTypeName

func ExtractRecvTypeName(method *ast.FuncDecl) string

ExtractRecvTypeName is a helper function to extract receiver type name (string) from method.

func ExtractTypeSpecsFromPackage

func ExtractTypeSpecsFromPackage(pkg Package) []*ast.TypeSpec

ExtractTypeSpecsFromPackage extracts type specs from a ast tree.

Types

type Analyzer

type Analyzer struct {
	// contains filtered or unexported fields
}

Analyzer is an analyzer, that extracts type specs and methods from package and groups them for quick access.

func NewAnalyzerFromPackage

func NewAnalyzerFromPackage(pkg Package) (*Analyzer, error)

NewAnalyzerFromPackage parses ast tree for TypeSpecs and associated methods.

func (Analyzer) PackageName

func (a Analyzer) PackageName() string

PackageName returns package name of analyzed package.

func (Analyzer) PackagePath

func (a Analyzer) PackagePath() string

PackagePath returns package path of analyzed package.

func (Analyzer) TypeSpecEntryByName

func (a Analyzer) TypeSpecEntryByName(name string) (*TypeSpecEntry, bool)

TypeSpecEntryByName returns TypeSpecEntry entry by name.

type Package

type Package interface {
	Name() string
	PkgPath() string
	Syntax() []*ast.File
}

Package is an interface that provides access to package data. It's used to abstract away the `packages.Package` type.

func NewPackage

func NewPackage(pkg *packages.Package) Package

NewPackage creates a new Package from a packages.Package.

type TypeSpecEntry

type TypeSpecEntry struct {
	Name    string
	Methods []string
	// contains filtered or unexported fields
}

TypeSpecEntry is an entry, that defines ast's TypeSpec and contains type name and methods.

func (TypeSpecEntry) HasMethod

func (e TypeSpecEntry) HasMethod(name string) bool

HasMethod returns true if type spec has method with given name.

Jump to

Keyboard shortcuts

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