Skip to content

Commit

Permalink
Add support for overriding getCommonSuperClass for writing frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brown committed Jul 23, 2011
1 parent 96dfbef commit b26d74a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lib/bitescript/builder.rb
Expand Up @@ -126,6 +126,7 @@ def self.build(filename, &block)

def define_class(class_name, opts, &block)
pkg = opts[:package] || @package.dup || []
opts[:widen] ||= @widen_proc

class_name = pkg.empty? ? class_name : "#{pkg.join('/')}/#{class_name}"
class_builder = ClassBuilder.new(self, class_name, @file_name, opts)
Expand All @@ -141,7 +142,11 @@ def define_class(class_name, opts, &block)
return class_builder
end
end


def to_widen(&block)
@widen_proc = block
end

def public_class(class_name, superclass = java.lang.Object, *interfaces, &block)
define_class(class_name, :visibility => :public, :superclass => superclass, :interfaces => interfaces, &block)
end
Expand Down Expand Up @@ -201,7 +206,22 @@ def method?
false
end
end


class CustomClassWriter < BiteScript::ASM::ClassWriter
def initialize(*args, &block)
super(*args)
@widen_proc = block
end
def getCommonSuperClass(a, b)
if @widen_proc
result = @widen_proc.call(a, b)
result
else
super
end
end
end

class ClassBuilder
include Util
include QuickTypes
Expand Down Expand Up @@ -232,7 +252,7 @@ def initialize(file_builder, class_name, file_name, opts)
flags = Opcodes::ACC_INTERFACE | Opcodes::ACC_ABSTRACT
end

@class_writer = ClassWriter.new(ClassWriter::COMPUTE_FRAMES | ClassWriter::COMPUTE_MAXS)
@class_writer = CustomClassWriter.new(ClassWriter::COMPUTE_FRAMES | ClassWriter::COMPUTE_MAXS, &opts[:widen])

interface_paths = []
(@interfaces).each {|interface| interface_paths << path(interface)}
Expand Down

0 comments on commit b26d74a

Please sign in to comment.