Skip to content

Commit

Permalink
method comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Oct 11, 2023
1 parent 4bd0d88 commit 69d2750
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewQDReader(options ...QDReaderOption) *QDReader {
return ret
}

// Read implements [io.Reader.Read].
func (d *QDReader) Read(p []byte) (n int, err error) {
return d.implRead(d.createContext("Read", d.implRead == nil), p)
}
Expand Down Expand Up @@ -133,6 +134,7 @@ func (d *QDReader) createContext(methodName string, implIsNil bool) *QDReaderCon

// Options

// WithQDReaderRead implements [io.Reader.Read].
func WithQDReaderRead(implRead func(qdCtx *QDReaderContext, p []byte) (n int, err error)) QDReaderOption {
return func(d *QDReader) {
d.implRead = implRead
Expand Down
8 changes: 8 additions & 0 deletions cmd/qdiimpl/jenutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ func addTypeList(typeList *types.TypeList) func(*jen.Group) {
}
}
}

func formatObjetName(obj types.Object) string {
pkg := ""
if obj.Pkg().Path() != "" {
pkg += obj.Pkg().Path()
}
return pkg + "." + obj.Name()
}
2 changes: 2 additions & 0 deletions cmd/qdiimpl/qdiimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func gen(outputName string, obj types.Object, iface *types.Interface) error {
sig := mtd.Type().(*types.Signature)

// # func (d *debugTYPE) METHOD(METHODPARAMS...) (METHODRESULTS...) {}
f.Commentf("%s implements [%s.%s].", mtd.Name(), formatObjetName(obj), mtd.Name())
f.Func().Params(Id("d").Op("*").Id(objName).TypesFunc(codeObjectTypes)).Id(mtd.Name()).ParamsFunc(func(pgroup *Group) {
for k := 0; k < sig.Params().Len(); k++ {
sigParam := sig.Params().At(k)
Expand Down Expand Up @@ -388,6 +389,7 @@ func gen(outputName string, obj types.Object, iface *types.Interface) error {
f.Line()

// # func WithQDTYPEMETHOD(implMETHOD func(qdCtx *QDTYPEContext, METHODPARAMS...) (METHODRESULTS...)) QDTYPEOption {}
f.Commentf("With%s%s implements [%s.%s].", objName, mtd.Name(), formatObjetName(obj), mtd.Name())
f.Func().Id("With" + objName + mtd.Name()).TypesFunc(codeObjectTypesWithType).Params(
Id("impl" + mtd.Name()).Func().ParamsFunc(func(pgroup *Group) {
// add debug context parameter
Expand Down
9 changes: 9 additions & 0 deletions sample/complex/myinterface_qdii.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sample/datatype/sampledata_qdii.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sample/package/reader_qdii.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 69d2750

Please sign in to comment.