cheri 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cheri/awt.rb +6 -7
- data/lib/cheri/builder/base.rb +1 -1
- data/lib/cheri/builder/config.rb +141 -55
- data/lib/cheri/builder/connecter.rb +23 -21
- data/lib/cheri/builder/context.rb +18 -16
- data/lib/cheri/cheri.rb +1 -1
- data/lib/cheri/explorer.rb +1 -4
- data/lib/cheri/java/builder/main.rb +4 -0
- data/lib/cheri/jruby.rb +1 -4
- data/lib/cheri/swing.rb +6 -7
- metadata +2 -2
data/lib/cheri/awt.rb
CHANGED
@@ -22,10 +22,7 @@
|
|
22
22
|
#++
|
23
23
|
#
|
24
24
|
|
25
|
-
if
|
26
|
-
((JRUBY_VERSION =~ /^(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/ &&
|
27
|
-
(($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')) ||
|
28
|
-
(JRUBY_VERSION =~ /^(\d+\.\d+)([-\.A-Z0-9]*)/ && $1 >= '1.0'))
|
25
|
+
if RUBY_PLATFORM =~ /java/ && defined?JRUBY_VERSION
|
29
26
|
|
30
27
|
require 'cheri/java/builder'
|
31
28
|
require 'cheri/builder/awt/types'
|
@@ -34,10 +31,12 @@ if (defined?JRUBY_VERSION) &&
|
|
34
31
|
require 'cheri/builder/awt/main'
|
35
32
|
|
36
33
|
else
|
34
|
+
|
37
35
|
STDERR.puts %{
|
38
|
-
Cheri::AWT requires JRuby
|
39
|
-
|
40
|
-
|
36
|
+
Cheri::AWT requires JRuby 1.0 or later
|
37
|
+
Download the latest version of JRuby at:
|
38
|
+
http://www.jruby.org/
|
39
|
+
|
41
40
|
}
|
42
41
|
|
43
42
|
end
|
data/lib/cheri/builder/base.rb
CHANGED
data/lib/cheri/builder/config.rb
CHANGED
@@ -31,8 +31,7 @@ class Config
|
|
31
31
|
@m = [] # included modules
|
32
32
|
@f = {} # factories, indexed by module
|
33
33
|
@c = {} # connecters, indexed by module
|
34
|
-
#
|
35
|
-
# @n = {} # consumers, indexed by module
|
34
|
+
@n = {} # consumers, indexed by module
|
36
35
|
# @r = {} # resolvers, indexed by module
|
37
36
|
mods.each do |mod| self << mod; end
|
38
37
|
end
|
@@ -50,9 +49,11 @@ class Config
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def consumers
|
53
|
-
@n
|
52
|
+
@n
|
54
53
|
end
|
55
54
|
|
55
|
+
|
56
|
+
# FIXME: eliminate!
|
56
57
|
def resolvers
|
57
58
|
@r || None
|
58
59
|
end
|
@@ -63,74 +64,159 @@ class Config
|
|
63
64
|
extendee = mod.respond_to?(:extends) ? mod.extends : nil
|
64
65
|
raise BuilderException,"extended builder module not included: #{extendee}" if extendee && !@m.include?(extendee)
|
65
66
|
@m << mod
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
if mod.respond_to?(:factory) && (obj = mod.factory)
|
69
|
+
@f[mod] = obj
|
70
|
+
end
|
71
|
+
|
72
|
+
if mod.respond_to?(:connecter) && (obj = mod.connecter)
|
73
|
+
@c[mod] = obj
|
74
|
+
end
|
75
|
+
|
76
|
+
if mod.respond_to?(:consumer) && (obj = mod.consumer)
|
77
|
+
@n[mod] = obj
|
78
|
+
end
|
79
|
+
|
80
|
+
# FIXME: eliminate (isolate in Java class stuff)
|
69
81
|
(@r ||= {})[mod] = mod.resolver if mod.respond_to?(:resolver) && mod.resolver
|
82
|
+
|
83
|
+
|
70
84
|
extend_mod(extendee,mod) if extendee
|
71
85
|
self
|
72
86
|
end
|
73
87
|
alias_method :add, :<<
|
74
88
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# if we're extending the factory...
|
80
|
-
if (fx = @f[ext])
|
81
|
-
if (fm = @f[mod])
|
82
|
-
# if there's already a factory, wrap it in a SuperFactory
|
83
|
-
# extender goes first so it can override
|
84
|
-
@f[mod] = SuperFactory[fx,fm]
|
89
|
+
def flatten(obj)
|
90
|
+
if obj
|
91
|
+
if Aggregate === obj
|
92
|
+
obj.flatten
|
85
93
|
else
|
86
|
-
|
87
|
-
@f[mod] = fx
|
94
|
+
[obj]
|
88
95
|
end
|
96
|
+
else
|
97
|
+
[]
|
89
98
|
end
|
99
|
+
end
|
100
|
+
private :flatten
|
90
101
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# not an issue... yet...
|
96
|
-
if (cm = @c[mod])
|
97
|
-
if TypeConnecter === cm && TypeConnecter === cx
|
98
|
-
# if they're both TypeConnecters, create a combined TypeConnecter
|
99
|
-
# extender goes second so it can override
|
100
|
-
@c[mod] = TypeConnecter.new(cm,cx)
|
101
|
-
else
|
102
|
-
# otherwise, combine them in a SuperConnecter
|
103
|
-
# extender goes first so it can override
|
104
|
-
@c[mod] = SuperConnecter[cx,cm]
|
105
|
-
end
|
106
|
-
else
|
107
|
-
# no connecter, use extender
|
108
|
-
@c[mod] = cx
|
109
|
-
end
|
102
|
+
def merge_aggregates(amod, aext, aggr_clazz)
|
103
|
+
aggr = aggr_clazz.new
|
104
|
+
flatten(aext).each do |elem|
|
105
|
+
aggr << elem
|
110
106
|
end
|
107
|
+
flatten(amod).each do |elem|
|
108
|
+
aggr << elem
|
109
|
+
end
|
110
|
+
aggr
|
111
|
+
end
|
112
|
+
private :merge_aggregates
|
113
|
+
|
114
|
+
def merge_factories(fmod, fext)
|
115
|
+
merge_aggregates(fmod,fext,SuperFactory)
|
116
|
+
end
|
117
|
+
private :merge_factories
|
118
|
+
|
119
|
+
def merge_consumers(cmod, cext)
|
120
|
+
merge_aggregates(cmod,cext,SuperConsumer)
|
121
|
+
end
|
122
|
+
private :merge_consumers
|
111
123
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
124
|
+
def merge_connecters(cmod, cext)
|
125
|
+
# first, break down connecters into TypeConnecters and others
|
126
|
+
tcs = []
|
127
|
+
others = []
|
128
|
+
flatten(cmod).each do |ctr|
|
129
|
+
if TypeConnecter === ctr
|
130
|
+
tcs << ctr
|
116
131
|
else
|
117
|
-
|
132
|
+
others << ctr
|
133
|
+
end
|
134
|
+
end
|
135
|
+
# we want extender's TC's after mod's
|
136
|
+
(fext = flatten(cext)).each do |ctr|
|
137
|
+
tcs << ctr if TypeConnecter === ctr
|
138
|
+
end
|
139
|
+
# we want extender's other connecters before mod's
|
140
|
+
fext.reverse_each do |ctr|
|
141
|
+
others.unshift(ctr) unless TypeConnecter === ctr
|
142
|
+
end
|
143
|
+
|
144
|
+
# combine (merge) any TypeConnecters
|
145
|
+
unless tcs.empty?
|
146
|
+
tc = TypeConnecter.new
|
147
|
+
tcs.each do |atc|
|
148
|
+
tc.merge!(atc)
|
118
149
|
end
|
150
|
+
# return the merged TC if there are no other
|
151
|
+
# connecters (the usual case)
|
152
|
+
return tc if others.empty?
|
153
|
+
else
|
154
|
+
tc = nil
|
155
|
+
end
|
156
|
+
|
157
|
+
# aggregate any 'other' (non-TypeConnecter) connecters,
|
158
|
+
# and add the (merged) TypeConnecter (if any) last
|
159
|
+
sc = SuperConnecter.new
|
160
|
+
others.each do |oth|
|
161
|
+
sc << oth
|
162
|
+
end
|
163
|
+
sc << tc if tc
|
164
|
+
sc
|
165
|
+
end
|
166
|
+
private :merge_connecters
|
167
|
+
|
168
|
+
def extend_mod(mod,ext)
|
169
|
+
# get to the base module to be extended
|
170
|
+
while mod.respond_to?(:extends) && (mext = mod.extends)
|
171
|
+
mod = mext
|
172
|
+
end
|
173
|
+
|
174
|
+
# merge the extendee's (mod) factory(s) with the extender's (ext)
|
175
|
+
# factory(s). update any reference to either to point to the
|
176
|
+
# merged factory(s).
|
177
|
+
mods = [mod,ext]
|
178
|
+
hash = @f
|
179
|
+
hmod = hash[mod]
|
180
|
+
hext = hash[ext]
|
181
|
+
hash.each_pair do |m,h|
|
182
|
+
mods << m if h == hmod || h == hext unless mods.include?(m)
|
183
|
+
end
|
184
|
+
merged = merge_factories(hmod,hext)
|
185
|
+
mods.each do |m|
|
186
|
+
hash[m] = merged
|
119
187
|
end
|
120
188
|
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
189
|
+
# merge the extendee's (mod) connecter(s) with the extender's (ext)
|
190
|
+
# connecter(s). update any reference to either to point to the
|
191
|
+
# merged connecter(s).
|
192
|
+
mods = [mod,ext]
|
193
|
+
hash = @c
|
194
|
+
hmod = hash[mod]
|
195
|
+
hext = hash[ext]
|
196
|
+
hash.each_pair do |m,h|
|
197
|
+
mods << m if h == hmod || h == hext unless mods.include?(m)
|
198
|
+
end
|
199
|
+
merged = merge_connecters(hmod,hext)
|
200
|
+
mods.each do |m|
|
201
|
+
hash[m] = merged
|
202
|
+
end
|
203
|
+
|
204
|
+
# merge the extendee's (mod) consumers(s) with the extender's (ext)
|
205
|
+
# consumers(s). update any reference to either to point to the
|
206
|
+
# merged consumer(s).
|
207
|
+
mods = [mod,ext]
|
208
|
+
hash = @n
|
209
|
+
hmod = hash[mod]
|
210
|
+
hext = hash[ext]
|
211
|
+
hash.each_pair do |m,h|
|
212
|
+
mods << m if h == hmod || h == hext unless mods.include?(m)
|
213
|
+
end
|
214
|
+
merged = merge_consumers(hmod,hext)
|
215
|
+
mods.each do |m|
|
216
|
+
hash[m] = merged
|
132
217
|
end
|
133
218
|
end
|
219
|
+
private :extend_mod
|
134
220
|
|
135
221
|
def include?(mod)
|
136
222
|
@m.include?(mod)
|
@@ -146,7 +232,7 @@ class Config
|
|
146
232
|
|
147
233
|
# Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.
|
148
234
|
def inspect
|
149
|
-
|
235
|
+
to_s
|
150
236
|
end
|
151
237
|
|
152
238
|
protected
|
@@ -154,7 +240,7 @@ protected
|
|
154
240
|
@m = m.dup
|
155
241
|
@f = f.dup
|
156
242
|
@c = c.dup
|
157
|
-
@n = n.dup
|
243
|
+
@n = n.dup
|
158
244
|
@r = r.dup if r
|
159
245
|
self
|
160
246
|
end
|
@@ -27,32 +27,33 @@ module Builder
|
|
27
27
|
|
28
28
|
class TypeConnecter
|
29
29
|
|
30
|
-
def initialize(*parents,&
|
30
|
+
def initialize(*parents,&block)
|
31
31
|
@t = {}
|
32
32
|
@s = {}
|
33
33
|
@c = {}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if (ssym = s[sym])
|
48
|
-
ssym.merge(symc)
|
49
|
-
else
|
50
|
-
s[sym] = symc.copy
|
51
|
-
end
|
52
|
-
end
|
34
|
+
parents.each do |parent| merge!(parent); end
|
35
|
+
instance_eval(&block) if block
|
36
|
+
end
|
37
|
+
|
38
|
+
def merge!(other)
|
39
|
+
raise Cheri.type_error(other,TypeConnecter) unless TypeConnecter === other
|
40
|
+
t = @t
|
41
|
+
s = @s
|
42
|
+
other.get_types.each_pair do |mod,type|
|
43
|
+
if (tmod = t[mod])
|
44
|
+
tmod.merge(type)
|
45
|
+
else
|
46
|
+
t[mod] = type.copy
|
53
47
|
end
|
54
48
|
end
|
55
|
-
|
49
|
+
other.get_syms.each_pair do |sym,symc|
|
50
|
+
if (ssym = s[sym])
|
51
|
+
ssym.merge(symc)
|
52
|
+
else
|
53
|
+
s[sym] = symc.copy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
self
|
56
57
|
end
|
57
58
|
|
58
59
|
def prepare(ctx,builder,obj,sym,props)
|
@@ -155,6 +156,7 @@ class TypeConnecter
|
|
155
156
|
@t[mod] ||= Type.new(mod)
|
156
157
|
end
|
157
158
|
|
159
|
+
|
158
160
|
class Type
|
159
161
|
def initialize(mod)
|
160
162
|
raise Cheri.type_error(mod,Class,Module) unless Module === mod
|
@@ -28,7 +28,7 @@ module Builder
|
|
28
28
|
class InstanceContext
|
29
29
|
# TODO: defined?Java pulls it in (same as require 'java' or include Java)
|
30
30
|
# not sure if anyone would object...
|
31
|
-
if (defined?Java) && (defined?JRUBY_VERSION) # JRuby 0.9.9 or later
|
31
|
+
if (defined?(::Java)) && (defined?JRUBY_VERSION) # JRuby 0.9.9 or later
|
32
32
|
Col = java.util.Collections
|
33
33
|
Map = java.util.HashMap
|
34
34
|
WMap = java.util.WeakHashMap
|
@@ -108,7 +108,7 @@ class InstanceContext
|
|
108
108
|
|
109
109
|
# Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.
|
110
110
|
def inspect
|
111
|
-
|
111
|
+
to_s
|
112
112
|
end
|
113
113
|
|
114
114
|
end #InstanceContext
|
@@ -134,7 +134,6 @@ class Context
|
|
134
134
|
# @r - array of ConstantResolver instances, lazily initialized
|
135
135
|
# @s - the stack, holds active builders and builder frames
|
136
136
|
# @u - auto-factories array, lazily initialized
|
137
|
-
##### TODO: REMOVE @v - flag used to prevent reentrant calls to #consume (aka #csm)
|
138
137
|
# @x - flag indicating whether instance_exec is supported, lazily initialized
|
139
138
|
#++
|
140
139
|
def initialize(ictx,client)
|
@@ -428,15 +427,15 @@ class Context
|
|
428
427
|
# in the order they were enabled. Returns nil if no builder is found.
|
429
428
|
def bld(*r,&k)
|
430
429
|
#puts "bld args: #{[r.join(',')]}"
|
431
|
-
|
430
|
+
queried = nil # lazily-allocated array to hold factories we've already queried
|
432
431
|
b = nil # builder
|
433
|
-
|
432
|
+
atf = @f
|
434
433
|
# search stack for a frame whose module's factory can supply a matching builder
|
435
434
|
@s.reverse_each do |s|
|
436
|
-
if (f =
|
437
|
-
unless
|
435
|
+
if (f = atf[s.mod])
|
436
|
+
unless queried && queried.include?(f)
|
438
437
|
return b if (b = f.builder(self,*r,&k))
|
439
|
-
(
|
438
|
+
(queried ||= []) << f
|
440
439
|
end
|
441
440
|
end
|
442
441
|
end
|
@@ -444,10 +443,10 @@ class Context
|
|
444
443
|
# try auto-enabled builders
|
445
444
|
if (u = auto)
|
446
445
|
u.each do |m|
|
447
|
-
if (f =
|
448
|
-
unless
|
446
|
+
if (f = atf[m])
|
447
|
+
unless queried && queried.include?(f)
|
449
448
|
return b if (b = f.builder(self,*r,&k))
|
450
|
-
(
|
449
|
+
(queried ||= []) << f
|
451
450
|
end
|
452
451
|
end
|
453
452
|
end
|
@@ -540,9 +539,12 @@ class Context
|
|
540
539
|
break
|
541
540
|
end
|
542
541
|
end
|
543
|
-
|
542
|
+
|
543
|
+
#puts "frame.object #{obj}"
|
544
|
+
#puts "parent #{parent}"
|
544
545
|
# if we got a builder (parent), attempt to connect it
|
545
546
|
if parent && (n = @n[parent.mod])
|
547
|
+
#puts "parent.mod #{n}"
|
546
548
|
n.prepare(self,parent,obj,sym,props)
|
547
549
|
end
|
548
550
|
|
@@ -624,7 +626,7 @@ class Context
|
|
624
626
|
|
625
627
|
# Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.
|
626
628
|
def inspect
|
627
|
-
|
629
|
+
to_s
|
628
630
|
end
|
629
631
|
|
630
632
|
# We want to prevent built objects passed as parameters from
|
@@ -669,14 +671,14 @@ class Context
|
|
669
671
|
# store a prepared connection.
|
670
672
|
def ppd(ctr,bldr,obj,sym,props=nil)
|
671
673
|
@o[obj.__id__] = bldr
|
672
|
-
@c[bldr.__id__] <<
|
674
|
+
@c[bldr.__id__] << Conn.new(ctr,bldr.object,obj,sym,props)
|
673
675
|
true
|
674
676
|
end
|
675
677
|
alias_method :prepared, :ppd #:nodoc:
|
676
678
|
|
677
679
|
# store a prepared 'any' connection.
|
678
680
|
def ppda(ctr,bldr,obj,sym,props=nil)
|
679
|
-
((@a ||= {})[bldr.__id__] ||= []) <<
|
681
|
+
((@a ||= {})[bldr.__id__] ||= []) << Conn.new(ctr,bldr.object,obj,sym,props)
|
680
682
|
true
|
681
683
|
end
|
682
684
|
alias_method :prepared_any, :ppda # :nodoc:
|
@@ -714,7 +716,7 @@ class Context
|
|
714
716
|
end
|
715
717
|
alias_method :check, :ck #:nodoc:
|
716
718
|
|
717
|
-
class
|
719
|
+
class Conn # :nodoc: all
|
718
720
|
def initialize(ctr,par,obj,sym,props)
|
719
721
|
@c = ctr
|
720
722
|
@p = par
|
data/lib/cheri/cheri.rb
CHANGED
data/lib/cheri/explorer.rb
CHANGED
@@ -24,10 +24,7 @@
|
|
24
24
|
|
25
25
|
require 'cheri/cheri'
|
26
26
|
|
27
|
-
if
|
28
|
-
((JRUBY_VERSION =~ /^(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/ &&
|
29
|
-
(($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')) ||
|
30
|
-
(JRUBY_VERSION =~ /^(\d+\.\d+)([-\.A-Z0-9]*)/ && $1 >= '1.0'))
|
27
|
+
if RUBY_PLATFORM =~ /java/ && defined?JRUBY_VERSION
|
31
28
|
require 'cheri/jruby'
|
32
29
|
end
|
33
30
|
|
@@ -370,6 +370,10 @@ class GenericCheriYieldBuilder < CheriYieldBuilder
|
|
370
370
|
end #GenericCheriYieldBuilder
|
371
371
|
|
372
372
|
class GenericBuilderFactory
|
373
|
+
# :stopdoc:
|
374
|
+
BuildType = Cheri::Builder::BuildType
|
375
|
+
BuildTypes = Cheri::Builder::BuildTypes
|
376
|
+
# :startdoc:
|
373
377
|
def initialize(mod,types)
|
374
378
|
raise Cheri.type_error(types,BuildType) unless BuildTypes === types
|
375
379
|
@mod = mod
|
data/lib/cheri/jruby.rb
CHANGED
@@ -22,10 +22,7 @@
|
|
22
22
|
#++
|
23
23
|
#
|
24
24
|
|
25
|
-
if
|
26
|
-
((JRUBY_VERSION =~ /^(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/ &&
|
27
|
-
(($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')) ||
|
28
|
-
(JRUBY_VERSION =~ /^(\d+\.\d+)([-\.A-Z0-9]*)/ && $1 >= '1.0'))
|
25
|
+
if RUBY_PLATFORM =~ /java/ && defined?JRUBY_VERSION
|
29
26
|
require 'java'
|
30
27
|
require 'cheri/cheri'
|
31
28
|
require 'cheri/jruby/jruby'
|
data/lib/cheri/swing.rb
CHANGED
@@ -22,10 +22,7 @@
|
|
22
22
|
#++
|
23
23
|
#
|
24
24
|
|
25
|
-
if
|
26
|
-
((JRUBY_VERSION =~ /^(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/ &&
|
27
|
-
(($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')) ||
|
28
|
-
(JRUBY_VERSION =~ /^(\d+\.\d+)([-\.A-Z0-9]*)/ && $1 >= '1.0'))
|
25
|
+
if RUBY_PLATFORM =~ /java/ && defined?JRUBY_VERSION
|
29
26
|
|
30
27
|
require 'cheri/awt'
|
31
28
|
require 'cheri/builder/swing/types'
|
@@ -34,10 +31,12 @@ if (defined?JRUBY_VERSION) &&
|
|
34
31
|
require 'cheri/builder/swing/main'
|
35
32
|
|
36
33
|
else
|
34
|
+
|
37
35
|
STDERR.puts %{
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
Cheri::Swing requires JRuby 1.0 or later
|
37
|
+
Download the latest version of JRuby at:
|
38
|
+
http://www.jruby.org/
|
39
|
+
|
41
40
|
}
|
42
41
|
|
43
42
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: cheri
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.8
|
7
|
+
date: 2007-12-10 00:00:00 -08:00
|
8
8
|
summary: Cheri Builder Platform
|
9
9
|
require_paths:
|
10
10
|
- lib
|