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

Unified Diff: dart/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegion.java

Issue 59073003: Version 0.8.10.4 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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: dart/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegion.java
===================================================================
--- dart/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegion.java (revision 29808)
+++ dart/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/dart/DartReconcilingRegion.java (working copy)
@@ -13,9 +13,6 @@
*/
package com.google.dart.tools.ui.internal.text.dart;
-import static java.lang.Math.max;
-import static java.lang.Math.min;
-
/**
* Instances of {@code DartReconcilingRegion} represent a source region that has changed.
*/
@@ -41,11 +38,13 @@
}
/**
- * Return a new region representing the union of the receiver with the specified region.
+ * Return a new region representing the union of the receiver with the specified region or
+ * {@code null} if the resulting region is disjoint and cannot be represented by this class.
*
* @param offset the offset of the first character that changed
* @param oldLength the number of characters that were replaced
* @param newLength the number of characters in the replacement text
+ * @return the region or {@code null} if disjoint
*/
public DartReconcilingRegion add(int offset, int oldLength, int newLength) {
if (oldLength == 0 && newLength == 0) {
@@ -54,9 +53,15 @@
if (isEmpty()) {
return new DartReconcilingRegion(offset, oldLength, newLength);
}
- int offset2 = min(this.offset, offset);
- int oldLength2 = max(this.offset + this.oldLength, offset + oldLength) - offset2;
- int newLength2 = max(this.offset + this.newLength, offset + newLength) - offset2;
+ if (offset + oldLength < this.offset) {
+ return null;
+ }
+ if (offset + oldLength > this.offset + this.newLength) {
+ return null;
+ }
+ int offset2 = Math.min(this.offset, offset);
+ int oldLength2 = this.oldLength + (this.offset - offset2);
+ int newLength2 = this.newLength + (newLength - oldLength) + (this.offset - offset2);
return new DartReconcilingRegion(offset2, oldLength2, newLength2);
}

Powered by Google App Engine
This is Rietveld 408576698