From 0f587b0e39797a43f362b43b00d71ee08157c383 Mon Sep 17 00:00:00 2001 From: Karol Bucek Date: Mon, 6 Jul 2020 13:42:55 +0200 Subject: [refactor] drop old JRuby 1.7 compat code --- java/src/json/ext/Generator.java | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'java') diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index 24bf049..b5dd73b 100644 --- a/java/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java @@ -10,13 +10,10 @@ import org.jruby.RubyArray; import org.jruby.RubyBasicObject; import org.jruby.RubyBignum; import org.jruby.RubyBoolean; -import org.jruby.RubyClass; import org.jruby.RubyFixnum; import org.jruby.RubyFloat; import org.jruby.RubyHash; -import org.jruby.RubyNumeric; import org.jruby.RubyString; -import org.jruby.runtime.ClassIndex; import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; @@ -32,8 +29,7 @@ public final class Generator { static RubyString generateJson(ThreadContext context, T object, Handler handler, IRubyObject[] args) { - Session session = new Session(context, args.length > 0 ? args[0] - : null); + Session session = new Session(context, args.length > 0 ? args[0] : null); return session.infect(handler.generateNew(session, object)); } @@ -43,7 +39,7 @@ public final class Generator { */ static RubyString generateJson(ThreadContext context, T object, IRubyObject[] args) { - Handler handler = getHandlerFor(context.getRuntime(), object); + Handler handler = getHandlerFor(context.runtime, object); return generateJson(context, object, handler, args); } @@ -55,33 +51,18 @@ public final class Generator { generateJson(ThreadContext context, T object, GeneratorState config) { Session session = new Session(context, config); - Handler handler = getHandlerFor(context.getRuntime(), object); + Handler handler = getHandlerFor(context.runtime, object); return handler.generateNew(session, object); } - // NOTE: drop this once Ruby 1.9.3 support is gone! - private static final int FIXNUM = 1; - private static final int BIGNUM = 2; - private static final int ARRAY = 3; - private static final int STRING = 4; - private static final int NIL = 5; - private static final int TRUE = 6; - private static final int FALSE = 7; - private static final int HASH = 10; - private static final int FLOAT = 11; - // hard-coded due JRuby 1.7 compatibility - // https://github.com/jruby/jruby/blob/1.7.27/core/src/main/java/org/jruby/runtime/ClassIndex.java - /** * Returns the best serialization handler for the given object. */ // Java's generics can't handle this satisfactorily, so I'll just leave // the best I could get and ignore the warnings @SuppressWarnings("unchecked") - private static - Handler getHandlerFor(Ruby runtime, T object) { - switch (((RubyBasicObject) object).getNativeTypeIndex()) { - // can not use getNativeClassIndex due 1.7 compatibility + private static Handler getHandlerFor(Ruby runtime, T object) { + switch (((RubyBasicObject) object).getNativeClassIndex()) { case NIL : return (Handler) NIL_HANDLER; case TRUE : return (Handler) TRUE_HANDLER; case FALSE : return (Handler) FALSE_HANDLER; -- cgit v1.2.1