FFI::ClangSourceFFIClangComment

class Comment

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.

Definitions

def self.build_from(comment)

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

Signature

parameter comment FFI::Pointer

The low-level comment handle.

returns Comment

A comment instance of the appropriate subclass based on the comment kind.

Implementation

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

def text

Get the text content of this comment.

Signature

returns String

The text content, empty string for base Comment class.

Implementation

def text
	return ""
end

def initialize(comment)

Create a new comment instance.

Signature

parameter comment FFI::Pointer

The low-level comment handle.

Implementation

def initialize(comment)
	@comment = comment
end

def kind

Get the kind of this comment.

Signature

returns Symbol

The comment kind (e.g., :comment_text, :comment_paragraph).

Implementation

def kind
	Lib.comment_get_kind(@comment)
end

def num_children

Get the number of child comments.

Signature

returns Integer

The number of child comments.

Implementation

def num_children
	Lib.comment_get_num_children(@comment)
end

def child(n = 0)

Get a specific child comment by index.

Signature

parameter n Integer

The child index (defaults to 0).

returns Comment

The child comment at the specified index.

Implementation

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

def children

Get all child comments.

Signature

returns Array<Comment>

An array of all child comments.

Implementation

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

def whitespace?

Check if this comment is whitespace only.

Signature

returns Boolean

True if the comment contains only whitespace.

Implementation

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

def has_trailing_newline?

Check if this comment has a trailing newline.

Signature

returns Boolean

True if the comment has a trailing newline.

Implementation

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

def each(&block)

Iterate over all child comments.

Signature

yields {|comment| ...}

Yields each child comment.

parameter comment Comment

The child comment.

Implementation

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