本文整理汇总了Java中java.lang.reflect.Constructor.getExceptionTypes方法的典型用法代码示例。如果您正苦于以下问题:Java Constructor.getExceptionTypes方法的具体用法?Java Constructor.getExceptionTypes怎么用?Java Constructor.getExceptionTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Constructor
的用法示例。
在下文中一共展示了Constructor.getExceptionTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMethods
import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private static String createMethods(String clsName, Constructor constructor) {
String sname = clsName.substring(4); // Cut "Tree"
Class[] params = constructor.getParameterTypes();
HashSet set = new HashSet();
String header = "";
String atrs = "";
String res = "";
// create header declaration an attr. list
for (int i = 0; i < params.length; i++) {
String pType = params[i].getName();
String pName;
if (params[i].isPrimitive()) {
pName = pType + "_val";
} else {
pName = pType.substring(pType.lastIndexOf('.') + 1).toLowerCase();
}
if (set.contains(pName)) {
pName += i;
}
set.add(pName);
header += pType + " " + pName;
atrs += pName;
if (i < params.length - 1) {
header += ", ";
atrs += ", ";
}
}
// create() method
res += "\n"
+ " static Tree" + sname + " create" + sname + "(" + header + ", String view) throws Exception {\n"
+ " Tree" + sname + " node = new Tree" + sname + "(" + atrs + ");\n"
+ " \n"
+ " assertEquals(node, view);\n"
+ " cloneNodeTest(node, view);\n"
+ " return node;\n"
+ " }\n";
Class[] exs = constructor.getExceptionTypes();
// if constructor throw InvalidArgumentException create method createInvalid()
for (int i = 0; i < exs.length; i++) {
if (InvalidArgumentException.class.isAssignableFrom(exs[i])) {
res += "\n"
+ " static void create" + sname + "Invalid(" + header + ") throws Exception {\n"
+ " try {\n"
+ " new Tree" + sname + "(" + atrs + ");\n"
+ " // Fail if previous line doesn't trhow exception.\n"
+ " fail(NOT_EXCEPTION + \"from: new Tree" + sname +"(" + atrs + ")\");\n"
+ " } catch (InvalidArgumentException e) {\n"
+ " // OK\n"
+ " }\n"
+ " }\n";
break;
}
}
return res;
}