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.



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

def initialize(comment)
	@comment = comment
end

Class Method Details

.build_from(comment) ⇒ Object

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



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
57
# File 'lib/ffi/clang/comment.rb', line 25

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.



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

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

#childrenObject

Get all child comments.



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

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

#each(&block) ⇒ Object

Iterate over all child comments.



112
113
114
115
116
117
118
119
120
# File 'lib/ffi/clang/comment.rb', line 112

def each(&block)
	return to_enum(__method__) unless block_given?
	
	num_children.times do |i|
		block.call(child(i))
	end
	
	self
end

#has_trailing_newline?Boolean

Check if this comment has a trailing newline.

Returns:

  • (Boolean)


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

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

#kindObject

Get the kind of this comment.



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

def kind
	Lib.comment_get_kind(@comment)
end

#num_childrenObject

Get the number of child comments.



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

def num_children
	Lib.comment_get_num_children(@comment)
end

#textObject

Get the text content of this comment.



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

def text
	return ""
end

#whitespace?Boolean

Check if this comment is whitespace only.

Returns:

  • (Boolean)


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

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