Mdb dislikes the date and points out that our tasks regenerate these
files every time, so it'll get in the way of version control. Mrmph. So: make the date optional, and leave it out for now. Other comments? git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6051 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -171,7 +171,7 @@ public class GenDObjectTask extends Task
|
||||
// create our velocity context
|
||||
VelocityContext ctx = new VelocityContext();
|
||||
ctx.put("field", fname);
|
||||
ctx.put("generated", GenUtil.getGeneratedAnnotation(getClass(), 4));
|
||||
ctx.put("generated", GenUtil.getGeneratedAnnotation(getClass(), 4, false));
|
||||
ctx.put("type", GenUtil.simpleName(f));
|
||||
ctx.put("wrapfield", GenUtil.boxArgument(ftype, "value"));
|
||||
ctx.put("wrapofield", GenUtil.boxArgument(ftype, "ovalue"));
|
||||
|
||||
@@ -265,7 +265,7 @@ public class GenServiceTask extends InvocationTask
|
||||
|
||||
VelocityContext ctx = new VelocityContext();
|
||||
ctx.put("name", name);
|
||||
ctx.put("generated", getGeneratedAnnotation());
|
||||
ctx.put("generated", getGeneratedAnnotation(name));
|
||||
ctx.put("package", mpackage);
|
||||
ctx.put("methods", sdesc.methods);
|
||||
ctx.put("listeners", sdesc.listeners);
|
||||
@@ -537,7 +537,7 @@ public class GenServiceTask extends InvocationTask
|
||||
|
||||
VelocityContext ctx = new VelocityContext();
|
||||
ctx.put("name", name);
|
||||
ctx.put("generated", getGeneratedAnnotation());
|
||||
ctx.put("generated", getGeneratedAnnotation(name));
|
||||
ctx.put("package", dpackage);
|
||||
ctx.put("methods", sdesc.methods);
|
||||
ctx.put("imports", imports.toList());
|
||||
@@ -596,7 +596,7 @@ public class GenServiceTask extends InvocationTask
|
||||
|
||||
VelocityContext ctx = new VelocityContext();
|
||||
ctx.put("name", name);
|
||||
ctx.put("generated", getGeneratedAnnotation());
|
||||
ctx.put("generated", getGeneratedAnnotation(name));
|
||||
ctx.put("package", mpackage);
|
||||
ctx.put("methods", sdesc.methods);
|
||||
ctx.put("listeners", sdesc.listeners);
|
||||
@@ -616,10 +616,10 @@ public class GenServiceTask extends InvocationTask
|
||||
/**
|
||||
* Helper to get the appropriate "@Generated" annotation for service classes.
|
||||
*/
|
||||
protected String getGeneratedAnnotation ()
|
||||
protected String getGeneratedAnnotation (String name)
|
||||
{
|
||||
return GenUtil.getGeneratedAnnotation(getClass(), 0,
|
||||
"Derived from the Service class java source.");
|
||||
return GenUtil.getGeneratedAnnotation(getClass(), 0, false,
|
||||
"Derived from " + name + "Service.java.");
|
||||
}
|
||||
|
||||
/** Rolls up everything needed for the generate* methods. */
|
||||
|
||||
@@ -246,24 +246,29 @@ public class GenUtil extends com.samskivert.util.GenUtil
|
||||
*
|
||||
* @param clazz the class doing the code generation, NOT the generation target.
|
||||
* @param indent the number of spaces that the annotation is indented.
|
||||
* @param includeDate include the date?
|
||||
* @param comments joined by a space and used as explanatory comments.
|
||||
*/
|
||||
public static String getGeneratedAnnotation (Class<?> clazz, int indent, String... comments)
|
||||
public static String getGeneratedAnnotation (
|
||||
Class<?> clazz, int indent, boolean includeDate, String... comments)
|
||||
{
|
||||
final int LINE_LENGTH = 100;
|
||||
String comm = StringUtil.join(comments, " ");
|
||||
boolean hasComment = !StringUtil.isBlank(comm);
|
||||
String anno = "@Generated(value={\"" + clazz.getName() + "\"},";
|
||||
// ISO 8601 date
|
||||
String date = " date=\"" +
|
||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()) + "\"";
|
||||
// wrap the date onto a new line if it's going to be too long, or if we're
|
||||
// adding a comment (which is also on a new line)
|
||||
if (hasComment || anno.length() + date.length() + 1 + indent > LINE_LENGTH) {
|
||||
// put the date on a new line, space it right
|
||||
date = "\n" + StringUtil.fill(' ', indent + 10) + date;
|
||||
String anno = "@Generated(value={\"" + clazz.getName() + "\"}";
|
||||
if (includeDate) {
|
||||
anno += ",";
|
||||
// ISO 8601 date
|
||||
String date = " date=\"" +
|
||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()) + "\"";
|
||||
// wrap the date onto a new line if it's going to be too long, or if we're
|
||||
// adding a comment (which is also on a new line)
|
||||
if (hasComment || anno.length() + date.length() + 1 + indent > LINE_LENGTH) {
|
||||
// put the date on a new line, space it right
|
||||
date = "\n" + StringUtil.fill(' ', indent + 10) + date;
|
||||
}
|
||||
anno += date;
|
||||
}
|
||||
anno += date;
|
||||
if (hasComment) {
|
||||
anno += ",\n" + StringUtil.fill(' ', indent + 11) + "comments=\"" + comm + "\"";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user