forked from mirror/enumer
use constant names
This commit is contained in:
parent
56342fda5f
commit
9793e421ce
|
@ -61,7 +61,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh
|
||||||
g.Printf("\nvar _%sValues = []%s{", typeName, typeName)
|
g.Printf("\nvar _%sValues = []%s{", typeName, typeName)
|
||||||
for _, values := range runs {
|
for _, values := range runs {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
g.Printf("\t%s, ", value.str)
|
g.Printf("\t%s, ", value.originalName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.Printf("}\n\n")
|
g.Printf("}\n\n")
|
||||||
|
@ -98,8 +98,8 @@ func (g *Generator) printValueMap(runs [][]Value, typeName string, runsThreshold
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
|
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
|
||||||
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
|
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
|
||||||
n += len(value.name)
|
n += len(value.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
stringer.go
12
stringer.go
|
@ -508,7 +508,8 @@ func (g *Generator) format() []byte {
|
||||||
|
|
||||||
// Value represents a declared constant.
|
// Value represents a declared constant.
|
||||||
type Value struct {
|
type Value struct {
|
||||||
name string // The name of the constant after transformation (i.e. camel case => snake case)
|
originalName string // The name of the constant before transformation
|
||||||
|
name string // The name of the constant after transformation (i.e. camel case => snake case)
|
||||||
// The value is stored as a bit pattern alone. The boolean tells us
|
// The value is stored as a bit pattern alone. The boolean tells us
|
||||||
// whether to interpret it as an int64 or a uint64; the only place
|
// whether to interpret it as an int64 or a uint64; the only place
|
||||||
// this matters is when sorting.
|
// this matters is when sorting.
|
||||||
|
@ -602,10 +603,11 @@ func (f *File) genDecl(node ast.Node) bool {
|
||||||
u64 = uint64(i64)
|
u64 = uint64(i64)
|
||||||
}
|
}
|
||||||
v := Value{
|
v := Value{
|
||||||
name: n.Name,
|
originalName: n.Name,
|
||||||
value: u64,
|
name: n.Name,
|
||||||
signed: info&types.IsUnsigned == 0,
|
value: u64,
|
||||||
str: value.String(),
|
signed: info&types.IsUnsigned == 0,
|
||||||
|
str: value.String(),
|
||||||
}
|
}
|
||||||
if c := vspec.Comment; f.lineComment && c != nil && len(c.List) == 1 {
|
if c := vspec.Comment; f.lineComment && c != nil && len(c.List) == 1 {
|
||||||
v.name = strings.TrimSpace(c.Text())
|
v.name = strings.TrimSpace(c.Text())
|
||||||
|
|
Loading…
Reference in New Issue