parser

package
v2.0.0-...-6ad1fbe Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 12 Imported by: 0

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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
const RenderNotes = 8

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

View Source
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 Alias

type Alias struct {
	Name        string
	PackageName string
	AliasOf     string
}

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

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 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

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

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

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