using Microsoft.CodeAnalysis;
using System.Collections.Generic;
namespace Semmle.Extraction.CommentProcessing
{
///
/// The type of a single comment line.
///
public enum CommentLineType
{
Singleline, // Comment starting // ...
XmlDoc, // Comment starting /// ...
Multiline, // Comment starting /* ..., even if the comment only spans one line.
MultilineContinuation // The second and subsequent lines of comment in a multiline comment.
};
///
/// Describes the relationship between a comment and a program element.
///
public enum CommentBinding
{
Parent, // The parent element of a comment
Best, // The most likely element associated with a comment
Before, // The element before the comment
After // The element after the comment
};
///
/// A single line in a comment.
///
public interface ICommentLine
{
///
/// The location of this comment line.
///
Location Location { get; }
///
/// The type of this comment line.
///
CommentLineType Type { get; }
///
/// The text body of this comment line, excluding comment delimiter and leading and trailing whitespace.
///
string Text { get; }
///
/// Full text of the comment including leading/trailing whitespace and comment delimiters.
///
string RawText { get; }
}
///
/// A block of comment lines combined into one unit.
///
public interface ICommentBlock
{
///
/// The full span of this comment block.
///
Location Location { get; }
///
/// The individual lines in the comment.
///
IEnumerable CommentLines { get; }
}
///
/// Callback for generated comment associations.
///
/// The label of the element
/// The duplication guard key of the element, if any
/// The comment block associated with the element
/// The relationship between the commentblock and the element
public delegate void CommentBindingCallback(Label elementLabel, Key? duplicationGuardKey, ICommentBlock commentBlock, CommentBinding binding);
///
/// Computes the binding information between comments and program elements.
///
public interface ICommentGenerator
{
///
/// Registers the location of a program element to associate comments with.
/// This can be called in any order.
///
/// Label of the element.
/// The duplication guard key of the element, if any.
/// Location of the element.
void AddElement(Label elementLabel, Key? duplicationGuardKey, Location location);
///
/// Registers a line of comment.
///
/// The comment to register.
void AddComment(ICommentLine comment);
///
/// Computes the binding information and calls `cb` with all of the comment binding information.
///
/// Receiver of the binding information.
void GenerateBindings(CommentBindingCallback cb);
}
}