Skip to content

Commit

Permalink
Merge pull request #104 from jfeliu007/issue-103
Browse files Browse the repository at this point in the history
issue-103 - Parser fails when processing this library https://github.…
  • Loading branch information
Javier Feliu authored Sep 22, 2020
2 parents beb9382 + ec3dc0b commit 84f20f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/class_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ func (p *ClassParser) parseFileDeclarations(node ast.Decl) {
func (p *ClassParser) handleFuncDecl(decl *ast.FuncDecl) {

if decl.Recv != nil {
if decl.Recv.List == nil {
return
}

// Only get in when the function is defined for a structure. Global functions are not needed for class diagram
theType, _ := getFieldType(decl.Recv.List[0].Type, p.allImports)
theType = replacePackageConstant(theType, "")
Expand Down
12 changes: 12 additions & 0 deletions parser/class_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,15 @@ func TestGenerateRenamedStructName(t *testing.T) {
t.Errorf("TestGenerateRenamedStructName: Expected result to be abcd, got %s", generatedName)
}
}

func TestClassParser_handleFuncDecl(t *testing.T) {
p := &ClassParser{}
p.handleFuncDecl(&ast.FuncDecl{
Recv: &ast.FieldList{
List: nil,
},
})
if len(p.allStructs) != 0 {
t.Error("expecting no structs to be created")
}
}

0 comments on commit 84f20f5

Please sign in to comment.