summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorKarol Bucek <self@kares.org>2020-07-06 13:42:55 +0200
committerKarol Bucek <self@kares.org>2020-07-06 13:42:55 +0200
commit0f587b0e39797a43f362b43b00d71ee08157c383 (patch)
tree00532cf4b07a2e7deb2b08dc1fbb997faea9c566 /java
parent0662debc5272186a357c16ed5164907cd97d7040 (diff)
downloadjson-0f587b0e39797a43f362b43b00d71ee08157c383.tar.gz
[refactor] drop old JRuby 1.7 compat code
Diffstat (limited to 'java')
-rw-r--r--java/src/json/ext/Generator.java29
1 files changed, 5 insertions, 24 deletions
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 <T extends IRubyObject> RubyString
generateJson(ThreadContext context, T object,
Handler<? super T> 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 <T extends IRubyObject> RubyString
generateJson(ThreadContext context, T object, IRubyObject[] args) {
- Handler<? super T> handler = getHandlerFor(context.getRuntime(), object);
+ Handler<? super T> 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<? super T> handler = getHandlerFor(context.getRuntime(), object);
+ Handler<? super T> 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 <T extends IRubyObject>
- Handler<? super T> getHandlerFor(Ruby runtime, T object) {
- switch (((RubyBasicObject) object).getNativeTypeIndex()) {
- // can not use getNativeClassIndex due 1.7 compatibility
+ private static <T extends IRubyObject> Handler<? super T> 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;