Commit 4363bcf2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Eliminate DocsCodeComparer class.

Move the methods in it to Merger.
parent 1a6efa4c
Loading
Loading
Loading
Loading

lib/jsduck/docs_code_comparer.rb

deleted100644 → 0
+0 −44
Original line number Diff line number Diff line
require 'jsduck/util/singleton'

module JsDuck

  # Compares documentation and code hashes.
  # Provides an utility method to help with merging.
  class DocsCodeComparer
    include Util::Singleton

    # Sets the value of a field in result hash based on its value in
    # docs and code hashes.
    #
    # - When docs has the key, gets value from there.
    #
    # - When code has the key and matches with docs, gets value from
    #   there, and also remembers the fact that we're using
    #   auto-detected value by recording it in :autodetected field.
    #
    def merge_if_matches(h, key, docs, code)
      if docs[key]
        h[key] = docs[key]
      elsif code[key] && matches?(docs, code)
        h[key] = code[key]
        mark_autodetected(h, key)
      else
        # nothing
      end
    end

    # True if the name detected from code matches with explicitly
    # documented name.  Also true when no explicit name documented.
    def matches?(docs, code)
      return docs[:name] == nil || docs[:name] == code[:name]
    end

    # Stores the key as flag into h[:autodetcted]
    def mark_autodetected(h, key)
      h[:autodetected] = {} unless h[:autodetected]
      h[:autodetected][key] = true
    end

  end

end
+14 −3
Original line number Diff line number Diff line
require 'jsduck/class'
require 'jsduck/tag_registry'
require 'jsduck/docs_code_comparer'

module JsDuck

@@ -58,16 +57,28 @@ module JsDuck
      # Add all items in code not already in result and mark them as
      # auto-detected.  But only if the explicit and auto-detected
      # names don't conflict.
      if DocsCodeComparer.matches?(docs, code)
      if can_be_autodetected?(docs, code)
        code.each_pair do |key, value|
          unless h[key]
            h[key] = value
            DocsCodeComparer.mark_autodetected(h, key)
            mark_autodetected(h, key)
          end
        end
      end
    end

    # True if the name detected from code matches with explicitly
    # documented name.  Also true when no explicit name documented.
    def can_be_autodetected?(docs, code)
      docs[:name] == nil || docs[:name] == code[:name]
    end

    # Stores the key as flag into h[:autodetcted]
    def mark_autodetected(h, key)
      h[:autodetected] = {} unless h[:autodetected]
      h[:autodetected][key] = true
    end

  end

end
+0 −1
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/docs_code_comparer"

module JsDuck::Tag
  # There is no @autodetected tag.
+0 −1
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/docs_code_comparer"
require "jsduck/util/html"

module JsDuck::Tag
+9 −4
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/doc/subproperties"
require "jsduck/render/subproperties"
require "jsduck/docs_code_comparer"
require "jsduck/logger"

module JsDuck::Tag
@@ -39,7 +38,7 @@ module JsDuck::Tag
        p[:type] = "Object" unless p[:type]
      end

      print_warnings(docs, code, h[:files].first)
      check_consistency(docs, code, h[:files].first)
    end

    def format(m, formatter)
@@ -52,9 +51,9 @@ module JsDuck::Tag

    private

    def print_warnings(docs, code, file)
    def check_consistency(docs, code, file)
      explicit = docs[:params] || []
      implicit = JsDuck::DocsCodeComparer.matches?(docs, code) ? (code[:params] || []) : []
      implicit = can_be_autodetected?(docs, code) ? (code[:params] || []) : []
      ex_len = explicit.length
      im_len = implicit.length

@@ -77,5 +76,11 @@ module JsDuck::Tag
      end
    end

    # True if the name detected from code matches with explicitly
    # documented name.  Also true when no explicit name documented.
    def can_be_autodetected?(docs, code)
      docs[:name] == nil || docs[:name] == code[:name]
    end

  end
end