From a0e94628eb8e0cf91b494f3babd00686543b19d3 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 9 Aug 2010 18:46:29 +0000 Subject: [PATCH] NIHVIVO-564 Refined method list output by describe directive --- .../directives/dump/DescribeDirective.java | 29 +++++++++++++++++-- .../body/partials/dump/describe.ftl | 4 +-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DescribeDirective.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DescribeDirective.java index d69d1e006..902e7266e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DescribeDirective.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DescribeDirective.java @@ -6,7 +6,7 @@ import java.io.IOException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,6 +14,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.web.directives.BaseTemplateDirectiveModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; import freemarker.core.Environment; @@ -78,6 +79,7 @@ public class DescribeDirective extends BaseTemplateDirectiveModel { for (Method m : methods) { methodDescriptions.add(getMethodDescription(m)); } + Collections.sort(methodDescriptions); Map map = new HashMap(); map.put("var", varName); @@ -118,7 +120,7 @@ public class DescribeDirective extends BaseTemplateDirectiveModel { private List getPublicMethods(Class cls) { List methods = new ArrayList(); - // Go up the class hierarchy only until we get to the immediate subclass of BaseTemplateModel + // Go up the class hierarchy only as far as the immediate subclass of BaseTemplateModel if (! cls.getName().equals("edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel")) { methods = getDeclaredPublicMethods(cls); methods.addAll(getPublicMethods(cls.getSuperclass())); @@ -142,7 +144,28 @@ public class DescribeDirective extends BaseTemplateDirectiveModel { private String getMethodDescription(Method method) { - return method.toString(); + + String methodName = method.getName(); + methodName = methodName.replaceAll("^(get|is)", ""); + methodName = methodName.substring(0, 1).toLowerCase() + methodName.substring(1); + + Class[] paramTypes = method.getParameterTypes(); + String paramList = ""; + if (paramTypes.length > 0) { + List paramTypeList = new ArrayList(paramTypes.length); + for (Class cls : paramTypes) { + String name = cls.getName(); + String[] nameParts = name.split("\\."); + String typeName = nameParts[nameParts.length-1]; + typeName = typeName.replaceAll(";", "s"); + typeName = typeName.substring(0,1).toLowerCase() + typeName.substring(1); + paramTypeList.add(typeName); + } + paramList = "(" + StringUtils.join(paramTypeList) + ")"; + } + + return methodName + paramList; + } } diff --git a/webapp/web/templates/freemarker/body/partials/dump/describe.ftl b/webapp/web/templates/freemarker/body/partials/dump/describe.ftl index a40dabe4f..2ffb81b3d 100644 --- a/webapp/web/templates/freemarker/body/partials/dump/describe.ftl +++ b/webapp/web/templates/freemarker/body/partials/dump/describe.ftl @@ -2,9 +2,9 @@ <#-- Template for displaying directive describe --> -

Methods available to variable ${var}

-
+

Methods available to variable ${var}

+ <#list methods as method> ${method}