use of java.lang.reflect.Method in project junit-interface by sbt.
the class OutputCapture method getScalaOut.
private static PrintStream getScalaOut() {
try {
Class<?> cl = Class.forName("scala.Console");
Method m = cl.getMethod("out");
return (PrintStream) m.invoke(null);
} catch (Throwable t) {
//t.printStackTrace(System.err);
return null;
}
}
use of java.lang.reflect.Method in project junit-interface by sbt.
the class RunSettings method decodeScalaName.
private static String decodeScalaName(String name) {
try {
Class<?> cl = Class.forName("scala.reflect.NameTransformer");
Method m = cl.getMethod("decode", String.class);
String decoded = (String) m.invoke(null, name);
return decoded == null ? name : decoded;
} catch (Throwable t) {
//t.printStackTrace(System.err);
return name;
}
}
use of java.lang.reflect.Method in project jadx by skylot.
the class IntegrationTest method runAutoCheck.
private void runAutoCheck(String clsName) {
try {
// run 'check' method from original class
Class<?> origCls;
try {
origCls = Class.forName(clsName);
} catch (ClassNotFoundException e) {
// ignore
return;
}
Method checkMth;
try {
checkMth = origCls.getMethod("check");
} catch (NoSuchMethodException e) {
// ignore
return;
}
if (!checkMth.getReturnType().equals(void.class) || !Modifier.isPublic(checkMth.getModifiers()) || Modifier.isStatic(checkMth.getModifiers())) {
fail("Wrong 'check' method");
return;
}
try {
checkMth.invoke(origCls.newInstance());
} catch (InvocationTargetException ie) {
rethrow("Java check failed", ie);
}
// run 'check' method from decompiled class
try {
invoke("check");
} catch (InvocationTargetException ie) {
rethrow("Decompiled check failed", ie);
}
System.out.println("Auto check: PASSED");
} catch (Exception e) {
e.printStackTrace();
fail("Auto check exception: " + e.getMessage());
}
}
use of java.lang.reflect.Method in project jadx by skylot.
the class TestBreakWithLabel method test.
@Test
public void test() throws Exception {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("loop0:"));
assertThat(code, containsOne("break loop0;"));
Method test = getReflectMethod("test", int[][].class, int.class);
int[][] testArray = { { 1, 2 }, { 3, 4 } };
assertTrue((Boolean) invoke(test, testArray, 3));
assertFalse((Boolean) invoke(test, testArray, 5));
}
use of java.lang.reflect.Method in project nokogiri by sparklemotion.
the class NokogiriHelpers method nkf.
// This method is used from HTML documents. HTML meta tag with encoding specification
// might appear after non-ascii characters are used. For example, a title tag before
// a meta tag. In such a case, Xerces encodes characters in UTF-8 without seeing meta tag.
// Nokogiri uses NKF library to convert characters correct encoding. This means the method
// works only for JIS/Shift_JIS/EUC-JP.
private static CharSequence nkf(ThreadContext context, Charset encoding, CharSequence str) {
final Ruby runtime = context.getRuntime();
final ByteList opt;
if (NokogiriHelpers.shift_jis.compareTo(encoding) == 0)
opt = _Sw;
else if (NokogiriHelpers.jis.compareTo(encoding) == 0)
opt = _Jw;
else if (NokogiriHelpers.euc_jp.compareTo(encoding) == 0)
opt = _Ew;
else
// should not come here. should be treated before this method.
opt = _Ww;
Class nkfClass;
try {
// JRuby 1.7 and later
nkfClass = runtime.getClassLoader().loadClass("org.jruby.ext.nkf.RubyNKF");
} catch (ClassNotFoundException e1) {
try {
// Before JRuby 1.7
nkfClass = runtime.getClassLoader().loadClass("org.jruby.RubyNKF");
} catch (ClassNotFoundException e2) {
return str;
}
}
Method nkf_method;
try {
nkf_method = nkfClass.getMethod("nkf", ThreadContext.class, IRubyObject.class, IRubyObject.class, IRubyObject.class);
RubyString r_str = (RubyString) nkf_method.invoke(null, context, null, runtime.newString(opt), runtime.newString(str.toString()));
return NokogiriHelpers.rubyStringToString(r_str);
} catch (SecurityException e) {
return str;
} catch (NoSuchMethodException e) {
return str;
} catch (IllegalArgumentException e) {
return str;
} catch (IllegalAccessException e) {
return str;
} catch (InvocationTargetException e) {
return str;
}
}
Aggregations