Class: FFI::Clang::Comment

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi/clang/comment.rb

Overview

Represents a documentation comment in parsed source code. This class provides access to structured documentation comments extracted from C/C++ source code. Comments can have different kinds (text, inline commands, HTML tags, block commands, etc.) and can be hierarchical.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment) ⇒ Comment

Create a new comment instance.



66
67
68
# File 'lib/ffi/clang/comment.rb', line 66

def initialize(comment)
  @comment = comment
end

Class Method Details

.build_from(comment) ⇒ Object

Build a comment instance from a low-level comment handle.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ffi/clang/comment.rb', line 24

def self.build_from(comment)
  kind = Lib.comment_get_kind(comment)
  case kind
  when :comment_null
    Comment.new comment
  when :comment_text
    TextComment.new comment
  when :comment_inline_command
    InlineCommandComment.new comment
  when :comment_html_start_tag
    HTMLStartTagComment.new comment
  when :comment_html_end_tag
    HTMLEndTagComment.new comment
  when :comment_paragraph
    ParagraphComment.new comment
  when :comment_block_command
    BlockCommandComment.new comment
  when :comment_param_command
    ParamCommandComment.new comment
  when :comment_tparam_command
    TParamCommandComment.new comment
  when :comment_verbatim_block_command
    VerbatimBlockCommandComment.new comment
  when :comment_verbatim_block_line
    VerbatimBlockLineComment.new comment
  when :comment_verbatim_line
    VerbatimLine.new comment
  when :comment_full
    FullComment.new comment
  else
    raise NotImplementedError, kind
  end
end

Instance Method Details

#child(n = 0) ⇒ Object

Get a specific child comment by index.



85
86
87
# File 'lib/ffi/clang/comment.rb', line 85

def child(n = 0)
  Comment.build_from Lib.comment_get_child(@comment, n)
end

#childrenObject

Get all child comments.



91
92
93
# File 'lib/ffi/clang/comment.rb', line 91

def children
  num_children.times.map {|i| child(i)}
end

#each(&block) ⇒ Object

Iterate over all child comments.



110
111
112
113
114
# File 'lib/ffi/clang/comment.rb', line 110

def each(&block)
  num_children.times.map do |i|
    block.call(child(i))
  end
end

#has_trailing_newline?Boolean

Check if this comment has a trailing newline.



103
104
105
# File 'lib/ffi/clang/comment.rb', line 103

def has_trailing_newline?
  Lib.inline_content_comment_has_trailing_newline(@comment) != 0
end

#kindObject

Get the kind of this comment.



72
73
74
# File 'lib/ffi/clang/comment.rb', line 72

def kind
  Lib.comment_get_kind(@comment)
end

#num_childrenObject

Get the number of child comments.



78
79
80
# File 'lib/ffi/clang/comment.rb', line 78

def num_children
  Lib.comment_get_num_children(@comment)
end

#textObject

Get the text content of this comment.



60
61
62
# File 'lib/ffi/clang/comment.rb', line 60

def text
  return ""
end

#whitespace?Boolean

Check if this comment is whitespace only.



97
98
99
# File 'lib/ffi/clang/comment.rb', line 97

def whitespace?
  Lib.comment_is_whitespace(@comment) != 0
end