Skip to content

Commit a10bef2

Browse files
authored
Merge pull request #30 from github/owen-mc/fix-embedded-fields
Fix printing of embedded fields
2 parents 9b61b6f + 10c5c82 commit a10bef2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

model/model.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,17 @@ func (pt PredeclaredType) String(map[string]string, string) string { return stri
598598
func (pt PredeclaredType) addImports(map[string]bool) {}
599599

600600
type Field struct {
601-
Name string
602-
Type Type
601+
Name string
602+
Type Type
603+
Anonymous bool
603604
}
604605

605606
func (f *Field) String(pm map[string]string, pkgOverride string) string {
606-
return f.Name + " " + f.Type.String(pm, pkgOverride)
607+
if f.Anonymous {
608+
return f.Type.String(pm, pkgOverride)
609+
} else {
610+
return f.Name + " " + f.Type.String(pm, pkgOverride)
611+
}
607612
}
608613

609614
// StructType is a struct type.
@@ -885,8 +890,9 @@ func (pkg *Package) unnamedTypeFromType(t reflect.Type) (Type, error) {
885890
}
886891

887892
m := &Field{
888-
Name: ft.Name,
889-
Type: typ,
893+
Name: ft.Name,
894+
Type: typ,
895+
Anonymous: ft.Anonymous,
890896
}
891897

892898
fields = append(fields, m)

reflect.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ func runInDir(program []byte, dir string) (*model.PackedPkg, error) {
116116

117117
if modRoot != "" {
118118
MustCopyFile(filepath.Join(modRoot, "go.mod"), filepath.Join(tmpDir, "go.mod"))
119+
120+
// To enable local development of model/model.go, uncomment the following lines
121+
// f, err := os.OpenFile(filepath.Join(tmpDir, "go.mod"), os.O_APPEND|os.O_WRONLY, 0600)
122+
// if err != nil {
123+
// return nil, fmt.Errorf("failed to open go.mod for appending: %v", err)
124+
// }
125+
// defer f.Close()
126+
127+
// replaceDirective := "\n\nreplace github.com/github/depstubber => /Users/owen-mc/workspace/depstubber\n"
128+
// if _, err := f.WriteString(replaceDirective); err != nil {
129+
// return nil, fmt.Errorf("failed to append replace directive to go.mod: %v", err)
130+
// }
119131
}
120132
}
121133

0 commit comments

Comments
 (0)