@RubyLevelMethod(name = "__load_with_reflection__", module = true) public static RubyValue loadWithReflection(RubyValue receiver, RubyValue arg, RubyBlock block) { String required_file = arg.toStr(); String name = NameFactory.createMainClassName(required_file); try { Class c = Class.forName(name); Object o = c.newInstance(); RubyProgram p = (RubyProgram) o; // $".push(file_name) unless $".include?(file_name) RubyArray a = (RubyArray) GlobalVariables.get("$\""); if (a.include(arg) == RubyConstant.QFALSE) { a.push(arg); } p.invoke(); return RubyConstant.QTRUE; } catch (ClassNotFoundException e) { return RubyConstant.QFALSE; } catch (InstantiationException e) { return RubyConstant.QFALSE; } catch (IllegalAccessException e) { return RubyConstant.QFALSE; } }
@RubyLevelMethod(name = "require_java", alias = "import", module = true) public static RubyValue requireJava(RubyValue receiver, RubyValue arg, RubyBlock block) { String className = arg.toStr(); String[] names = packagePattern.split(className); String name = names[names.length - 1]; if (name.equals("*")) { JavaClass.addPackage(className.substring(0, className.lastIndexOf('.'))); } else { try { Class clazz = Class.forName(className); JavaClass.createJavaClass(clazz); } catch (ClassNotFoundException e) { throw new RubyException("Couldn't find class " + className); } } RubyRuntime.setJavaSupported(true); return RubyConstant.QTRUE; }