cheri 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +98 -0
- data/Rakefile +121 -0
- data/examples/hello_world_1.rb +28 -0
- data/examples/table_1.rb +44 -0
- data/lib/cheri/awt.rb +41 -0
- data/lib/cheri/builder.rb +31 -0
- data/lib/cheri/builder/awt/connecter.rb +63 -0
- data/lib/cheri/builder/awt/constants.rb +1003 -0
- data/lib/cheri/builder/awt/main.rb +191 -0
- data/lib/cheri/builder/awt/types.rb +220 -0
- data/lib/cheri/builder/base.rb +533 -0
- data/lib/cheri/builder/config.rb +187 -0
- data/lib/cheri/builder/connecter.rb +386 -0
- data/lib/cheri/builder/context.rb +655 -0
- data/lib/cheri/builder/generator.rb +425 -0
- data/lib/cheri/builder/html/charsets.rb +154 -0
- data/lib/cheri/builder/html/common.rb +32 -0
- data/lib/cheri/builder/html/connecter.rb +57 -0
- data/lib/cheri/builder/html/element.rb +156 -0
- data/lib/cheri/builder/html/main.rb +116 -0
- data/lib/cheri/builder/html/types.rb +123 -0
- data/lib/cheri/builder/main.rb +483 -0
- data/lib/cheri/builder/swing/connecter.rb +141 -0
- data/lib/cheri/builder/swing/constants.rb +420 -0
- data/lib/cheri/builder/swing/main.rb +446 -0
- data/lib/cheri/builder/swing/types.rb +270 -0
- data/lib/cheri/builder/xml/charsets.rb +154 -0
- data/lib/cheri/builder/xml/common.rb +32 -0
- data/lib/cheri/builder/xml/connecter.rb +42 -0
- data/lib/cheri/builder/xml/element.rb +189 -0
- data/lib/cheri/builder/xml/main.rb +130 -0
- data/lib/cheri/builder/xml/types.rb +36 -0
- data/lib/cheri/cheri.rb +70 -0
- data/lib/cheri/cjx.rb +3 -0
- data/lib/cheri/explorer.rb +32 -0
- data/lib/cheri/explorer/explorer.rb +560 -0
- data/lib/cheri/html.rb +31 -0
- data/lib/cheri/image/Delete24.gif +0 -0
- data/lib/cheri/image/Find24.gif +0 -0
- data/lib/cheri/image/FindAgain24.gif +0 -0
- data/lib/cheri/image/Refresh24.gif +0 -0
- data/lib/cheri/image/Search24.gif +0 -0
- data/lib/cheri/image/Thumbs.db +0 -0
- data/lib/cheri/image/cheri_icon_16x16.png +0 -0
- data/lib/cheri/image/cheri_icon_24x24.png +0 -0
- data/lib/cheri/image/cheri_logo_medium.png +0 -0
- data/lib/cheri/image/close_10x10.png +0 -0
- data/lib/cheri/image/close_10x10s.png +0 -0
- data/lib/cheri/image/close_12x12.png +0 -0
- data/lib/cheri/image/close_14x14.png +0 -0
- data/lib/cheri/image/close_24x24.png +0 -0
- data/lib/cheri/image/close_dim2_12x12.png +0 -0
- data/lib/cheri/image/close_dim_12x12.png +0 -0
- data/lib/cheri/image/cls_tree.png +0 -0
- data/lib/cheri/image/con_tree.png +0 -0
- data/lib/cheri/image/jruby_14x16.png +0 -0
- data/lib/cheri/image/jruby_logo.png +0 -0
- data/lib/cheri/image/mod_tree.png +0 -0
- data/lib/cheri/image/obj_tree.png +0 -0
- data/lib/cheri/image/ruby_16x16.png +0 -0
- data/lib/cheri/image/vars_tree.png +0 -0
- data/lib/cheri/java.rb +26 -0
- data/lib/cheri/java/builder.rb +28 -0
- data/lib/cheri/java/builder/main.rb +407 -0
- data/lib/cheri/java/builder/util.rb +480 -0
- data/lib/cheri/java/java.rb +56 -0
- data/lib/cheri/jruby.rb +32 -0
- data/lib/cheri/jruby/explorer.rb +43 -0
- data/lib/cheri/jruby/explorer/common.rb +38 -0
- data/lib/cheri/jruby/explorer/dialogs.rb +383 -0
- data/lib/cheri/jruby/explorer/explorer.rb +904 -0
- data/lib/cheri/jruby/explorer/splash.rb +80 -0
- data/lib/cheri/jruby/explorer/viewer.rb +619 -0
- data/lib/cheri/jruby/explorer/viewers.rb +1057 -0
- data/lib/cheri/jruby/jruby.rb +59 -0
- data/lib/cheri/swing.rb +41 -0
- data/lib/cheri/xml.rb +31 -0
- metadata +135 -0
data/lib/cheri/html.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cheri/builder'
|
26
|
+
require 'cheri/builder/html/common'
|
27
|
+
require 'cheri/builder/html/charsets'
|
28
|
+
require 'cheri/builder/html/element'
|
29
|
+
require 'cheri/builder/html/connecter'
|
30
|
+
require 'cheri/builder/html/types'
|
31
|
+
require 'cheri/builder/html/main'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/cheri/java.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cheri/jruby'
|
26
|
+
require 'cheri/java/java'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'cheri/java'
|
26
|
+
require 'cheri/builder'
|
27
|
+
require 'cheri/java/builder/util'
|
28
|
+
require 'cheri/java/builder/main'
|
@@ -0,0 +1,407 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2007 William N Dortch <bill.dortch@gmail.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
# cheri/java/builder/main
|
26
|
+
|
27
|
+
module Cheri
|
28
|
+
module Java
|
29
|
+
module Builder
|
30
|
+
#:stopdoc:
|
31
|
+
CJava = Cheri::Java
|
32
|
+
CBuilder = Cheri::Builder
|
33
|
+
#:startdoc:
|
34
|
+
class << self
|
35
|
+
def append_features(clazz)
|
36
|
+
CBuilder.module_included(self,clazz)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
private :append_features
|
40
|
+
|
41
|
+
def factory
|
42
|
+
DefaultFactory
|
43
|
+
end
|
44
|
+
|
45
|
+
def consumer
|
46
|
+
DefaultConsumer
|
47
|
+
end
|
48
|
+
|
49
|
+
def connecter
|
50
|
+
DefaultConnecter
|
51
|
+
end
|
52
|
+
|
53
|
+
def resolver
|
54
|
+
end
|
55
|
+
|
56
|
+
# def consume(*r,&k)
|
57
|
+
# DefaultConsumer.consume(*r,&k)
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# def prepare(*r)
|
61
|
+
# DefaultConnecter.prepare(*r)
|
62
|
+
# end
|
63
|
+
|
64
|
+
end #self
|
65
|
+
|
66
|
+
class BaseBuilder < Cheri::Builder::BaseBuilder
|
67
|
+
def initialize(ctx,sym,*args,&block)
|
68
|
+
super
|
69
|
+
@props = @args.pop if Hash === args.last
|
70
|
+
end
|
71
|
+
|
72
|
+
def mod
|
73
|
+
Cheri::Java::Builder
|
74
|
+
end
|
75
|
+
|
76
|
+
def run
|
77
|
+
pre
|
78
|
+
# we add the resolve_ctor method, not defined in Cheri::Builder::BaseBuilder
|
79
|
+
resolve_ctor if @resolve
|
80
|
+
create unless @no_create
|
81
|
+
post
|
82
|
+
call unless @no_call
|
83
|
+
@obj
|
84
|
+
end
|
85
|
+
|
86
|
+
def props
|
87
|
+
@props
|
88
|
+
end
|
89
|
+
|
90
|
+
def resolve?
|
91
|
+
@resolve
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
# called if @resolve is set, before object created
|
96
|
+
def resolve_ctor
|
97
|
+
@ctx.crz(mod, @clazz, @args) if @clazz && @args && !@args.empty?
|
98
|
+
end
|
99
|
+
|
100
|
+
end #BaseBuilder
|
101
|
+
|
102
|
+
class ClassBuilder < BaseBuilder
|
103
|
+
def initialize(ctx,sym,clazz,*args,&block)
|
104
|
+
super(ctx,sym,*args,&block)
|
105
|
+
@clazz = clazz
|
106
|
+
# TODO: I don't know if we want this as default...
|
107
|
+
# *ANSWER* yes, because a :SYMBOL will never be a valid Java arg,
|
108
|
+
# and doing it this way simplifies adding later Java types and constants.
|
109
|
+
# The first simple_resolve check is cheap, so this won't hurt performance
|
110
|
+
@resolve = true
|
111
|
+
end
|
112
|
+
private
|
113
|
+
def create
|
114
|
+
@obj = @clazz.new(*@args)
|
115
|
+
end
|
116
|
+
end #ClassBasedBuilder
|
117
|
+
|
118
|
+
class ProcBuilder < BaseBuilder
|
119
|
+
def initialize(ctx,sym,proc,*args,&block)
|
120
|
+
super(ctx,sym,*args,&block)
|
121
|
+
@proc = proc
|
122
|
+
end
|
123
|
+
private
|
124
|
+
def create
|
125
|
+
@obj = @proc.call(*@args)
|
126
|
+
@clazz = @object.class
|
127
|
+
@resolve = true
|
128
|
+
end
|
129
|
+
end #ProcBasedBuilder
|
130
|
+
|
131
|
+
class CherifyBuilder < BaseBuilder
|
132
|
+
def initialize(ctx,sym,object,*args,&block)
|
133
|
+
super(ctx,sym,*args,&block)
|
134
|
+
@obj = object
|
135
|
+
@clazz = object.class
|
136
|
+
@no_create = true
|
137
|
+
@resolve = true
|
138
|
+
end
|
139
|
+
end #CherifyBuilder
|
140
|
+
|
141
|
+
class CheriYieldBuilder < BaseBuilder
|
142
|
+
def initialize(ctx,sym,object,*args,&block)
|
143
|
+
super(ctx,sym,*args,&block)
|
144
|
+
@obj = object
|
145
|
+
@clazz = object.class
|
146
|
+
@no_create = true
|
147
|
+
@not_child = true
|
148
|
+
@resolve = true
|
149
|
+
end
|
150
|
+
end #CheriYieldBuilder
|
151
|
+
|
152
|
+
# TODO: comments
|
153
|
+
module CherifyFactory # < Cheri::AbstractFactory
|
154
|
+
def self.builder(ctx,sym,*args,&block)
|
155
|
+
return nil unless sym == :cherify && args[0].respond_to?(:java_class)
|
156
|
+
raise Cheri.argument_error(args.length,1..2) unless args.length == 1 || args.length == 2
|
157
|
+
CherifyBuilder.new(ctx,sym,*args,&block)
|
158
|
+
end
|
159
|
+
end #CherifyFactory
|
160
|
+
|
161
|
+
# TODO: comments
|
162
|
+
module CheriYieldFactory # < Cheri::AbstractFactory
|
163
|
+
def self.builder(ctx,sym,*args,&block)
|
164
|
+
return nil unless sym == :cheri_yield && args[0].respond_to?(:java_class)
|
165
|
+
raise Cheri.argument_error(args.length,1) unless args.length == 1
|
166
|
+
CheriYieldBuilder.new(ctx,sym,*args,&block)
|
167
|
+
end
|
168
|
+
end #CheriYieldFactory
|
169
|
+
|
170
|
+
DefaultFactory = Cheri::Builder::SuperFactory.new do |f|
|
171
|
+
f << CherifyFactory
|
172
|
+
f << CheriYieldFactory
|
173
|
+
end
|
174
|
+
|
175
|
+
# The Java connecter of last resort
|
176
|
+
DefaultConnecter = Cheri::Builder::TypeConnecter.new do
|
177
|
+
U = Cheri::Java::Builder::Util
|
178
|
+
|
179
|
+
type java.lang.Object do
|
180
|
+
connect java.lang.Object do |parent,obj,sym,props|
|
181
|
+
snd = U.setter?(s = sym.to_s) ? sym : U.setter(s)
|
182
|
+
if parent.respond_to?(snd) ||
|
183
|
+
parent.respond_to?(snd = s << ?= ) ||
|
184
|
+
parent.respond_to?(snd = :add)
|
185
|
+
#puts "Java::DefaultConnecter for #{parent},\n #{obj}: #{snd}"
|
186
|
+
parent.__send__(snd,obj) rescue nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
module GenericConsumer
|
194
|
+
Util = Cheri::Java::Builder::Util
|
195
|
+
G = 'get'
|
196
|
+
S = 'set'
|
197
|
+
I = 'is'
|
198
|
+
E = '='
|
199
|
+
class << self
|
200
|
+
def consume(ctx,bld,sym,*args,&k)
|
201
|
+
#puts "JGC: #{sym}"
|
202
|
+
return false,nil unless (obj = bld.object).respond_to?(:java_class)
|
203
|
+
s = sym.to_s
|
204
|
+
# if sym is already an accessor, use it as is
|
205
|
+
|
206
|
+
if Util.acc?(s)
|
207
|
+
snd = sym
|
208
|
+
else
|
209
|
+
cc = Util.cc(s) #upper-camel-cased name
|
210
|
+
if ((!args.empty?) && (obj.respond_to?(snd = S + cc) || obj.respond_to?(snd = s + E )))
|
211
|
+
elsif obj.respond_to?(snd = G + cc)
|
212
|
+
elsif obj.respond_to?(snd = I + cc)
|
213
|
+
else
|
214
|
+
snd = sym
|
215
|
+
end
|
216
|
+
end
|
217
|
+
#puts "JGC: snd = #{snd}"
|
218
|
+
if obj.respond_to?(snd)
|
219
|
+
if !args.empty? && bld.respond_to?(:resolve?) && bld.resolve?
|
220
|
+
ctx.mrz(bld.mod,obj,snd,args)
|
221
|
+
end
|
222
|
+
|
223
|
+
# TODO: do we want to rescue here? maybe better to fail noisily...
|
224
|
+
|
225
|
+
#res = nil
|
226
|
+
#begin
|
227
|
+
res = obj.__send__(snd, *args)
|
228
|
+
#rescue
|
229
|
+
#return false,nil
|
230
|
+
#end
|
231
|
+
if k && res
|
232
|
+
ctx.send(:cheri_yield,res,&k)
|
233
|
+
end
|
234
|
+
return true,res
|
235
|
+
end
|
236
|
+
return false,nil # consumed,res
|
237
|
+
end
|
238
|
+
end #self
|
239
|
+
end #DefaultConsumer
|
240
|
+
|
241
|
+
module EventMethodConsumer
|
242
|
+
#:stopdoc:
|
243
|
+
On = 'on_'.freeze
|
244
|
+
Eq = '='.freeze
|
245
|
+
# TODO: any other useful aliases?
|
246
|
+
Aliases = {:on_click => 'actionPerformed'.freeze}
|
247
|
+
#:startdoc:
|
248
|
+
def self.consume(ctx,bld,sym,*args,&block)
|
249
|
+
return false,nil unless (obj = bld.object).respond_to?(:java_class) &&
|
250
|
+
((method_name = Aliases[sym]) || (s = sym.to_s).rindex(On,0))
|
251
|
+
method_name ||= Util.lcc(s[3,s.length])
|
252
|
+
unless (info = Interfaces.get_listener_info(obj.java_class,method_name))
|
253
|
+
raise NameError,"no Java interface found matching event handler name: #{sym}"
|
254
|
+
end
|
255
|
+
raise ArgumentError,"missing block for event handler: #{sym}" unless block
|
256
|
+
listener = Interfaces.get_listener_impl(info).new
|
257
|
+
listener.__send__(method_name + Eq , block)
|
258
|
+
obj.__send__(info.add_method_name,listener)
|
259
|
+
return true,listener
|
260
|
+
end
|
261
|
+
end #EventMethodConsumer
|
262
|
+
|
263
|
+
DefaultConsumer = Cheri::Builder::SuperConsumer.new do |cns|
|
264
|
+
cns << EventMethodConsumer
|
265
|
+
cns << GenericConsumer
|
266
|
+
end
|
267
|
+
|
268
|
+
class ConstantResolver < Cheri::Builder::AbstractConstantResolver
|
269
|
+
Const = Cheri::Java::Builder::Constants
|
270
|
+
def initialize(*sources,&k)
|
271
|
+
@sources = []
|
272
|
+
@cache = {}
|
273
|
+
sources.each do |s|
|
274
|
+
self << s
|
275
|
+
end
|
276
|
+
yield self if block_given?
|
277
|
+
end
|
278
|
+
|
279
|
+
# note that we pass args, not *args, as we want the original array
|
280
|
+
def resolve_ctor(clazz,args)
|
281
|
+
return false unless clazz.respond_to?(:java_class)
|
282
|
+
Const.resolve_ctor(clazz,args,self)
|
283
|
+
end
|
284
|
+
|
285
|
+
# note that we pass args, not *args, as we want the original array
|
286
|
+
def resolve_meth(object,sym,args)
|
287
|
+
return false unless object.respond_to?(:java_class)
|
288
|
+
Const.resolve_meth(object.class,sym,args,self)
|
289
|
+
end
|
290
|
+
|
291
|
+
def add_constant_source(source)
|
292
|
+
# not much of a validity check, better than none...
|
293
|
+
unless source.respond_to?(:get)
|
294
|
+
raise Cheri::CheriException,"invalid constants source specified: #{source}"
|
295
|
+
end
|
296
|
+
unless @sources.include?(source)
|
297
|
+
@sources << source
|
298
|
+
# flush the cache
|
299
|
+
@cache.clear
|
300
|
+
end
|
301
|
+
end
|
302
|
+
alias_method :<<, :add_constant_source
|
303
|
+
|
304
|
+
def get(constant)
|
305
|
+
rec_arr = @cache[constant]
|
306
|
+
return (rec_arr == :no_match ? nil : rec_arr) if rec_arr
|
307
|
+
@sources.each do |s|
|
308
|
+
const_rec = s.get(constant)
|
309
|
+
while const_rec
|
310
|
+
(rec_arr ||= []) << const_rec
|
311
|
+
const_rec = const_rec.next_rec
|
312
|
+
end
|
313
|
+
end
|
314
|
+
@cache[constant] = rec_arr || :no_match
|
315
|
+
rec_arr
|
316
|
+
end
|
317
|
+
|
318
|
+
def copy
|
319
|
+
self.class.allocate.copy_from(@sources)
|
320
|
+
end
|
321
|
+
|
322
|
+
protected
|
323
|
+
def copy_from(sources)
|
324
|
+
@sources = sources.dup
|
325
|
+
@cache = {}
|
326
|
+
self
|
327
|
+
end
|
328
|
+
end #ConstantResolver
|
329
|
+
|
330
|
+
class GenericClassBuilder < ClassBuilder
|
331
|
+
def initialize(mod,*args,&block)
|
332
|
+
super(*args,&block)
|
333
|
+
@mod = mod
|
334
|
+
end
|
335
|
+
def mod
|
336
|
+
@mod
|
337
|
+
end
|
338
|
+
end #GenericClassBuilder
|
339
|
+
|
340
|
+
|
341
|
+
class GenericCherifyBuilder < CherifyBuilder
|
342
|
+
def initialize(mod,*r,&k)
|
343
|
+
super(*r,&k)
|
344
|
+
@mod = mod
|
345
|
+
end
|
346
|
+
def mod
|
347
|
+
@mod
|
348
|
+
end
|
349
|
+
end #GenericCherifyBuilder
|
350
|
+
|
351
|
+
class GenericCheriYieldBuilder < CheriYieldBuilder
|
352
|
+
def initialize(mod,*r,&k)
|
353
|
+
super(*r,&k)
|
354
|
+
@mod = mod
|
355
|
+
end
|
356
|
+
def mod
|
357
|
+
@mod
|
358
|
+
end
|
359
|
+
end #GenericCheriYieldBuilder
|
360
|
+
|
361
|
+
class GenericBuilderFactory
|
362
|
+
def initialize(mod,types)
|
363
|
+
raise Cheri.type_error(types,Hash) unless Hash === types
|
364
|
+
@mod = mod
|
365
|
+
@types = types
|
366
|
+
@inv = types.invert
|
367
|
+
end
|
368
|
+
def builder(ctx,sym,*r,&k)
|
369
|
+
if (clazz = @types[sym])
|
370
|
+
GenericClassBuilder.new(@mod,ctx,sym,clazz,*r,&k)
|
371
|
+
elsif @inv[r.first.class]
|
372
|
+
if sym == :cherify
|
373
|
+
GenericCherifyBuilder.new(@mod,ctx,sym,*r,&k)
|
374
|
+
elsif sym == :cheri_yield
|
375
|
+
GenericCheriYieldBuilder.new(@mod,ctx,sym,*r,&k)
|
376
|
+
else
|
377
|
+
nil
|
378
|
+
end
|
379
|
+
else
|
380
|
+
nil
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end #GenericBuilderFactory
|
384
|
+
|
385
|
+
class PackageFactory
|
386
|
+
#:stopdoc:
|
387
|
+
Dot = '.'
|
388
|
+
CJ = Cheri::Java
|
389
|
+
#Util = Cheri::Java::Builder::Util
|
390
|
+
#:startdoc:
|
391
|
+
def initialize(pkg_str,mod)
|
392
|
+
raise Cheri.type_error(pkg_str,String) unless String === pkg_str
|
393
|
+
@pkg = pkg_str.empty? || pkg_str[-1] == ?. ? pkg_str.dup : pkg_str + Dot
|
394
|
+
@mod = mod
|
395
|
+
@classes = {}
|
396
|
+
end
|
397
|
+
def builder(ctx,sym,*r,&k)
|
398
|
+
if (clazz = @classes[sym] ||= (CJ.get_class(@pkg + Util.cc(sym)) rescue :none)) != :none
|
399
|
+
return GenericClassBuilder.new(@mod,ctx,sym,clazz,*r,&k)
|
400
|
+
end
|
401
|
+
nil
|
402
|
+
end
|
403
|
+
end #PackageFactory
|
404
|
+
|
405
|
+
end #Builder
|
406
|
+
end #Java
|
407
|
+
end #Cheri
|