signature

package
v2.1.7 Latest Latest
Warning

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

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

Documentation

Overview

Package signature provides utilities for extracting and formatting Go function signatures and types.

This package handles:

  • Extracting function signatures from types.Signature
  • Type qualification using import aliases
  • Converting types to strings with proper package selectors

The Extractor type maintains the context needed for proper type qualification, including the current package and import aliases from the source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

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

Extractor extracts function signatures and formats types with proper package qualification.

func New

func New(currentPackage *types.Package, importAliases map[string]string) *Extractor

New creates a signature extractor.

The currentPackage is used to determine when type qualification is needed. The importAliases map provides the mapping from import paths to the aliases used in the source code (e.g., "net/http/httputil" -> "httputil").

func (*Extractor) ElidedQualifier

func (e *Extractor) ElidedQualifier(t types.Type) string

ElidedQualifier returns the selector used for a type, as its import package alias used in source, or the empty string if this is a local declaration.

func (*Extractor) ElidedType

func (e *Extractor) ElidedType(t types.Type) string

ElidedType returns a string representation of the type with package names as they appear in source.

Uses import aliases when available (e.g., "httputil.Handler" if imported as "httputil").

func (*Extractor) ExtractFunctionSignature

func (e *Extractor) ExtractFunctionSignature(signature *types.Signature, name string) model.Function

ExtractFunctionSignature extracts function signature details from a types.Signature.

This is used for both regular functions and function types (var/type declarations).

func (*Extractor) Qualifier

func (e *Extractor) Qualifier(pkg *types.Package) string

Qualifier returns the appropriate package name for type qualification.

It uses import aliases from the source (AST) rather than the package's actual name.

Jump to

Keyboard shortcuts

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