Class: Mirah::JVM::Types::JavaMethod

Inherits:
JavaConstructor show all
Defined in:
lib/mirah/jvm/types/methods.rb

Instance Attribute Summary

Attributes inherited from JavaCallable

#member

Instance Method Summary collapse

Methods inherited from JavaConstructor

#argument_types, #declaring_class, #exceptions

Methods inherited from JavaCallable

#field?, #initialize, #name, #parameter_types

Methods included from ArgumentConversion

#convert_args

Constructor Details

This class inherits a constructor from Mirah::JVM::Types::JavaCallable

Instance Method Details

#abstract?Boolean

Returns:



167
168
169
# File 'lib/mirah/jvm/types/methods.rb', line 167

def abstract?
  @member.abstract?
end

#call(compiler, ast, expression) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/mirah/jvm/types/methods.rb', line 184

def call(compiler, ast, expression)
  target = ast.target.inferred_type
  ast.target.compile(compiler, true)

  # if expression, void methods return the called object,
  # for consistency and chaining
  # TODO: inference phase needs to track that signature is
  # void but actual type is callee
  if expression && void?
    compiler.method.dup
  end

  convert_args(compiler, ast.parameters)
  if target.interface?
    compiler.method.invokeinterface(
      target,
      name,
      [@member.return_type, *@member.argument_types])
  else
    compiler.method.invokevirtual(
      target,
      name,
      [@member.return_type, *@member.argument_types])
  end

  unless expression || void?
    return_type.pop(compiler.method)
  end
end

#call_special(compiler, ast, expression) ⇒ Object



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
# File 'lib/mirah/jvm/types/methods.rb', line 214

def call_special(compiler, ast, expression)
  target = ast.target.inferred_type
  ast.target.compile(compiler, true)

  # if expression, void methods return the called object,
  # for consistency and chaining
  # TODO: inference phase needs to track that signature is
  # void but actual type is callee
  if expression && void?
    compiler.method.dup
  end

  convert_args(compiler, ast.parameters)
  if target.interface?
    raise "interfaces should not receive call_special"
  else
    compiler.method.invokespecial(
      target,
      name,
      [@member.return_type, *@member.argument_types])
  end

  unless expression || void?
    return_type.pop(compiler.method)
  end
end

#constructor?Boolean

Returns:



180
181
182
# File 'lib/mirah/jvm/types/methods.rb', line 180

def constructor?
  false
end

#return_typeObject



153
154
155
156
157
158
159
160
161
# File 'lib/mirah/jvm/types/methods.rb', line 153

def return_type
  @return_type ||= begin
    if void?
      Void
    else
      AST.type(nil, @member.return_type)
    end
  end
end

#static?Boolean

Returns:



163
164
165
# File 'lib/mirah/jvm/types/methods.rb', line 163

def static?
  @member.static?
end

#void?Boolean

Returns:



171
172
173
174
175
176
177
178
# File 'lib/mirah/jvm/types/methods.rb', line 171

def void?
  return_type = @member.return_type
  return true if return_type.nil?
  if return_type.respond_to?(:descriptor) && return_type.descriptor == 'V'
    return true
  end
  false
end