extractor

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRestMetadata

func BuildRestMetadata(comments []string) definitions.RestMetadata

func DoesStructEmbedStruct

func DoesStructEmbedStruct(
	sourceFile *ast.File,
	structFullPackageName string,
	structNode *ast.StructType,
	embeddedStructName string,
) bool

func DoesStructEmbedStructByName

func DoesStructEmbedStructByName(structNode *ast.StructType, embeddedStructName string) bool

DoesStructEmbedStructByName Checks whether `structNode` embeds a struct who's name equals embeddedStructName. Note this function does NOT take into account

func DoesTypeOrInterfaceExistInPackage

func DoesTypeOrInterfaceExistInPackage(
	packages []*packages.Package,
	packageFullName string,
	ident *ast.Ident,
) (bool, bool)

func EmbedsBaseStruct

func EmbedsBaseStruct(structType *ast.StructType, baseStruct string) bool

EmbedsBaseStruct checks if a struct embeds the specified base struct.

func ExtractClassMetadata

func ExtractClassMetadata(d ast.GenDecl, baseStruct string) (*definitions.ControllerMetadata, error)

func ExtractClassRoutesMetaData

func ExtractClassRoutesMetaData(routeFuncDecl ast.FuncDecl) (*definitions.RouteMetadata, error)

func ExtractMetadata

func ExtractMetadata() ([]definitions.ControllerMetadata, error)

func ExtractParamTerm

func ExtractParamTerm(line string) string

ExtractParamTerm extracts the term immediately after "// @" and trims surrounding spaces.

func ExtractParenthesesContent

func ExtractParenthesesContent(line string) string

ExtractParenthesesContent extracts the text inside parentheses after the word immediately following "@" If no parentheses exist, it returns an empty string.

func FilterDecls

func FilterDecls(decls []ast.Decl, check func(ast.Decl) bool) []ast.Decl

FilterDecls filters a slice of ast.Decl using a custom type-checking function.

func FilterPackageByFullName

func FilterPackageByFullName(packages []*packages.Package, fullName string) *packages.Package

func FindAndExtract

func FindAndExtract(input []string, search string) string

func FindAndExtractArray

func FindAndExtractArray(input []string, search string) []string

func FindAndExtractOccurrences

func FindAndExtractOccurrences(input []string, search string, maxMatchCount uint) []string

func GetAllPackageFiles

func GetAllPackageFiles(codeFiles []*ast.File, fileSet *token.FileSet, fullPackageNameToFind string) ([]*ast.File, error)

func GetCommentsFromIdent

func GetCommentsFromIdent(ident *ast.Ident) []string

func GetDefaultAlias

func GetDefaultAlias(fullyQualifiedPackage string) string

func GetDefaultPackageAlias

func GetDefaultPackageAlias(file *ast.File) (string, error)

func GetDotImportedPackageNames

func GetDotImportedPackageNames(file *ast.File) []string

func GetFieldUsageType

func GetFieldUsageType(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	value *ast.Field,
) (definitions.TypeMetadata, error)

func GetFileByImportNode

func GetFileByImportNode(codeFiles []*ast.File, fileSet *token.FileSet, importNode *ast.ImportSpec) (*ast.File, error)

func GetFullPackageName

func GetFullPackageName(file *ast.File, fileSet *token.FileSet) (string, error)

func GetFuncReturnTypeList

func GetFuncReturnTypeList(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	funcDecl ast.FuncDecl,
)

func GetImportAliases

func GetImportAliases(file *ast.File) map[string]string

func GetMetadata

func GetMetadata()

func GetPackageAndDependencies

func GetPackageAndDependencies(
	codeFiles []*ast.File,
	fileSet *token.FileSet,
	fullPackageNameToFind string,
	relevantFilesOutput *MapSet.Set[*ast.File],
) error

func GetPackagesFromExpressions

func GetPackagesFromExpressions(packageExpressions []string) ([]*packages.Package, error)

func GetResponseInterface

func GetResponseInterface(file *ast.File, fileSet *token.FileSet, funcDecl ast.FuncDecl) definitions.ResponseMetadata

func GetTextAfterParenthesis

func GetTextAfterParenthesis(input string, splitter string) string

GetTextAfterParenthesis extracts the text before the character '(' in a given string. If '(' is not present, it returns the original string.

func GetTextBeforeParenthesis

func GetTextBeforeParenthesis(input string, splitter string) string

GetTextBeforeParenthesis extracts the text before the character '(' in a given string.

func GetTypeMetaByIdent

func GetTypeMetaByIdent(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	ident *ast.Ident,
) (definitions.TypeMetadata, error)

func GetTypeMetaBySelectorExpr

func GetTypeMetaBySelectorExpr(
	file *ast.File,
	fileSet *token.FileSet,
	packages []*packages.Package,
	selector *ast.SelectorExpr,
) (definitions.TypeMetadata, error)

func IsAliasDefault

func IsAliasDefault(fullPackageName string, alias string) bool

func IsAliasDefaultImport

func IsAliasDefaultImport(file *ast.File, alias string) bool

func IsFuncDeclReceiverForStruct

func IsFuncDeclReceiverForStruct(structName string, funcDecl *ast.FuncDecl) bool

func IsIdentFromDotImport

func IsIdentFromDotImport(file *ast.File, ident *ast.Ident, typeInfo *types.Info) (bool, error)

IsIdentFromDotImport resolves whether an `*ast.Ident` refers to a type from a dot-imported package.

func IsIdentInPackage

func IsIdentInPackage(pkg *packages.Package, ident *ast.Ident) bool

func IsPackageDotImported

func IsPackageDotImported(file *ast.File, packageName string) (bool, string)

func IsUniverseType

func IsUniverseType(typeName string) bool

func MapDocListToStrings

func MapDocListToStrings(docList []*ast.Comment) []string

MapDocListToStrings converts a list of comment nodes (ast.Comment) to a string array

func SearchForParamTerm

func SearchForParamTerm(lines []string, searchTerm string) string

SearchForParamTerm searches for a term in a list of strings that comes immediately after "// @" with no space, and with space after it.

Types

type ControllerVisitor

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

func (*ControllerVisitor) GetFiles

func (v *ControllerVisitor) GetFiles() []*ast.File

func (*ControllerVisitor) GetLastError

func (v *ControllerVisitor) GetLastError() *error

func (*ControllerVisitor) Init

func (v *ControllerVisitor) Init(sourceFileGlobs []string) error

func (*ControllerVisitor) Visit

func (v *ControllerVisitor) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

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