Skip to content

Commit 3ade585

Browse files
authored
Merge pull request #611 from headius/jruby_cleanup
Minor cleanup of JRuby ext
2 parents 2da715a + d1316dc commit 3ade585

5 files changed

Lines changed: 116 additions & 149 deletions

File tree

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ if RUBY_PLATFORM =~ /java/
2121
# this is basically the same as running from the commandline:
2222
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
2323
Maven::Ruby::Maven.new.exec('dependency:build-classpath', "-Dsnakeyaml.version=#{Psych::DEFAULT_SNAKEYAML_VERSION}", '-Dverbose=true')
24-
ext.source_version = '1.7'
25-
ext.target_version = '1.7'
24+
ext.source_version = '1.8'
25+
ext.target_version = '1.8'
2626
ext.classpath = File.read('pkg/classpath')
2727
ext.ext_dir = 'ext/java'
2828
end

ext/java/org/jruby/ext/psych/PsychEmitter.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@
7373
public class PsychEmitter extends RubyObject {
7474
public static void initPsychEmitter(Ruby runtime, RubyModule psych) {
7575
RubyClass psychHandler = runtime.defineClassUnder("Handler", runtime.getObject(), runtime.getObject().getAllocator(), psych);
76-
RubyClass psychEmitter = runtime.defineClassUnder("Emitter", psychHandler, new ObjectAllocator() {
77-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
78-
return new PsychEmitter(runtime, klazz);
79-
}
80-
}, psych);
76+
RubyClass psychEmitter = runtime.defineClassUnder("Emitter", psychHandler, PsychEmitter::new, psych);
8177

8278
psychEmitter.defineAnnotatedMethods(PsychEmitter.class);
8379
}
@@ -135,16 +131,19 @@ public IRubyObject end_stream(ThreadContext context) {
135131

136132
@JRubyMethod
137133
public IRubyObject start_document(ThreadContext context, IRubyObject _version, IRubyObject tags, IRubyObject implicit) {
134+
Ruby runtime = context.runtime;
135+
138136
DumperOptions.Version version = null;
139137
boolean implicitBool = implicit.isTrue();
140138
Map<String, String> tagsMap = null;
141139

142-
TypeConverter.checkType(context, _version, context.runtime.getArray());
140+
RubyClass arrayClass = runtime.getArray();
141+
TypeConverter.checkType(context, _version, arrayClass);
143142

144143
RubyArray versionAry = _version.convertToArray();
145144
if (versionAry.size() == 2) {
146-
int versionInt0 = (int)versionAry.eltInternal(0).convertToInteger().getLongValue();
147-
int versionInt1 = (int)versionAry.eltInternal(1).convertToInteger().getLongValue();
145+
int versionInt0 = versionAry.eltInternal(0).convertToInteger().getIntValue();
146+
int versionInt1 = versionAry.eltInternal(1).convertToInteger().getIntValue();
148147

149148
if (versionInt0 == 1) {
150149
if (versionInt1 == 0) {
@@ -154,20 +153,20 @@ public IRubyObject start_document(ThreadContext context, IRubyObject _version, I
154153
}
155154
}
156155
if (version == null) {
157-
throw context.runtime.newArgumentError("invalid YAML version: " + versionAry);
156+
throw runtime.newArgumentError("invalid YAML version: " + versionAry);
158157
}
159158
}
160159

161160
if (!tags.isNil()) {
162-
TypeConverter.checkType(context, tags, context.runtime.getArray());
161+
TypeConverter.checkType(context, tags, arrayClass);
163162

164163
RubyArray tagsAry = tags.convertToArray();
165164
if (tagsAry.size() > 0) {
166165
tagsMap = new HashMap<>(tagsAry.size());
167166
for (int i = 0; i < tagsAry.size(); i++) {
168167
RubyArray tagsTuple = tagsAry.eltInternal(i).convertToArray();
169168
if (tagsTuple.size() != 2) {
170-
throw context.runtime.newRuntimeError("tags tuple must be of length 2");
169+
throw runtime.newRuntimeError("tags tuple must be of length 2");
171170
}
172171
IRubyObject key = tagsTuple.eltInternal(0);
173172
IRubyObject value = tagsTuple.eltInternal(1);

ext/java/org/jruby/ext/psych/PsychLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
105105
PsychParser.initPsychParser(runtime, psych);
106106
PsychEmitter.initPsychEmitter(runtime, psych);
107107
PsychToRuby.initPsychToRuby(runtime, psych);
108-
PsychYamlTree.initPsychYamlTree(runtime, psych);
109108
}
110109

111110
public enum YAMLEncoding {

0 commit comments

Comments
 (0)