Class: Mirah::AST::JsniMethodDefinition

Inherits:
MethodDefinition show all
Defined in:
lib/mirah/plugin/gwt.rb

Instance Attribute Summary

Attributes inherited from MethodDefinition

#abstract, #defining_class, #exceptions, #return_type, #visibility

Attributes included from Scope

#static_scope, #type_scope

Attributes included from Named

#name

Attributes included from Annotated

#annotations

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods inherited from MethodDefinition

#name, #resolve_if

Methods included from Binding

#binding_type, #binding_type=, #has_binding?

Methods included from ClassScoped

#class_scope

Methods included from Scoped

#containing_scope, #scope

Methods included from Named

#string_value, #to_s, #validate_name

Methods included from Annotated

#annotation

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(static, parent, line_number, name, annotations = [], &block) ⇒ JsniMethodDefinition

Returns a new instance of JsniMethodDefinition.



101
102
103
104
# File 'lib/mirah/plugin/gwt.rb', line 101

def initialize(static, parent, line_number, name, annotations=[], &block)
  super(parent, line_number, name, annotations, &block)
  @static = static
end

Instance Method Details

#abstract?Boolean

JSNI can’t be abstract.

Returns:



130
131
132
# File 'lib/mirah/plugin/gwt.rb', line 130

def abstract?
  false
end

#compile(compiler, expression) ⇒ Object



106
107
108
# File 'lib/mirah/plugin/gwt.rb', line 106

def compile(compiler, expression)
  compiler.define_jsni_method(self)
end

#infer(typer, expression) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/mirah/plugin/gwt.rb', line 110

def infer(typer, expression)
  @static ||= scope.static_scope.self_type.meta? unless scope.nil?
  @defining_class ||= begin
    static_scope.self_node = :self
    static_scope.self_type = if static?
      scope.static_scope.self_type.meta
    else
      scope.static_scope.self_type
    end
  end
  resolve_if(typer) do
    argument_types = typer.infer(arguments, true)
    if argument_types.all?
      typer.learn_method_type(defining_class, name, argument_types,
        signature[:return], signature[:throws])
    end
  end
end

#static?Boolean

Returns:



134
135
136
# File 'lib/mirah/plugin/gwt.rb', line 134

def static?
  @static
end