Module: Cheri::Java::Builder::GenericConsumer

Defined in:
lib/cheri/java/builder/main.rb

Constant Summary collapse

Util =
Cheri::Java::Builder::Util
G =
'get'
S =
'set'
I =
'is'
E =
'='

Class Method Summary collapse

Class Method Details

.consume(ctx, bld, sym, *args, &k) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/cheri/java/builder/main.rb', line 203

def consume(ctx,bld,sym,*args,&k)
  #puts "JGC: #{sym}"
  return false,nil unless (obj = bld.object).respond_to?(:java_class)
  s = sym.to_s
  # if sym is already an accessor, use it as is

  if Util.acc?(s)
    snd = sym
  else
    cc = Util.cc(s) #upper-camel-cased name
    if ((!args.empty?) && (obj.respond_to?(snd = S + cc) || obj.respond_to?(snd = s + E )))
    elsif obj.respond_to?(snd = G + cc)
    elsif obj.respond_to?(snd = I + cc)
    else
       snd = sym
    end
  end
  #puts "JGC: snd = #{snd}"
  if obj.respond_to?(snd)
    if !args.empty? && bld.respond_to?(:resolve?) && bld.resolve?
      ctx.mrz(bld.mod,obj,snd,args)
    end
    
    # TODO: do we want to rescue here? maybe better to fail noisily...
    
    #res = nil
    #begin
      res = obj.__send__(snd, *args)
    #rescue
      #return false,nil
    #end
    if k && res
      ctx.send(:cheri_yield,res,&k)
    end
    return true,res
  end
  return false,nil # consumed,res
end