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:



270
271
272
273
274
275
276
277
# File 'lib/cheri/java/builder/main.rb', line 270

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: <<



291
292
293
294
295
296
297
298
299
300
301
# File 'lib/cheri/java/builder/main.rb', line 291

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



318
319
320
# File 'lib/cheri/java/builder/main.rb', line 318

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

#get(constant) ⇒ Object



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/cheri/java/builder/main.rb', line 304

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



280
281
282
283
# File 'lib/cheri/java/builder/main.rb', line 280

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



286
287
288
289
# File 'lib/cheri/java/builder/main.rb', line 286

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