<commit_before>package org.ruboto;

import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import dalvik.system.PathClassLoader;

public class JRubyAdapter {
    private static Object ruby;
    private static boolean isDebugBuild = false;
    private static PrintStream output = null;
    private static boolean initialized = false;
    private static String localContextScope = "SINGLETON"; // FIXME(uwe):  Why not CONCURRENT ?  Help needed!
    private static String localVariableBehavior = "TRANSIENT";
    private static String RUBOTO_CORE_VERSION_NAME;

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object receiver, String methodName, Object[] args) {
        runRubyMethod(receiver, methodName, args);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object object, String methodName, Object arg) {
        runRubyMethod(object, methodName, arg);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object object, String methodName) {
        runRubyMethod(object, methodName, new Object[] {});
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType) {
        return runRubyMethod(returnType, receiver, methodName, args);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object arg, Class<T> returnType) {
        return runRubyMethod(returnType, receiver, methodName, arg);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Class<T> returnType) {
        return runRubyMethod(returnType, receiver, methodName);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
     */
    @Deprecated public static void defineGlobalConstant(String name, Object object) {
        put(name, object);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
     */
    @Deprecated public static void defineGlobalVariable(String name, Object object) {
        put(name, object);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
     */
    @Deprecated public static Object exec(String code) {
        try {
            Method runScriptletMethod = ruby.getClass().getMethod("runScriptlet", String.class);
            return runScriptletMethod.invoke(ruby, code);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (java.lang.reflect.InvocationTargetException ite) {
            if (isDebugBuild) {
                throw ((RuntimeException) ite.getCause());
            } else {
                return null;
            }
        }
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
     */
    @Deprecated public static String execute(String code) {
        return runRubyMethod(String.class, exec(code), "inspect");
    }

    public static Object get(String name) {
        try {
            Method getMethod = ruby.getClass().getMethod("get", String.class);
            return getMethod.invoke(ruby, name);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (java.lang.reflect.InvocationTargetException ite) {
            throw new RuntimeException(ite);
        }
    }

    public static String getPlatformVersionName() {
        return RUBOTO_CORE_VERSION_NAME;
    }

    public static String getScriptFilename() {
        return callScriptingContainerMethod(String.class, "getScriptFilename");
    }

    public static Object runRubyMethod(Object receiver, String methodName, Object... args) {
        try {
            // FIXME(uwe):  Simplify when we stop supporting JRuby < 1.7.0
            if (isJRubyPreOneSeven()) {
                if (args.length == 0) {
                    Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Class.class);
                    // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + Object.class + ")");
                    return m.invoke(ruby, receiver, methodName, Object.class);
                } else {
                    Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
                    // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + args + ", " + Object.class + ")");
                    return m.invoke(ruby, receiver, methodName, args, Object.class);<commit_msg>Minor casting changes to allow ruboto apps to compile in AIDE<commit_after>package org.ruboto;

import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import dalvik.system.PathClassLoader;

public class JRubyAdapter {
    private static Object ruby;
    private static boolean isDebugBuild = false;
    private static PrintStream output = null;
    private static boolean initialized = false;
    private static String localContextScope = "SINGLETON"; // FIXME(uwe):  Why not CONCURRENT ?  Help needed!
    private static String localVariableBehavior = "TRANSIENT";
    private static String RUBOTO_CORE_VERSION_NAME;

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object receiver, String methodName, Object[] args) {
        runRubyMethod(receiver, methodName, args);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object object, String methodName, Object arg) {
        runRubyMethod(object, methodName, arg);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Object receiver, String methodName, Object... args)}
     */
    @Deprecated public static void callMethod(Object object, String methodName) {
        runRubyMethod(object, methodName, new Object[] {});
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType) {
        return (T) runRubyMethod(returnType, receiver, methodName, args);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Object arg, Class<T> returnType) {
        return (T) runRubyMethod(returnType, receiver, methodName, arg);
    }

    /**
     * @deprecated  As of Ruboto 0.7.1, replaced by {@link #runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object... args)}
     */
    @SuppressWarnings("unchecked")
    @Deprecated public static <T> T callMethod(Object receiver, String methodName, Class<T> returnType) {
        return (T) runRubyMethod(returnType, receiver, methodName);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
     */
    @Deprecated public static void defineGlobalConstant(String name, Object object) {
        put(name, object);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #put(String name, Object object)}
     */
    @Deprecated public static void defineGlobalVariable(String name, Object object) {
        put(name, object);
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
     */
    @Deprecated public static Object exec(String code) {
        try {
            Method runScriptletMethod = ruby.getClass().getMethod("runScriptlet", String.class);
            return runScriptletMethod.invoke(ruby, code);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (java.lang.reflect.InvocationTargetException ite) {
            if (isDebugBuild) {
                throw ((RuntimeException) ite.getCause());
            } else {
                return null;
            }
        }
    }

    /**
     * @deprecated  As of Ruboto 0.7.0, replaced by {@link #runScriptlet(String code)}
     */
    @Deprecated public static String execute(String code) {
        return (String) runRubyMethod(String.class, exec(code), "inspect");
    }

    public static Object get(String name) {
        try {
            Method getMethod = ruby.getClass().getMethod("get", String.class);
            return getMethod.invoke(ruby, name);
        } catch (NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (java.lang.reflect.InvocationTargetException ite) {
            throw new RuntimeException(ite);
        }
    }

    public static String getPlatformVersionName() {
        return RUBOTO_CORE_VERSION_NAME;
    }

    public static String getScriptFilename() {
        return (String) callScriptingContainerMethod(String.class, "getScriptFilename");
    }

    public static Object runRubyMethod(Object receiver, String methodName, Object... args) {
        try {
            // FIXME(uwe):  Simplify when we stop supporting JRuby < 1.7.0
            if (isJRubyPreOneSeven()) {
                if (args.length == 0) {
                    Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Class.class);
                    // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + Object.class + ")");
                    return m.invoke(ruby, receiver, methodName, Object.class);
                } else {
                    Method m = ruby.getClass().getMethod("callMethod", Object.class, String.class, Object[].class, Class.class);
                    // System.out.println("Calling callMethod(" + receiver + ", " + methodName + ", " + args + ", " + Object.class + ")");
                    return m.invoke(ruby, receiver, methodName, args, Object.class);
{'fraction_non_alphanumeric': 0.11132749107432652, 'fraction_numerical': 0.00551768906199286, 'mean_word_length': 2.8880126182965298, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6945919', 'n_tokens_mistral': 3463, 'n_tokens_neox': 3312, 'n_words': 942}