Git Product home page Git Product logo

nested_inherited_jruby_include_package

JRuby's include_package (mentioned in https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby) includes Java packages in JRuby on const_missing. However, it does not trickle down to subclasses/submodules nor nested-classes/nested-modules.

nested_inherited_jruby_include_package patches up JRuby to add that capability.

Example (nesting):

require 'nested_inherited_jruby_include_package'

class OuterClass
  include_package java.util
  class InnerClass
    def initialize
      p Arrays.asList(1, 2, 3)
    end
  end
end

OuterClass::InnerClass.new
# prints #<Java::JavaUtil::Arrays::ArrayList:0x233fe9b6>

Example (inheritance):

require 'nested_inherited_jruby_include_package'

class SuperClass
  include_package java.util
end

class SubClass < SuperClass
  def initialize
    p Arrays.asList(1, 2, 3)
  end
end

SubClass.new
# prints #<Java::JavaUtil::Arrays::ArrayList:0x7ce3cb8e>

Example (java inheritance):

module GUI
  include_package 'javax.swing'
  include_package 'java.awt.image' # BufferedImage
  # bellow won't work without accessing BufferedImage before :
  class ShowImage < JFrame
    p BufferedImage.new(10, 20, BufferedImage::TYPE_BYTE_BINARY)
  end
end
# prints #<Java::JavaAwtImage::BufferedImage:0x2f112965>

More examples can be found in:

spec/lib/core/src/main/ruby/jruby/java/core_ext/module_spec.rb

Setup

Add the following to Gemfile:

gem 'nested_inherited_jruby_include_package', '~> 0.3.0'

And, then run:

jruby -S bundle install

If you are not using Bundler, run:

jruby -S gem install nested_inherited_jruby_include_package -v 0.3.0

Then add this line to your code:

require 'nested_inherited_jruby_include_package'

Caveats

This gem relies on Module#const_missing after it aliases it to Module#const_missing_without_nested_inherited_jruby_include_package

As such, it works optimally if your project and loaded gems do not override Module#const_missing

Implementation Note

To avoid method and constant pollution in Module, the implementation intentionally trades off code clarity for lack of pollution by not relying on methods, yet local lambdas, in modularizing logic.

Issue Reporting

This is an early alpha. It has only been used in a couple of projects. As such, there are no guarantees for its functionality. Please report any issues you might discover when using on your own projects.

Change Log

CHANGELOG.md

License

The MIT License

LICENSE.txt

Copyright

Copyright (c) 2020 Andy Maleh

Andy Maleh's Projects

git-tui icon git-tui

Git Text-Based User Interface (Written in Ruby)

glimmer icon glimmer

DSL Framework consisting of a DSL Engine and a Data-Binding Library used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Opal (Pure Ruby Web GUI), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS

glimmer-dsl-fx icon glimmer-dsl-fx

Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library)

glimmer-dsl-libui icon glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.

glimmer-dsl-opal icon glimmer-dsl-opal

Glimmer DSL for Opal (Pure-Ruby Web GUI and Auto-Webifier of Desktop Apps)

glimmer-dsl-swing icon glimmer-dsl-swing

Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library) - Enables development of desktop applications using Java Swing and Java 2D, including vector graphics and AWT geometry.

glimmer-dsl-swt icon glimmer-dsl-swt

Glimmer DSL for SWT (JRuby Desktop Development Cross-Platform Native GUI Framework) - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer!

glimmer-dsl-wx icon glimmer-dsl-wx

Glimmer DSL for WX - Ruby Desktop Development GUI Library for the wxWidgets GUI toolkit and wxruby3 binding

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.