Created
February 2, 2011 21:51
-
-
Save tmhedberg/808527 to your computer and use it in GitHub Desktop.
Generate a JavaBean class body from a list of properties
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
#!/bin/awk -f | |
{ | |
printf "private %s %s;\n", $1, $2; | |
cap = sprintf("%s%s", toupper(substr($2, 1, 1)), substr($2, 2)); | |
get[NR] = sprintf("public %s get%s() {\n\treturn %s;\n}", $1, cap, $2); | |
set[NR] = sprintf("public void set%s(final %s %s) {\n\tthis.%s = %s;\n}", cap, $1, $2, $2, $2); | |
} | |
END { | |
printf "\n"; | |
for (i = 1; i <= NR; ++i) { | |
print get[i]; | |
print set[i]; | |
printf "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment