From 423f532222c58d045bc960fedbd615193ba45514 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Sun, 24 Oct 2010 21:08:46 +0300 Subject: [PATCH] Renamed @function tag to @method. To comply with ext-doc. --- doc_comment.rb | 8 +++---- doc_comment_parser.rb | 16 ++++++------- tc_doc_comment_parser.rb | 24 +++++++++---------- tc_jsduck.rb | 50 ++++++++++++++++++++-------------------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/doc_comment.rb b/doc_comment.rb index e65e84b1..2f5bbd0b 100644 --- a/doc_comment.rb +++ b/doc_comment.rb @@ -5,7 +5,7 @@ module JsDuck def initialize(tags) @tags = tags - [:class, :function, :event, :cfg].each do |name| + [:class, :method, :event, :cfg].each do |name| if @tags[name] then @root_tag = @tags[name] end @@ -15,16 +15,16 @@ module JsDuck # Sets the name property of the default at-tag. # # When name begins with uppercase it's considered to be class - # name, otherwise a function name. + # name, otherwise a method name. # # When the name consists of several parts like foo.bar.baz, then # the parts should be passed as multiple arguments. def set_default_name(*name_chain) name = name_chain.last - tagname = (name[0,1] == name[0,1].upcase) ? :class : :function + tagname = (name[0,1] == name[0,1].upcase) ? :class : :method if !@root_tag then - @root_tag = {:name => (tagname == :function) ? name : name_chain.join(".")} + @root_tag = {:name => (tagname == :method) ? name : name_chain.join(".")} @root_tag[:doc] = @tags[:default][:doc] @tags[tagname] = @root_tag @tags.delete(:default) diff --git a/doc_comment_parser.rb b/doc_comment_parser.rb index 9e02114e..1ce2a586 100644 --- a/doc_comment_parser.rb +++ b/doc_comment_parser.rb @@ -51,8 +51,8 @@ module JsDuck at_singleton elsif look(/@event\b/) then at_event - elsif look(/@function\b/) then - at_function + elsif look(/@method\b/) then + at_method elsif look(/@constructor\b/) then at_constructor elsif look(/@param\b/) then @@ -129,10 +129,10 @@ module JsDuck skip_white end - # matches @function name ... - def at_function - match(/@function/) - set_root_tag(:function, {:doc => ""}) + # matches @method name ... + def at_method + match(/@method/) + set_root_tag(:method, {:doc => ""}) skip_horiz_white if look(/\w/) then @current_tag[:name] = ident @@ -141,10 +141,10 @@ module JsDuck end # matches @constructor ... - # Which is equivalent of: @function constructor ... + # Which is equivalent of: @method constructor ... def at_constructor match(/@constructor/) - set_root_tag(:function, {:doc => "", :name => "constructor"}) + set_root_tag(:method, {:doc => "", :name => "constructor"}) skip_white end diff --git a/tc_doc_comment_parser.rb b/tc_doc_comment_parser.rb index b85aad87..61024d6b 100644 --- a/tc_doc_comment_parser.rb +++ b/tc_doc_comment_parser.rb @@ -7,16 +7,16 @@ class TestDocCommentParser < Test::Unit::TestCase return JsDuck::DocCommentParser.new.parse(doc)[0] end - def test_function + def test_method doc = parse_single("/** - * @function foo + * @method foo * Some docs. * @param {Number} x doc for x * @param {Integer} y doc for y * @return {String} resulting value */") - assert_equal("foo", doc[:function][:name]) - assert_equal("Some docs.", doc[:function][:doc]) + assert_equal("foo", doc[:method][:name]) + assert_equal("Some docs.", doc[:method][:doc]) assert_equal(2, doc[:param].length) @@ -37,8 +37,8 @@ class TestDocCommentParser < Test::Unit::TestCase * @constructor * Some docs. */") - assert_equal("constructor", doc[:function][:name]) - assert_equal("Some docs.", doc[:function][:doc]) + assert_equal("constructor", doc[:method][:name]) + assert_equal("Some docs.", doc[:method][:doc]) end def test_class @@ -93,7 +93,7 @@ class TestDocCommentParser < Test::Unit::TestCase def test_long_docs doc = parse_single("/** - * @function foo + * @method foo * * Some docs. * @@ -106,7 +106,7 @@ class TestDocCommentParser < Test::Unit::TestCase * long * docs. */") - assert_equal("Some docs.\n\nNice docs.", doc[:function][:doc]) + assert_equal("Some docs.\n\nNice docs.", doc[:method][:doc]) assert_equal("some\nlong\ndocs.", doc[:param][0][:doc]) assert_equal("more\nlong\ndocs.", doc[:return][:doc]) end @@ -124,13 +124,13 @@ class TestDocCommentParser < Test::Unit::TestCase assert_equal(nil, doc[:return][:type]) end - def test_nameless_function + def test_nameless_method doc = parse_single("/** - * @function + * @method * Comment for this func. */") - assert_equal(nil, doc[:function][:name]) - assert_equal("Comment for this func.", doc[:function][:doc]) + assert_equal(nil, doc[:method][:name]) + assert_equal("Comment for this func.", doc[:method][:doc]) end def test_nameless_class diff --git a/tc_jsduck.rb b/tc_jsduck.rb index 6e7e530a..aefbfa2e 100644 --- a/tc_jsduck.rb +++ b/tc_jsduck.rb @@ -3,7 +3,7 @@ require "test/unit" class TestJsDuck < Test::Unit::TestCase - def test_function + def test_method docs = JsDuck.parse(" /** * Some function @@ -11,67 +11,67 @@ class TestJsDuck < Test::Unit::TestCase function foo(x) { } ") - assert_equal("Some function", docs[0][:function][:doc]) - assert_equal("foo", docs[0][:function][:name]) + assert_equal("Some function", docs[0][:method][:doc]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_with_var + def test_method_with_var docs = JsDuck.parse(" /** */ var foo = function(x) { } ") - assert_equal("foo", docs[0][:function][:name]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_without_var + def test_method_without_var docs = JsDuck.parse(" /** */ foo = function(x) { } ") - assert_equal("foo", docs[0][:function][:name]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_in_object_literal + def test_method_in_object_literal docs = JsDuck.parse(" /** */ foo: function(x) { } ") - assert_equal("foo", docs[0][:function][:name]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_in_object_literal_string + def test_method_in_object_literal_string docs = JsDuck.parse(" /** */ 'foo': function(x) { } ") - assert_equal("foo", docs[0][:function][:name]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_in_prototype + def test_method_in_prototype docs = JsDuck.parse(" /** */ Some.Long.prototype.foo = function(x) { } ") - assert_equal("foo", docs[0][:function][:name]) + assert_equal("foo", docs[0][:method][:name]) assert_equal("x", docs[0][:param][0][:name]) end - def test_function_private + def test_method_private docs = JsDuck.parse(" // no doc-comment for this function function foo() { @@ -80,31 +80,31 @@ function foo() { assert_equal([], docs) end - def test_explicit_function_doc + def test_explicit_method_doc docs = JsDuck.parse(" /** - * @function hello + * @method hello * Just some function */ eval('hello = new Function();'); ") - assert_equal("hello", docs[0][:function][:name]) - assert_equal("Just some function", docs[0][:function][:doc]) + assert_equal("hello", docs[0][:method][:name]) + assert_equal("Just some function", docs[0][:method][:doc]) end - def test_explicit_function_doc_overrides_implicit_code + def test_explicit_method_doc_overrides_implicit_code docs = JsDuck.parse(" /** - * @function hello + * @method hello * Just some function */ function goodby(){} ") - assert_equal("hello", docs[0][:function][:name]) - assert_equal("Just some function", docs[0][:function][:doc]) + assert_equal("hello", docs[0][:method][:name]) + assert_equal("Just some function", docs[0][:method][:doc]) end - def test_implicit_function_parameters + def test_implicit_method_parameters docs = JsDuck.parse(" /** */ @@ -116,7 +116,7 @@ function f(foo, bar, baz){} assert_equal("baz", params[2][:name]) end - def test_explicit_function_parameters_override_implicit_ones + def test_explicit_method_parameters_override_implicit_ones docs = JsDuck.parse(" /** * @param {String} x @@ -170,7 +170,7 @@ function Bar(){} assert_equal("My class", docs[0][:class][:doc]) end - def test_uppercase_function_name_implies_class_name + def test_uppercase_method_name_implies_class_name docs = JsDuck.parse(" /** * My class -- GitLab