godmt

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MapType    = 1
	VarType    = 2
	ConstType  = 3
	StructType = 4
	SliceType  = 5
)

The below constants represent the InternalType for a scanned type this is used in the translators to determine more easily the type of object we are performing operations on.

Variables

This section is empty.

Functions

func CleanTagName

func CleanTagName(rawTagName string) string

func ExtractComments

func ExtractComments(rawCommentGroup *ast.CommentGroup) []string

ExtractComments will transform a *ast.CommentGroup into a []string which makes it more accessible and usable.

func ExtractSliceValues

func ExtractSliceValues(items []ast.Expr) []string

ExtractSliceValues will return the values of a []ast.Expr in the form of a []string for ease of use.

func GetMapValueType

func GetMapValueType(item ast.Expr) string

GetMapValueType will return the type of a map's value fields.

func GetSliceType added in v1.2.0

func GetSliceType(objectTypeDetails *ast.ArrayType) string

func SliceValuesToPrettyList

func SliceValuesToPrettyList(raw []string) string

SliceValuesToPrettyList will turn a normal []string into a line & comma separated string, for pretty display of a slice's values.

Types

type ImportedEntityDetails

type ImportedEntityDetails struct {
	EntityName  string
	PackageName string
}

ImportedEntityDetails represents the details of an imported item. With that information an attempt of an import can be re-created in the translators.

type ScannedStruct

type ScannedStruct struct {
	Doc          []string             `json:"doc"`
	Name         string               `json:"name"`
	Fields       []ScannedStructField `json:"fields"`
	InternalType int                  `json:"internalType"`
}

ScannedStruct represents the details of a scanned struct.

func ParseStruct added in v1.3.0

func ParseStruct(d *ast.Ident) []ScannedStruct

type ScannedStructField

type ScannedStructField struct {
	Name          string                 `json:"name"`
	Kind          string                 `json:"kind"`
	Tag           string                 `json:"tag"`
	Doc           []string               `json:"doc"`
	ImportDetails *ImportedEntityDetails `json:"importedEntity"`
	SubFields     []ScannedStructField   `json:"subFields"`
	InternalType  int                    `json:"internalType"`
	IsPointer     bool                   `json:"isPointer"`
}

ScannedStructField represents the details of a field inside a scanned struct.

func ImportedStructFieldParser

func ImportedStructFieldParser(field *ast.Field) *ScannedStructField

ImportedStructFieldParser will transform a field of a struct that contains an imported entity into a program readable ScannedStructField.

func ParseComplexStructField added in v1.3.0

func ParseComplexStructField(item *ast.Ident) *ScannedStructField

func ParseNestedStruct added in v1.3.0

func ParseNestedStruct(field *ast.Field) *ScannedStructField

func ParseStructField added in v1.3.0

func ParseStructField(item *ast.Field) *ScannedStructField

func SimpleStructFieldParser

func SimpleStructFieldParser(field *ast.Field) *ScannedStructField

ImportedStructFieldParser will transform a field of a struct that contains a basic entity into a program readable ScannedStructField.

type ScannedType

type ScannedType struct {
	Name         string      `json:"name"`
	Kind         string      `json:"kind"`
	Value        interface{} `json:"value"`
	Doc          []string    `json:"doc"`
	InternalType int         `json:"internalType"`
}

ScannedType represents a basic entity to be translated. More specifically const and var items.

func BasicTypeLiteralParser

func BasicTypeLiteralParser(d *ast.Ident, item *ast.BasicLit) ScannedType

BasicTypeLiteralParser will try to extract the type of a basic literal type, whether const or var.

func CompositeLiteralMapParser

func CompositeLiteralMapParser(d *ast.Ident, mapElements []ast.Expr, item *ast.CompositeLit) ScannedType

CompositeLiteralSliceParser will extract a map ScannedType from the valid corresponding composite literal declaration.

func CompositeLiteralSliceParser

func CompositeLiteralSliceParser(d *ast.Ident, sliceType string, item *ast.CompositeLit) ScannedType

CompositeLiteralSliceParser will extract a slice ScannedType from the valid corresponding composite literal declaration.

func IdentifierParser

func IdentifierParser(d, item *ast.Ident) *ScannedType

IdentifierParser will try to extract the type of an identifier, like booleans. This will return a pointer to a ScannedType, thus the result should be checked for nil.

func ParseConstantsAndVariables added in v1.3.0

func ParseConstantsAndVariables(d *ast.Ident) []ScannedType

func ParseIotaConstants added in v1.4.4

func ParseIotaConstants(d *ast.ValueSpec) []ScannedType

Jump to

Keyboard shortcuts

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