Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2008-07-15 09:40:11 -0400
committerMichael Valenta2008-07-15 09:40:11 -0400
commit7796c473e6a9db2db7865ecddce6fd647b813ccf (patch)
treedf961bf748de22c0658d0c9dd949e1f2af03ff48
parent98d5ec1224ff14d387f0abb5551fa7c20bae0dba (diff)
downloadeclipse.platform.team-7796c473e6a9db2db7865ecddce6fd647b813ccf.tar.gz
eclipse.platform.team-7796c473e6a9db2db7865ecddce6fd647b813ccf.tar.xz
eclipse.platform.team-7796c473e6a9db2db7865ecddce6fd647b813ccf.zip
Bug 207704 Decouple org.eclipse.compare from UI
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/Hunk.java63
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/PatchReader.java8
2 files changed, 36 insertions, 35 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/Hunk.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/Hunk.java
index bd3844030..6f2c41504 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/Hunk.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/Hunk.java
@@ -20,47 +20,29 @@ import org.eclipse.core.runtime.Assert;
* A Hunk describes a range of changed lines and some context lines.
*/
public class Hunk {
-
+
private FileDiff fParent;
private int fOldStart, fOldLength;
private int fNewStart, fNewLength;
private String[] fLines;
private int hunkType;
- public Hunk(FileDiff parent, Hunk toCopy) {
- fParent = parent;
- if (fParent != null) {
- fParent.add(this);
- }
-
- fOldStart = toCopy.fOldStart;
- fOldLength = toCopy.fOldLength;
- fNewStart = toCopy.fNewStart;
- fNewLength = toCopy.fOldLength;
- fLines = toCopy.fLines;
- hunkType = toCopy.hunkType;
- }
-
- public Hunk(FileDiff parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
-
- fParent= parent;
- if (fParent != null)
- fParent.add(this);
-
+ public static Hunk createHunk(FileDiff parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
+ int oldStart = 0;
+ int oldLength = 0;
+ int newStart = 0;
+ int newLength = 0;
if (oldRange[0] > 0)
- fOldStart= oldRange[0]-1; // line number start at 0!
+ oldStart= oldRange[0]-1; // line number start at 0!
else
- fOldStart= 0;
- fOldLength= oldRange[1];
+ oldStart= 0;
+ oldLength= oldRange[1];
if (newRange[0] > 0)
- fNewStart= newRange[0]-1; // line number start at 0!
+ newStart= newRange[0]-1; // line number start at 0!
else
- fNewStart= 0;
- fNewLength= newRange[1];
-
- fLines= (String[]) lines.toArray(new String[lines.size()]);
-
- hunkType = FileDiff.CHANGE;
+ newStart= 0;
+ newLength= newRange[1];
+ int hunkType = FileDiff.CHANGE;
if (!hasContextLines) {
if (hasLineAdditions && !hasLineDeletions) {
hunkType = FileDiff.ADDITION;
@@ -68,7 +50,26 @@ public class Hunk {
hunkType = FileDiff.DELETION;
}
}
+ return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, (String[]) lines.toArray(new String[lines.size()]));
+ }
+
+ public Hunk(FileDiff parent, int hunkType, int oldLength, int oldStart,
+ int newLength, int newStart, String[] lines) {
+ fParent = parent;
+ if (fParent != null) {
+ fParent.add(this);
+ }
+ this.hunkType = hunkType;
+ fOldLength = oldLength;
+ fOldStart = oldStart;
+ fNewLength = newLength;
+ fNewStart = newStart;
+ fLines = lines;
}
+
+ public Hunk(FileDiff parent, Hunk toCopy) {
+ this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines);
+ }
/*
* Returns the contents of this hunk.
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/PatchReader.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/PatchReader.java
index da93ef7fc..a1cb56706 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/PatchReader.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare.core/src/org/eclipse/compare/internal/patch/PatchReader.java
@@ -266,7 +266,7 @@ public class PatchReader {
if (line.startsWith("@@ ")) { //$NON-NLS-1$
// flush old hunk
if (lines.size() > 0) {
- new Hunk(diff, oldRange, newRange, lines,encounteredPlus, encounteredMinus, encounteredSpace);
+ Hunk.createHunk(diff, oldRange, newRange, lines,encounteredPlus, encounteredMinus, encounteredSpace);
lines.clear();
}
@@ -321,7 +321,7 @@ public class PatchReader {
}
} finally {
if (lines.size() > 0)
- new Hunk(diff, oldRange, newRange, lines, encounteredPlus, encounteredMinus, encounteredSpace);
+ Hunk.createHunk(diff, oldRange, newRange, lines, encounteredPlus, encounteredMinus, encounteredSpace);
}
}
@@ -371,7 +371,7 @@ public class PatchReader {
if (line.startsWith("***************")) { // new hunk //$NON-NLS-1$
// flush old hunk
if (oldLines.size() > 0 || newLines.size() > 0) {
- new Hunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace);
+ Hunk.createHunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace);
oldLines.clear();
newLines.clear();
}
@@ -428,7 +428,7 @@ public class PatchReader {
} finally {
// flush last hunk
if (oldLines.size() > 0 || newLines.size() > 0)
- new Hunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace);
+ Hunk.createHunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace);
}
}

Back to the top