Class: NeuronCheckSystem::Declaration

Inherits:
Object
  • Object
show all
Defined in:
lib/neuroncheck/declaration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeclaration

Returns a new instance of Declaration.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/neuroncheck/declaration.rb', line 169

def initialize
  @arg_matchers = []
  @return_matcher = nil
  @attr_matcher = nil
  @precond = nil
  @precond_allow_instance_method = false
  @postcond = nil
  @postcond_allow_instance_method = false

  @assigned_class_or_module = nil
  @assigned_method = nil
  @assigned_singleton_original_class = nil
  @assigned_attribute_name = nil

  @shorthand = false
  @declared_caller_locations = nil
end

Instance Attribute Details

#arg_matchersObject

Returns the value of attribute arg_matchers.



152
153
154
# File 'lib/neuroncheck/declaration.rb', line 152

def arg_matchers
  @arg_matchers
end

#assigned_attribute_nameObject

Returns the value of attribute assigned_attribute_name.



164
165
166
# File 'lib/neuroncheck/declaration.rb', line 164

def assigned_attribute_name
  @assigned_attribute_name
end

#assigned_class_or_moduleObject

Returns the value of attribute assigned_class_or_module.



161
162
163
# File 'lib/neuroncheck/declaration.rb', line 161

def assigned_class_or_module
  @assigned_class_or_module
end

#assigned_methodObject

Returns the value of attribute assigned_method.



162
163
164
# File 'lib/neuroncheck/declaration.rb', line 162

def assigned_method
  @assigned_method
end

#assigned_singleton_original_classObject

Returns the value of attribute assigned_singleton_original_class.



163
164
165
# File 'lib/neuroncheck/declaration.rb', line 163

def assigned_singleton_original_class
  @assigned_singleton_original_class
end

#attr_matcherObject

Returns the value of attribute attr_matcher.



154
155
156
# File 'lib/neuroncheck/declaration.rb', line 154

def attr_matcher
  @attr_matcher
end

#declared_caller_locationsObject

Returns the value of attribute declared_caller_locations.



166
167
168
# File 'lib/neuroncheck/declaration.rb', line 166

def declared_caller_locations
  @declared_caller_locations
end

#postcondObject

Returns the value of attribute postcond.



158
159
160
# File 'lib/neuroncheck/declaration.rb', line 158

def postcond
  @postcond
end

#postcond_allow_instance_methodObject

Returns the value of attribute postcond_allow_instance_method.



159
160
161
# File 'lib/neuroncheck/declaration.rb', line 159

def postcond_allow_instance_method
  @postcond_allow_instance_method
end

#precondObject

Returns the value of attribute precond.



156
157
158
# File 'lib/neuroncheck/declaration.rb', line 156

def precond
  @precond
end

#precond_allow_instance_methodObject

Returns the value of attribute precond_allow_instance_method.



157
158
159
# File 'lib/neuroncheck/declaration.rb', line 157

def precond_allow_instance_method
  @precond_allow_instance_method
end

#return_matcherObject

Returns the value of attribute return_matcher.



153
154
155
# File 'lib/neuroncheck/declaration.rb', line 153

def return_matcher
  @return_matcher
end

#shorthandObject

Returns the value of attribute shorthand.



165
166
167
# File 'lib/neuroncheck/declaration.rb', line 165

def shorthand
  @shorthand
end

Instance Method Details

#assinged_to_singleton_method?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/neuroncheck/declaration.rb', line 194

def assinged_to_singleton_method?
  @assigned_singleton_original_class
end

#assinged_to_toplevel_method?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/neuroncheck/declaration.rb', line 191

def assinged_to_toplevel_method?
  @assigned_class_or_module == Object
end

#attribute?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/neuroncheck/declaration.rb', line 187

def attribute?
  (@assigned_attribute_name ? true : false)
end

#meta_info_as_jsonObject



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/neuroncheck/declaration.rb', line 276

def meta_info_as_json
  re = {}

  if attribute? then
    re['value'] = (@attr_matcher ? @attr_matcher.meta_info_as_json : nil)
    re['signature_caption'] = signature_caption
    re['signature_caption_name_only'] = signature_caption_name_only
  else
    re['args'] = @arg_matchers.map{|x| x.meta_info_as_json}
    re['returns'] = (@return_matcher ? @return_matcher.meta_info_as_json : nil)
    re['signature_caption'] = signature_caption
    re['signature_caption_name_only'] = signature_caption_name_only
  end
  re['precond_source_location'] = (@precond ? @precond.source_location : nil)
  re['postcond_source_location'] = (@postcond ? @postcond.source_location : nil)

  re
end

#signature_captionObject

メソッド名/属性名+引数+戻り値の表記文字列を取得



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/neuroncheck/declaration.rb', line 237

def signature_caption
  ret = signature_caption_name_only
  if ret then
    if attribute? then

      if @attr_matcher then
        ret << " -> #{@attr_matcher.expected_short_caption}"
      end
    else

      # 引数出力
      unless @assigned_method.parameters.empty? then
        ret << "("
        @assigned_method.parameters.each_with_index do |param_info, i|
          _, param_name = param_info
          if i >= 1 then
            ret << ", "
          end

          if (matcher = @arg_matchers[i]) then
            ret << "#{param_name}:#{matcher.expected_short_caption}"
          else
            ret << "#{param_name}:any"
          end
        end
        ret << ")"
      end

      if @return_matcher then
        ret << " -> #{@return_matcher.expected_short_caption}"
      end
    end

    return ret
  else
    nil
  end
end

#signature_caption_name_onlyObject

メソッド名/属性名の表記文字列を取得



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/neuroncheck/declaration.rb', line 199

def signature_caption_name_only
  if @assigned_class_or_module and (@assigned_method or attribute?) then
    ret = ""

    # 属性、特異メソッド、インスタンスメソッドのそれぞれで処理を分岐
    if attribute? then
      if @assigned_class_or_module.name then
        ret << @assigned_class_or_module.name
      end

      # 属性名出力
      ret << "##{@assigned_attribute_name}"

    elsif assinged_to_toplevel_method? then
      # メソッド名出力
      ret << "#{@assigned_method.name}"

    elsif assinged_to_singleton_method? then
      if @assigned_singleton_original_class.name then
        ret << @assigned_singleton_original_class.name
      end

      # メソッド名出力
      ret << ".#{@assigned_method.name}"
    else
      if @assigned_class_or_module.name then
        ret << @assigned_class_or_module.name
      end

      # メソッド名出力
      ret << "##{@assigned_method.name}"
    end
  else
    nil
  end
end