当前位置: 首页>>代码示例>>Java>>正文


Java Constructor.getExceptionTypes方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:FactoryTestGenerator.java


注:本文中的java.lang.reflect.Constructor.getExceptionTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。