-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from jmattheis/dont-copy
- Loading branch information
Showing
13 changed files
with
192 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package builder | ||
|
||
import ( | ||
"github.com/dave/jennifer/jen" | ||
"github.com/jmattheis/goverter/xtype" | ||
) | ||
|
||
// SkipCopy handles FlagSkipCopySameType. | ||
type SkipCopy struct{} | ||
|
||
// Matches returns true, if the builder can create handle the given types. | ||
func (*SkipCopy) Matches(ctx *MethodContext, source, target *xtype.Type) bool { | ||
return ctx.Flags.Has(FlagSkipCopySameType) && source.T.String() == target.T.String() | ||
} | ||
|
||
// Build creates conversion source code for the given source and target type. | ||
func (*SkipCopy) Build(_ Generator, _ *MethodContext, sourceID *xtype.JenID, _, _ *xtype.Type) ([]jen.Code, *xtype.JenID, *Error) { | ||
return nil, sourceID, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
input: | ||
input.go: | | ||
package skip | ||
// goverter:converter | ||
// goverter:skipCopySameType | ||
type Converter interface { | ||
Convert(source map[string]int) map[string]int | ||
} | ||
success: | | ||
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT. | ||
package generated | ||
type ConverterImpl struct{} | ||
func (c *ConverterImpl) Convert(source map[string]int) map[string]int { | ||
return source | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
input: | ||
input.go: | | ||
package skip | ||
import "time" | ||
// goverter:converter | ||
// goverter:skipCopySameType | ||
type Converter interface { | ||
Convert(source Input) Output | ||
} | ||
type Input struct { | ||
ID *int | ||
Map map[string]int | ||
MapDifferentType map[string]int | ||
CreatedAt time.Time | ||
Unnamed struct{Name string} | ||
} | ||
type Output struct { | ||
ID *int | ||
Map map[string]int | ||
MapDifferentType map[string]ID | ||
CreatedAt *time.Time | ||
Unnamed struct{Name string} | ||
} | ||
type ID int | ||
success: | | ||
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT. | ||
package generated | ||
import ( | ||
execution "github.com/jmattheis/goverter/execution" | ||
"time" | ||
) | ||
type ConverterImpl struct{} | ||
func (c *ConverterImpl) Convert(source execution.Input) execution.Output { | ||
var skipOutput execution.Output | ||
skipOutput.ID = source.ID | ||
skipOutput.Map = source.Map | ||
mapStringSkipID := make(map[string]execution.ID, len(source.MapDifferentType)) | ||
for key, value := range source.MapDifferentType { | ||
mapStringSkipID[key] = execution.ID(value) | ||
} | ||
skipOutput.MapDifferentType = mapStringSkipID | ||
skipOutput.CreatedAt = c.timeTimeToPTimeTime(source.CreatedAt) | ||
skipOutput.Unnamed = source.Unnamed | ||
return skipOutput | ||
} | ||
func (c *ConverterImpl) timeTimeToPTimeTime(source time.Time) *time.Time { | ||
return &source | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
input: | ||
input.go: | | ||
package skip | ||
// goverter:converter | ||
type Converter interface { | ||
// goverter:skipCopySameType | ||
Convert(source Input) Output | ||
} | ||
type Input struct { | ||
ID *int | ||
} | ||
type Output struct { | ||
ID *int | ||
} | ||
success: | | ||
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT. | ||
package generated | ||
import execution "github.com/jmattheis/goverter/execution" | ||
type ConverterImpl struct{} | ||
func (c *ConverterImpl) Convert(source execution.Input) execution.Output { | ||
var skipOutput execution.Output | ||
skipOutput.ID = source.ID | ||
return skipOutput | ||
} |