diff options
Diffstat (limited to 'bundles/org.eclipse.compare.core/src/org')
22 files changed, 283 insertions, 283 deletions
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/ComparePlugin.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/ComparePlugin.java index 916ebb7f4..3caaef68e 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/ComparePlugin.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/ComparePlugin.java @@ -57,7 +57,7 @@ public class ComparePlugin extends Plugin { /** * Returns the shared instance - * + * * @return the shared instance */ public static ComparePlugin getDefault() { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/LCS.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/LCS.java index 78c3096c2..e4fcd1b86 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/LCS.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/LCS.java @@ -25,23 +25,23 @@ public abstract class LCS { private int max_differences; // the maximum number of differences from // each end to consider - + private int length; /** * Myers' algorithm for longest common subsequence. O((M + N)D) worst case * time, O(M + N + D^2) expected time, O(M + N) space * (http://citeseer.ist.psu.edu/myers86ond.html) - * + * * Note: Beyond implementing the algorithm as described in the paper I have * added diagonal range compression which helps when finding the LCS of a * very long and a very short sequence, also bound the running time to (N + * M)^1.5 when both sequences are very long. - * + * * After this method is called, the longest common subsequence is available * by calling getResult() where result[0] is composed of * entries from l1 and result[1] is composed of entries from l2 - * @param subMonitor + * @param subMonitor */ public void longestCommonSubsequence(SubMonitor subMonitor) { int length1 = getLength1(); @@ -58,9 +58,9 @@ public abstract class LCS { } initializeLcs(length1); - + subMonitor.beginTask(null, length1); - + /* * The common prefixes and suffixes are always part of some LCS, include * them now to reduce our search space @@ -102,7 +102,7 @@ public abstract class LCS { * The recursive helper function for Myers' LCS. Computes the LCS of * l1[bottoml1 .. topl1] and l2[bottoml2 .. topl2] fills in the appropriate * location in lcs and returns the length - * + * * @param l1 The 1st sequence * @param bottoml1 Index in the 1st sequence to start from (inclusive) * @param topl1 Index in the 1st sequence to end on (inclusive) @@ -113,16 +113,16 @@ public abstract class LCS { * to store furthest reaching D-paths * @param snake should be allocated as int[3], used to store the beginning * x, y coordinates and the length of the latest snake traversed - * @param subMonitor + * @param subMonitor * @param lcs should be allocated as TextLine[2][l1.length], used to store * the common points found to be part of the LCS where lcs[0] * references lines of l1 and lcs[1] references lines of l2. - * + * * @return the length of the LCS */ private int lcs_rec( int bottoml1, int topl1, - int bottoml2, int topl2, + int bottoml2, int topl2, int[][] V, int[] snake, SubMonitor subMonitor) { // check that both sequences are non-empty @@ -169,7 +169,7 @@ public abstract class LCS { private void worked(SubMonitor subMonitor, int work) { if (subMonitor.isCanceled()) throw new OperationCanceledException(); - subMonitor.worked(work); + subMonitor.worked(work); } /** @@ -177,7 +177,7 @@ public abstract class LCS { * l1[bottoml1..topl1] and l2[bottoml2..topl2] The x, y coodrdinates of the * start of the middle snake are saved in snake[0], snake[1] respectively * and the length of the snake is saved in s[2]. - * + * * @param l1 The 1st sequence * @param bottoml1 Index in the 1st sequence to start from (inclusive) * @param topl1 Index in the 1st sequence to end on (inclusive) @@ -189,13 +189,13 @@ public abstract class LCS { * @param snake should be allocated as int[3], used to store the beginning * x, y coordinates and the length of the middle snake * @subMonitor subMonitor - * + * * @return The number of differences (SES) between l1[bottoml1..topl1] and * l2[bottoml2..topl2] */ private int find_middle_snake( int bottoml1, int topl1, - int bottoml2, int topl2, + int bottoml2, int topl2, int[][] V, int[] snake, SubMonitor subMonitor) { int N = topl1 - bottoml1 + 1; @@ -353,7 +353,7 @@ public abstract class LCS { * Takes the array with furthest reaching D-paths from an LCS computation * and returns the x,y coordinates and progress made in the middle diagonal * among those with maximum progress, both from the front and from the back. - * + * * @param M the length of the 1st sequence for which LCS is being computed * @param N the length of the 2nd sequence for which LCS is being computed * @param limit the number of steps made in an attempt to find the LCS from @@ -444,15 +444,15 @@ public abstract class LCS { // return the middle diagonal with maximal progress. return max_progress[num_progress / 2]; } - + protected abstract int getLength2(); protected abstract int getLength1(); - + protected abstract boolean isRangeEqual(int i1, int i2); - + protected abstract void setLcs(int sl1, int sl2); - + protected abstract void initializeLcs(int lcsLength); public int getLength() { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/TextLineLCS.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/TextLineLCS.java index 63a394a29..0aa2205a1 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/TextLineLCS.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/TextLineLCS.java @@ -47,37 +47,37 @@ public class TextLineLCS extends LCS { protected int getLength1() { return this.lines1.length; } - + @Override protected boolean isRangeEqual(int i1, int i2) { return this.lines1[i1].sameText(this.lines2[i2]); } - + @Override protected void setLcs(int sl1, int sl2) { this.lcs[0][sl1] = this.lines1[sl1]; this.lcs[1][sl1] = this.lines2[sl2]; } - + @Override protected void initializeLcs(int length) { this.lcs = new TextLine[2][length]; } - + /** * This method takes an lcs result interspersed with nulls, compacts it and * shifts the LCS chunks as far towards the front as possible. This tends to * produce good results most of the time. - * + * * TODO: investigate what to do about comments. shifting either up or down * hurts them - * + * * @param lcsSide A subsequence of original, presumably it is the LCS of it and * some other collection of lines * @param len The number of non-null entries in lcs * @param original The original sequence of lines of which lcs is a * subsequence - * + * * @return The subsequence lcs compacted and chunks shifted towards the * front */ @@ -113,7 +113,7 @@ public class TextLineLCS extends LCS { return result; } - + /** * Breaks the given text up into lines and returns an array of TextLine * objects each corresponding to a single line, ordered according to the @@ -121,7 +121,7 @@ public class TextLineLCS extends LCS { * text (starting from 0) Note: there are 1 more lines than there are * newline characters in text. Corollary 1: if the last character is * newline, the last line is empty Corollary 2: the empty string is 1 line - * + * * @param text The text to extract lines from * @return the array of TextLine object each corresponding to a line of text */ @@ -155,7 +155,7 @@ public class TextLineLCS extends LCS { /** * Returns the index of the next end of line marker ('\n' or '\r') after * start - * + * * @param text The string to examine * @param start The location in the string to start looking * @return the index such that text.charAt(index) == '\n' or '\r', -1 if not @@ -186,7 +186,7 @@ public class TextLineLCS extends LCS { /** * Compares this TextLine to l and returns true if they have the same * text - * + * * @param l the TextLine to compare to * @return true if this and l have the same text */ @@ -198,7 +198,7 @@ public class TextLineLCS extends LCS { /** * Returns the line number of this line - * + * * @return the line number */ public int lineNumber() { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java index 878e2fc51..a5e30b641 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FileDiffResult.java @@ -39,22 +39,22 @@ public class FileDiffResult implements IFilePatchResult { private List<String> fBeforeLines, fAfterLines; private final PatchConfiguration configuration; private String charset; - + public FileDiffResult(FilePatch2 diff, PatchConfiguration configuration) { super(); this.fDiff = diff; this.configuration = configuration; } - + public PatchConfiguration getConfiguration() { return this.configuration; } - + public boolean canApplyHunk(Hunk hunk) { HunkResult result = getHunkResult(hunk); return result.isOK() && !this.fDiffProblem; } - + /** * Refreshes the state of the diff to {no matches, no problems} and checks to see what hunks contained * by this Diff can actually be applied. @@ -169,7 +169,7 @@ public class FileDiffResult implements IFilePatchResult { } this.fAfterLines = lines; } - + public boolean getDiffProblem() { return this.fDiffProblem; } @@ -188,14 +188,14 @@ public class FileDiffResult implements IFilePatchResult { } return false; } - + public String getLabel() { String label= getTargetPath().toString(); if (this.fDiffProblem) return NLS.bind(Messages.FileDiffResult_2, new String[] {label, this.fErrorMessage}); return label; } - + @Override public boolean hasMatches() { return this.fMatches; @@ -243,7 +243,7 @@ public class FileDiffResult implements IFilePatchResult { this.fAfterLines = lines; return highestFuzz; } - + public IPath getTargetPath() { return this.fDiff.getStrippedPath(getConfiguration().getPrefixSegmentStripCount(), getConfiguration().isReversed()); } @@ -281,7 +281,7 @@ public class FileDiffResult implements IFilePatchResult { } public HunkResult[] getHunkResults() { - // return hunk results in the same order as hunks are placed in file diff + // return hunk results in the same order as hunks are placed in file diff List<HunkResult> results = new ArrayList<HunkResult>(); IHunk[] hunks = this.fDiff.getHunks(); for (int i = 0; i < hunks.length; i++) { @@ -339,5 +339,5 @@ public class FileDiffResult implements IFilePatchResult { } return new ByteArrayInputStream(bytes); } - + } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java index f15997db9..4406872f9 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/FilePatch2.java @@ -40,14 +40,14 @@ public class FilePatch2 implements IFilePatch2 { * Difference constant (value 3) indicating side changed. */ public static final int CHANGE= 3; - + private IPath fOldPath, fNewPath; private long oldDate, newDate; private List<Hunk> fHunks= new ArrayList<Hunk>(); private DiffProject fProject; //the project that contains this diff private String header; private int addedLines, removedLines; - + /** * Create a file diff for the given path and date information. * @param oldPath the path of the before state of the file @@ -61,7 +61,7 @@ public class FilePatch2 implements IFilePatch2 { this.fNewPath= newPath; this.newDate = newDate; } - + /** * Return the parent project or <code>null</code> if there isn't one. * @return the parent project or <code>null</code> @@ -69,7 +69,7 @@ public class FilePatch2 implements IFilePatch2 { public DiffProject getProject() { return this.fProject; } - + /** * Set the project of this diff to the given project. * This method should only be called from @@ -83,10 +83,10 @@ public class FilePatch2 implements IFilePatch2 { this.fProject.remove(this); this.fProject= diffProject; } - + /** * Get the path of the file diff. - * @param reverse whether the path of the before state or after state + * @param reverse whether the path of the before state or after state * should be used * @return the path of the file diff */ @@ -102,7 +102,7 @@ public class FilePatch2 implements IFilePatch2 { return this.fOldPath; return this.fNewPath; } - + /** * Add the hunk to this file diff. * @param hunk the hunk @@ -111,7 +111,7 @@ public class FilePatch2 implements IFilePatch2 { this.fHunks.add(hunk); hunk.setParent(this); } - + /** * Remove the hunk from this file diff * @param hunk the hunk @@ -119,7 +119,7 @@ public class FilePatch2 implements IFilePatch2 { protected void remove(Hunk hunk) { this.fHunks.remove(hunk); } - + /** * Returns the hunks associated with this file diff. * @return the hunks associated with this file diff @@ -128,7 +128,7 @@ public class FilePatch2 implements IFilePatch2 { public IHunk[] getHunks() { return this.fHunks.toArray(new IHunk[this.fHunks.size()]); } - + /** * Returns the number of hunks associated with this file diff. * @return the number of hunks associated with this file diff @@ -136,7 +136,7 @@ public class FilePatch2 implements IFilePatch2 { public int getHunkCount() { return this.fHunks.size(); } - + /** * Returns the difference type of this file diff. * @param reverse whether the patch is being reversed @@ -164,7 +164,7 @@ public class FilePatch2 implements IFilePatch2 { } return CHANGE; } - + /** * Return the path of this file diff with the specified number * of leading segments striped. @@ -179,7 +179,7 @@ public class FilePatch2 implements IFilePatch2 { path= path.removeFirstSegments(strip); return path; } - + /** * Return the segment count of the path of this file diff. * @return the segment count of the path of this file diff @@ -194,7 +194,7 @@ public class FilePatch2 implements IFilePatch2 { length= Math.min(length, this.fNewPath.segmentCount()); return length; } - + @Override public IFilePatchResult apply(ReaderCreator content, PatchConfiguration configuration, IProgressMonitor monitor) { @@ -255,7 +255,7 @@ public class FilePatch2 implements IFilePatch2 { public void setAddedLines(int addedLines) { this.addedLines = addedLines; } - + public void setRemovedLines(int removedLines) { this.removedLines = removedLines; } @@ -263,7 +263,7 @@ public class FilePatch2 implements IFilePatch2 { public int getAddedLines() { return this.addedLines; } - + public int getRemovedLines() { return this.removedLines; } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java index 358d2750d..033cf8e26 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/Hunk.java @@ -56,7 +56,7 @@ public class Hunk implements IHunk { } return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, lines.toArray(new String[lines.size()])); } - + public Hunk(FilePatch2 parent, int hunkType, int oldStart, int oldLength, int newStart, int newLength, String[] lines) { this.fParent = parent; @@ -70,7 +70,7 @@ public class Hunk implements IHunk { this.fNewStart = newStart; this.fLines = lines; } - + public Hunk(FilePatch2 parent, Hunk toCopy) { this(parent, toCopy.hunkType, toCopy.fOldStart, toCopy.fOldLength, toCopy.fNewStart, toCopy.fNewLength, toCopy.fLines); } @@ -96,7 +96,7 @@ public class Hunk implements IHunk { } return sb.toString(); } - + /* * Returns a descriptive String for this hunk. * It is in the form old_start,old_length -> new_start,new_length. @@ -112,7 +112,7 @@ public class Hunk implements IHunk { sb.append(Integer.toString(this.fNewLength)); return sb.toString(); } - + public String getRejectedDescription() { StringBuffer sb= new StringBuffer(); sb.append("@@ -"); //$NON-NLS-1$ @@ -126,7 +126,7 @@ public class Hunk implements IHunk { sb.append(" @@"); //$NON-NLS-1$ return sb.toString(); } - + public int getHunkType(boolean reverse) { if (reverse) { if (this.hunkType == FilePatch2.ADDITION) @@ -162,13 +162,13 @@ public class Hunk implements IHunk { return; if (this.fParent != null) this.fParent.remove(this); - this.fParent = diff; + this.fParent = diff; } public FilePatch2 getParent() { return this.fParent; } - + /* * Tries to apply the given hunk on the specified lines. * The parameter shift is added to the line numbers given @@ -185,9 +185,9 @@ public class Hunk implements IHunk { Assert.isTrue(s.length() > 0); String line = s.substring(1); char controlChar = s.charAt(0); - + if (controlChar == ' ') { // context lines - + if (pos < 0 || pos >= lines.size()) return false; contextLines.add(line); @@ -199,15 +199,15 @@ public class Hunk implements IHunk { contextLinesMatched = false; pos++; continue; - } + } return false; } else if (isDeletedDelimeter(controlChar, reverse)) { // deleted lines - + if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0) // context lines inside hunk don't match return false; - + // check following context lines if exist // use the fuzz factor if needed if (!precedingLinesChecked @@ -218,11 +218,11 @@ public class Hunk implements IHunk { return false; // else if there is less or equal context line to the fuzz // factor we ignore them all and treat as matching - + precedingLinesChecked = true; contextLines.clear(); contextLinesMatched = true; - + if (pos < 0 || pos >= lines.size()) // out of the file return false; if (linesMatch(configuration, line, lines.get(pos))) { @@ -235,10 +235,10 @@ public class Hunk implements IHunk { // must be found one by one. return false; } else if (isAddedDelimeter(controlChar, reverse)) { - + if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0) return false; - + if (!precedingLinesChecked && !contextLinesMatched && contextLines.size() >= fuzz @@ -249,12 +249,12 @@ public class Hunk implements IHunk { precedingLinesChecked = true; contextLines.clear(); contextLinesMatched = true; - + // we don't have to do anything more for a 'try' } else Assert.isTrue(false, "tryPatch: unknown control character: " + controlChar); //$NON-NLS-1$ } - + // check following context lines if exist if (!contextLinesMatched && fuzz > 0 @@ -262,7 +262,7 @@ public class Hunk implements IHunk { && !checkFollowingContextLines(configuration, lines, fuzz, pos, contextLines)) return false; - + return true; } @@ -277,7 +277,7 @@ public class Hunk implements IHunk { } return true; } - + private boolean checkFollowingContextLines( PatchConfiguration configuration, List<String> lines, int fuzz, int pos, List<String> contextLines) { @@ -291,7 +291,7 @@ public class Hunk implements IHunk { } return true; } - + public int getStart(boolean after) { if (after) { return this.fNewStart; @@ -313,14 +313,14 @@ public class Hunk implements IHunk { } return this.fOldLength; } - + private int getShift(boolean reverse) { if (reverse) { return this.fOldLength - this.fNewLength; } return this.fNewLength - this.fOldLength; } - + int doPatch(PatchConfiguration configuration, List<String> lines, int shift, int fuzz) { boolean reverse = configuration.isReversed(); int pos = getStart(reverse) + shift; @@ -334,7 +334,7 @@ public class Hunk implements IHunk { Assert.isTrue(s.length() > 0); String line= s.substring(1); char controlChar= s.charAt(0); - if (controlChar == ' ') { + if (controlChar == ' ') { // context lines Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in context"); //$NON-NLS-1$ contextLines.add(line); @@ -350,11 +350,11 @@ public class Hunk implements IHunk { Assert.isTrue(false, "doPatch: context doesn't match"); //$NON-NLS-1$ // pos++; } else if (isDeletedDelimeter(controlChar, reverse)) { - // deleted lines + // deleted lines if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0) // context lines inside hunk don't match Assert.isTrue(false, "doPatch: context lines inside hunk don't match"); //$NON-NLS-1$ - + // check following context lines if exist // use the fuzz factor if needed if (!precedingLinesChecked @@ -365,17 +365,17 @@ public class Hunk implements IHunk { Assert.isTrue(false, "doPatch: preceding context lines don't match, even though fuzz factor has been used"); //$NON-NLS-1$; // else if there is less or equal context line to the fuzz // factor we ignore them all and treat as matching - + precedingLinesChecked = true; contextLines.clear(); contextLinesMatched = true; - + lines.remove(pos); } else if (isAddedDelimeter(controlChar, reverse)) { // added lines if (precedingLinesChecked && !contextLinesMatched && contextLines.size() > 0) Assert.isTrue(false, "doPatch: context lines inside hunk don't match"); //$NON-NLS-1$ - + if (!precedingLinesChecked && !contextLinesMatched && contextLines.size() >= fuzz @@ -386,11 +386,11 @@ public class Hunk implements IHunk { precedingLinesChecked = true; contextLines.clear(); contextLinesMatched = true; - + // if the line contains a delimiter, use a proper one if (line.length() > LineReader.length(line)) line = line.substring(0, LineReader.length(line)) + lineDelimiter; - + if (getLength(reverse) == 0 && pos+1 < lines.size()) lines.add(pos+1, line); else @@ -405,11 +405,11 @@ public class Hunk implements IHunk { private boolean isDeletedDelimeter(char controlChar, boolean reverse) { return (!reverse && controlChar == '-') || (reverse && controlChar == '+'); } - + private boolean isAddedDelimeter(char controlChar, boolean reverse) { return (reverse && controlChar == '-') || (!reverse && controlChar == '+'); } - + /* * Compares two strings. * If fIgnoreWhitespace is true whitespace is ignored. @@ -426,7 +426,7 @@ public class Hunk implements IHunk { } return line1.equals(line2); } - + private boolean isIgnoreLineDelimiter() { return true; } @@ -457,7 +457,7 @@ public class Hunk implements IHunk { } return sb.toString(); } - + public String getContents(boolean isAfterState, boolean reverse) { StringBuffer result= new StringBuffer(); for (int i= 0; i<this.fLines.length; i++) { @@ -467,7 +467,7 @@ public class Hunk implements IHunk { if (c == ' ') { result.append(rest); } else if (isDeletedDelimeter(c, reverse) && !isAfterState) { - result.append(rest); + result.append(rest); } else if (isAddedDelimeter(c, reverse) && isAfterState) { result.append(rest); } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java index 6b37d90dc..f73ffa444 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/HunkResult.java @@ -26,7 +26,7 @@ public class HunkResult { * number of context lines, which is 3. */ private static final int MAXIMUM_FUZZ_FACTOR = 2; - + private Hunk fHunk; private boolean fMatches; private int fShift; @@ -64,7 +64,7 @@ public class HunkResult { } else { boolean found= false; int oldShift= this.fShift; - + int hugeShift = lines.size(); for (int i = 1; i <= hugeShift; i++) { if (this.fHunk.tryPatch(configuration, lines, this.fShift - i, fuzz)) { @@ -74,7 +74,7 @@ public class HunkResult { break; } } - + if (!found) { for (int i = 1; i <= hugeShift; i++) { if (this.fHunk.tryPatch(configuration, lines, this.fShift + i, fuzz)) { @@ -85,7 +85,7 @@ public class HunkResult { } } } - + if (found) { if (DEBUG) System.out.println("patched hunk at offset: " + (this.fShift-oldShift)); //$NON-NLS-1$ this.fShift+= this.fHunk.doPatch(configuration, lines, this.fShift, fuzz); @@ -108,7 +108,7 @@ public class HunkResult { * Calculate the fuzz that will allow the most hunks to be matched. Even * though we're interested only in the value of the fuzz, the shifting is * done anyway. - * + * * @param lines * the lines of the target file * @param monitor @@ -129,14 +129,14 @@ public class HunkResult { this.fMatches = true; break; } - + // TODO (tzarna): hugeShift=lines.size() is more than we need. // Lines to the beg/end of a file would be enough but this can still // in matching hunks out of order. Try to shift using only lines // available "between" hunks. - int hugeShift = lines.size(); - - // shift up + int hugeShift = lines.size(); + + // shift up for (int i = 1; i <= hugeShift; i++) { if (monitor.isCanceled()) { throw new OperationCanceledException(); @@ -266,7 +266,7 @@ public class HunkResult { public String getCharset() { return this.fDiffResult.getCharset(); } - + public int getFuzz() { return this.fFuzz; } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java index 019874b29..43a843769 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/LineReader.java @@ -86,7 +86,7 @@ public class LineReader { } return sb.toString(); } - + /* * Returns the length (excluding a line delimiter CR, LF, CR/LF) * of the given string. @@ -105,14 +105,14 @@ public class LineReader { } return l; } - + private boolean fHaveChar= false; private int fLastChar; private boolean fSawEOF= false; private BufferedReader fReader; private boolean fIgnoreSingleCR= false; private StringBuffer fBuffer= new StringBuffer(); - + public LineReader(BufferedReader reader) { this.fReader= reader; Assert.isNotNull(reader); @@ -121,7 +121,7 @@ public class LineReader { public void ignoreSingleCR() { this.fIgnoreSingleCR= true; } - + /** * Reads a line of text. A line is considered to be terminated by any one * of a line feed ('\n'), a carriage return ('\r'), or a carriage return @@ -150,17 +150,17 @@ public class LineReader { } if (c != '\n') { if (this.fIgnoreSingleCR) { - this.fBuffer.append((char)c); + this.fBuffer.append((char)c); continue; } this.fHaveChar= true; this.fLastChar= c; } else - this.fBuffer.append((char)c); + this.fBuffer.append((char)c); break; } } - + if (this.fBuffer.length() != 0) { return this.fBuffer.toString(); } @@ -169,7 +169,7 @@ public class LineReader { this.fBuffer.setLength(0); } } - + void close() { try { this.fReader.close(); @@ -177,7 +177,7 @@ public class LineReader { // silently ignored } } - + public List<String> readLines() { try { List<String> lines= new ArrayList<>(); @@ -193,7 +193,7 @@ public class LineReader { } return null; } - + /* * Returns the number of characters in the given string without * counting a trailing line separator. @@ -211,9 +211,9 @@ public class LineReader { } return length; } - + //---- private - + private int readChar() throws IOException { if (this.fHaveChar) { this.fHaveChar= false; diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java index 255f50382..05a617aef 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/PatchReader.java @@ -33,7 +33,7 @@ import com.ibm.icu.text.SimpleDateFormat; public class PatchReader { private static final boolean DEBUG= false; - + private static final String DEV_NULL= "/dev/null"; //$NON-NLS-1$ protected static final String MARKER_TYPE= "org.eclipse.compare.rejectedPatchMarker"; //$NON-NLS-1$ @@ -74,7 +74,7 @@ public class PatchReader { /** * Create a patch reader for the given date formats. - * + * * @param dateFormats * Array of <code>DateFormat</code>s to be used when * extracting dates from the patch. @@ -83,7 +83,7 @@ public class PatchReader { this(); this.fDateFormats = dateFormats; } - + public void parse(BufferedReader reader) throws IOException { List<FilePatch2> diffs= new ArrayList<FilePatch2>(); HashMap<String, DiffProject> diffProjects= new HashMap<String, DiffProject>(4); @@ -174,7 +174,7 @@ public class PatchReader { } return nextLine; } - + public void parse(LineReader lr, String line) throws IOException { List<FilePatch2> diffs= new ArrayList<FilePatch2>(); boolean reread= false; @@ -191,7 +191,7 @@ public class PatchReader { reread= false; if (line == null) break; - + // remember some infos if (line.startsWith("Index: ")) { //$NON-NLS-1$ fileName= line.substring(7).trim(); @@ -213,19 +213,19 @@ public class PatchReader { diffArgs= fileName= null; reread= true; } - + // Any lines we read here are header lines. // However, if reread is set, we will add them to the header on the next pass through if (!reread) { headerLines.add(line); } } - + lr.close(); - + this.fDiffs = diffs.toArray(new FilePatch2[diffs.size()]); } - + private void setHeader(FilePatch2 diff, List<String> headerLines) { String header = LineReader.createString(false, headerLines); diff.setHeader(header); @@ -243,14 +243,14 @@ public class PatchReader { line= reader.readLine(); if (line == null || !line.startsWith("+++ ")) //$NON-NLS-1$ return line; - + String[] newArgs= split(line.substring(4)); - + FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName), extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName), extractDate(newArgs, 1)); diffs.add(diff); - + int[] oldRange= new int[2]; int[] newRange= new int[2]; int remainingOld= -1; // remaining old lines for current hunk @@ -260,7 +260,7 @@ public class PatchReader { boolean encounteredPlus = false; boolean encounteredMinus = false; boolean encounteredSpace = false; - + try { // read lines of hunk while (true) { @@ -357,51 +357,51 @@ public class PatchReader { Hunk.createHunk(diff, oldRange, newRange, lines, encounteredPlus, encounteredMinus, encounteredSpace); } } - + /* * Returns the next line that does not belong to this diff */ private String readContextDiff(List<FilePatch2> diffs, LineReader reader, String line, String args, String fileName) throws IOException { - + String[] oldArgs= split(line.substring(4)); - + // read info about new file line= reader.readLine(); if (line == null || !line.startsWith("--- ")) //$NON-NLS-1$ return line; - + String[] newArgs= split(line.substring(4)); - + FilePatch2 diff = createFileDiff(extractPath(oldArgs, 0, fileName), extractDate(oldArgs, 1), extractPath(newArgs, 0, fileName), extractDate(newArgs, 1)); diffs.add(diff); - + int[] oldRange= new int[2]; int[] newRange= new int[2]; List<String> oldLines= new ArrayList<String>(); List<String> newLines= new ArrayList<String>(); List<String> lines= oldLines; - + boolean encounteredPlus = false; boolean encounteredMinus = false; boolean encounteredSpace = false; - + try { // read lines of hunk while (true) { - + line= reader.readLine(); if (line == null) return line; - + int l= line.length(); if (l == 0) continue; if (l > 1) { switch (line.charAt(0)) { - case '*': + case '*': if (line.startsWith("***************")) { // new hunk //$NON-NLS-1$ // flush old hunk if (oldLines.size() > 0 || newLines.size() > 0) { @@ -473,7 +473,7 @@ public class PatchReader { Hunk.createHunk(diff, oldRange, newRange, unifyLines(oldLines, newLines), encounteredPlus, encounteredMinus, encounteredSpace); } } - + /* * Creates a List of lines in the unified format from * two Lists of lines in the 'classic' format. @@ -483,29 +483,29 @@ public class PatchReader { String[] ol= oldLines.toArray(new String[oldLines.size()]); String[] nl= newLines.toArray(new String[newLines.size()]); - + int oi= 0, ni= 0; - + while (true) { - + char oc= 0; String o= null; if (oi < ol.length) { o= ol[oi]; oc= o.charAt(0); } - + char nc= 0; String n= null; if (ni < nl.length) { n= nl[ni]; nc= n.charAt(0); } - + // EOF if (oc == 0 && nc == 0) break; - + // deletion in old if (oc == '-') { do { @@ -517,7 +517,7 @@ public class PatchReader { } while (o.charAt(0) == '-'); continue; } - + // addition in new if (nc == '+') { do { @@ -529,7 +529,7 @@ public class PatchReader { } while (n.charAt(0) == '+'); continue; } - + // differing lines on both sides if (oc == '!' && nc == '!') { // remove old @@ -540,7 +540,7 @@ public class PatchReader { break; o= ol[oi]; } while (o.charAt(0) == '!'); - + // add new do { result.add('+' + n.substring(2)); @@ -549,10 +549,10 @@ public class PatchReader { break; n= nl[ni]; } while (n.charAt(0) == '!'); - + continue; } - + // context lines if (oc == ' ' && nc == ' ') { do { @@ -567,7 +567,7 @@ public class PatchReader { } while (o.charAt(0) == ' ' && n.charAt(0) == ' '); continue; } - + if (oc == ' ') { do { result.add(' ' + o.substring(2)); @@ -589,13 +589,13 @@ public class PatchReader { } while (n.charAt(0) == ' '); continue; } - + Assert.isTrue(false, "unexpected char <" + oc + "> <" + nc + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - + return result; } - + /* * @return the parsed time/date in milliseconds or IFilePatch.DATE_UNKNOWN * (0) on error @@ -607,7 +607,7 @@ public class PatchReader { this.fDateFormats[i].setLenient(true); try { Date date= this.fDateFormats[i].parse(line); - return date.getTime(); + return date.getTime(); } catch (ParseException ex) { // silently ignored } @@ -616,7 +616,7 @@ public class PatchReader { } return IFilePatch2.DATE_UNKNOWN; } - + /* * Returns null if file name is "/dev/null". */ @@ -636,7 +636,7 @@ public class PatchReader { } return null; } - + /* * Tries to extract two integers separated by a comma. * The parsing of the line starts at the position after @@ -672,7 +672,7 @@ public class PatchReader { /* * Breaks the given string into tab separated substrings. * Leading and trailing whitespace is removed from each token. - */ + */ private String[] split(String line) { List<String> l= new ArrayList<>(); StringTokenizer st= new StringTokenizer(line, "\t"); //$NON-NLS-1$ @@ -699,7 +699,7 @@ public class PatchReader { public FilePatch2[] getDiffs() { return this.fDiffs; } - + public FilePatch2[] getAdjustedDiffs() { if (!isWorkspacePatch() || this.fDiffs.length == 0) return this.fDiffs; diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch2.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch2.java index 17b7be26c..308cdcef7 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch2.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatch2.java @@ -15,7 +15,7 @@ import org.eclipse.core.runtime.IProgressMonitor; /** * A representation of a file patch that can be applied to an input stream. - * + * * @noimplement This interface is not intended to be implemented by clients. * @since org.eclipse.compare.core 3.5 */ @@ -31,7 +31,7 @@ public interface IFilePatch2 { /** * Return the target path for this patch. The target path may differ * depending on whether the patch is being reversed or not. - * + * * @param configuration * the patch configuration * @return the target path for this patch @@ -43,7 +43,7 @@ public interface IFilePatch2 { * Apply this patch to the given contents. The result provides the * original and patch contents and also indicates whether some portions of * the patch (called hunks) failed to apply. - * + * * @param content * the contents * @param configuration @@ -58,7 +58,7 @@ public interface IFilePatch2 { /** * Return the header information of the patch or <code>null</code> if there * was no header text. The header may be multi-line. - * + * * @return the header information of the patch or <code>null</code> */ public String getHeader(); @@ -66,7 +66,7 @@ public interface IFilePatch2 { /** * Returns the milliseconds time value of the before date from the patch, or * DATE_UNKNOWN if the date is unknown. - * + * * @return milliseconds time value of the before date from the patch */ public long getBeforeDate(); @@ -74,14 +74,14 @@ public interface IFilePatch2 { /** * Returns the milliseconds time value of the after date from the patch, or * DATE_UNKNOWN if the date is unknown. - * + * * @return milliseconds time value of the after date from the patch */ public long getAfterDate(); /** * Returns all the hunks this file patch contains. - * + * * @return array of hunks */ public IHunk[] getHunks(); diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatchResult.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatchResult.java index f738a8873..993a75ed5 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatchResult.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IFilePatchResult.java @@ -17,14 +17,14 @@ import org.eclipse.core.runtime.CoreException; /** * A file patch result provides the results of an attempt to apply an * {@link IFilePatch2} to the contents of a file. * - * + * * @see IFilePatch2 * @since 3.3 * @noimplement This interface is not intended to be implemented by clients. * Clients can obtain patch results from an {@link IFilePatch2}. */ public interface IFilePatchResult { - + /** * Return a stream the contains the original contents of the file before * any portions of the patch have been applied. @@ -33,35 +33,35 @@ public interface IFilePatchResult { * @see #getPatchedContents() */ public InputStream getOriginalContents(); - + /** - * Return a stream that contains the file with as much of the patch + * Return a stream that contains the file with as much of the patch * applied as possible. if {@link #hasMatches()} returns <code>false</code> * then the patched contents will match the original contents. Otherwise, * at least a portion of the patch could be successfully applied. if * {@link #hasRejects()} returns <code>false</code>, then the entire patch was * applied. Otherwise, portions could not be applied. The portions that could * not be applied can be obtained by calling {@link #getRejects()}. - * - * @return a stream that contains the file with as much of the patch + * + * @return a stream that contains the file with as much of the patch * applied as possible. */ public InputStream getPatchedContents(); - + /** * Return whether the patch has portions that were successfully applied. * @return whether the patch has portions that were successfully applied * @see #getPatchedContents() */ public boolean hasMatches(); - + /** * Return whether the patch has portions that were not successfully applied. * @return whether the patch has portions that were not successfully applied * @see #getPatchedContents() */ public boolean hasRejects(); - + /** * Return the portions of the patch (referred to a hunks) that could not * be applied. @@ -70,19 +70,19 @@ public interface IFilePatchResult { * @see #getPatchedContents() */ public IHunk[] getRejects(); - + /** - * Returns the name of a charset encoding to be used when decoding the contents - * of this result into characters. Returns <code>null</code> if a proper + * Returns the name of a charset encoding to be used when decoding the contents + * of this result into characters. Returns <code>null</code> if a proper * encoding cannot be determined. * <p> * Note that this method does not check whether the result is a supported - * charset name. Callers should be prepared to handle - * <code>UnsupportedEncodingException</code> where this charset is used. + * charset name. Callers should be prepared to handle + * <code>UnsupportedEncodingException</code> where this charset is used. * </p> * * @return the name of a charset, or <code>null</code> - * @exception CoreException if an error happens while determining + * @exception CoreException if an error happens while determining * the charset. See any refinements for more information. */ public String getCharset() throws CoreException; diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunk.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunk.java index 41560d3a7..b32a29a59 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunk.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunk.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.IAdaptable; * this interface is a means to communicate to content merge viewers that one of * the sides of a compare input is a patch hunk. Clients can determine which * side it is by adapting the side to this interface (see {@link IAdaptable}. - * + * * @since 3.3 * @noimplement This interface is not intended to be implemented by clients but * can be obtained from an {@link IFilePatchResult} @@ -33,10 +33,10 @@ public interface IHunk { * @return a label that can be used to describe the hunk */ public String getLabel(); - + /** * Return the start position of the hunk in the target file. - * + * * @return the start position of the hunk in the target file. */ public int getStartPosition(); @@ -51,7 +51,7 @@ public interface IHunk { * <li> <code>'+'</code> for addition * <li> <code>'-'</code> for removal * </ul> - * + * * @return hunk's content in the unified format * @since org.eclipse.compare 3.5 */ @@ -64,7 +64,7 @@ public interface IHunk { * @return the original contents from which the hunk was generated */ public InputStream getOriginalContents(); - + /** * Return the contents that contain the modifications for this hunk. * The returned contents usually only represent a portion of the @@ -72,19 +72,19 @@ public interface IHunk { * @return the contents that contain the modifications for this hunk */ public InputStream getPatchedContents(); - + /** - * Returns the name of a charset encoding to be used when decoding the contents - * of this hunk into characters. Returns <code>null</code> if a proper + * Returns the name of a charset encoding to be used when decoding the contents + * of this hunk into characters. Returns <code>null</code> if a proper * encoding cannot be determined. * <p> * Note that this method does not check whether the result is a supported - * charset name. Callers should be prepared to handle - * <code>UnsupportedEncodingException</code> where this charset is used. + * charset name. Callers should be prepared to handle + * <code>UnsupportedEncodingException</code> where this charset is used. * </p> * * @return the name of a charset, or <code>null</code> - * @exception CoreException if an error happens while determining + * @exception CoreException if an error happens while determining * the charset. See any refinements for more information. * @deprecated This method can be called before the first attempt to apply * the hunk when it is impossible to determine the encoding and @@ -94,6 +94,6 @@ public interface IHunk { */ @Deprecated public String getCharset() throws CoreException; - - + + } diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunkFilter.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunkFilter.java index 55597349e..b7552a45e 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunkFilter.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/IHunkFilter.java @@ -12,14 +12,14 @@ package org.eclipse.compare.patch; /** * Filter that is used to determine if a hunk should be applied or not - * + * * @since org.eclipse.compare.core 3.5 */ public interface IHunkFilter { /** * Returns true if the given hunk should be applied - * + * * @param hunk * the hunk * @return true if the given hunk should be applied diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchBuilder.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchBuilder.java index 3dadf0836..ac881a04e 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchBuilder.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchBuilder.java @@ -20,10 +20,10 @@ import org.eclipse.core.runtime.IPath; /** * Builder for creating IFilePatch2 and IHunk objects as well as building * relationship between them. - * + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. - * + * * @since org.eclipse.compare.core 3.5 */ public class PatchBuilder { @@ -43,7 +43,7 @@ public class PatchBuilder { /** * Creates an IHunk instance. - * + * * @param start * the start position in the before file * @param lines @@ -72,7 +72,7 @@ public class PatchBuilder { * after applying a patch. It is affected by all the hunks that are to be * applied before a given one. This recalculation is necessary to keep * IFilePatch2's state coherent. - * + * * @param oldPath * the path of the before state of the file * @param oldDate @@ -103,7 +103,7 @@ public class PatchBuilder { * state after applying a patch. It is affected by all the hunks that are to * be applied before a given one. This recalculation is necessary to keep * IFilePatch2's state coherent. - * + * * @param filePatch * a file patch to add hunks to * @param toAdd @@ -122,7 +122,7 @@ public class PatchBuilder { * state after applying a patch. It is affected by all the hunks that are to * be applied before a given one. This recalculation is necessary to keep * IFilePatch2's state coherent. - * + * * @param filePatch * a file patch to add hunks to * @param toRemove diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchConfiguration.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchConfiguration.java index 72dfd0fe6..8a335e73e 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchConfiguration.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchConfiguration.java @@ -17,7 +17,7 @@ import java.util.List; /** * A patch configuration allows clients to set parameters that control how a * patch is applied. - * + * * @see IFilePatch2 * @since 3.3 * @noextend This class may be instantiated by clients but is not intended to be @@ -49,9 +49,9 @@ public class PatchConfiguration { } /** - * Return the number of prefix segments to be stripped when attempting + * Return the number of prefix segments to be stripped when attempting * to apply a patch. - * @return the number of prefix segments to be stripped when attempting + * @return the number of prefix segments to be stripped when attempting * to apply a patch */ public int getPrefixSegmentStripCount() { @@ -59,9 +59,9 @@ public class PatchConfiguration { } /** - * Set the number of prefix segments to be stripped when attempting + * Set the number of prefix segments to be stripped when attempting * to apply a patch. - * @param stripCount the number of prefix segments to be stripped when attempting + * @param stripCount the number of prefix segments to be stripped when attempting * to apply a patch. */ public void setPrefixSegmentStripCount(int stripCount) { @@ -78,7 +78,7 @@ public class PatchConfiguration { public int getFuzz() { return this.fFuzz; } - + /** * Set the fuzz factor to be used when applying a patch. * @param fuzz the fuzz factor to be used when applying a patch. @@ -94,7 +94,7 @@ public class PatchConfiguration { public boolean isIgnoreWhitespace() { return this.fIgnoreWhitespace; } - + /** * Set whether whitespace should be ignored * @param ignoreWhitespace whether whitespace should be ignored @@ -102,18 +102,18 @@ public class PatchConfiguration { public void setIgnoreWhitespace(boolean ignoreWhitespace) { this.fIgnoreWhitespace = ignoreWhitespace; } - + /** - * Return the property associated with the given key or + * Return the property associated with the given key or * <code>null</code> if there is no property for the key. * @param key the key - * @return the property associated with the given key or + * @return the property associated with the given key or * <code>null</code> */ public Object getProperty(String key) { return this.properties.get(key); } - + /** * Set the property associated with the given key * @param key the key @@ -125,7 +125,7 @@ public class PatchConfiguration { /** * Adds a hunk filter. - * + * * @param filter the filter * @since org.eclipse.compare.core 3.5 */ @@ -135,7 +135,7 @@ public class PatchConfiguration { /** * Removes a hunk filter. - * + * * @param filter the filter * @since org.eclipse.compare.core 3.5 */ @@ -146,7 +146,7 @@ public class PatchConfiguration { /** * Return an array of hunk filters that have been added to this * configuration. - * + * * @return an array of hunk filters that have been added to this configuration * @since org.eclipse.compare.core 3.5 */ diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchParser.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchParser.java index 37b0d6abf..b2113a069 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchParser.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/PatchParser.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.Status; /** * Helper class for parsing patches. - * + * * @since org.eclipse.compare.core 3.5 */ public class PatchParser { @@ -29,7 +29,7 @@ public class PatchParser { /** * Parse the given patch and return the set of file patches that it * contains. - * + * * @param content * a patch reader creator * @return the set of file patches that the patch contains diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/ReaderCreator.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/ReaderCreator.java index b7d4433e5..d65ee010d 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/ReaderCreator.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/patch/ReaderCreator.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.CoreException; /** * Abstract class for creating readers. - * + * * @since org.eclipse.compare.core 3.5 */ public abstract class ReaderCreator { @@ -24,7 +24,7 @@ public abstract class ReaderCreator { /** * Creates new reader. The caller is responsible for closing the reader when * finished. - * + * * @return a reader * @exception CoreException * if the reader can't be created @@ -33,7 +33,7 @@ public abstract class ReaderCreator { /** * Returns whether the reader can be created. - * + * * @return true if the reader can be created, false otherwise */ public boolean canCreateReader() { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java index e4465613a..a088c0475 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/DifferencesIterator.java @@ -21,14 +21,14 @@ import java.util.List; List fRange; int fIndex; - RangeDifference[] fArray; + RangeDifference[] fArray; RangeDifference fDifference; - + /* * Creates a differences iterator on an array of <code>RangeDifference</code>s. */ DifferencesIterator(RangeDifference[] differenceRanges) { - + this.fArray= differenceRanges; this.fIndex= 0; this.fRange= new ArrayList(); diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/IRangeComparator.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/IRangeComparator.java index c466aa030..31ba1eefb 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/IRangeComparator.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/IRangeComparator.java @@ -18,8 +18,8 @@ package org.eclipse.compare.rangedifferencer; * <p> * For example, to compare two text documents and find longest common sequences * of matching and non-matching lines, the implementation must break the document - * into lines. <code>getRangeCount</code> would return the number of lines in the - * document, and <code>rangesEqual</code> would compare a specified line given + * into lines. <code>getRangeCount</code> would return the number of lines in the + * document, and <code>rangesEqual</code> would compare a specified line given * with one in another <code>IRangeComparator</code>. * </p> * <p> @@ -31,7 +31,7 @@ public interface IRangeComparator { /** * Returns the number of comparable entities. * - * @return the number of comparable entities + * @return the number of comparable entities */ int getRangeCount(); @@ -48,7 +48,7 @@ public interface IRangeComparator { /** * Returns whether a comparison should be skipped because it would be too costly (or lengthy). - * + * * @param length a number on which to base the decision whether to return * <code>true</code> or <code>false</code> * @param maxLength another number on which to base the decision whether to return diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java index c4cd87844..2e8899032 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeComparatorLCS.java @@ -20,10 +20,10 @@ import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; /* package */ class RangeComparatorLCS extends LCS { - + private final IRangeComparator comparator1, comparator2; private int[][] lcs; - + public static RangeDifference[] findDifferences(AbstractRangeDifferenceFactory factory, IProgressMonitor pm, IRangeComparator left, IRangeComparator right) { RangeComparatorLCS lcs = new RangeComparatorLCS(left, right); SubMonitor monitor = SubMonitor.convert(pm, Messages.RangeComparatorLCS_0, 100); @@ -35,12 +35,12 @@ import org.eclipse.core.runtime.SubMonitor; pm.done(); } } - + public RangeComparatorLCS(IRangeComparator comparator1, IRangeComparator comparator2) { this.comparator1 = comparator1; this.comparator2 = comparator2; } - + @Override protected int getLength1() { return this.comparator1.getRangeCount(); @@ -67,7 +67,7 @@ import org.eclipse.core.runtime.SubMonitor; this.lcs[0][sl1] = sl1 + 1; this.lcs[1][sl1] = sl2 + 1; } - + public RangeDifference[] getDifferences(SubMonitor subMonitor, AbstractRangeDifferenceFactory factory) { try { List differences = new ArrayList(); @@ -126,25 +126,25 @@ import org.eclipse.core.runtime.SubMonitor; // TODO: We need to confirm that this is the proper order differences.add(factory.createRangeDifference(RangeDifference.CHANGE, rightStart, this.comparator2.getRangeCount() - (s2 + 1), leftStart, this.comparator1.getRangeCount() - (s1 + 1))); } - + } return (RangeDifference[]) differences.toArray(new RangeDifference[differences.size()]); } finally { subMonitor.done(); } } - + private void worked(SubMonitor subMonitor, int work) { if (subMonitor.isCanceled()) throw new OperationCanceledException(); - subMonitor.worked(work); + subMonitor.worked(work); } /** - * This method takes an LCS result interspersed with zeros (i.e. empty slots - * from the LCS algorithm), compacts it and shifts the LCS chunks as far towards + * This method takes an LCS result interspersed with zeros (i.e. empty slots + * from the LCS algorithm), compacts it and shifts the LCS chunks as far towards * the front as possible. This tends to produce good results most of the time. - * + * * @param lcsSide A subsequence of original, presumably it is the LCS of it and * some other collection of lines * @param length The number of non-empty (i.e non-zero) entries in LCS @@ -168,7 +168,7 @@ import org.eclipse.core.runtime.SubMonitor; while (lcsSide[j] == 0) { j++; } - // Push the difference down as far as possible by comparing the line at the + // Push the difference down as far as possible by comparing the line at the // start of the diff with the line and the end and adjusting if they are the same int nextLine = lcsSide[i - 1] + 1; if (nextLine != lcsSide[j] && comparator.rangesEqual(nextLine - 1, comparator, lcsSide[j] - 1)) { @@ -183,7 +183,7 @@ import org.eclipse.core.runtime.SubMonitor; lcsSide[i] = 0; } } - + /* (non-Javadoc) * @see org.eclipse.compare.internal.LCS#longestCommonSubsequence(org.eclipse.core.runtime.SubMonitor) */ diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifference.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifference.java index 24bd5f46f..cc3ae72d8 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifference.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifference.java @@ -59,7 +59,7 @@ public class RangeDifference { /** * the kind of change: NOCHANGE, CHANGE, LEFT, RIGHT, ANCESTOR, CONFLICT, * ERROR - * + * * @since org.eclipse.compare.core 3.5 */ protected int kind; @@ -93,10 +93,10 @@ public class RangeDifference { * @since org.eclipse.compare.core 3.5 */ protected int ancestorLength; - + /** * Creates a new range difference with the given change kind. - * + * * @param changeKind * the kind of change * @since org.eclipse.compare.core 3.5 @@ -108,7 +108,7 @@ public class RangeDifference { /** * Creates a new <code>RangeDifference</code> with the given change kind and * left and right ranges. - * + * * @param kind * the kind of change * @param rightStart @@ -132,7 +132,7 @@ public class RangeDifference { /** * Creates a new <code>RangeDifference</code> with the given change kind and * left, right, and ancestor ranges. - * + * * @param kind * the kind of change * @param rightStart @@ -256,7 +256,7 @@ public class RangeDifference { public int maxLength() { return Math.max(this.rightLength, Math.max(this.leftLength, this.ancestorLength)); } - + @Override public boolean equals(Object obj) { if (obj instanceof RangeDifference) { diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifferencer.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifferencer.java index e91a8b4bc..0937a0bd4 100644 --- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifferencer.java +++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/rangedifferencer/RangeDifferencer.java @@ -38,28 +38,28 @@ import org.eclipse.core.runtime.SubMonitor; * @see RangeDifference */ public final class RangeDifferencer { - + private static final RangeDifference[] EMPTY_RESULT= new RangeDifference[0]; - + private static final AbstractRangeDifferenceFactory defaultFactory = new AbstractRangeDifferenceFactory() { @Override protected RangeDifference createRangeDifference() { return new RangeDifference(RangeDifference.NOCHANGE); } }; - + /* (non Javadoc) * Cannot be instantiated! */ private RangeDifferencer() { // nothing to do } - + /** * Finds the differences between two <code>IRangeComparator</code>s. * The differences are returned as an array of <code>RangeDifference</code>s. * If no differences are detected an empty array is returned. - * + * * @param left the left range comparator * @param right the right range comparator * @return an array of range differences, or an empty array if no differences were found @@ -67,12 +67,12 @@ public final class RangeDifferencer { public static RangeDifference[] findDifferences(IRangeComparator left, IRangeComparator right) { return findDifferences((IProgressMonitor)null, left, right); } - + /** * Finds the differences between two <code>IRangeComparator</code>s. * The differences are returned as an array of <code>RangeDifference</code>s. * If no differences are detected an empty array is returned. - * + * * @param pm if not <code>null</code> used to report progress * @param left the left range comparator * @param right the right range comparator @@ -82,12 +82,12 @@ public final class RangeDifferencer { public static RangeDifference[] findDifferences(IProgressMonitor pm, IRangeComparator left, IRangeComparator right) { return findDifferences(defaultFactory, null, left, right); } - + /** * Finds the differences between two <code>IRangeComparator</code>s. * The differences are returned as an array of <code>RangeDifference</code>s. * If no differences are detected an empty array is returned. - * + * * @param factory * @param pm if not <code>null</code> used to report progress * @param left the left range comparator @@ -105,7 +105,7 @@ public final class RangeDifferencer { * If no differences are detected an empty list is returned. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param ancestor the ancestor range comparator or <code>null</code> * @param left the left range comparator * @param right the right range comparator @@ -114,14 +114,14 @@ public final class RangeDifferencer { public static RangeDifference[] findDifferences(IRangeComparator ancestor, IRangeComparator left, IRangeComparator right) { return findDifferences(null, ancestor, left, right); } - + /** * Finds the differences among three <code>IRangeComparator</code>s. * The differences are returned as a list of <code>RangeDifference</code>s. * If no differences are detected an empty list is returned. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param pm if not <code>null</code> used to report progress * @param ancestor the ancestor range comparator or <code>null</code> * @param left the left range comparator @@ -132,14 +132,14 @@ public final class RangeDifferencer { public static RangeDifference[] findDifferences(IProgressMonitor pm, IRangeComparator ancestor, IRangeComparator left, IRangeComparator right) { return findDifferences(defaultFactory, pm, ancestor, left, right); } - + /** * Finds the differences among three <code>IRangeComparator</code>s. * The differences are returned as a list of <code>RangeDifference</code>s. * If no differences are detected an empty list is returned. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param factory * @param pm if not <code>null</code> used to report progress * @param ancestor the ancestor range comparator or <code>null</code> @@ -161,13 +161,13 @@ public final class RangeDifferencer { } if (rightAncestorScript == null || leftAncestorScript == null) return null; - + DifferencesIterator myIter= new DifferencesIterator(rightAncestorScript); DifferencesIterator yourIter= new DifferencesIterator(leftAncestorScript); - + List diff3= new ArrayList(); diff3.add(factory.createRangeDifference(RangeDifference.ERROR)); // add a sentinel - + int changeRangeStart= 0; int changeRangeEnd= 0; // @@ -175,7 +175,7 @@ public final class RangeDifferencer { // monitor.setWorkRemaining(rightAncestorScript.length + leftAncestorScript.length); while (myIter.fDifference != null || yourIter.fDifference != null) { - + DifferencesIterator startThread; myIter.removeAll(); yourIter.removeAll(); @@ -193,7 +193,7 @@ public final class RangeDifferencer { startThread= yourIter; } else { if (myIter.fDifference.leftLength == 0 && yourIter.fDifference.leftLength == 0) { - //insertion into the same position is conflict. + //insertion into the same position is conflict. changeRangeStart= myIter.fDifference.leftStart; changeRangeEnd= myIter.fDifference.leftEnd(); myIter.next(); @@ -210,11 +210,11 @@ public final class RangeDifferencer { startThread= myIter; } } - + } changeRangeStart= startThread.fDifference.leftStart; changeRangeEnd= startThread.fDifference.leftEnd(); - + startThread.next(); monitor.worked(1); // @@ -233,7 +233,7 @@ public final class RangeDifferencer { } diff3.add(createRangeDifference3(factory, myIter, yourIter, diff3, right, left, changeRangeStart, changeRangeEnd)); } - + // remove sentinel diff3.remove(0); return (RangeDifference[]) diff3.toArray(EMPTY_RESULT); @@ -247,7 +247,7 @@ public final class RangeDifferencer { * Finds the differences among two <code>IRangeComparator</code>s. * In contrast to <code>findDifferences</code>, the result * contains <code>RangeDifference</code> elements for non-differing ranges too. - * + * * @param left the left range comparator * @param right the right range comparator * @return an array of range differences @@ -256,12 +256,12 @@ public final class RangeDifferencer { IRangeComparator right) { return findRanges((IProgressMonitor) null, left, right); } - + /** * Finds the differences among two <code>IRangeComparator</code>s. * In contrast to <code>findDifferences</code>, the result * contains <code>RangeDifference</code> elements for non-differing ranges too. - * + * * @param pm if not <code>null</code> used to report progress * @param left the left range comparator * @param right the right range comparator @@ -271,12 +271,12 @@ public final class RangeDifferencer { public static RangeDifference[] findRanges(IProgressMonitor pm, IRangeComparator left, IRangeComparator right) { return findRanges(defaultFactory, pm, left, right); } - + /** * Finds the differences among two <code>IRangeComparator</code>s. * In contrast to <code>findDifferences</code>, the result * contains <code>RangeDifference</code> elements for non-differing ranges too. - * + * * @param factory * @param pm if not <code>null</code> used to report progress * @param left the left range comparator @@ -318,7 +318,7 @@ public final class RangeDifferencer { * contains <code>RangeDifference</code> elements for non-differing ranges too. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param ancestor the ancestor range comparator or <code>null</code> * @param left the left range comparator * @param right the right range comparator @@ -327,14 +327,14 @@ public final class RangeDifferencer { public static RangeDifference[] findRanges(IRangeComparator ancestor, IRangeComparator left, IRangeComparator right) { return findRanges(null, ancestor, left, right); } - + /** * Finds the differences among three <code>IRangeComparator</code>s. * In contrast to <code>findDifferences</code>, the result * contains <code>RangeDifference</code> elements for non-differing ranges too. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param pm if not <code>null</code> used to report progress * @param ancestor the ancestor range comparator or <code>null</code> * @param left the left range comparator @@ -345,14 +345,14 @@ public final class RangeDifferencer { public static RangeDifference[] findRanges(IProgressMonitor pm, IRangeComparator ancestor, IRangeComparator left, IRangeComparator right) { return findRanges(defaultFactory, pm, ancestor, left, right); } - + /** * Finds the differences among three <code>IRangeComparator</code>s. * In contrast to <code>findDifferences</code>, the result * contains <code>RangeDifference</code> elements for non-differing ranges too. * If the ancestor range comparator is <code>null</code>, a two-way * comparison is performed. - * + * * @param factory * @param pm if not <code>null</code> used to report progress * @param ancestor the ancestor range comparator or <code>null</code> @@ -400,7 +400,7 @@ public final class RangeDifferencer { * Creates a <code>RangeDifference3</code> given the * state of two DifferenceIterators. */ - private static RangeDifference createRangeDifference3(AbstractRangeDifferenceFactory configurator, DifferencesIterator myIter, DifferencesIterator yourIter, List diff3, + private static RangeDifference createRangeDifference3(AbstractRangeDifferenceFactory configurator, DifferencesIterator myIter, DifferencesIterator yourIter, List diff3, IRangeComparator right, IRangeComparator left, int changeRangeStart, int changeRangeEnd) { int rightStart, rightEnd; @@ -458,7 +458,7 @@ public final class RangeDifferencer { } return false; } - + /* * Tests if two ranges are equal */ |