findDependencyLines static method
Find all lines that belong to a dependency (including multi-line dependencies)
Implementation
static List<int> findDependencyLines(
List<String> lines, int startIndex, int sectionEndIndex) {
final dependencyLines = <int>[startIndex];
final startLine = lines[startIndex];
final baseIndentation = _getIndentation(startLine);
// Check if this is a multi-line dependency
// Look for lines that are more indented than the package name line
for (int i = startIndex + 1;
i <= sectionEndIndex && i < lines.length;
i++) {
final line = lines[i];
final currentIndentation = _getIndentation(line);
// If this line is more indented than the package line, it belongs to this dependency
if (currentIndentation > baseIndentation && line.trim().isNotEmpty) {
dependencyLines.add(i);
} else if (line.trim().isEmpty) {
// Empty line - could be part of the dependency or separator
// Only include if the next non-empty line is still part of this dependency
bool includeEmptyLine = false;
for (int j = i + 1; j <= sectionEndIndex && j < lines.length; j++) {
final nextLine = lines[j];
if (nextLine.trim().isNotEmpty) {
final nextIndentation = _getIndentation(nextLine);
if (nextIndentation > baseIndentation) {
includeEmptyLine = true;
}
break;
}
}
if (includeEmptyLine) {
dependencyLines.add(i);
} else {
break; // Empty line followed by same/less indented line - end of dependency
}
} else {
// If we hit a line with same or less indentation, we've reached the next dependency
break;
}
}
return dependencyLines;
}