class NeuronCheckSystem::Declaration

Attributes

arg_matchers[RW]
assigned_attribute_name[RW]
assigned_class_or_module[RW]
assigned_method[RW]
assigned_singleton_original_class[RW]
attr_matcher[RW]
declared_caller_locations[RW]
postcond[RW]
postcond_allow_instance_method[RW]
precond[RW]
precond_allow_instance_method[RW]
return_matcher[RW]
shorthand[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

assinged_to_singleton_method?() click to toggle source
# File lib/neuroncheck/declaration.rb, line 194
def assinged_to_singleton_method?
  @assigned_singleton_original_class
end
assinged_to_toplevel_method?() click to toggle source
# File lib/neuroncheck/declaration.rb, line 191
def assinged_to_toplevel_method?
  @assigned_class_or_module == Object
end
attribute?() click to toggle source
# File lib/neuroncheck/declaration.rb, line 187
def attribute?
  (@assigned_attribute_name ? true : false)
end
meta_info_as_json() click to toggle source
# 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_caption() click to toggle source

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

# 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_only() click to toggle source

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

# 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