Created
May 13, 2016 08:51
-
-
Save holmeszyx/aca7cf3fd56492610411d68a52ab245e to your computer and use it in GitHub Desktop.
生成一下java的mask或者index常量
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
type item struct { | |
Name string | |
Comment string | |
} | |
func createMasks(src []item) { | |
//var index uint | |
for index, item := range src { | |
if index > 0 { | |
fmt.Println() | |
} | |
if item.Comment != "" { | |
fmt.Printf("/** %s */\n", item.Comment) | |
} | |
fmt.Printf("public static final int MASK_%s = %d;\n", strings.ToUpper(item.Name), 1<<uint(index)) | |
index++ | |
} | |
} | |
func createIndex(src []item, fromIndex int) { | |
//var index uint | |
for index, item := range src { | |
if index > 0 { | |
fmt.Println() | |
} | |
if item.Comment != "" { | |
fmt.Printf("/** %s */\n", item.Comment) | |
} | |
fmt.Printf("public static final int INDEX_%s = %d;\n", strings.ToUpper(item.Name), index + fromIndex) | |
index++ | |
} | |
} | |
func main() { | |
m := make([]item, 0, 32) | |
add := func (n, c string) { | |
m = append(m, item{ | |
Name : n, | |
Comment : c, | |
}) | |
} | |
add("type_int", "int") | |
add("type_long", "long") | |
add("type_boolean", "boolean") | |
add("type_float", "float") | |
add("type_string", "string") | |
add("type_string_set", "string_set") | |
createMasks(m) | |
fmt.Print("\n\n// ============ index ===========\n\n") | |
createIndex(m, 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment