replaceSourceRangeIndent method
Returns the source of the given SourceRange with indentation changed
from oldIndent to newIndent, keeping indentation of lines relative
to each other.
Indentation on the first line will only be updated if includeLeading is
true.
If ensureTrailingNewline is true, a newline will be added to
the end of the returned code if it does not already have one.
Usually includeLeading and ensureTrailingNewline are set together,
when indenting a set of statements to go inside a block (as opposed to
just wrapping a nested expression that might span multiple lines).
Implementation
String replaceSourceRangeIndent(
SourceRange range,
String oldIndent,
String newIndent, {
bool includeLeading = false,
bool ensureTrailingNewline = false,
}) {
var oldSource = getRangeText(range);
return replaceSourceIndent(
oldSource,
oldIndent,
newIndent,
includeLeading: includeLeading,
ensureTrailingNewline: ensureTrailingNewline,
);
}