fileHeader property
List<Token>
get
fileHeader
Return the list of tokens that comprise the file header comment for this compilation unit.
If there is no file comment the list will be empty. If the file comment is a block comment the list will contain a single token. If the file comment is comprised of one or more single line comments, then the list will contain all of the tokens, and the comment is assumed to stop at the first line that contains anything other than a single line comment (either a blank line, a directive, a declaration, or a multi-line comment). The list will never include a documentation comment.
Implementation
List<Token> get fileHeader {
final lineInfo = this.lineInfo;
var firstToken = beginToken;
if (firstToken.type == TokenType.SCRIPT_TAG) {
firstToken = firstToken.next!;
}
final firstComment = firstToken.precedingComments;
if (firstComment == null ||
firstComment.lexeme.startsWith('/**') ||
firstComment.lexeme.startsWith('///')) {
return const [];
} else if (firstComment.lexeme.startsWith('/*')) {
return [firstComment];
} else if (!firstComment.lexeme.startsWith('//')) {
return const [];
}
final header = <Token>[firstComment];
var previousLine = lineInfo.getLocation(firstComment.offset).lineNumber;
var currentToken = firstComment.next;
while (currentToken != null) {
if (!currentToken.lexeme.startsWith('//') ||
currentToken.lexeme.startsWith('///')) {
return header;
}
final currentLine = lineInfo.getLocation(currentToken.offset).lineNumber;
if (currentLine != previousLine + 1) {
return header;
}
header.add(currentToken);
currentToken = currentToken.next;
previousLine = currentLine;
}
return header;
}