下面列出了org.apache.commons.lang3.reflect.MethodUtils#invokeExactMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Main method.
* @param args program arguments
* @throws Exception s
*/
public static void main(final String[] args) throws Exception {
// final Class<? extends WebDriverTestCase> testClass = JQuery1x8x2Test.class;
// final Class<? extends WebDriverTestCase> testClass = JQuery1x11x3Test.class;
final Class<? extends WebDriverTestCase> testClass = JQuery3x3x1Test.class;
final String version = (String) MethodUtils.invokeExactMethod(testClass.newInstance(), "getVersion");
final File baseDir = new File("src/test/resources/libraries/jQuery/" + version + "/expectations");
for (String browser : new String[] {"CHROME", "FF", "FF68", "FF60", "IE"}) {
final File out = new File(baseDir, browser + ".out");
final File results = new File(baseDir, "results." + browser + ".txt");
extractExpectations(out, results);
}
generateTestCases(testClass, baseDir);
}
/** Calls the value() method of the given enum. */
public static <E extends Enum<E>> String value(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
try {
return (String) MethodUtils.invokeExactMethod(type, "value",
new Object[]{});
} catch (Exception e) {
return null;
}
}
public static <E extends Enum<E>> String getStr(E type) /*throws NoSuchMethodException, IllegalAccessException, InvocationTargetException*/ {
try {
return (String) MethodUtils.invokeExactMethod(type, "getStr",
new Object[]{});
} catch (Exception e) {
return null;
}
}
/**
* Loads a Gui from a given input stream.
* Throws a {@link RuntimeException} instead of returning null in case of a failure.
*
* @param instance the class instance for all reflection lookups
* @param inputStream the file
* @return the gui
* @see #load(Object, InputStream)
*/
@NotNull
public static Gui loadOrThrow(@NotNull Object instance, @NotNull InputStream inputStream) {
Plugin plugin = JavaPlugin.getProvidingPlugin(Gui.class);
try {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
Element documentElement = document.getDocumentElement();
documentElement.normalize();
Gui gui = new Gui(plugin, Integer.parseInt(documentElement.getAttribute("rows")), ChatColor
.translateAlternateColorCodes('&', documentElement.getAttribute("title")));
if (documentElement.hasAttribute("field"))
XMLUtil.loadFieldAttribute(instance, documentElement, gui);
if (documentElement.hasAttribute("onTopClick")) {
gui.setOnTopClick(XMLUtil.loadOnEventAttribute(instance,
documentElement, InventoryClickEvent.class, "onTopClick"));
}
if (documentElement.hasAttribute("onBottomClick")) {
gui.setOnBottomClick(XMLUtil.loadOnEventAttribute(instance,
documentElement, InventoryClickEvent.class, "onBottomClick"));
}
if (documentElement.hasAttribute("onGlobalClick")) {
gui.setOnGlobalClick(XMLUtil.loadOnEventAttribute(instance,
documentElement, InventoryClickEvent.class, "onGlobalClick"));
}
if (documentElement.hasAttribute("onOutsideClick")) {
gui.setOnOutsideClick(XMLUtil.loadOnEventAttribute(instance,
documentElement, InventoryClickEvent.class, "onOutsideClick"));
}
if (documentElement.hasAttribute("onClose")) {
gui.setOnClose(XMLUtil.loadOnEventAttribute(instance,
documentElement, InventoryCloseEvent.class, "onClose"));
}
if (documentElement.hasAttribute("populate")) {
MethodUtils.invokeExactMethod(instance, "populate", gui, Gui.class);
} else {
NodeList childNodes = documentElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (item.getNodeType() == Node.ELEMENT_NODE)
gui.addPane(loadPane(instance, item));
}
}
return gui;
} catch (Exception e) {
throw new XMLLoadException("Error loading " + plugin.getName() + "'s gui with associated class: "
+ instance.getClass().getSimpleName(), e);
}
}