From cb2a038fb522881890e65f94cb469acb242f3b30 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Tue, 30 Aug 2016 17:06:55 -0700
Subject: Fixed compiler warnings.
Change-Id: I97279754360d3135cbc6e30025bd8c2f4b3fb0ce
---
.../compare/internal/core/patch/DiffProject.java | 5 +-
.../internal/core/patch/FileDiffResult.java | 57 ++++++++-------
.../compare/internal/core/patch/FilePatch2.java | 25 ++++---
.../eclipse/compare/internal/core/patch/Hunk.java | 51 +++++++------
.../compare/internal/core/patch/HunkResult.java | 6 +-
.../compare/internal/core/patch/LineReader.java | 36 +++++-----
.../compare/internal/core/patch/PatchReader.java | 71 +++++++++---------
.../eclipse/compare/internal/patch/LineReader.java | 33 +++++----
.../internal/patch/PatchFileTypedElement.java | 6 +-
.../eclipse/compare/internal/patch/Patcher.java | 6 +-
.../structuremergeviewer/DiffContainer.java | 27 +++----
.../compare/structuremergeviewer/DiffElement.java | 17 ++---
.../compare/structuremergeviewer/DiffNode.java | 17 +++--
.../structuremergeviewer/DiffTreeViewer.java | 55 ++++++++++----
.../compare/structuremergeviewer/Differencer.java | 51 ++++++-------
.../structuremergeviewer/DocumentRangeNode.java | 66 +++++++++--------
.../structuremergeviewer/IStructureComparator.java | 2 +-
.../SharedDocumentAdapterWrapper.java | 24 ++-----
.../structuremergeviewer/StructureCreator.java | 37 +++++-----
.../structuremergeviewer/StructureDiffViewer.java | 84 +++++++++++++++-------
.../structuremergeviewer/StructureRootNode.java | 22 ++++--
21 files changed, 385 insertions(+), 313 deletions(-)
diff --git a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/DiffProject.java b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/DiffProject.java
index f0c73f2d9..4d850f6d4 100644
--- a/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/DiffProject.java
+++ b/bundles/org.eclipse.compare.core/src/org/eclipse/compare/internal/core/patch/DiffProject.java
@@ -19,9 +19,8 @@ import java.util.Set;
* in the patch file.
*/
public class DiffProject {
-
private String project;
- private Set fDiffs= new HashSet();
+ private Set fDiffs= new HashSet<>();
/**
* Create a diff project for the given workspace project.
@@ -71,6 +70,6 @@ public class DiffProject {
* @return the file diffs associated with this project
*/
public FilePatch2[] getFileDiffs() {
- return (FilePatch2[]) this.fDiffs.toArray(new FilePatch2[this.fDiffs.size()]);
+ return this.fDiffs.toArray(new FilePatch2[this.fDiffs.size()]);
}
}
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 da5363b7f..878e2fc51 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
@@ -31,13 +31,12 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.osgi.util.NLS;
public class FileDiffResult implements IFilePatchResult {
-
private FilePatch2 fDiff;
private boolean fMatches= false;
private boolean fDiffProblem;
private String fErrorMessage;
- private Map fHunkResults = new HashMap();
- private List fBeforeLines, fAfterLines;
+ private Map fHunkResults = new HashMap();
+ private List fBeforeLines, fAfterLines;
private final PatchConfiguration configuration;
private String charset;
@@ -97,8 +96,8 @@ public class FileDiffResult implements IFilePatchResult {
// We couldn't find the target file or the patch is trying to add a
// file that already exists but we need to initialize the hunk
// results for display
- this.fBeforeLines = new ArrayList(getLines(content, false));
- this.fAfterLines = this.fMatches ? new ArrayList() : this.fBeforeLines;
+ this.fBeforeLines = new ArrayList<>(getLines(content, false));
+ this.fAfterLines = this.fMatches ? new ArrayList<>() : this.fBeforeLines;
IHunk[] hunks = this.fDiff.getHunks();
for (int i = 0; i < hunks.length; i++) {
Hunk hunk = (Hunk) hunks[i];
@@ -136,8 +135,8 @@ public class FileDiffResult implements IFilePatchResult {
return content != null && content.canCreateReader();
}
- protected List getLines(ReaderCreator content, boolean create) {
- List lines = LineReader.load(content, create);
+ protected List getLines(ReaderCreator content, boolean create) {
+ List lines = LineReader.load(content, create);
return lines;
}
@@ -151,8 +150,8 @@ public class FileDiffResult implements IFilePatchResult {
* Tries to patch the given lines with the specified Diff.
* Any hunk that couldn't be applied is returned in the list failedHunks.
*/
- public void patch(List lines, IProgressMonitor monitor) {
- this.fBeforeLines = new ArrayList();
+ public void patch(List lines, IProgressMonitor monitor) {
+ this.fBeforeLines = new ArrayList<>();
this.fBeforeLines.addAll(lines);
if (getConfiguration().getFuzz() != 0) {
calculateFuzz(this.fBeforeLines, monitor);
@@ -182,8 +181,8 @@ public class FileDiffResult implements IFilePatchResult {
public boolean containsProblems() {
if (this.fDiffProblem)
return true;
- for (Iterator iterator = this.fHunkResults.values().iterator(); iterator.hasNext();) {
- HunkResult result = (HunkResult) iterator.next();
+ for (Iterator iterator = this.fHunkResults.values().iterator(); iterator.hasNext();) {
+ HunkResult result = iterator.next();
if (!result.isOK())
return true;
}
@@ -197,6 +196,7 @@ public class FileDiffResult implements IFilePatchResult {
return label;
}
+ @Override
public boolean hasMatches() {
return this.fMatches;
}
@@ -205,7 +205,7 @@ public class FileDiffResult implements IFilePatchResult {
* Return the lines of the target file with all matched hunks applied.
* @return the lines of the target file with all matched hunks applied
*/
- public List getLines() {
+ public List getLines() {
return this.fAfterLines;
}
@@ -215,10 +215,10 @@ public class FileDiffResult implements IFilePatchResult {
* @param monitor a progress monitor
* @return the fuzz factor or -1 if no hunks could be matched
*/
- public int calculateFuzz(List lines, IProgressMonitor monitor) {
+ public int calculateFuzz(List lines, IProgressMonitor monitor) {
if (monitor == null)
monitor = new NullProgressMonitor();
- this.fBeforeLines = new ArrayList(lines);
+ this.fBeforeLines = new ArrayList(lines);
// TODO: What about deletions?
if (this.fDiff.getDiffType(getConfiguration().isReversed()) == FilePatch2.ADDITION) {
// Additions don't need to adjust the fuzz factor
@@ -249,19 +249,19 @@ public class FileDiffResult implements IFilePatchResult {
}
private HunkResult getHunkResult(Hunk hunk) {
- HunkResult result = (HunkResult)this.fHunkResults.get(hunk);
+ HunkResult result = this.fHunkResults.get(hunk);
if (result == null) {
result = new HunkResult(this, hunk);
- this.fHunkResults .put(hunk, result);
+ this.fHunkResults.put(hunk, result);
}
return result;
}
- public List getFailedHunks() {
- List failedHunks = new ArrayList();
+ public List getFailedHunks() {
+ List failedHunks = new ArrayList();
IHunk[] hunks = this.fDiff.getHunks();
for (int i = 0; i < hunks.length; i++) {
- HunkResult result = (HunkResult) this.fHunkResults.get(hunks[i]);
+ HunkResult result = this.fHunkResults.get(hunks[i]);
if (result != null && !result.isOK())
failedHunks.add(result.getHunk());
}
@@ -272,37 +272,40 @@ public class FileDiffResult implements IFilePatchResult {
return this.fDiff;
}
- public List getBeforeLines() {
+ public List getBeforeLines() {
return this.fBeforeLines;
}
- public List getAfterLines() {
+ public List getAfterLines() {
return this.fAfterLines;
}
public HunkResult[] getHunkResults() {
// return hunk results in the same order as hunks are placed in file diff
- List results = new ArrayList();
+ List results = new ArrayList();
IHunk[] hunks = this.fDiff.getHunks();
for (int i = 0; i < hunks.length; i++) {
- HunkResult result = (HunkResult) this.fHunkResults.get(hunks[i]);
+ HunkResult result = this.fHunkResults.get(hunks[i]);
if (result != null) {
results.add(result);
}
}
- return (HunkResult[]) results.toArray(new HunkResult[results.size()]);
+ return results.toArray(new HunkResult[results.size()]);
}
+ @Override
public InputStream getOriginalContents() {
String contents = LineReader.createString(isPreserveLineDelimeters(), getBeforeLines());
return asInputStream(contents, getCharset());
}
+ @Override
public InputStream getPatchedContents() {
String contents = LineReader.createString(isPreserveLineDelimeters(), getLines());
return asInputStream(contents, getCharset());
}
+ @Override
public String getCharset() {
return this.charset;
}
@@ -311,11 +314,13 @@ public class FileDiffResult implements IFilePatchResult {
return false;
}
+ @Override
public IHunk[] getRejects() {
- List failedHunks = getFailedHunks();
- return (IHunk[]) failedHunks.toArray(new IHunk[failedHunks.size()]);
+ List failedHunks = getFailedHunks();
+ return failedHunks.toArray(new IHunk[failedHunks.size()]);
}
+ @Override
public boolean hasRejects() {
return getFailedHunks().size() > 0;
}
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 f171acb95..f15997db9 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
@@ -28,7 +28,6 @@ import org.eclipse.core.runtime.Path;
* same path in a patch file.
*/
public class FilePatch2 implements IFilePatch2 {
-
/**
* Difference constant (value 1) indicating one side was added.
*/
@@ -44,7 +43,7 @@ public class FilePatch2 implements IFilePatch2 {
private IPath fOldPath, fNewPath;
private long oldDate, newDate;
- private List fHunks= new ArrayList();
+ private List fHunks= new ArrayList();
private DiffProject fProject; //the project that contains this diff
private String header;
private int addedLines, removedLines;
@@ -122,15 +121,16 @@ public class FilePatch2 implements IFilePatch2 {
}
/**
- * Return the hunks associated with this file diff.
+ * Returns the hunks associated with this file diff.
* @return the hunks associated with this file diff
*/
+ @Override
public IHunk[] getHunks() {
- return (IHunk[]) this.fHunks.toArray(new IHunk[this.fHunks.size()]);
+ return this.fHunks.toArray(new IHunk[this.fHunks.size()]);
}
/**
- * Return the number of hunks associated with this file diff.
+ * Returns the number of hunks associated with this file diff.
* @return the number of hunks associated with this file diff
*/
public int getHunkCount() {
@@ -138,7 +138,7 @@ public class FilePatch2 implements IFilePatch2 {
}
/**
- * Return the difference type of this file diff.
+ * Returns the difference type of this file diff.
* @param reverse whether the patch is being reversed
* @return the type of this file diff
*/
@@ -146,9 +146,9 @@ public class FilePatch2 implements IFilePatch2 {
if (this.fHunks.size() == 1) {
boolean add = false;
boolean delete = false;
- Iterator iter = this.fHunks.iterator();
+ Iterator iter = this.fHunks.iterator();
while (iter.hasNext()){
- Hunk hunk = (Hunk) iter.next();
+ Hunk hunk = iter.next();
int type =hunk.getHunkType(reverse);
if (type == ADDITION){
add = true;
@@ -195,6 +195,7 @@ public class FilePatch2 implements IFilePatch2 {
return length;
}
+ @Override
public IFilePatchResult apply(ReaderCreator content,
PatchConfiguration configuration, IProgressMonitor monitor) {
FileDiffResult result = new FileDiffResult(this, configuration);
@@ -202,6 +203,7 @@ public class FilePatch2 implements IFilePatch2 {
return result;
}
+ @Override
public IPath getTargetPath(PatchConfiguration configuration) {
return getStrippedPath(configuration.getPrefixSegmentStripCount(), configuration.isReversed());
}
@@ -218,8 +220,8 @@ public class FilePatch2 implements IFilePatch2 {
adjustedNewPath = new Path(null, this.fProject.getName()).append(this.fNewPath);
}
FilePatch2 diff = create(adjustedOldPath, 0, adjustedNewPath, 0);
- for (Iterator iterator = this.fHunks.iterator(); iterator.hasNext();) {
- Hunk hunk = (Hunk) iterator.next();
+ for (Iterator iterator = this.fHunks.iterator(); iterator.hasNext();) {
+ Hunk hunk = iterator.next();
// Creating the hunk adds it to the parent diff
new Hunk(diff, hunk);
}
@@ -235,14 +237,17 @@ public class FilePatch2 implements IFilePatch2 {
this.header = header;
}
+ @Override
public String getHeader() {
return this.header;
}
+ @Override
public long getBeforeDate() {
return this.oldDate;
}
+ @Override
public long getAfterDate() {
return this.newDate;
}
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 2a8d45b89..358d2750d 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
@@ -14,17 +14,15 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.Assert;
-
import org.eclipse.compare.patch.IFilePatchResult;
import org.eclipse.compare.patch.IHunk;
import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.core.runtime.Assert;
/**
* A Hunk describes a range of changed lines and some context lines.
*/
public class Hunk implements IHunk {
-
private FilePatch2 fParent;
private int fOldStart, fOldLength;
private int fNewStart, fNewLength;
@@ -32,7 +30,8 @@ public class Hunk implements IHunk {
private int hunkType;
private String charset = null;
- public static Hunk createHunk(FilePatch2 parent, int[] oldRange, int[] newRange, List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
+ public static Hunk createHunk(FilePatch2 parent, int[] oldRange, int[] newRange,
+ List lines, boolean hasLineAdditions, boolean hasLineDeletions, boolean hasContextLines) {
int oldStart = 0;
int oldLength = 0;
int newStart = 0;
@@ -55,7 +54,7 @@ public class Hunk implements IHunk {
hunkType = FilePatch2.DELETION;
}
}
- return new Hunk(parent, hunkType, oldStart, oldLength, newStart, newLength, (String[]) lines.toArray(new String[lines.size()]));
+ 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,
@@ -146,6 +145,7 @@ public class Hunk implements IHunk {
return this.fLines;
}
+ @Override
public String[] getUnifiedLines() {
String[] ret = new String[this.fLines.length];
System.arraycopy(this.fLines, 0, ret, 0, this.fLines.length);
@@ -174,10 +174,10 @@ public class Hunk implements IHunk {
* The parameter shift is added to the line numbers given
* in the hunk.
*/
- public boolean tryPatch(PatchConfiguration configuration, List lines, int shift, int fuzz) {
+ public boolean tryPatch(PatchConfiguration configuration, List lines, int shift, int fuzz) {
boolean reverse = configuration.isReversed();
int pos = getStart(reverse) + shift;
- List contextLines = new ArrayList();
+ List contextLines = new ArrayList<>();
boolean contextLinesMatched = true;
boolean precedingLinesChecked = false;
for (int i= 0; i < this.fLines.length; i++) {
@@ -191,7 +191,7 @@ public class Hunk implements IHunk {
if (pos < 0 || pos >= lines.size())
return false;
contextLines.add(line);
- if (linesMatch(configuration, line, (String) lines.get(pos))) {
+ if (linesMatch(configuration, line, lines.get(pos))) {
pos++;
continue;
} else if (fuzz > 0) {
@@ -225,7 +225,7 @@ public class Hunk implements IHunk {
if (pos < 0 || pos >= lines.size()) // out of the file
return false;
- if (linesMatch(configuration, line, (String) lines.get(pos))) {
+ if (linesMatch(configuration, line, lines.get(pos))) {
pos++;
continue; // line matched, continue with the next one
}
@@ -267,26 +267,25 @@ public class Hunk implements IHunk {
}
private boolean checkPrecedingContextLines(
- PatchConfiguration configuration, List lines, int fuzz, int pos,
- List contextLines) {
-
+ PatchConfiguration configuration, List lines, int fuzz, int pos,
+ List contextLines) {
// ignore from the beginning
for (int j = fuzz; j < contextLines.size(); j++) {
- if (!linesMatch(configuration, (String) contextLines.get(j),
- (String) lines.get(pos - contextLines.size() + j)))
+ if (!linesMatch(configuration, contextLines.get(j),
+ lines.get(pos - contextLines.size() + j)))
return false;
}
return true;
}
private boolean checkFollowingContextLines(
- PatchConfiguration configuration, List lines, int fuzz, int pos,
- List contextLines) {
+ PatchConfiguration configuration, List lines, int fuzz, int pos,
+ List contextLines) {
if (!contextLines.isEmpty()) {
// ignore from the end
for (int j = 0; j < contextLines.size() - fuzz; j++) {
- if (!linesMatch(configuration, (String) contextLines.get(j),
- (String) lines.get(pos - contextLines.size() + j)))
+ if (!linesMatch(configuration, contextLines.get(j),
+ lines.get(pos - contextLines.size() + j)))
return false;
}
}
@@ -322,10 +321,10 @@ public class Hunk implements IHunk {
return this.fNewLength - this.fOldLength;
}
- int doPatch(PatchConfiguration configuration, List lines, int shift, int fuzz) {
+ int doPatch(PatchConfiguration configuration, List lines, int shift, int fuzz) {
boolean reverse = configuration.isReversed();
int pos = getStart(reverse) + shift;
- List contextLines = new ArrayList();
+ List contextLines = new ArrayList<>();
boolean contextLinesMatched = true;
boolean precedingLinesChecked = false;
String lineDelimiter = getLineDelimiter(lines);
@@ -339,7 +338,7 @@ public class Hunk implements IHunk {
// context lines
Assert.isTrue(pos < lines.size(), "doPatch: inconsistency in context"); //$NON-NLS-1$
contextLines.add(line);
- if (linesMatch(configuration, line, (String) lines.get(pos))) {
+ if (linesMatch(configuration, line, lines.get(pos))) {
pos++;
continue;
} else if (fuzz > 0) {
@@ -432,10 +431,10 @@ public class Hunk implements IHunk {
return true;
}
- private String getLineDelimiter(List lines) {
+ private String getLineDelimiter(List lines) {
if (lines.size() > 0) {
// get a line separator from the file being patched
- String line0 = (String) lines.get(0);
+ String line0 = lines.get(0);
return line0.substring(LineReader.length(line0));
} else if (this.fLines.length > 0) {
// if the file doesn't exist use a line separator from the patch
@@ -476,19 +475,23 @@ public class Hunk implements IHunk {
return result.toString();
}
+ @Override
public String getLabel() {
return getDescription();
}
+ @Override
public int getStartPosition() {
return getStart(false);
}
+ @Override
public InputStream getOriginalContents() {
String contents = getContents(false, false);
return asInputStream(contents);
}
+ @Override
public InputStream getPatchedContents() {
String contents = getContents(true, false);
return asInputStream(contents);
@@ -511,6 +514,8 @@ public class Hunk implements IHunk {
* {@link IFilePatchResult#getCharset()} as a proper way to
* obtain charset.
*/
+ @Deprecated
+ @Override
public String getCharset() {
return this.charset;
}
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 a488540f8..6b37d90dc 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
@@ -51,7 +51,7 @@ public class HunkResult {
* @param lines the lines to be patched
* @return whether the hunk could be applied
*/
- public boolean patch(List lines) {
+ public boolean patch(List lines) {
this.fMatches = false;
PatchConfiguration configuration = getConfiguration();
// if the fuzz is not set for the current hunk use the one from fDiffResult
@@ -115,7 +115,7 @@ public class HunkResult {
* a progress monitor
* @return the fuzz factor or -1 if the hunk could not be matched
*/
- public int calculateFuzz(List lines, IProgressMonitor monitor) {
+ public int calculateFuzz(List lines, IProgressMonitor monitor) {
this.fMatches = false;
PatchConfiguration configuration = getConfiguration();
int fuzz = 0;
@@ -228,7 +228,7 @@ public class HunkResult {
public String getContents(boolean afterState, boolean fullContext) {
if (fullContext) {
boolean problemFound = false;
- List lines = getDiffResult().getBeforeLines();
+ List lines = getDiffResult().getBeforeLines();
if (afterState) {
if (isOK()) {
int oldShift = this.fShift;
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 37b02420c..019874b29 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
@@ -24,12 +24,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
public class LineReader {
-
- /*
+ /**
* Reads the contents and returns them as a List of lines.
*/
- public static List load(ReaderCreator content, boolean create) {
- List lines = null;
+ public static List load(ReaderCreator content, boolean create) {
+ List lines = null;
BufferedReader bufferedReader = null;
if (!create && content != null && content.canCreateReader()) {
// read current contents
@@ -39,22 +38,23 @@ public class LineReader {
} catch (CoreException ex) {
ComparePlugin.log(ex);
} finally {
- if (bufferedReader != null)
+ if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
// silently ignored
}
+ }
}
}
if (lines == null)
- lines = new ArrayList();
+ lines = new ArrayList<>();
return lines;
}
- public static List readLines(BufferedReader reader) {
- List lines;
+ public static List readLines(BufferedReader reader) {
+ List lines;
LineReader lr= new LineReader(reader);
if (!Platform.WS_CARBON.equals(Platform.getWS()))
lr.ignoreSingleCR(); // Don't treat single CRs as line feeds to be consistent with command line patch
@@ -65,16 +65,16 @@ public class LineReader {
/*
* Concatenates all strings found in the given List.
*/
- public static String createString(boolean preserveLineDelimeters, List lines) {
+ public static String createString(boolean preserveLineDelimeters, List lines) {
StringBuffer sb= new StringBuffer();
- Iterator iter= lines.iterator();
+ Iterator iter= lines.iterator();
if (preserveLineDelimeters) {
while (iter.hasNext())
- sb.append((String)iter.next());
+ sb.append(iter.next());
} else {
String lineSeparator= System.getProperty("line.separator"); //$NON-NLS-1$
while (iter.hasNext()) {
- String line= (String)iter.next();
+ String line= iter.next();
int l= length(line);
if (l < line.length()) { // line has delimiter
sb.append(line.substring(0, l));
@@ -91,7 +91,7 @@ public class LineReader {
* Returns the length (excluding a line delimiter CR, LF, CR/LF)
* of the given string.
*/
- /* package */ static int length(String s) {
+ static int length(String s) {
int l= s.length();
if (l > 0) {
char c= s.charAt(l-1);
@@ -131,7 +131,7 @@ public class LineReader {
* stream has been reached
* @exception IOException If an I/O error occurs
*/
- /* package */ String readLine() throws IOException {
+ String readLine() throws IOException {
try {
while (!this.fSawEOF) {
int c= readChar();
@@ -170,7 +170,7 @@ public class LineReader {
}
}
- /* package */ void close() {
+ void close() {
try {
this.fReader.close();
} catch (IOException ex) {
@@ -178,9 +178,9 @@ public class LineReader {
}
}
- public List readLines() {
+ public List readLines() {
try {
- List lines= new ArrayList();
+ List lines= new ArrayList<>();
String line;
while ((line= readLine()) != null)
lines.add(line);
@@ -198,7 +198,7 @@ public class LineReader {
* Returns the number of characters in the given string without
* counting a trailing line separator.
*/
- /* package */ int lineContentLength(String line) {
+ int lineContentLength(String line) {
if (line == null)
return 0;
int length= line.length();
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 c103e1b8a..255f50382 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
@@ -22,18 +22,16 @@ import java.util.Locale;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
-import com.ibm.icu.text.DateFormat;
-import com.ibm.icu.text.SimpleDateFormat;
-
+import org.eclipse.compare.patch.IFilePatch2;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.compare.patch.IFilePatch2;
+import com.ibm.icu.text.DateFormat;
+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$
@@ -87,8 +85,8 @@ public class PatchReader {
}
public void parse(BufferedReader reader) throws IOException {
- List diffs= new ArrayList();
- HashMap diffProjects= new HashMap(4);
+ List diffs= new ArrayList();
+ HashMap diffProjects= new HashMap(4);
String line= null;
boolean reread= false;
String diffArgs= null;
@@ -146,7 +144,7 @@ public class PatchReader {
diffProject= new DiffProject(projectName);
diffProjects.put(projectName, diffProject);
} else {
- diffProject= (DiffProject) diffProjects.get(projectName);
+ diffProject= diffProjects.get(projectName);
}
line= readUnifiedDiff(diffs, lr, line, diffArgs, fileName, diffProject);
@@ -157,8 +155,8 @@ public class PatchReader {
lr.close();
- this.fDiffProjects= (DiffProject[]) diffProjects.values().toArray(new DiffProject[diffProjects.size()]);
- this.fDiffs = (FilePatch2[]) diffs.toArray(new FilePatch2[diffs.size()]);
+ this.fDiffProjects= diffProjects.values().toArray(new DiffProject[diffProjects.size()]);
+ this.fDiffs = diffs.toArray(new FilePatch2[diffs.size()]);
}
protected FilePatch2 createFileDiff(IPath oldPath, long oldDate,
@@ -166,11 +164,11 @@ public class PatchReader {
return new FilePatch2(oldPath, oldDate, newPath, newDate);
}
- private String readUnifiedDiff(List diffs, LineReader lr, String line, String diffArgs, String fileName, DiffProject diffProject) throws IOException {
- List newDiffs= new ArrayList();
+ private String readUnifiedDiff(List diffs, LineReader lr, String line, String diffArgs, String fileName, DiffProject diffProject) throws IOException {
+ List newDiffs= new ArrayList();
String nextLine= readUnifiedDiff(newDiffs, lr, line, diffArgs, fileName);
- for (Iterator iter= newDiffs.iterator(); iter.hasNext();) {
- FilePatch2 diff= (FilePatch2) iter.next();
+ for (Iterator iter= newDiffs.iterator(); iter.hasNext();) {
+ FilePatch2 diff= iter.next();
diffProject.add(diff);
diffs.add(diff);
}
@@ -178,11 +176,11 @@ public class PatchReader {
}
public void parse(LineReader lr, String line) throws IOException {
- List diffs= new ArrayList();
+ List diffs= new ArrayList();
boolean reread= false;
String diffArgs= null;
String fileName= null;
- List headerLines = new ArrayList();
+ List headerLines = new ArrayList();
boolean foundDiff= false;
// read leading garbage
@@ -205,13 +203,13 @@ public class PatchReader {
} else if (line.startsWith("--- ")) { //$NON-NLS-1$
line= readUnifiedDiff(diffs, lr, line, diffArgs, fileName);
if (!headerLines.isEmpty())
- setHeader((FilePatch2)diffs.get(diffs.size() - 1), headerLines);
+ setHeader(diffs.get(diffs.size() - 1), headerLines);
diffArgs= fileName= null;
reread= true;
} else if (line.startsWith("*** ")) { //$NON-NLS-1$
line= readContextDiff(diffs, lr, line, diffArgs, fileName);
if (!headerLines.isEmpty())
- setHeader((FilePatch2)diffs.get(diffs.size() - 1), headerLines);
+ setHeader(diffs.get(diffs.size() - 1), headerLines);
diffArgs= fileName= null;
reread= true;
}
@@ -225,10 +223,10 @@ public class PatchReader {
lr.close();
- this.fDiffs = (FilePatch2[]) diffs.toArray(new FilePatch2[diffs.size()]);
+ this.fDiffs = diffs.toArray(new FilePatch2[diffs.size()]);
}
- private void setHeader(FilePatch2 diff, List headerLines) {
+ private void setHeader(FilePatch2 diff, List headerLines) {
String header = LineReader.createString(false, headerLines);
diff.setHeader(header);
headerLines.clear();
@@ -237,7 +235,7 @@ public class PatchReader {
/*
* Returns the next line that does not belong to this diff
*/
- protected String readUnifiedDiff(List diffs, LineReader reader, String line, String args, String fileName) throws IOException {
+ protected String readUnifiedDiff(List diffs, LineReader reader, String line, String args, String fileName) throws IOException {
String[] oldArgs= split(line.substring(4));
@@ -257,7 +255,7 @@ public class PatchReader {
int[] newRange= new int[2];
int remainingOld= -1; // remaining old lines for current hunk
int remainingNew= -1; // remaining new lines for current hunk
- List lines= new ArrayList();
+ List lines= new ArrayList();
boolean encounteredPlus = false;
boolean encounteredMinus = false;
@@ -319,7 +317,7 @@ public class PatchReader {
if (line.indexOf("newline at end") > 0) { //$NON-NLS-1$
int lastIndex= lines.size();
if (lastIndex > 0) {
- line= (String)lines.get(lastIndex - 1);
+ line= lines.get(lastIndex - 1);
int end= line.length() - 1;
char lc= line.charAt(end);
if (lc == '\n') {
@@ -363,7 +361,7 @@ public class PatchReader {
/*
* Returns the next line that does not belong to this diff
*/
- private String readContextDiff(List diffs, LineReader reader, String line, String args, String fileName) throws IOException {
+ private String readContextDiff(List diffs, LineReader reader, String line, String args, String fileName) throws IOException {
String[] oldArgs= split(line.substring(4));
@@ -381,9 +379,9 @@ public class PatchReader {
int[] oldRange= new int[2];
int[] newRange= new int[2];
- List oldLines= new ArrayList();
- List newLines= new ArrayList();
- List lines= oldLines;
+ List oldLines= new ArrayList();
+ List newLines= new ArrayList();
+ List lines= oldLines;
boolean encounteredPlus = false;
@@ -480,11 +478,11 @@ public class PatchReader {
* Creates a List of lines in the unified format from
* two Lists of lines in the 'classic' format.
*/
- private List unifyLines(List oldLines, List newLines) {
- List result= new ArrayList();
+ private List unifyLines(List oldLines, List newLines) {
+ List result= new ArrayList();
- String[] ol= (String[]) oldLines.toArray(new String[oldLines.size()]);
- String[] nl= (String[]) newLines.toArray(new String[newLines.size()]);
+ String[] ol= oldLines.toArray(new String[oldLines.size()]);
+ String[] nl= newLines.toArray(new String[newLines.size()]);
int oi= 0, ni= 0;
@@ -670,21 +668,20 @@ public class PatchReader {
pair[1]= 1;
}
}
-
-
+
/*
* Breaks the given string into tab separated substrings.
* Leading and trailing whitespace is removed from each token.
*/
private String[] split(String line) {
- List l= new ArrayList();
+ List l= new ArrayList<>();
StringTokenizer st= new StringTokenizer(line, "\t"); //$NON-NLS-1$
while (st.hasMoreElements()) {
String token= st.nextToken().trim();
if (token.length() > 0)
l.add(token);
}
- return (String[]) l.toArray(new String[l.size()]);
+ return l.toArray(new String[l.size()]);
}
public boolean isWorkspacePatch() {
@@ -706,12 +703,12 @@ public class PatchReader {
public FilePatch2[] getAdjustedDiffs() {
if (!isWorkspacePatch() || this.fDiffs.length == 0)
return this.fDiffs;
- List result = new ArrayList();
+ List result = new ArrayList();
for (int i = 0; i < this.fDiffs.length; i++) {
FilePatch2 diff = this.fDiffs[i];
result.add(diff.asRelativeDiff());
}
- return (FilePatch2[]) result.toArray(new FilePatch2[result.size()]);
+ return result.toArray(new FilePatch2[result.size()]);
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java
index ae029457c..578c0e187 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/LineReader.java
@@ -29,13 +29,12 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
public class LineReader {
-
- /*
+ /**
* Reads the contents from the given file and returns them as a List of
* lines.
*/
- public static List load(IStorage file, boolean create) {
- List lines = null;
+ public static List load(IStorage file, boolean create) {
+ List lines = null;
if (!create && file != null && exists(file)) {
// read current contents
String charset = Utilities.getCharset(file);
@@ -67,7 +66,7 @@ public class LineReader {
}
if (lines == null)
- lines = new ArrayList();
+ lines = new ArrayList<>();
return lines;
}
@@ -78,8 +77,8 @@ public class LineReader {
return true;
}
- public static List readLines(BufferedReader reader) {
- List lines;
+ public static List readLines(BufferedReader reader) {
+ List lines;
LineReader lr = new LineReader(reader);
if (!Platform.WS_CARBON.equals(Platform.getWS()))
// Don't treat single CRs as line feeds to be consistent with command line patch
@@ -91,16 +90,16 @@ public class LineReader {
/*
* Concatenates all strings found in the given List.
*/
- public static String createString(boolean preserveLineDelimeters, List lines) {
+ public static String createString(boolean preserveLineDelimeters, List lines) {
StringBuffer sb = new StringBuffer();
- Iterator iter = lines.iterator();
+ Iterator iter = lines.iterator();
if (preserveLineDelimeters) {
while (iter.hasNext())
- sb.append((String) iter.next());
+ sb.append(iter.next());
} else {
String lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$
while (iter.hasNext()) {
- String line = (String) iter.next();
+ String line = iter.next();
int l = length(line);
if (l < line.length()) { // line has delimiter
sb.append(line.substring(0, l));
@@ -117,7 +116,7 @@ public class LineReader {
* Returns the length (excluding a line delimiter CR, LF, CR/LF) of the
* given string.
*/
- /* package */static int length(String s) {
+ static int length(String s) {
int l = s.length();
if (l > 0) {
char c = s.charAt(l - 1);
@@ -159,7 +158,7 @@ public class LineReader {
* @exception IOException
* If an I/O error occurs
*/
- /* package */String readLine() throws IOException {
+ String readLine() throws IOException {
try {
while (!fSawEOF) {
int c = readChar();
@@ -198,7 +197,7 @@ public class LineReader {
}
}
- /* package */void close() {
+ void close() {
try {
fReader.close();
} catch (IOException ex) {
@@ -206,9 +205,9 @@ public class LineReader {
}
}
- public List readLines() {
+ public List readLines() {
try {
- List lines = new ArrayList();
+ List lines = new ArrayList<>();
String line;
while ((line = readLine()) != null)
lines.add(line);
@@ -227,7 +226,7 @@ public class LineReader {
* Returns the number of characters in the given string without counting a
* trailing line separator.
*/
- /* package */int lineContentLength(String line) {
+ int lineContentLength(String line) {
if (line == null)
return 0;
int length = line.length();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java
index 12d959cfc..ed468befa 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchFileTypedElement.java
@@ -39,6 +39,7 @@ public class PatchFileTypedElement implements ITypedElement,
this.isAfterState = isAfterState;
}
+ @Override
public Image getImage() {
IFile file = getPatcher().getTargetFile(result.getDiff());
if (file == null) {
@@ -75,6 +76,7 @@ public class PatchFileTypedElement implements ITypedElement,
*
* @see org.eclipse.compare.ITypedElement#getName()
*/
+ @Override
public String getName() {
return result.getTargetPath().toString();
}
@@ -84,14 +86,17 @@ public class PatchFileTypedElement implements ITypedElement,
*
* @see org.eclipse.compare.ITypedElement#getType()
*/
+ @Override
public String getType() {
return result.getTargetPath().getFileExtension();
}
+ @Override
public String getCharset() throws CoreException {
return result.getCharset();
}
+ @Override
public InputStream getContents() throws CoreException {
// If there are cached contents, use them
if (isAfterState && getPatcher().hasCachedContents(result.getDiff()))
@@ -124,5 +129,4 @@ public class PatchFileTypedElement implements ITypedElement,
private Patcher getPatcher() {
return Patcher.getPatcher(result.getConfiguration());
}
-
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
index 651d0443d..17d5afac0 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
@@ -184,6 +184,7 @@ public class Patcher implements IHunkFilter {
public void parse(BufferedReader reader) throws IOException {
PatchReader patchReader = new PatchReader() {
+ @Override
protected FilePatch2 createFileDiff(IPath oldPath, long oldDate,
IPath newPath, long newDate) {
return new FilePatch(oldPath, oldDate, newPath, newDate);
@@ -342,7 +343,7 @@ public class Patcher implements IHunkFilter {
List apply(FilePatch2 diff, IFile file, boolean create, List failedHunks) {
FileDiffResult result = getDiffResult(diff);
- List lines = LineReader.load(file, create);
+ List lines = LineReader.load(file, create);
result.patch(lines, null);
failedHunks.addAll(result.getFailedHunks());
if (hasCachedContents(diff)) {
@@ -713,7 +714,7 @@ public class Patcher implements IHunkFilter {
* @param diff the file diff
* @return the content lines that are cached for the file diff
*/
- public List getCachedLines(FilePatch2 diff) {
+ public List getCachedLines(FilePatch2 diff) {
byte[] contents = (byte[])contentCache.get(diff);
if (contents != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(contents)));
@@ -793,6 +794,7 @@ public class Patcher implements IHunkFilter {
return false;
}
+ @Override
public boolean select(IHunk hunk) {
return isEnabled(hunk);
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffContainer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffContainer.java
index 7599f540f..95a14d3f7 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffContainer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffContainer.java
@@ -19,9 +19,8 @@ import java.util.ArrayList;
*
*/
public abstract class DiffContainer extends DiffElement implements IDiffContainer {
-
private static IDiffElement[] fgEmptyArray= new IDiffElement[0];
- private ArrayList fChildren;
+ private ArrayList fChildren;
/**
* Creates a new container with the specified kind under the given parent.
@@ -50,25 +49,20 @@ public abstract class DiffContainer extends DiffElement implements IDiffContaine
return null;
}
- /* (non Javadoc)
- * see IDiffContainer.add
- */
+ @Override
public void add(IDiffElement diff) {
if (fChildren == null)
- fChildren= new ArrayList();
+ fChildren= new ArrayList<>();
fChildren.add(diff);
diff.setParent(this);
}
- /*
- * Removes the given child from this container.
- * If the container becomes empty it is removed from its container.
- */
+ @Override
public void removeToRoot(IDiffElement child) {
if (fChildren != null) {
fChildren.remove(child);
child.setParent(null);
- if (fChildren.size() == 0) {
+ if (fChildren.isEmpty()) {
IDiffContainer p= getParent();
if (p != null)
p.removeToRoot(this);
@@ -88,20 +82,15 @@ public abstract class DiffContainer extends DiffElement implements IDiffContaine
}
}
- /* (non Javadoc)
- * see IDiffContainer.hasChildren
- */
+ @Override
public boolean hasChildren() {
return fChildren != null && fChildren.size() > 0;
}
- /* (non Javadoc)
- * see IDiffContainer.getChildren
- */
+ @Override
public IDiffElement[] getChildren() {
if (fChildren != null)
- return (IDiffElement[]) fChildren.toArray(fgEmptyArray);
+ return fChildren.toArray(fgEmptyArray);
return fgEmptyArray;
}
}
-
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffElement.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffElement.java
index e69764a65..0cd40eda3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffElement.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffElement.java
@@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.compare.structuremergeviewer;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.compare.ITypedElement;
+import org.eclipse.swt.graphics.Image;
/**
* An abstract base implementation of the IDiffElement interface.
@@ -21,7 +21,6 @@ import org.eclipse.compare.ITypedElement;
*
*/
public abstract class DiffElement implements IDiffElement {
-
private int fKind;
private IDiffContainer fParent;
@@ -45,6 +44,7 @@ public abstract class DiffElement implements IDiffElement {
* an image for this element.
* @return null.
*/
+ @Override
public Image getImage() {
return null;
}
@@ -55,6 +55,7 @@ public abstract class DiffElement implements IDiffElement {
* re-implement to provide a type for this element.
* @return ITypedElement.UNKNOWN_TYPE.
*/
+ @Override
public String getType() {
return ITypedElement.UNKNOWN_TYPE;
}
@@ -69,23 +70,17 @@ public abstract class DiffElement implements IDiffElement {
fKind= kind;
}
- /* (non Javadoc)
- * see IDiffElement.getKind
- */
+ @Override
public int getKind() {
return fKind;
}
- /* (non Javadoc)
- * see IDiffElement.getParent
- */
+ @Override
public IDiffContainer getParent() {
return fParent;
}
- /* (non Javadoc)
- * see IDiffElement.setParent
- */
+ @Override
public void setParent(IDiffContainer parent) {
fParent= parent;
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffNode.java
index b1775f0f1..4f6d3316e 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffNode.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffNode.java
@@ -34,14 +34,12 @@ import com.ibm.icu.text.MessageFormat;
* @see Differencer
*/
public class DiffNode extends DiffContainer implements ICompareInput {
-
private ITypedElement fAncestor;
private ITypedElement fLeft;
private ITypedElement fRight;
private boolean fDontExpand;
- private ListenerList fListener;
+ private ListenerList fListener;
private boolean fSwapSides;
-
/**
* Creates a new DiffNode and initializes with the given values.
@@ -107,9 +105,10 @@ public class DiffNode extends DiffContainer implements ICompareInput {
*
* @param listener the listener to add
*/
+ @Override
public void addCompareInputChangeListener(ICompareInputChangeListener listener) {
if (fListener == null)
- fListener= new ListenerList();
+ fListener= new ListenerList<>();
fListener.add(listener);
}
@@ -119,6 +118,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
*
* @param listener the listener to remove
*/
+ @Override
public void removeCompareInputChangeListener(ICompareInputChangeListener listener) {
if (fListener != null) {
fListener.remove(listener);
@@ -181,6 +181,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
* Subclasses may re-implement to provide a different name for this node.
* @return the name of this node.
*/
+ @Override
public String getName() {
String right= null;
if (fRight != null)
@@ -226,6 +227,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ITypedElement.getImage
*/
+ @Override
public Image getImage() {
ITypedElement id= getId();
if (id != null)
@@ -236,6 +238,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ITypedElement.getType
*/
+ @Override
public String getType() {
ITypedElement id= getId();
if (id != null)
@@ -256,6 +259,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ICompareInput.getAncestor
*/
+ @Override
public ITypedElement getAncestor() {
return fAncestor;
}
@@ -272,6 +276,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ICompareInput.getLeft
*/
+ @Override
public ITypedElement getLeft() {
return fLeft;
}
@@ -288,6 +293,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ICompareInput.getRight
*/
+ @Override
public ITypedElement getRight() {
return fRight;
}
@@ -295,6 +301,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see ICompareInput.copy
*/
+ @Override
public void copy(boolean leftToRight) {
//System.out.println("DiffNode.copy: " + leftToRight);
@@ -322,6 +329,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see Object.hashCode
*/
+ @Override
public int hashCode() {
String[] path= getPath(this, 0);
int hashCode= 1;
@@ -335,6 +343,7 @@ public class DiffNode extends DiffContainer implements ICompareInput {
/* (non Javadoc)
* see Object.equals
*/
+ @Override
public boolean equals(Object other) {
if (other != null && getClass() == other.getClass()) {
String[] path1= getPath(this, 0);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
index d5df14bd0..b59aa5115 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java
@@ -13,17 +13,38 @@ package org.eclipse.compare.structuremergeviewer;
import java.util.Iterator;
import java.util.ResourceBundle;
-import org.eclipse.compare.*;
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareUI;
+import org.eclipse.compare.CompareViewerPane;
+import org.eclipse.compare.INavigatable;
import org.eclipse.compare.internal.Utilities;
import org.eclipse.compare.internal.patch.DiffViewerComparator;
-import org.eclipse.jface.action.*;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
/**
* A tree viewer that works on objects implementing
@@ -40,7 +61,7 @@ import org.eclipse.swt.widgets.*;
public class DiffTreeViewer extends TreeViewer {
class DiffViewerContentProvider implements ITreeContentProvider {
-
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// empty implementation
}
@@ -49,22 +70,26 @@ public class DiffTreeViewer extends TreeViewer {
return false;
}
+ @Override
public void dispose() {
inputChanged(DiffTreeViewer.this, getInput(), null);
}
+ @Override
public Object getParent(Object element) {
if (element instanceof IDiffElement)
return ((IDiffElement)element).getParent();
return null;
}
+ @Override
public final boolean hasChildren(Object element) {
if (element instanceof IDiffContainer)
return ((IDiffContainer)element).hasChildren();
return false;
}
+ @Override
public final Object[] getChildren(Object element) {
if (element instanceof IDiffContainer)
return ((IDiffContainer)element).getChildren();
@@ -84,7 +109,6 @@ public class DiffTreeViewer extends TreeViewer {
class DiffViewerLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
-
if (element instanceof IDiffElement)
return ((IDiffElement)element).getName();
@@ -130,6 +154,7 @@ public class DiffTreeViewer extends TreeViewer {
}
static class FilterSame extends ViewerFilter {
+ @Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IDiffElement)
return (((IDiffElement)element).getKind() & Differencer.PSEUDO_CONFLICT) == 0;
@@ -171,10 +196,10 @@ public class DiffTreeViewer extends TreeViewer {
}
private void initialize(CompareConfiguration configuration) {
-
Control tree= getControl();
INavigatable nav= new INavigatable() {
+ @Override
public boolean selectChange(int flag) {
if (flag == INavigatable.FIRST_CHANGE) {
setSelection(StructuredSelection.EMPTY);
@@ -186,12 +211,15 @@ public class DiffTreeViewer extends TreeViewer {
// Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106
return internalNavigate(flag == INavigatable.NEXT_CHANGE, true);
}
+ @Override
public Object getInput() {
return DiffTreeViewer.this.getInput();
}
+ @Override
public boolean openSelectedChange() {
return internalOpen();
}
+ @Override
public boolean hasChange(int changeFlag) {
return getNextItem(changeFlag == INavigatable.NEXT_CHANGE, false) != null;
}
@@ -235,6 +263,7 @@ public class DiffTreeViewer extends TreeViewer {
mm.setRemoveAllWhenShown(true);
mm.addMenuListener(
new IMenuListener() {
+ @Override
public void menuAboutToShow(IMenuManager mm2) {
fillContextMenu(mm2);
if (mm2.isEmpty()) {
@@ -288,8 +317,8 @@ public class DiffTreeViewer extends TreeViewer {
* Clients may extend if they have to do additional cleanup.
* @param event dispose event that triggered call to this method
*/
+ @Override
protected void handleDispose(DisposeEvent event) {
-
if (fCompareConfiguration != null) {
if (fPropertyChangeListener != null)
fCompareConfiguration.removePropertyChangeListener(fPropertyChangeListener);
@@ -341,8 +370,8 @@ public class DiffTreeViewer extends TreeViewer {
* @param node the node to expand
* @param level non-negative level, or ALL_LEVELS to collapse all levels of the tree
*/
+ @Override
protected void internalExpandToLevel(Widget node, int level) {
-
Object data= node.getData();
if (dontExpand(data))
@@ -394,6 +423,7 @@ public class DiffTreeViewer extends TreeViewer {
protected void fillContextMenu(IMenuManager manager) {
if (fExpandAllAction == null) {
fExpandAllAction= new Action() {
+ @Override
public void run() {
expandSelection();
}
@@ -404,7 +434,7 @@ public class DiffTreeViewer extends TreeViewer {
boolean enable= false;
ISelection selection= getSelection();
if (selection instanceof IStructuredSelection) {
- Iterator elements= ((IStructuredSelection)selection).iterator();
+ Iterator> elements= ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
Object element= elements.next();
if (element instanceof IDiffContainer) {
@@ -427,7 +457,7 @@ public class DiffTreeViewer extends TreeViewer {
protected void expandSelection() {
ISelection selection= getSelection();
if (selection instanceof IStructuredSelection) {
- Iterator elements= ((IStructuredSelection)selection).iterator();
+ Iterator> elements= ((IStructuredSelection)selection).iterator();
while (elements.hasNext()) {
Object next= elements.next();
expandToLevel(next, ALL_LEVELS);
@@ -446,7 +476,7 @@ public class DiffTreeViewer extends TreeViewer {
protected void copySelected(boolean leftToRight) {
ISelection selection= getSelection();
if (selection instanceof IStructuredSelection) {
- Iterator e= ((IStructuredSelection) selection).iterator();
+ Iterator> e= ((IStructuredSelection) selection).iterator();
while (e.hasNext()) {
Object element= e.next();
if (element instanceof ICompareInput)
@@ -464,7 +494,6 @@ public class DiffTreeViewer extends TreeViewer {
* If false the right side is copied to the left side
*/
protected void copyOne(ICompareInput node, boolean leftToRight) {
-
node.copy(leftToRight);
// update node's image
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
index 182790e3e..e42185a4c 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/Differencer.java
@@ -15,7 +15,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -58,7 +57,6 @@ import com.ibm.icu.text.MessageFormat;
* LEFT, RIGHT, and CONFLICTING.
*/
public class Differencer {
-
// The kind of differences.
/**
* Difference constant (value 0) indicating no difference.
@@ -112,7 +110,7 @@ public class Differencer {
static class Node {
- List fChildren;
+ List fChildren;
int fCode;
Object fAncestor;
Object fLeft;
@@ -121,31 +119,33 @@ public class Differencer {
Node() {
// nothing to do
}
+
Node(Node parent, Object ancestor, Object left, Object right) {
parent.add(this);
fAncestor= ancestor;
fLeft= left;
fRight= right;
}
+
void add(Node child) {
if (fChildren == null)
- fChildren= new ArrayList();
+ fChildren= new ArrayList<>();
fChildren.add(child);
}
+
Object visit(Differencer d, Object parent, int level) {
if (fCode == NO_CHANGE)
return null;
//dump(level);
Object data= d.visit(parent, fCode, fAncestor, fLeft, fRight);
if (fChildren != null) {
- Iterator i= fChildren.iterator();
- while (i.hasNext()) {
- Node n= (Node) i.next();
- n.visit(d, data, level+1);
+ for (Node n : fChildren) {
+ n.visit(d, data, level + 1);
}
}
return data;
}
+
// private void dump(int level) {
// String name= null;
// if (fAncestor instanceof ITypedElement)
@@ -216,15 +216,14 @@ public class Differencer {
* possibly null
*/
public Object findDifferences(boolean threeWay, IProgressMonitor pm, Object data, Object ancestor, Object left, Object right) {
-
Node root= new Node();
int code= traverse(threeWay, root, pm, threeWay ? ancestor : null, left, right);
if (code != NO_CHANGE) {
- List l= root.fChildren;
- if (l.size() > 0) {
- Node first= (Node)l.get(0);
+ List l= root.fChildren;
+ if (!l.isEmpty()) {
+ Node first= l.get(0);
return first.visit(this, data, 0);
}
}
@@ -234,8 +233,8 @@ public class Differencer {
/*
* Traverse tree in postorder.
*/
- private int traverse(boolean threeWay, Node parent, IProgressMonitor pm, Object ancestor, Object left, Object right) {
-
+ private int traverse(boolean threeWay, Node parent, IProgressMonitor pm,
+ Object ancestor, Object left, Object right) {
Object[] ancestorChildren= getChildren(ancestor);
Object[] rightChildren= getChildren(right);
Object[] leftChildren= getChildren(left);
@@ -251,13 +250,13 @@ public class Differencer {
// we only recurse down if no leg is null
// a node
- Set allSet= new HashSet(20);
- Map ancestorSet= null;
- Map rightSet= null;
- Map leftSet= null;
+ Set