Skip to content

Instantly share code, notes, and snippets.

@tmhedberg
Created February 2, 2011 21:51
Show Gist options
  • Save tmhedberg/808527 to your computer and use it in GitHub Desktop.
Save tmhedberg/808527 to your computer and use it in GitHub Desktop.
Generate a JavaBean class body from a list of properties
#!/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