analysis

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package analysis provides function metadata and classification for unused function detection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncInfo

type FuncInfo struct {
	// Object is the types.Object representing this function.
	Object types.Object

	// Name is the display name for this function, including generic type instantiation.
	// For non-generic functions, this is the same as Object.Name()
	// For generic functions/methods, this includes type parameters (e.g., "Container[T].Clear")
	Name string

	// IsUsed indicates whether this function has been found to be used.
	IsUsed bool

	// IsExported indicates whether this function is exported (starts with uppercase)
	IsExported bool

	// IsInInternal indicates whether this function is defined in an internal package.
	IsInInternal bool

	// IsSuppressed indicates whether this function has suppression comments.
	IsSuppressed bool

	// HasLinkname indicates whether this function has a //go:linkname directive.
	HasLinkname bool

	// HasRuntimeDirective indicates whether this function has runtime directives.
	HasRuntimeDirective bool

	// HasAssemblyImplementation indicates whether this function is implemented in assembly.
	HasAssemblyImplementation bool

	// CalledFromAssembly indicates whether this function is called from assembly code.
	CalledFromAssembly bool

	// HasCGoExport indicates whether this function has a //export directive for CGo.
	HasCGoExport bool

	// DeclarationPos is the position where this function is declared.
	DeclarationPos token.Pos

	// Package is the package containing this function.
	Package *packages.Package

	// Strict indicates strict mode where ALL exported functions are checked for usage.
	Strict bool
}

FuncInfo represents information about a function in the codebase.

func NewFuncInfo

func NewFuncInfo(obj types.Object, pkg *packages.Package, nameCache *NameCache, strict bool) *FuncInfo

NewFuncInfo creates a new FuncInfo for the given function object and package.

func (*FuncInfo) IsInInternalPackage

func (fi *FuncInfo) IsInInternalPackage() bool

IsInInternalPackage checks if this function is defined in an internal package.

func (*FuncInfo) ShouldReport

func (fi *FuncInfo) ShouldReport() bool

ShouldReport determines if this function should be reported as unused. Returns true if: - Method is unexported and unused, OR - Method is exported, unused, AND in an internal package

type FuncSignature

type FuncSignature struct {
	Name       string
	Params     []string // Parameter type names
	Results    []string // Result type names
	IsVariadic bool
}

FuncSignature represents a function signature for interface matching.

type NameCache

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

NameCache provides efficient caching of fully-qualified symbol names for deduplication across generic instantiations and type analysis.

func NewNameCache

func NewNameCache() *NameCache

func (*NameCache) ComputeObjectName

func (c *NameCache) ComputeObjectName(obj types.Object) string

ComputeObjectName generates a canonical name for an Object. For functions, returns packagePath.objName() or packagePath.objName[T] for generics. For methods, includes receiver type information (e.g., "packagePath.Container[T].Clear" or "packagePath.Person.GetName").

func (*NameCache) ComputeTypeName

func (c *NameCache) ComputeTypeName(typ types.Type) string

ComputeTypeName generates a canonical name for a types.Type. For named types, returns packagePath.TypeName[TypeParams] (if generic) For pointer types, returns packagePath.*TypeName. For other types, returns the string representation with package path when available.

Jump to

Keyboard shortcuts

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