Search in sources :

Example 31 with Method

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;
    }
}
Also used : PrintStream(java.io.PrintStream) Method(java.lang.reflect.Method)

Example 32 with Method

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;
    }
}
Also used : Method(java.lang.reflect.Method)

Example 33 with Method

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());
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) URISyntaxException(java.net.URISyntaxException) JadxException(jadx.core.utils.exceptions.JadxException) CodegenException(jadx.core.utils.exceptions.CodegenException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 34 with Method

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));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) Method(java.lang.reflect.Method) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 35 with Method

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;
    }
}
Also used : ByteList(org.jruby.util.ByteList) RubyString(org.jruby.RubyString) ThreadContext(org.jruby.runtime.ThreadContext) Method(java.lang.reflect.Method) IRubyObject(org.jruby.runtime.builtin.IRubyObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) RubyClass(org.jruby.RubyClass) Ruby(org.jruby.Ruby)

Aggregations

Method (java.lang.reflect.Method)8797 Test (org.junit.Test)1772 InvocationTargetException (java.lang.reflect.InvocationTargetException)1084 ArrayList (java.util.ArrayList)665 Field (java.lang.reflect.Field)611 IOException (java.io.IOException)549 HashMap (java.util.HashMap)352 Map (java.util.Map)290 List (java.util.List)275 PropertyDescriptor (java.beans.PropertyDescriptor)253 Annotation (java.lang.annotation.Annotation)212 Type (java.lang.reflect.Type)202 HashSet (java.util.HashSet)199 File (java.io.File)173 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)170 BeanInfo (java.beans.BeanInfo)166 ParameterizedType (java.lang.reflect.ParameterizedType)132 Constructor (java.lang.reflect.Constructor)131 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128