getLineNr method
Implementation
int? getLineNr(Element docCommentsOwner) {
final session = docCommentsOwner.session;
if (session == null) {
return null;
}
var library = docCommentsOwner.library;
if (library == null) {
return null;
}
final parsedLibrary =
session.getParsedLibraryByElement(library) as ParsedLibraryResult;
final declaration = parsedLibrary.getElementDeclaration(docCommentsOwner);
if (declaration == null) {
return null;
}
final node = declaration.node;
final elementOffset = node.offset;
var compilationUnit = declaration.node.root as CompilationUnit;
var lineInfo = compilationUnit.lineInfo;
return lineInfo.getLocation(elementOffset).lineNumber;
}