Modified: trunk/rcov4jr/java/src/RcovrtService.java (1031 => 1032)
--- trunk/rcov4jr/java/src/RcovrtService.java 2008-06-23 20:10:26 UTC (rev 1031)
+++ trunk/rcov4jr/java/src/RcovrtService.java 2008-06-27 02:06:47 UTC (rev 1032)
@@ -3,43 +3,34 @@
import org.jruby.RubyFixnum;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
+import org.jruby.RubyObjectAdapter;
import org.jruby.RubySymbol;
import org.jruby.exceptions.RaiseException;
-import org.jruby.runtime.CallbackFactory;
+import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.BasicLibraryService;
+import org.jruby.javasupport.JavaEmbedUtils;
public class RcovrtService implements BasicLibraryService {
+
+ private static RubyObjectAdapter rubyApi;
public boolean basicLoad(Ruby runtime) {
- RubyModule rcov = runtime.getModule("Rcov");
- if (rcov == null) {
- rcov = runtime.defineModule("Rcov");
- }
- RubyModule rcov__ = (RubyModule) rcov.getConstantAt("RCOV__");
- if (rcov__ == null) {
- rcov__ = rcov.defineModuleUnder("RCOV__");
- }
+ RubyModule rcov = runtime.getOrCreateModule("Rcov");
+ RubyModule rcov__ = runtime.defineModuleUnder("RCOV__", rcov);
+
IRubyObject sl = runtime.getObject().getConstantAt("SCRIPT_LINES__");
- if (sl == null)
+ if (sl == null) {
runtime.getObject().setConstant("SCRIPT_LINES__", RubyHash.newHash(runtime));
-
- CallbackFactory rcovrt_cb = runtime
- .callbackFactory(RcovrtService.class);
- rcov__.getMetaClass().defineMethod("ABI", rcovrt_cb.getFastSingletonMethod("getAbi"));
- rcov__.getMetaClass().defineMethod("generate_callsite_info", rcovrt_cb.getFastSingletonMethod("generateCallsiteInfo"));
- rcov__.getMetaClass().defineMethod("install_callsite_hook", rcovrt_cb.getFastSingletonMethod("installCallsiteHook"));
- rcov__.getMetaClass().defineMethod("remove_callsite_hook", rcovrt_cb.getFastSingletonMethod("removeCallsiteHook"));
- rcov__.getMetaClass().defineMethod("generate_coverage_info", rcovrt_cb.getFastSingletonMethod("generateCoverageInfo"));
- rcov__.getMetaClass().defineMethod("install_coverage_hook", rcovrt_cb.getFastSingletonMethod("installCoverageHook"));
- rcov__.getMetaClass().defineMethod("remove_coverage_hook", rcovrt_cb.getFastSingletonMethod("removeCoverageHook"));
- rcov__.getMetaClass().defineMethod("reset_coverage", rcovrt_cb.getFastSingletonMethod("resetCoverage"));
- rcov__.getMetaClass().defineMethod("reset_callsite", rcovrt_cb.getFastSingletonMethod("resetCallsite"));
-
+ }
+
+ rubyApi = JavaEmbedUtils.newObjectAdapter();
+ rcov__.defineAnnotatedMethods(RcovrtService.class);
return true;
}
+ @JRubyMethod(name="reset_callsite", meta = true)
public static IRubyObject resetCallsite(IRubyObject recv) {
CallsiteHook hook = CallsiteHook.getCallsiteHook();
if (hook.isActive()) {
@@ -50,6 +41,7 @@
return hook.resetDefsites();
}
+ @JRubyMethod(name="reset_coverage", meta = true)
public static IRubyObject resetCoverage(IRubyObject recv) {
CoverageHook hook = CoverageHook.getCoverageHook();
if (hook.isActive()) {
@@ -60,17 +52,21 @@
return hook.resetCoverage(recv.getRuntime());
}
+ @JRubyMethod(name="remove_coverage_hook", meta = true)
public static IRubyObject removeCoverageHook(IRubyObject recv) {
return removeRcovHook(recv, CoverageHook.getCoverageHook());
}
+ @JRubyMethod(name="install_coverage_hook", meta = true)
public static IRubyObject installCoverageHook(IRubyObject recv) {
return installRcovHook(recv, CoverageHook.getCoverageHook());
}
/**
- TODO: I think this is broken. I'm not sure why, but recreating cover all the time seems bad.
+ TODO: I think this is broken. I'm not sure why, but recreating
+ cover all the time seems bad.
*/
+ @JRubyMethod(name="generate_coverage_info", meta = true)
public static IRubyObject generateCoverageInfo(IRubyObject recv) {
IRubyObject cover = CoverageHook.getCoverageHook().getCover(recv.getRuntime()).dup();
RubyModule rcov__ = (RubyModule) recv.getRuntime().getModule("Rcov").getConstant("RCOV__");
@@ -82,18 +78,22 @@
return cover;
}
+ @JRubyMethod(name="remove_callsite_hook", meta = true)
public static IRubyObject removeCallsiteHook(IRubyObject recv) {
return removeRcovHook( recv, CallsiteHook.getCallsiteHook() );
}
+ @JRubyMethod(name="install_callsite_hook", meta = true)
public static IRubyObject installCallsiteHook(IRubyObject recv) {
return installRcovHook( recv, CallsiteHook.getCallsiteHook() );
}
+ @JRubyMethod(name="generate_callsite_info", meta = true)
public static IRubyObject generateCallsiteInfo(IRubyObject recv) {
return CallsiteHook.getCallsiteHook().getCallsiteInfo( recv.getRuntime() ).dup();
}
+ @JRubyMethod(name="ABI", meta = true)
public static IRubyObject getAbi( IRubyObject recv ) {
RubyArray ary = recv.getRuntime().newArray();
ary.add( RubyFixnum.int2fix( recv.getRuntime(), 2L ) );