jfeliu007 / goplantuml

PlantUML Class Diagram Generator for golang projects
MIT License
1.78k stars 167 forks source link

Bug: parsing and rendering of named imports #84

Open Justin-W opened 4 years ago

Justin-W commented 4 years ago

I think I have discovered 2 related problems with the way that named imports are being parsed and rendered.

Problem 1

func (p *ClassParser) parseImports(impt *ast.ImportSpec) is the func which maps import statements' names to the import path. Since the imports map is global and shared across all packages for an entire puml diagram, and since the map associates each name with only 1 import path, it results incorrect parsing/rendering in the following scenario:

In order to fix this problem, you will have to perform parsing and rendering of named imports, and of other code constructs that use the import name/alias, in a way that correctly associates the import name with the import path associated with that import name in that file (and without assuming that the import name is associated with a single, unique import path across the entire set of parsed files/packages).

Problem 2

Related to the problem above, func (p *ClassParser) parseImports(impt *ast.ImportSpec) is called from func (p *ClassParser) parsePackage(node ast.Node), which iterates over an unsorted map of the package's files. Therefore:

To fix the non-repeatability (#61) portion of the problem you will need to parse the go files in a repeatable order within func (p *ClassParser) parsePackage(node ast.Node).