Skip to content

Commit

Permalink
Merge pull request #69 from jfeliu007/issue-68
Browse files Browse the repository at this point in the history
Fix Cyclomatic complexities for release 1.2.2
  • Loading branch information
jfeliu007 authored Oct 25, 2019
2 parents c28e896 + bd94968 commit fc85942
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions parser/class_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,28 @@ func (p *ClassParser) handleFuncDecl(decl *ast.FuncDecl) {
}
}

func handleGenDecStructType(p *ClassParser, typeName string, c *ast.StructType) {
for _, f := range c.Fields.List {
p.getOrCreateStruct(typeName).AddField(f, p.allImports)
}
}

func handleGenDecInterfaceType(p *ClassParser, typeName string, c *ast.InterfaceType) {
for _, f := range c.Methods.List {
switch t := f.Type.(type) {
case *ast.FuncType:
p.getOrCreateStruct(typeName).AddMethod(f, p.allImports)
break
case *ast.Ident:
f, _ := getFieldType(t, p.allImports)
st := p.getOrCreateStruct(typeName)
f = replacePackageConstant(f, st.PackageName)
st.AddToComposition(f)
break
}
}
}

func (p *ClassParser) handleGenDecl(decl *ast.GenDecl) {
if decl.Specs == nil || len(decl.Specs) < 1 {
//This might be a type of General Declaration we do not know how to handle.
Expand All @@ -218,24 +240,10 @@ func (p *ClassParser) handleGenDecl(decl *ast.GenDecl) {
switch c := v.Type.(type) {
case *ast.StructType:
declarationType = "class"
for _, f := range c.Fields.List {
p.getOrCreateStruct(typeName).AddField(f, p.allImports)
}
handleGenDecStructType(p, typeName, c)
case *ast.InterfaceType:
declarationType = "interface"
for _, f := range c.Methods.List {
switch t := f.Type.(type) {
case *ast.FuncType:
p.getOrCreateStruct(typeName).AddMethod(f, p.allImports)
break
case *ast.Ident:
f, _ := getFieldType(t, p.allImports)
st := p.getOrCreateStruct(typeName)
f = replacePackageConstant(f, st.PackageName)
st.AddToComposition(f)
break
}
}
handleGenDecInterfaceType(p, typeName, c)
default:
basicType, _ := getFieldType(getBasicType(c), p.allImports)

Expand Down

0 comments on commit fc85942

Please sign in to comment.