scala-library-jars 2.8.2-java → 2.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,295 @@
1
+ # encoding: utf-8
2
+
3
+ require 'set'
4
+
5
+
6
+ class Proc
7
+ ARITY_MAP = [
8
+ Java::Scala::Function0,
9
+ Java::Scala::Function1,
10
+ Java::Scala::Function2,
11
+ Java::Scala::Function3,
12
+ Java::Scala::Function4
13
+ ]
14
+
15
+ def to_function
16
+ f = ARITY_MAP[arity].new
17
+ f.define_singleton_method(:apply, self)
18
+ f
19
+ end
20
+ end
21
+
22
+ $make_java_package_module = proc do |name|
23
+ Module.new do
24
+ include_package name.downcase
25
+
26
+ define_singleton_method :const_missing do |const|
27
+ begin
28
+ java_class = JavaUtilities.get_java_class("#{name.downcase}.#{const}")
29
+ proxy_class = JavaUtilities.create_proxy_class(const, java_class, self)
30
+ proxy_class
31
+ rescue => e
32
+ const_set(const, $make_java_package_module.call("#{name.downcase}.#{const.downcase}"))
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ Scala = $make_java_package_module.call(:Scala)
39
+
40
+ # The following is from:
41
+ # http://www.codecommit.com/blog/ruby/integrating-scala-into-jruby
42
+ # http://www.codecommit.com/blog/misc/scala.rb
43
+
44
+ OPERATORS = {
45
+ '=' => '$eq',
46
+ '>' => '$greater',
47
+ '<' => '$less',
48
+ '+' => '$plus',
49
+ '-' => '$minus',
50
+ '*' => '$times',
51
+ '/' => 'div',
52
+ '!' => '$bang',
53
+ '@' => '$at',
54
+ '#' => '$hash',
55
+ '%' => '$percent',
56
+ '^' => '$up',
57
+ '&' => '$amp',
58
+ '~' => '$tilde',
59
+ '?' => '$qmark',
60
+ '|' => '$bar',
61
+ "\\" => '$bslash'
62
+ }
63
+
64
+ module OperatorRewrites
65
+ @__operator_rewrites_included__ = true
66
+
67
+ alias_method :__old_method_missing_in_scala_rb__, :method_missing
68
+ def method_missing(sym, *args)
69
+ str = sym.to_s
70
+ str = $&[1] + '_=' if str =~ /^(.*[^\]=])=$/
71
+
72
+ OPERATORS.each { |from, to| str.gsub!(from, to) }
73
+
74
+ gen_with_args = proc do |name, args|
75
+ code = "#{name}("
76
+ unless args.empty?
77
+ for i in 0..(args.size - 2)
78
+ code += "args[#{i}], "
79
+ end
80
+ code += "args[#{args.size - 1}]"
81
+ end
82
+ code += ')'
83
+ end
84
+
85
+ if str == '[]'
86
+ eval(gen_with_args.call('apply', args))
87
+ elsif sym.to_s == '[]='
88
+ eval gen_with_args.call('update', args) # doesn't work right
89
+ elsif sym == :call and type_of_scala_function self
90
+ eval(gen_with_args.call('apply', args))
91
+ elsif sym == :arity and (ar = type_of_scala_function self) != nil
92
+ ar
93
+ elsif sym == :binding and type_of_scala_function self
94
+ binding
95
+ elsif sym == :to_proc and type_of_scala_function self
96
+ self
97
+ elsif methods.include? str
98
+ send(str.to_sym, args)
99
+ else
100
+ __old_method_missing_in_scala_rb__(sym, args)
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def type_of_scala_function(obj)
107
+ if obj.java_kind_of? Scala::Function0 then 0
108
+ elsif obj.java_kind_of? Scala::Function1 then 1
109
+ elsif obj.java_kind_of? Scala::Function2 then 2
110
+ elsif obj.java_kind_of? Scala::Function3 then 3
111
+ elsif obj.java_kind_of? Scala::Function4 then 4
112
+ elsif obj.java_kind_of? Scala::Function5 then 5
113
+ elsif obj.java_kind_of? Scala::Function6 then 6
114
+ elsif obj.java_kind_of? Scala::Function7 then 7
115
+ elsif obj.java_kind_of? Scala::Function8 then 8
116
+ elsif obj.java_kind_of? Scala::Function9 then 9
117
+ elsif obj.java_kind_of? Scala::Function10 then 10
118
+ elsif obj.java_kind_of? Scala::Function11 then 11
119
+ elsif obj.java_kind_of? Scala::Function12 then 12
120
+ elsif obj.java_kind_of? Scala::Function13 then 13
121
+ elsif obj.java_kind_of? Scala::Function14 then 14
122
+ elsif obj.java_kind_of? Scala::Function15 then 15
123
+ elsif obj.java_kind_of? Scala::Function16 then 16
124
+ elsif obj.java_kind_of? Scala::Function17 then 17
125
+ elsif obj.java_kind_of? Scala::Function18 then 18
126
+ elsif obj.java_kind_of? Scala::Function19 then 19
127
+ elsif obj.java_kind_of? Scala::Function20 then 20
128
+ elsif obj.java_kind_of? Scala::Function21 then 21
129
+ elsif obj.java_kind_of? Scala::Function22 then 22
130
+ else nil
131
+ end
132
+ end
133
+ end
134
+
135
+ class Java::JavaLang::Object
136
+ include OperatorRewrites
137
+ end
138
+
139
+ class Module
140
+ alias_method :__old_include_in_scala_rb__, :include
141
+ def include(*modules)
142
+ modules.each do |m|
143
+ clazz = nil
144
+ begin
145
+ if m.respond_to?(:java_class) && m.java_class.interface?
146
+ cl = m.java_class.class_loader
147
+ mixin_methods_for_trait(cl, cl.load_class(m.java_class.to_s))
148
+ __old_include_in_scala_rb__(OperatorRewrites) unless @__operator_rewrites_included__
149
+ end
150
+ rescue => e
151
+ puts "*** #{e.message}"
152
+ end
153
+
154
+ if defined? @@trait_methods
155
+ define_method :scala_reflective_trait_methods do
156
+ @@trait_methods
157
+ end
158
+ end
159
+ end
160
+
161
+ modules.each {|m| __old_include_in_scala_rb__(m) }
162
+ end
163
+
164
+ def mixin_methods_for_trait(cl, trait_class, done=Set.new)
165
+ return if done.include?(trait_class)
166
+ done << trait_class
167
+
168
+ clazz = cl.loadClass("#{trait_class.name}$class")
169
+
170
+ trait_class.interfaces.each do |i|
171
+ mixin_methods_for_trait(cl, i, done) rescue nil
172
+ end
173
+
174
+ clazz.declared_methods.each do |meth|
175
+ mod = meth.modifiers
176
+ if java.lang.reflect.Modifier.isStatic(mod) and java.lang.reflect.Modifier.isPublic(mod)
177
+ @@trait_methods ||= []
178
+ unless meth.name.include?('$')
179
+ module_eval <<-CODE
180
+ def #{meth.name}(*args, &block)
181
+ args.insert(0, self)
182
+ args << block unless block.nil?
183
+
184
+ args.map! do |a|
185
+ if defined? a.java_object
186
+ a.java_object
187
+ else
188
+ a
189
+ end
190
+ end
191
+
192
+ begin
193
+ scala_reflective_trait_methods[#{@@trait_methods.size}].invoke(nil, args.to_java)
194
+ rescue java.lang.reflect.InvocationTargetException => e
195
+ # TODO change over for 1.1.4
196
+ raise e.cause.message.to_s
197
+ end
198
+ end
199
+ CODE
200
+
201
+ @@trait_methods << meth
202
+ else
203
+ define_method meth.name do |*args| # fallback for methods with special names
204
+ args.insert(0, self)
205
+
206
+ begin
207
+ meth.invoke(nil, args.to_java)
208
+ rescue java.lang.reflectInvocationTargetException => e
209
+ raise e.cause.message.to_s
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ class BoxedRubyArray
219
+ include Scala::Collection::IndexedSeq
220
+
221
+ def initialize(delegate)
222
+ @delegate = delegate
223
+ end
224
+
225
+ def apply(i)
226
+ @delegate[i]
227
+ end
228
+
229
+ def length
230
+ @delegate.size
231
+ end
232
+ end
233
+
234
+ class Array
235
+ def to_scala
236
+ BoxedRubyArray.new self
237
+ end
238
+ end
239
+
240
+ class BoxedRubyHash
241
+ include Scala::Collection::Mutable::Map
242
+
243
+ def initialize(delegate)
244
+ @delegate = delegate
245
+ end
246
+
247
+ define_method '$minus$eq' do |e|
248
+ @delegate.delete e
249
+ end
250
+
251
+ def get(k)
252
+ if @delegate.has_key? k
253
+ Scala::Some.new @delegate[k]
254
+ else
255
+ clazz = Scala::None.java_class.class_loader.loadClass('scala.None$')
256
+ clazz.getField('MODULE$').get nil
257
+ end
258
+ end
259
+
260
+ def update(k, v)
261
+ @delegate[k] = v
262
+ nil
263
+ end
264
+
265
+ def elements
266
+ BoxedRubyHashIterator.new @delegate
267
+ end
268
+ end
269
+
270
+ class BoxedRubyHashIterator
271
+ include Scala::Collection::Iterator
272
+
273
+ def initialize(delegate)
274
+ @delegate = delegate
275
+ @keys = delegate.keys
276
+ @index = 0
277
+ end
278
+
279
+ def hasNext
280
+ @index < @keys.size
281
+ end
282
+
283
+ define_method :next do
284
+ back = @delegate[@keys[@index]]
285
+ @index += 1
286
+
287
+ back
288
+ end
289
+ end
290
+
291
+ class Hash
292
+ def to_scala
293
+ BoxedRubyHash.new self
294
+ end
295
+ end
Binary file
@@ -2,4 +2,6 @@
2
2
 
3
3
  require 'java'
4
4
 
5
- Dir["#{File.expand_path('..', __FILE__)}/*.jar"].each { |jar| require(jar) }
5
+ Dir["#{File.expand_path('..', __FILE__)}/*.jar"].each { |jar| require(jar) }
6
+
7
+ require 'scala-integration'
metadata CHANGED
@@ -2,20 +2,21 @@
2
2
  name: scala-library-jars
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.8.2
5
+ version: 2.9.0
6
6
  platform: java
7
7
  authors:
8
- - Theo Hultberg
8
+ - Theo Hultberg
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-05 00:00:00 Z
13
+ date: 2011-08-07 00:00:00 +02:00
14
+ default_executable:
14
15
  dependencies: []
15
16
 
16
17
  description: ""
17
18
  email:
18
- - theo@iconara.net
19
+ - theo@iconara.net
19
20
  executables: []
20
21
 
21
22
  extensions: []
@@ -23,8 +24,10 @@ extensions: []
23
24
  extra_rdoc_files: []
24
25
 
25
26
  files:
26
- - lib/scala-library-jars.rb
27
- - lib/scala-library-2.8.2.jar
27
+ - lib/scala-integration.rb
28
+ - lib/scala-library-jars.rb
29
+ - lib/scala-library-2.9.0.jar
30
+ has_rdoc: true
28
31
  homepage: http://scala-lang.org
29
32
  licenses: []
30
33
 
@@ -32,23 +35,23 @@ post_install_message:
32
35
  rdoc_options: []
33
36
 
34
37
  require_paths:
35
- - lib
38
+ - lib
36
39
  required_ruby_version: !ruby/object:Gem::Requirement
37
40
  none: false
38
41
  requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: "0"
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
42
45
  required_rubygems_version: !ruby/object:Gem::Requirement
43
46
  none: false
44
47
  requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
48
51
  requirements: []
49
52
 
50
53
  rubyforge_project: scala-library-jars
51
- rubygems_version: 1.8.11
54
+ rubygems_version: 1.5.1
52
55
  signing_key:
53
56
  specification_version: 3
54
57
  summary: Scala Library JARs
Binary file