parser

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 12 Imported by: 13

Documentation

Overview

Package parser generates PlantUml http://plantuml.com/ Class diagrams for your golang projects The main structure is the ClassParser which you can generate by calling the NewClassDiagram(dir) function.

Pass the directory where the .go files are and the parser will analyze the code and build a structure containing the information it needs to Render the class diagram.

call the Render() function and this will return a string with the class diagram.

See github.com/jfeliu007/goplantuml/cmd/goplantuml/main.go for a command that uses this functions and outputs the text to the console.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias added in v1.0.2

type Alias struct {
	Name        string
	PackageName string
	AliasOf     string
}

Alias defines a type that is an alias for some other type

type AliasSlice added in v1.4.0

type AliasSlice []Alias

AliasSlice implement the sort.Interface interface to allow for proper sorting of an alias slice

func (AliasSlice) Len added in v1.4.0

func (as AliasSlice) Len() int

Len is the number of elements in the collection.

func (AliasSlice) Less added in v1.4.0

func (as AliasSlice) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (AliasSlice) Swap added in v1.4.0

func (as AliasSlice) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ClassDiagramOptions added in v1.4.0

type ClassDiagramOptions struct {
	FileSystem         afero.Fs
	Directories        []string
	IgnoredDirectories []string
	RenderingOptions   map[RenderingOption]interface{}
	Recursive          bool
}

ClassDiagramOptions will provide a way for callers of the NewClassDiagramFs() function to pass all the necessary arguments.

type ClassParser

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

ClassParser contains the structure of the parsed files. The structure is a map of package_names that contains a map of structure_names -> Structs

func NewClassDiagram

func NewClassDiagram(directoryPaths []string, ignoreDirectories []string, recursive bool) (*ClassParser, error)

NewClassDiagram returns a new classParser with which can Render the class diagram of files in the given directory

func NewClassDiagramWithOptions added in v1.4.0

func NewClassDiagramWithOptions(options *ClassDiagramOptions) (*ClassParser, error)

NewClassDiagramWithOptions returns a new classParser with which can Render the class diagram of files in the given directory passed in the ClassDiargamOptions. This will also alow for different types of FileSystems Passed since it is part of the ClassDiagramOptions as well.

func (*ClassParser) Render

func (p *ClassParser) Render() string

Render returns a string of the class diagram that this parser has generated.

func (*ClassParser) SetRenderingOptions added in v1.2.0

func (p *ClassParser) SetRenderingOptions(ro map[RenderingOption]interface{}) error

SetRenderingOptions Sets the rendering options for the Render() Function

type Field

type Field struct {
	Name     string
	Type     string
	FullType string
}

Field can hold the name and type of any field

type Function

type Function struct {
	Name                 string
	Parameters           []*Field
	ReturnValues         []string
	PackageName          string
	FullNameReturnValues []string
}

Function holds the signature of a function with name, Parameters and Return values

func (*Function) SignturesAreEqual

func (f *Function) SignturesAreEqual(function *Function) bool

SignturesAreEqual Returns true if the two functions have the same signature (parameter names are not checked)

type LineStringBuilder

type LineStringBuilder struct {
	strings.Builder
}

LineStringBuilder extends the strings.Builder and adds functionality to build a string with tabs and adding new lines

func (*LineStringBuilder) WriteLineWithDepth

func (lsb *LineStringBuilder) WriteLineWithDepth(depth int, str string)

WriteLineWithDepth will write the given text with added tabs at the beginning into the string builder.

type RenderingOption added in v1.3.0

type RenderingOption int

RenderingOption is an alias for an it so it is easier to use it as options in a map (see SetRenderingOptions(map[RenderingOption]bool) error)

const (
	// RenderAggregations is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render aggregations
	RenderAggregations RenderingOption = iota

	// RenderCompositions is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render compositions
	RenderCompositions

	// RenderImplementations is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render implementations
	RenderImplementations

	// RenderAliases is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render aliases
	RenderAliases

	// RenderFields is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render fields
	RenderFields

	// RenderMethods is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render methods
	RenderMethods

	// RenderConnectionLabels is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will set the parser to render the connection labels
	RenderConnectionLabels

	// RenderTitle is the options for the Title of the diagram. The value of this will be rendered as a title unless empty
	RenderTitle

	// RenderNotes contains a list of notes to be rendered in the class diagram
	RenderNotes

	// AggregatePrivateMembers is to be used in the SetRenderingOptions argument as the key to the map, when value is true, it will connect aggregations with private members
	AggregatePrivateMembers

	// RenderPrivateMembers is used if private members (fields, methods) should be rendered
	RenderPrivateMembers
)

type RenderingOptions added in v1.2.0

type RenderingOptions struct {
	Title                   string
	Notes                   string
	Aggregations            bool
	Fields                  bool
	Methods                 bool
	Compositions            bool
	Implementations         bool
	Aliases                 bool
	ConnectionLabels        bool
	AggregatePrivateMembers bool
	PrivateMembers          bool
}

RenderingOptions will allow the class parser to optionally enebale or disable the things to render.

type Struct

type Struct struct {
	PackageName         string
	Functions           []*Function
	Fields              []*Field
	Type                string
	Composition         map[string]struct{}
	Extends             map[string]struct{}
	Aggregations        map[string]struct{}
	PrivateAggregations map[string]struct{}
}

Struct represent a struct in golang, it can be of Type "class" or "interface" and can be associated with other structs via Composition and Extends

func (*Struct) AddField

func (st *Struct) AddField(field *ast.Field, aliases map[string]string)

AddField adds a field into this structure. It parses the ast.Field and extract all needed information

func (*Struct) AddMethod

func (st *Struct) AddMethod(method *ast.Field, aliases map[string]string)

AddMethod Parse the Field and if it is an ast.FuncType, then add the methods into the structure

func (*Struct) AddToAggregation added in v1.2.0

func (st *Struct) AddToAggregation(fType string)

AddToAggregation adds an aggregation type to the list of aggregations

func (*Struct) AddToComposition

func (st *Struct) AddToComposition(fType string)

AddToComposition adds the composition relation to the structure. We want to make sure that *ExampleStruct gets added as ExampleStruct so that we can properly build the relation later to the class identifier

func (*Struct) AddToExtends

func (st *Struct) AddToExtends(fType string)

AddToExtends Adds an extends relationship to this struct. We want to make sure that *ExampleStruct gets added as ExampleStruct so that we can properly build the relation later to the class identifier

func (*Struct) ImplementsInterface

func (st *Struct) ImplementsInterface(inter *Struct) bool

ImplementsInterface returns true if the struct st conforms ot the given interface

Jump to

Keyboard shortcuts

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