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 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(directoryPath string, recursive bool) (*ClassParser, error)
NewClassDiagram returns a new classParser with which can Render the class diagram of files int eh given directory
func (*ClassParser) Render ¶
func (p *ClassParser) Render() string
Render returns a string of the class diagram that this parser has generated.
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 Struct ¶
type Struct struct { PackageName string Functions []*Function Fields []*Field Type string Composition map[string]struct{} Extends 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) 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