Class: Duby::JVM::Types::JavaMethod

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

Direct Known Subclasses

JavaStaticMethod

Instance Method Summary collapse

Methods inherited from JavaConstructor

#argument_types, #declaring_class, #exceptions, #initialize, #name

Methods included from ArgumentConversion

#convert_args

Constructor Details

This class inherits a constructor from Duby::JVM::Types::JavaConstructor

Instance Method Details

#actual_return_typeObject



123
124
125
126
127
128
129
# File 'lib/duby/jvm/types/methods.rb', line 123

def actual_return_type
  if @member.return_type
    return_type
  else
    Void
  end
end

#call(compiler, ast, expression) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/duby/jvm/types/methods.rb', line 143

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?
    compiler.method.pop
  end
end

#constructor?Boolean

Returns:



139
140
141
# File 'lib/duby/jvm/types/methods.rb', line 139

def constructor?
  false
end

#return_typeObject



113
114
115
116
117
118
119
120
121
# File 'lib/duby/jvm/types/methods.rb', line 113

def return_type
  @return_type ||= begin
    if @member.return_type
      AST.type(@member.return_type)
    else
      declaring_class
    end
  end
end

#static?Boolean

Returns:



131
132
133
# File 'lib/duby/jvm/types/methods.rb', line 131

def static?
  @member.static?
end

#void?Boolean

Returns:



135
136
137
# File 'lib/duby/jvm/types/methods.rb', line 135

def void?
  @member.return_type.nil?
end