java_override 0.1.3-java → 0.1.4-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -14
- data/Rakefile +1 -1
- data/java_override.gemspec +1 -1
- data/lib/java/override/version.rb +1 -1
- data/test/{test_java_override.rb → java_override_test.rb} +5 -4
- metadata +5 -5
data/README.md
CHANGED
@@ -2,29 +2,33 @@ Java::Override JRuby Module
|
|
2
2
|
===========================
|
3
3
|
|
4
4
|
* [Homepage](https://rubygems.org/gems/java_override)
|
5
|
-
* [Documentation](
|
5
|
+
* [Documentation](https://github.com/szw/java_override/blob/master/README.md)
|
6
6
|
|
7
7
|
Description
|
8
8
|
-----------
|
9
9
|
|
10
|
-
Java::Override is a JRuby module
|
11
|
-
Ruby naming conventions. JRuby allows you to call Java methods (of
|
12
|
-
with Ruby
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
Java::Override is a JRuby module that enables overriding native Java methods with
|
11
|
+
Ruby naming conventions. JRuby allows you to call Java methods (members of native
|
12
|
+
Java classes/interfaces) with Ruby naming style. Therefore you can use *snake_case* and
|
13
|
+
Ruby-like accessors instead of JavaBean ones.
|
14
|
+
|
15
|
+
In JRuby JavaBean accessors are *translated* to their Ruby counterparts
|
16
|
+
(e.g. <code>getFooBar</code> can be accessed via <code>foo\_bar</code>,
|
17
|
+
<code>isFooBar</code> via <code>foo\_bar?</code>, or <code>setFooBar</code> via
|
18
|
+
<code>foo\_bar=</code>). Those methods are added to Java classes as JRuby aliases.
|
19
|
+
However, if we want to override a Java method we cannot define a Ruby-like method
|
20
|
+
because JVM won't see it. JVM performs polymorphic calls on its own, native methods.
|
21
|
+
And so we have to override native Java methods and it doesn't look much pretty
|
22
|
+
in JRuby code.
|
23
|
+
|
24
|
+
But the Java::Override module abolishes this inconvenience. Once included in the subclass
|
25
|
+
it creates aliases to native Java methods and supports inheritance and polymorphism that way.
|
22
26
|
Moreover, it adds proper aliases for Java interfaces included as modules.
|
23
27
|
|
24
28
|
Examples
|
25
29
|
--------
|
26
30
|
|
27
|
-
|
31
|
+
Here is a good looking simple implementation of <code>javax.swing.table.AbstractTableModel</code> class.
|
28
32
|
|
29
33
|
require 'java/override'
|
30
34
|
|
data/Rakefile
CHANGED
data/java_override.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.name = "java_override"
|
7
7
|
gem.version = Java::Override::VERSION
|
8
8
|
gem.summary = %q{Support for Java class and interface inheritance in JRuby}
|
9
|
-
gem.description = %q{Support for Java class and interface inheritance in JRuby. Enable overriding native Java methods with JRuby ones
|
9
|
+
gem.description = %q{Support for Java class and interface inheritance in JRuby. Enable overriding native Java methods with JRuby ones following Ruby naming conventions.}
|
10
10
|
gem.license = "MIT"
|
11
11
|
gem.authors = ["Szymon Wrozynski"]
|
12
12
|
gem.email = "szymon@wrozynski.com"
|
@@ -12,9 +12,8 @@ java_import "TestSuperclass"
|
|
12
12
|
FileUtils.rm 'TestInterface.class'
|
13
13
|
FileUtils.rm 'TestSuperclass.class'
|
14
14
|
|
15
|
-
class
|
15
|
+
class JavaOverrideTest < Test::Unit::TestCase
|
16
16
|
def setup
|
17
|
-
@superclass = TestSuperclass.new
|
18
17
|
@my_class = MyClass.new
|
19
18
|
end
|
20
19
|
|
@@ -35,8 +34,10 @@ class TestJavaOverride < Test::Unit::TestCase
|
|
35
34
|
assert_equal "MyClassGetter: MyClassSetter: FOO", @my_class.foo
|
36
35
|
assert_equal "MyClassGetter: MyClassSetter: FOO", @my_class.getFoo
|
37
36
|
|
38
|
-
|
39
|
-
|
37
|
+
test_superclass = TestSuperclass.new
|
38
|
+
|
39
|
+
assert test_superclass.foo_bar?
|
40
|
+
assert test_superclass.isFooBar
|
40
41
|
|
41
42
|
refute @my_class.foo_bar?
|
42
43
|
refute @my_class.isFooBar
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: java_override
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Szymon Wrozynski
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
none: false
|
76
76
|
prerelease: false
|
77
77
|
type: :development
|
78
|
-
description: Support for Java class and interface inheritance in JRuby. Enable overriding native Java methods with JRuby ones
|
78
|
+
description: Support for Java class and interface inheritance in JRuby. Enable overriding native Java methods with JRuby ones following Ruby naming conventions.
|
79
79
|
email: szymon@wrozynski.com
|
80
80
|
executables: []
|
81
81
|
extensions: []
|
@@ -93,7 +93,7 @@ files:
|
|
93
93
|
- test/helper.rb
|
94
94
|
- test/java/TestInterface.java
|
95
95
|
- test/java/TestSuperclass.java
|
96
|
-
- test/
|
96
|
+
- test/java_override_test.rb
|
97
97
|
homepage: https://rubygems.org/gems/java_override
|
98
98
|
licenses:
|
99
99
|
- MIT
|
@@ -123,5 +123,5 @@ test_files:
|
|
123
123
|
- test/helper.rb
|
124
124
|
- test/java/TestInterface.java
|
125
125
|
- test/java/TestSuperclass.java
|
126
|
-
- test/
|
126
|
+
- test/java_override_test.rb
|
127
127
|
...
|