Some of this got moved into samskivert.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4628 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2007-03-16 20:51:18 +00:00
parent 6508abbc11
commit 94cdf6f2dc
@@ -39,7 +39,7 @@ import com.samskivert.util.StringUtil;
/** /**
* Utility methods used by our various source code generating tasks. * Utility methods used by our various source code generating tasks.
*/ */
public class GenUtil public class GenUtil extends com.samskivert.util.GenUtil
{ {
/** A regular expression for matching the package declaration. */ /** A regular expression for matching the package declaration. */
public static final Pattern PACKAGE_PATTERN = public static final Pattern PACKAGE_PATTERN =
@@ -51,56 +51,6 @@ public class GenUtil
Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?" + Pattern.compile("^\\s*public\\s+(?:abstract\\s+)?" +
"(interface|class)\\s+(\\S+)(\\W|$)"); "(interface|class)\\s+(\\S+)(\\W|$)");
/**
* Returns the name of the supplied class as it would likely appear in code
* using the class (no package prefix, arrays specified as
* <code>type[]</code>).
*/
public static String simpleName (Field field)
{
String cname;
Class<?> clazz = field.getType();
if (clazz.isArray()) {
if (field.getGenericType() instanceof GenericArrayType) {
GenericArrayType atype = (GenericArrayType)
field.getGenericType();
cname = atype.getGenericComponentType().toString();
} else {
return simpleName(clazz.getComponentType(),
field.getGenericType()) + "[]";
}
} else if (field.getGenericType() instanceof ParameterizedType) {
cname = field.getGenericType().toString();
} else {
cname = clazz.getName();
}
Package pkg = clazz.getPackage();
int offset = (pkg == null) ? 0 : pkg.getName().length()+1;
return StringUtil.replace(cname.substring(offset), "$", ".");
}
/**
* Returns the name of the supplied class as it would likely appear in code
* using the class (no package prefix, arrays specified as
* <code>type[]</code>).
*/
public static String simpleName (Class<?> clazz, Type type)
{
if (clazz.isArray()) {
return simpleName(clazz.getComponentType(), type) + "[]";
} else {
String cname = clazz.getName();
if (type instanceof ParameterizedType) {
cname = type.toString();
}
Package pkg = clazz.getPackage();
int offset = (pkg == null) ? 0 : pkg.getName().length()+1;
String name = cname.substring(offset);
return StringUtil.replace(name, "$", ".");
}
}
/** /**
* Returns the name of the supplied class as it would appear in * Returns the name of the supplied class as it would appear in
* ActionScript code using the class (no package prefix, arrays specified * ActionScript code using the class (no package prefix, arrays specified