Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 1628623002: Isse 25404. When remove a method during inlining, remove also leading empty lines. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/correction/util.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index ef836c1b99824a46c989b4fd9ad18bac2113648d..63aefd964ef13af869e17bbc7db7d17c69625546 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -664,7 +664,8 @@ class CorrectionUtils {
AstNode enclosingNode = findNode(offset);
Block enclosingBlock = enclosingNode.getAncestor((node) => node is Block);
if (enclosingBlock != null) {
- _CollectReferencedUnprefixedNames visitor = new _CollectReferencedUnprefixedNames();
+ _CollectReferencedUnprefixedNames visitor =
+ new _CollectReferencedUnprefixedNames();
enclosingBlock.accept(visitor);
return visitor.names;
}
@@ -903,10 +904,14 @@ class CorrectionUtils {
* Returns a [SourceRange] that covers [range] and extends (if possible) to
* cover whole lines.
*/
- SourceRange getLinesRange(SourceRange range) {
+ SourceRange getLinesRange(SourceRange range,
+ {bool skipLeadingEmptyLines: false}) {
// start
int startOffset = range.offset;
int startLineOffset = getLineContentStart(startOffset);
+ if (skipLeadingEmptyLines) {
+ startLineOffset = skipEmptyLinesLeft(startLineOffset);
+ }
// end
int endOffset = range.end;
int afterEndLineOffset = getLineContentEnd(endOffset);
@@ -1221,6 +1226,27 @@ class CorrectionUtils {
}
/**
+ * Skip spaces, tabs and EOLs on the left from [index].
+ *
+ * If [index] is the start of a method, then in the most cases return the end
+ * of the previous not-whitespace line.
+ */
+ int skipEmptyLinesLeft(int index) {
+ int lastLine = index;
+ while (index > 0) {
+ int c = _buffer.codeUnitAt(index - 1);
+ if (!isWhitespace(c)) {
+ return lastLine;
+ }
+ if (isEOL(c)) {
+ lastLine = index;
+ }
+ index--;
+ }
+ return 0;
+ }
+
+ /**
* @return the [ImportElement] used to import given [Element] into [library].
* May be `null` if was not imported, i.e. declared in the same library.
*/

Powered by Google App Engine
This is Rietveld 408576698