package hitimes;

import java.lang.Math;
import java.lang.System;

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.anno.JRubyConstant;
import org.jruby.runtime.Visibility;

import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyException;
import org.jruby.RubyModule;
import org.jruby.RubyObject;

import org.jruby.exceptions.RaiseException;

import org.jruby.runtime.builtin.IRubyObject;


/**
 * @author <a href="mailto:jeremy@hinegardner.org">Jeremy Hinegardner</a>
 */
@JRubyModule( name = "Hitimes" )
public class Hitimes {

    public static final double INSTANT_CONVERSION_FACTOR = 1000000000d;

    public static RubyClass hitimesIntervalClass;
    
    /**
     * Create the Hitimes module and add it to the Ruby runtime.
     */
    public static RubyModule createHitimesModule( Ruby runtime ) {
        RubyModule mHitimes = runtime.defineModule("Hitimes");
        mHitimes.defineConstant("INSTANT_CONVERSION_FACTOR", runtime.newFloat(INSTANT_CONVERSION_FACTOR));
        mHitimes.defineAnnotatedMethods( Hitimes.class );

        RubyClass  cStandardError = runtime.getStandardError();
        RubyClass  cHitimesError  = mHitimes.defineClassUnder("Error", cStandardError, cStandardError.getAllocator());

        RubyClass  cHitimesStats  = mHitimes.defineClassUnder("Stats", runtime.getObject(), HitimesStats.ALLOCATOR );
        cHitimesStats.defineAnnotatedMethods( HitimesStats.class );

        RubyClass  cHitimesInterval  = mHitimes.defineClassUnder("Interval", runtime.getObject(), HitimesInterval.ALLOCATOR );
        Hitimes.hitimesIntervalClass = cHitimesInterval;
        cHitimesInterval.defineAnnotatedMethods( HitimesInterval.class );

        return mHitimes;
    }

    static RaiseException newHitimesError( Ruby runtime, String message ) {
        RubyClass errorClass = runtime.getModule("Hitimes").getClass( "Error" );
        return new RaiseException( RubyException.newException( runtime, errorClass, message ), true );
    }


    @JRubyMethod( name = "raw_instant", module = true )
    public static IRubyObject rawInstant(ThreadContext context, IRubyObject self) {
        return context.runtime.newFixnum( System.nanoTime() );
    }

}

@@ -73,30 +73,47 @@
 t org.jruby.
-anno.J
+Ruby;%0Aimport org.jruby.
 RubyClass;%0Ai
@@ -132,24 +132,21 @@
 uby.
-anno.JRubyMethod
+RubyException
 ;%0Aim
@@ -156,30 +156,24 @@
 t org.jruby.
-anno.J
 RubyModule;%0A
@@ -193,25 +193,17 @@
 uby.
-anno.JRubyConstan
+RubyObjec
 t;%0Ai
@@ -222,28 +222,24 @@
 uby.
-runtime.Visibility;%0A
+anno.JRubyClass;
 %0Aimp
@@ -244,36 +244,48 @@
 mport org.jruby.
-Ruby
+anno.JRubyMethod
 ;%0Aimport org.jru
@@ -283,33 +283,40 @@
 t org.jruby.
-RubyClass
+anno.JRubyModule
 ;%0Aimport org
@@ -318,37 +318,42 @@
 t org.jruby.
-RubyException
+anno.JRubyConstant
 ;%0Aimport org
@@ -363,50 +363,75 @@
 uby.
-RubyModule;%0Aimport org.jruby.RubyObjec
+exceptions.RaiseException;%0Aimport org.jruby.runtime.ThreadContex
 t;%0A
-%0A
 impo
@@ -447,35 +447,27 @@
 uby.
-exceptions.RaiseException;%0A
+runtime.Visibility;
 %0Aimp

update (missing) imports