forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_package_module_template.rb
More file actions
43 lines (38 loc) · 1.41 KB
/
java_package_module_template.rb
File metadata and controls
43 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module JavaPackageModuleTemplate
# don't undefine important methods
@@keep = /^(__|<|>|=)|^(class|const_missing|inspect|method_missing|to_s)$|(\?|!|=)$/
# don't alias "special" methods
@@no_alias = /^(eval|module_eval|class_eval|instance_eval|module_exec|class_exec|instance_exec|binding|local_variables)$/
class << self
# blank-slate logic relocated from org.jruby.javasupport.Java
instance_methods.each do |meth|
unless meth.to_s =~ @@keep
# keep aliased methods for those we'll undef, for use by IRB and other utilities
unless meth.to_s =~ @@no_alias || method_defined?(method_alias = :"__#{meth}__")
alias_method method_alias, meth
end
undef_method meth
end
end
def __block__(name)
if (name_str = name.to_s) !~ @@keep
(class<<self;self;end).__send__(:undef_method, name) rescue nil
end
end
def const_missing(const)
JavaUtilities.get_proxy_class(@package_name + const.to_s)
end
private :const_missing
def method_missing(sym, *args)
raise ArgumentError, "Java package `#{package_name}' does not have a method `#{sym}'" unless args.empty?
JavaUtilities.get_proxy_or_package_under_package self, sym
end
private :method_missing
def package_name
# strip off trailing .
@package_name[0..-2]
end
end
end
# pull in the default package
JavaUtilities.get_package_module("Default")