tree

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tree provides utilities for parsing and formatting Go packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

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

Function represents a function in a parsed Go package

func (*Function) Code

func (f *Function) Code() string

Code returns the full function code

func (*Function) IsMethod

func (f *Function) IsMethod() bool

IsMethod returns true if the function is a method (has a receiver)

func (*Function) Name

func (f *Function) Name() string

Name returns the function name

func (*Function) ReceiverType

func (f *Function) ReceiverType() string

ReceiverType returns the receiver type for methods, or empty string for functions

func (*Function) Signature

func (f *Function) Signature() string

Signature returns the function signature

type Options

type Options struct {
	// IncludeTestFiles determines whether to include test files in parsing
	IncludeTestFiles bool

	// PreserveFormattingStyle determines whether to preserve the original formatting style
	// If false, Go's standard formatting will be applied
	PreserveFormattingStyle bool

	// SkipComments determines whether to skip comments during parsing
	SkipComments bool

	// CustomPackageName sets a custom package name for formatting
	// If empty, the original package name will be used
	CustomPackageName string
}

Options configures the behavior of the parser and formatter

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default options

type Package

type Package struct {
	Model *model.GoPackage
}

Package represents a parsed Go package

func Parse

func Parse(dir string) (*Package, error)

Parse parses a Go package from the given directory and returns a Package.

func ParseWithOptions

func ParseWithOptions(dir string, opts *Options) (*Package, error)

ParseWithOptions parses a Go package from the given directory with the specified options

func (*Package) ConstantNames

func (p *Package) ConstantNames() []string

ConstantNames returns the names of all constants in the package

func (*Package) Format

func (p *Package) Format() (string, error)

Format formats a Package into a single Go source file.

func (*Package) FormatWithOptions

func (p *Package) FormatWithOptions(opts *Options) (string, error)

FormatWithOptions formats a Package into a single Go source file with the specified options

func (*Package) FunctionNames

func (p *Package) FunctionNames() []string

FunctionNames returns the names of all functions in the package

func (*Package) GetFunction

func (p *Package) GetFunction(name string) *Function

GetFunction returns a function by name, or nil if not found

func (*Package) GetType

func (p *Package) GetType(name string) *Type

GetType returns a type by name, or nil if not found

func (*Package) Imports

func (p *Package) Imports() []string

Imports returns the package imports

func (*Package) Name

func (p *Package) Name() string

Name returns the package name

func (*Package) TypeNames

func (p *Package) TypeNames() []string

TypeNames returns the names of all types in the package

func (*Package) VariableNames

func (p *Package) VariableNames() []string

VariableNames returns the names of all variables in the package

type Type

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

Type represents a type in a parsed Go package

func (*Type) Code

func (t *Type) Code() string

Code returns the full type definition code

func (*Type) IsInterface

func (t *Type) IsInterface() bool

IsInterface returns true if the type is an interface

func (*Type) IsStruct

func (t *Type) IsStruct() bool

IsStruct returns true if the type is a struct

func (*Type) Kind

func (t *Type) Kind() string

Kind returns the kind of type (struct, interface, alias, etc.)

func (*Type) Name

func (t *Type) Name() string

Name returns the type name

Jump to

Keyboard shortcuts

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