Class: Cheri::Java::Builder::ConstantResolver

Inherits:
Builder::AbstractConstantResolver
  • Object
show all
Defined in:
lib/cheri/java/builder/main.rb

Constant Summary collapse

Const =
Cheri::Java::Builder::Constants

Instance Method Summary collapse

Constructor Details

#initialize(*sources) {|_self| ... } ⇒ ConstantResolver

Returns a new instance of ConstantResolver.

Yields:

  • (_self)

Yield Parameters:



273
274
275
276
277
278
279
280
# File 'lib/cheri/java/builder/main.rb', line 273

def initialize(*sources,&k)
  @sources = []
  @cache = {}
  sources.each do |s|
    self << s    
  end
  yield self if block_given?
end

Instance Method Details

#add_constant_source(source) ⇒ Object Also known as: <<



294
295
296
297
298
299
300
301
302
303
304
# File 'lib/cheri/java/builder/main.rb', line 294

def add_constant_source(source)
  # not much of a validity check, better than none...
  unless source.respond_to?(:get)
    raise Cheri::CheriException,"invalid constants source specified: #{source}"
  end
  unless @sources.include?(source)
    @sources << source
    # flush the cache
    @cache.clear 
  end
end

#copyObject



321
322
323
# File 'lib/cheri/java/builder/main.rb', line 321

def copy
  self.class.allocate.copy_from(@sources)
end

#get(constant) ⇒ Object



307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/cheri/java/builder/main.rb', line 307

def get(constant)
  rec_arr = @cache[constant]
  return (rec_arr == :no_match ? nil : rec_arr) if rec_arr
  @sources.each do |s|
    const_rec = s.get(constant)
    while const_rec
      (rec_arr ||= []) << const_rec
      const_rec = const_rec.next_rec
    end
  end
  @cache[constant] = rec_arr || :no_match
  rec_arr
end

#resolve_ctor(clazz, args) ⇒ Object

note that we pass args, not *args, as we want the original array



283
284
285
286
# File 'lib/cheri/java/builder/main.rb', line 283

def resolve_ctor(clazz,args)
  return false unless clazz.respond_to?(:java_class)
  Const.resolve_ctor(clazz,args,self)
end

#resolve_meth(object, sym, args) ⇒ Object

note that we pass args, not *args, as we want the original array



289
290
291
292
# File 'lib/cheri/java/builder/main.rb', line 289

def resolve_meth(object,sym,args)
  return false unless object.respond_to?(:java_class)
  Const.resolve_meth(object.class,sym,args,self)
end