mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
diff: do not expose potentially dangerous methods
DiffUtil.replaceLines has confusing name, as it doesn't work with deletions and insertions. DiffUtil.applyModification() should be used instead.
This commit is contained in:
@@ -99,8 +99,6 @@ import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.diff.tools.util.base.TextDiffViewerUtil.areEqualLineSeparators;
|
||||
|
||||
public class DiffUtil {
|
||||
private static final Logger LOG = Logger.getInstance(DiffUtil.class);
|
||||
|
||||
@@ -658,7 +656,7 @@ public class DiffUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteLines(@NotNull Document document, int line1, int line2) {
|
||||
private static void deleteLines(@NotNull Document document, int line1, int line2) {
|
||||
TextRange range = getLinesRange(document, line1, line2);
|
||||
int offset1 = range.getStartOffset();
|
||||
int offset2 = range.getEndOffset();
|
||||
@@ -672,7 +670,7 @@ public class DiffUtil {
|
||||
document.deleteString(offset1, offset2);
|
||||
}
|
||||
|
||||
public static void insertLines(@NotNull Document document, int line, @NotNull CharSequence text) {
|
||||
private static void insertLines(@NotNull Document document, int line, @NotNull CharSequence text) {
|
||||
if (line == getLineCount(document)) {
|
||||
document.insertString(document.getTextLength(), "\n" + text);
|
||||
}
|
||||
@@ -681,7 +679,7 @@ public class DiffUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void replaceLines(@NotNull Document document, int line1, int line2, @NotNull CharSequence text) {
|
||||
private static void replaceLines(@NotNull Document document, int line1, int line2, @NotNull CharSequence text) {
|
||||
TextRange currentTextRange = getLinesRange(document, line1, line2);
|
||||
int offset1 = currentTextRange.getStartOffset();
|
||||
int offset2 = currentTextRange.getEndOffset();
|
||||
@@ -689,14 +687,6 @@ public class DiffUtil {
|
||||
document.replaceString(offset1, offset2, text);
|
||||
}
|
||||
|
||||
public static void insertLines(@NotNull Document document1, int line, @NotNull Document document2, int otherLine1, int otherLine2) {
|
||||
insertLines(document1, line, getLinesContent(document2, otherLine1, otherLine2));
|
||||
}
|
||||
|
||||
public static void replaceLines(@NotNull Document document1, int line1, int line2, @NotNull Document document2, int oLine1, int oLine2) {
|
||||
replaceLines(document1, line1, line2, getLinesContent(document2, oLine1, oLine2));
|
||||
}
|
||||
|
||||
public static void applyModification(@NotNull Document document1,
|
||||
int line1,
|
||||
int line2,
|
||||
@@ -705,13 +695,13 @@ public class DiffUtil {
|
||||
int oLine2) {
|
||||
if (line1 == line2 && oLine1 == oLine2) return;
|
||||
if (line1 == line2) {
|
||||
insertLines(document1, line1, document2, oLine1, oLine2);
|
||||
insertLines(document1, line1, getLinesContent(document2, oLine1, oLine2));
|
||||
}
|
||||
else if (oLine1 == oLine2) {
|
||||
deleteLines(document1, line1, line2);
|
||||
}
|
||||
else {
|
||||
replaceLines(document1, line1, line2, document2, oLine1, oLine2);
|
||||
replaceLines(document1, line1, line2, getLinesContent(document2, oLine1, oLine2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user