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
- type Alias
- type AliasSlice
- type ClassDiagramOptions
- type ClassParser
- type Field
- type Function
- type LineStringBuilder
- type RenderingOption
- type RenderingOptions
- type Struct
- func (st *Struct) AddField(field *ast.Field, aliases map[string]string)
- func (st *Struct) AddMethod(method *ast.Field, aliases map[string]string)
- func (st *Struct) AddToAggregation(fType string)
- func (st *Struct) AddToComposition(fType string)
- func (st *Struct) AddToExtends(fType string)
- func (st *Struct) ImplementsInterface(inter *Struct) bool
Constants ¶
const AggregatePrivateMembers = 9
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
const RenderAggregations = 0
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
const RenderAliases = 3
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
const RenderCompositions = 1
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
const RenderConnectionLabels = 6
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
const RenderFields = 4
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
const RenderImplementations = 2
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
const RenderMethods = 5
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
const RenderNotes = 8
RenderNotes contains a list of notes to be rendered in the class diagram
const RenderTitle = 7
RenderTitle is the options for the Title of the diagram. The value of this will be rendered as a title unless empty
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AliasSlice ¶
type AliasSlice []Alias
AliasSlice implement the sort.Interface interface to allow for proper sorting of an alias slice
func (AliasSlice) Len ¶
func (as AliasSlice) Len() int
Len is the number of elements in the collection.
func (AliasSlice) Less ¶
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 ¶
func (as AliasSlice) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type ClassDiagramOptions ¶
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 ¶
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 ¶
func (p *ClassParser) SetRenderingOptions(ro map[RenderingOption]interface{}) error
SetRenderingOptions Sets the rendering options for the Render() Function
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 ¶
SignturesAreEqual Returns true if the two functions have the same signature (parameter names are not checked)
type LineStringBuilder ¶
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 ¶
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)
type RenderingOptions ¶
type RenderingOptions struct { Title string Notes string Aggregations bool Fields bool Methods bool Compositions bool Implementations bool Aliases bool ConnectionLabels bool AggregatePrivateMembers 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 ¶
AddField adds a field into this structure. It parses the ast.Field and extract all needed information
func (*Struct) AddMethod ¶
AddMethod Parse the Field and if it is an ast.FuncType, then add the methods into the structure
func (*Struct) AddToAggregation ¶
AddToAggregation adds an aggregation type to the list of aggregations
func (*Struct) AddToComposition ¶
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 ¶
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 ¶
ImplementsInterface returns true if the struct st conforms ot the given interface