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


Java MethodUtils.invokeExactStaticMethod方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.reflect.MethodUtils.invokeExactStaticMethod方法的典型用法代码示例。如果您正苦于以下问题:Java MethodUtils.invokeExactStaticMethod方法的具体用法?Java MethodUtils.invokeExactStaticMethod怎么用?Java MethodUtils.invokeExactStaticMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.reflect.MethodUtils的用法示例。


在下文中一共展示了MethodUtils.invokeExactStaticMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromValue

import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/** Calls the fromValue(String v) method of the given enum. If the value was not found, null is returned instead of an IllegalArgumentException. */
	@SuppressWarnings("unchecked")
	public static <E extends Enum<E>> E fromValue(Class<E> enumClass, String value) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
		try {
			return (E) MethodUtils.invokeExactStaticMethod(enumClass, "fromValue", 
					new Object[]{value});
		} catch (Exception e) {
			return null;
//			// if illegal argument given -> return null!
//			if (e.getCause() instanceof IllegalArgumentException) {
//				return null;
//			} else
//				throw e;
		}		
	}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:16,代码来源:EnumUtils.java

示例2: fromString

import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/** Calls the fromString(String v) method of the given enum. If the value was not found, null is returned instead of an IllegalArgumentException. */
@SuppressWarnings("unchecked")
public static <E extends Enum<E>> E fromString(Class<E> enumClass, String value) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
	try {
		return (E) MethodUtils.invokeExactStaticMethod(enumClass, "fromString", 
				new Object[]{value});
	} catch (Exception e) {
		return null;
	}		
}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:11,代码来源:EnumUtils.java

示例3: unescapeHtml2

import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
/**
 * Unescape html2.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void unescapeHtml2() throws Exception{
    String a = "第572章 三十年后(大结局) *局";
    String result = (String) MethodUtils.invokeExactStaticMethod(IOWriteUtil.class, "getFormatFilePath", a);
    LOGGER.debug(result);
}
 
开发者ID:venusdrogon,项目名称:feilong-io,代码行数:13,代码来源:IOWriteUtilTest.java

示例4: main

import org.apache.commons.lang3.reflect.MethodUtils; //导入方法依赖的package包/类
public static void main(String... args) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        if (args.length == 0) {
            printHelp();
            System.exit(0);
        }

        File programFile = new File(args[0]);
        if (!programFile.exists()) {
            System.err.format("The script file '%s' does not exist.\n", programFile.getAbsolutePath());
            System.exit(1);
        }
        if (!programFile.canRead()) {
            System.err.format("The script file '%s' is not readable.\n", programFile.getAbsolutePath());
            System.exit(1);
        }

        // The process of compiling TinyScript to an executable format is
        // basically a two step process. First, lex and parse the input file.
        // Second, transform it to byte code and load it into memory.

        // Step 1: Lex and parse the input file.  The lexer and parser are
        // generated by ANTLR. To see the grammar, have a look at the .g4 file.
        // If you find some of the TinyScript* classes are missing or out of
        // date, that is because those classes are generated from the .g4 file
        // from the ANTR tool.
        ANTLRInputStream input = new ANTLRInputStream(new FileInputStream(programFile));
        TinyScriptLexer lexer = new TinyScriptLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        TinyScriptParser parser = new TinyScriptParser(tokens);

        // The .program() method is the root node of the grammar specified in
        // the .g4 file.
        ParseTree tree = parser.program();

        // Step 2: Use the generated ANTLR visitor to generate byte code.
        // Parsed computer programs are stored in a tree structure, commonly
        // called an AST. A visitor for the tree will receive callbacks at each
        // node of the tree, giving it a chance to see what information the
        // parser found at that node and take some action at that time. The
        // SimpleScript visitor will use the ASM library to generate byte code
        // that corresponds to program statements SimpleScript supports.
        final String className = "NewClass";
        ByteCodeGenerationVisitor visitor = new ByteCodeGenerationVisitor(className);
        visitor.visit(tree);

        // Write the byte code to an output file. The produced class file
        // should be executable with javac.
//        try (FileOutputStream fos = new FileOutputStream(className + ".class")) {
//            fos.write(visitor.getResult());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        // This little trick, recommended on the ASM website, will turn the
        // byte[] produced by the ASM library, into a Java class, loaded in
        // memory.
        Class c = loadClass(className, visitor.getResult());

        // Now that the new class is loaded into memory, use reflection to call
        // the main method. Pass in the arguments to this method with the
        // program name trimmed off.
        MethodUtils.invokeExactStaticMethod(c,
                "main",
                new Object[]{Arrays.copyOfRange(args, 1, args.length)},
                new Class<?>[]{String[].class});

    }
 
开发者ID:jacobsimpson,项目名称:tinyscript,代码行数:68,代码来源:Main.java


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