humanize

package module
v0.0.0-...-22d9b98 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2017 License: MIT Imports: 12 Imported by: 10

README

Go humanize ast representation

Build Status Coverage Status GoDoc

This is a simple "go source file into friendly structure" for prevent repeat my code over and over for create a simple code generator.

This code is not maintained anymore. I'm working on a new version of this, with better (almost better :)) structure. you can find the new code at https://github.com/fzerorubigd/humanize

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayType

type ArrayType struct {
	Slice bool
	Len   int
	Type  Type
	// contains filtered or unexported fields
}

ArrayType is the base array

func (*ArrayType) GetDefinition

func (i *ArrayType) GetDefinition() string

GetName the name of this type

func (ArrayType) Package

func (s ArrayType) Package() *Package

type ChannelType

type ChannelType struct {
	Direction ast.ChanDir
	Type      Type
	// contains filtered or unexported fields
}

ChannelType is used to handle channel type definition

func (*ChannelType) GetDefinition

func (i *ChannelType) GetDefinition() string

GetName the name of this type

func (ChannelType) Package

func (s ChannelType) Package() *Package

type Constant

type Constant struct {
	Name  string
	Type  Type
	Docs  Docs
	Value string
	// contains filtered or unexported fields
}

Constant is a string represent of a function parameter

func NewConstant

func NewConstant(v *ast.ValueSpec, c *ast.CommentGroup, src string, f *File, p *Package) []*Constant

NewConstant return an array of constant in the scope

type Docs

type Docs []string

Docs is use to store documents

type EllipsisType

type EllipsisType struct {
	*ArrayType
}

EllipsisType is slice type but with ...type definition

func (*EllipsisType) GetDefinition

func (i *EllipsisType) GetDefinition() string

GetName the name of this type

func (EllipsisType) Package

func (s EllipsisType) Package() *Package

type Embed

type Embed struct {
	Type
	Docs Docs
	Tags reflect.StructTag
}

Embed is the embeded type in the struct or interface

type Field

type Field struct {
	Variable
	Tags reflect.StructTag
}

Field is a single field of a structure, a variable, with tag

type File

type File struct {
	FileName    string
	PackageName string
	Docs        Docs
	Functions   []*Function
	Imports     []*Import
	Variables   []*Variable
	Constants   []*Constant
	Types       []*TypeName
}

File is the annotations in package and all its sub types

func ParseFile

func ParseFile(src string, p *Package) (*File, error)

ParseFile try to parse a single file for its annotations

type FuncType

type FuncType struct {
	Parameters []*Variable
	Results    []*Variable
	// contains filtered or unexported fields
}

FuncType is for function type

func (*FuncType) GetDefinition

func (i *FuncType) GetDefinition() string

GetName the name of this type

func (FuncType) Package

func (s FuncType) Package() *Package

type Function

type Function struct {
	Name     string
	Receiver *Variable // Nil means normal function
	Docs     Docs
	Type     *FuncType
}

Function is annotation data for a single function

func NewFunction

func NewFunction(f *ast.FuncDecl, src string, fl *File, p *Package) *Function

NewFunction return a single function annotation

type IdentType

type IdentType struct {
	Ident string
	// contains filtered or unexported fields
}

IdentType is for simple definition of a type, like int, string ...

func (*IdentType) GetDefinition

func (i *IdentType) GetDefinition() string

GetName the name of this type

func (IdentType) Package

func (s IdentType) Package() *Package

type Import

type Import struct {
	Name string
	Path string
	Docs Docs
}

Import is a single import entity

func NewImport

func NewImport(i *ast.ImportSpec, c *ast.CommentGroup) *Import

NewImport extract a new import entry

func (Import) LoadPackage

func (i Import) LoadPackage() *Package

LoadPackage is the function to load import package

type InterfaceType

type InterfaceType struct {
	Functions []*Function
	Embed     []Type // IdentType or SelectorType
	// contains filtered or unexported fields
}

InterfaceType is a single interface in system

func (*InterfaceType) GetDefinition

func (i *InterfaceType) GetDefinition() string

GetName the name of this type

func (InterfaceType) Package

func (s InterfaceType) Package() *Package

type MapType

type MapType struct {
	Key   Type
	Value Type
	// contains filtered or unexported fields
}

MapType is the map type

func (*MapType) GetDefinition

func (i *MapType) GetDefinition() string

GetName the name of this type

func (MapType) Package

func (s MapType) Package() *Package

type Package

type Package struct {
	Files []*File
	Path  string
	Name  string
	// contains filtered or unexported fields
}

pkg is list of files

func ParsePackage

func ParsePackage(path string) (*Package, error)

ParsePackage is here for loading a single package and parse all files in it

func (Package) FindConstant

func (p Package) FindConstant(t string) (*Constant, error)

FindConstant try to find a package level variable

func (Package) FindFunction

func (p Package) FindFunction(t string) (*Function, error)

FindFunction try to find a package level variable

func (Package) FindImport

func (p Package) FindImport(t string) (*Import, error)

FindImport try to find an import by its full import path

func (Package) FindType

func (p Package) FindType(t string) (*TypeName, error)

FindType return a base type interface base on the string name of the type

func (Package) FindVariable

func (p Package) FindVariable(t string) (*Variable, error)

FindVariable try to find a package level variable

type SelectorType

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

SelectorType a type from another package

func (*SelectorType) GetDefinition

func (i *SelectorType) GetDefinition() string

GetName the name of this type

func (*SelectorType) IdentType

func (st *SelectorType) IdentType() *IdentType

func (*SelectorType) Package

func (st *SelectorType) Package() *Package

Package in selector type is not this package

type StarType

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

StarType is a pointer to another type

func (*StarType) GetDefinition

func (i *StarType) GetDefinition() string

GetName the name of this type

func (StarType) Package

func (s StarType) Package() *Package

type StructType

type StructType struct {
	Fields []*Field
	Embeds []*Embed
	// contains filtered or unexported fields
}

StructType is a struct in source code

func (*StructType) GetDefinition

func (i *StructType) GetDefinition() string

GetName the name of this type

func (StructType) Package

func (s StructType) Package() *Package

type Type

type Type interface {
	// GetDefinition return the definition of type
	GetDefinition() string
	// pkg return the package where this type is inside it
	Package() *Package
}

Type is for handling a type definition

type TypeName

type TypeName struct {
	Type Type
	Name string
	Docs Docs

	Methods     []*Function
	StarMethods []*Function
}

TypeName contain type and its name, means the type is in this package

func NewType

func NewType(t *ast.TypeSpec, c *ast.CommentGroup, src string, f *File, p *Package) *TypeName

NewType handle a type

func (TypeName) GetAllMethods

func (tn TypeName) GetAllMethods(pointer bool) []*Function

func (TypeName) GetDefinition

func (tn TypeName) GetDefinition() string

GetDefinition return the definition of this type

func (TypeName) Support

func (tn TypeName) Support(in *InterfaceType, pointer bool) bool

Support return true if the type support the interface, if pointer is true then it checked with pointer receiver

type Variable

type Variable struct {
	Name string
	Type Type
	Docs Docs
	// contains filtered or unexported fields
}

Variable is a string represent of a function parameter

func NewVariable

func NewVariable(v *ast.ValueSpec, c *ast.CommentGroup, src string, f *File, p *Package) []*Variable

NewVariable return an array of variables in the scope

Jump to

Keyboard shortcuts

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