parser

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 9 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

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

func (*ClassParser) SetRenderingOptions added in v1.2.0

func (p *ClassParser) SetRenderingOptions(ro *RenderingOptions)

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 RenderingOptions added in v1.2.0

type RenderingOptions struct {
	Aggregation 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{}
}

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