detect

package
v0.0.0-...-3621051 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package detect provides symbol detection and type resolution for Go packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectStructMethods

func CollectStructMethods(
	astFiles []*dst.File,
	fset *token.FileSet,
	structName string,
) map[string]*dst.FuncType

CollectStructMethods collects all methods for a given struct type from AST files.

func ExtractPackageName

func ExtractPackageName(qualifiedName string) string

ExtractPackageName extracts the package name from a fully qualified name.

func FindImportPath

func FindImportPath(
	astFiles []*dst.File, pkgName string, pkgLoader PackageLoader,
) (string, error)

FindImportPath finds the import path for a given package name by parsing the provided AST files.

func GetImportPathFromFiles

func GetImportPathFromFiles(files []*dst.File, fset *token.FileSet, _ string) (string, error)

GetImportPathFromFiles determines the import path of a package by examining its loaded files.

func InferImportPathFromTestFile

func InferImportPathFromTestFile(goFilePath, pkgName string) (string, error)

InferImportPathFromTestFile parses the given test file and attempts to find the import path for a package with the given name.

func IsStdlibPackage

func IsStdlibPackage(pkgName string) bool

IsStdlibPackage checks if a package name is a standard library package.

Types

type FuncTypeWithDetails

type FuncTypeWithDetails struct {
	FuncType   *dst.FuncType
	TypeParams *dst.FieldList
	TypeName   string // The name of the type (e.g., "WalkFunc")
}

type IfaceWithDetails

type IfaceWithDetails struct {
	Iface         *dst.InterfaceType
	TypeParams    *dst.FieldList
	SourceImports []*dst.ImportSpec // imports from the file containing the interface
	IsStructType  bool              // true if this was synthesized from a struct type
}

func GetMatchingInterfaceFromAST

func GetMatchingInterfaceFromAST(
	astFiles []*dst.File, interfaceName, pkgImportPath string,
) (IfaceWithDetails, error)

GetMatchingInterfaceFromAST extracts the target interface declaration from AST files.

type PackageLoader

type PackageLoader interface {
	Load(importPath string) ([]*dst.File, *token.FileSet, *types.Info, error)
}

type StructWithDetails

type StructWithDetails struct {
	TypeParams    *dst.FieldList
	TypeName      string            // The name of the struct type (e.g., "Calculator")
	SourceImports []*dst.ImportSpec // imports from the file containing the struct
}

type SymbolDetails

type SymbolDetails struct {
	Kind SymbolType

	Iface      IfaceWithDetails
	FuncDecl   *dst.FuncDecl
	FuncType   FuncTypeWithDetails
	StructType StructWithDetails
	// PkgPath tracks which package the symbol was found in.
	// For symbols found via dot imports, this differs from the search package.
	PkgPath string
}

func FindSymbol

func FindSymbol(
	astFiles []*dst.File,
	fset *token.FileSet,
	symbolName, pkgImportPath string,
	pkgLoader PackageLoader,
) (SymbolDetails, error)

FindSymbol looks for either an interface, struct type, function type, or function/method in the given AST files.

type SymbolType

type SymbolType int
const (
	SymbolInterface SymbolType = iota
	SymbolFunction
	SymbolFunctionType
	SymbolStructType
)

SymbolType values.

Jump to

Keyboard shortcuts

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