Method: RDoc::Parser::C#find_class_comment

Defined in:
lib/rdoc/parser/c.rb

#find_class_comment(class_name, class_mod) ⇒ Object

Look for class or module documentation above Init_class_name(void), in a Document-class class_name (or module) comment or above an rb_define_class (or module). If a comment is supplied above a matching Init_ and a rb_define_class the Init_ comment is used.

/*
 * This is a comment for Foo
 */
Init_Foo(void) {
    VALUE cFoo = rb_define_class("Foo", rb_cObject);
}

/*
 * Document-class: Foo
 * This is a comment for Foo
 */
Init_foo(void) {
    VALUE cFoo = rb_define_class("Foo", rb_cObject);
}

/*
 * This is a comment for Foo
 */
VALUE cFoo = rb_define_class("Foo", rb_cObject);


724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/rdoc/parser/c.rb', line 724

def find_class_comment class_name, class_mod
  comment = nil

  if @content =~ %r%
      ((?>/\*.*?\*/\s+))
      (static\s+)?
      void\s+
      Init(?:VM)?_(?i:#{class_name})\s*(?:_\(\s*)?\(\s*(?:void\s*)?\)%xm then
    comment = $1.sub(%r%Document-(?:class|module):\s+#{class_name}%, '')
  elsif @content =~ %r%Document-(?:class|module):\s+#{class_name}\s*?
                       (?:<\s+[:,\w]+)?\n((?>.*?\*/))%xm then
    comment = "/*\n#{$1}"
  elsif @content =~ %r%((?>/\*.*?\*/\s+))
                       ([\w\.\s]+\s* = \s+)?rb_define_(class|module)[\t (]*?"(#{class_name})"%xm then
    comment = $1
  elsif @content =~ %r%((?>/\*.*?\*/\s+))
                       ([\w\. \t]+ = \s+)?rb_define_(class|module)_under[\t\w, (]*?"(#{class_name.split('::').last})"%xm then
    comment = $1
  else
    comment = ''
  end

  comment = new_comment comment, @top_level, :c
  comment.normalize

  look_for_directives_in class_mod, comment

  class_mod.add_comment comment, @top_level
end