Skip to content

Instantly share code, notes, and snippets.

@oehme
Created November 28, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oehme/6fba9907ea5e8a7f1192 to your computer and use it in GitHub Desktop.
Save oehme/6fba9907ea5e8a7f1192 to your computer and use it in GitHub Desktop.
Generating Methods from Messagekeys
Iterators.forEnumeration(resourceBundle.keys).forEach [ key |
cls.addMethod(key.keyToMethodName) [
patternVariables.forEach [ patternVariable, index |
addParameter("arg" + index, patternVariable.argumentType(context))
]
returnType = string
body = '''
«String» pattern = bundle.getString("«key»");
«MessageFormat» format = new «MessageFormat»(pattern);
return format.format(new «Object»[]{«parameters.join(", ")[simpleName]»});
'''
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment