jtor-stdlib 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0fdfc6074c7499532f2e3dd014930bba384aede
4
+ data.tar.gz: fdf32a96588e40df135d24c36155d7c673c872f2
5
+ SHA512:
6
+ metadata.gz: 894a61cbb2d23e7b24d7aa98323fdeee47fe09526951b2fdaa850855bc7f0aa599958599bc6b8cb2791dc45557c9d4a2c6134f66e1ac36256edff093d9ef40d4
7
+ data.tar.gz: f1e5f839f16d855fbcf19d59aae44305a082247e1f9b047e9950a84d269da78f1bd080b472ffd57d6ccf9fa72be3e04b7c9e85d998c6f704577f3087912241ba
@@ -0,0 +1,6 @@
1
+ warn 'Loading jtor-stdlib in a non-JRuby interpreter' unless defined? JRUBY_VERSION
2
+
3
+ require 'java'
4
+
5
+ require 'jtor-stdlib/base'
6
+ require 'jtor-stdlib/jtor_import'
@@ -0,0 +1,45 @@
1
+ module Jtor
2
+ module StdLib
3
+ class Base
4
+ @@_lookup = {}
5
+
6
+ class << self
7
+ # Method overloading is not a ruby thing, so we implement a pseudo-lookup
8
+ # mechanism for method based on the type/count of their args
9
+ def add_java_method(name, param_types, &block)
10
+ add_method_to_lookup(name, param_types, &block)
11
+ unless method_defined?(name)
12
+ define_method(name) { |*args| self.class.lookup(name, *args) }
13
+ end
14
+ end
15
+
16
+ def lookup(name, *args)
17
+ if @@_lookup[name]
18
+ @@_lookup[name].each do |param_types, method|
19
+ # NOTE: This is an oversimplification of the way Java determines
20
+ # which method to invoke. I may work further into this later (see
21
+ # http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12)
22
+ next unless params_match(param_types, args)
23
+ return method.call(*args)
24
+ end
25
+ end
26
+ method_missing(name, *args)
27
+ end
28
+
29
+ def params_match(types, values)
30
+ # TODO: Handle var args (...)
31
+ types.each_with_index do |type, index|
32
+ value = values[index]
33
+ return false unless value.is_a?(type) || value.to_java.is_a?(type)
34
+ end
35
+ true
36
+ end
37
+
38
+ def add_method_to_lookup(name, param_types, &block)
39
+ @@_lookup[name] ||= {}
40
+ @@_lookup[name][param_types] = block
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ def jtor_import(import_string)
2
+ require import_string.split('.').join('/')
3
+ rescue LoadError
4
+ # :O `eval` 3spooky5me
5
+ java_import eval(import_string)
6
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtor-stdlib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: java
6
+ authors:
7
+ - Alejandro Rodríguez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem will be included on the Gemfile of your translated JtoR project
14
+ email: alejandroluis24@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/jtor-stdlib.rb
20
+ - lib/jtor-stdlib/base.rb
21
+ - lib/jtor-stdlib/jtor_import.rb
22
+ homepage: https://gitlab.com/eReGeBe/jtor-stdlib
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.0
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: stdlib for JtoR
46
+ test_files: []