diff options
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org')
14 files changed, 254 insertions, 193 deletions
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<String> load(IStorage file, boolean create) { + List <String> 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<String> readLines(BufferedReader reader) { + List<String> 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<String> lines) { StringBuffer sb = new StringBuffer(); - Iterator iter = lines.iterator(); + Iterator<String> 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<String> readLines() { try { - List lines = new ArrayList(); + List<String> 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<String> 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<String> 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; * </p> */ public abstract class DiffContainer extends DiffElement implements IDiffContainer { - private static IDiffElement[] fgEmptyArray= new IDiffElement[0]; - private ArrayList fChildren; + private ArrayList<IDiffElement> 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 <code>IDiffElement</code> interface. @@ -21,7 +21,6 @@ import org.eclipse.compare.ITypedElement; * </p> */ 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 <code>null</code>. */ + @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 <code>ITypedElement.UNKNOWN_TYPE</code>. */ + @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<ICompareInputChangeListener> fListener; private boolean fSwapSides; - /** * Creates a new <code>DiffNode</code> 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 <code>ALL_LEVELS</code> 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 <code>false</code> 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<Node> 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 <code>null</code> */ 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<Node> 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<Object> allSet= new HashSet<>(20); + Map<Object, Object> ancestorSet= null; + Map<Object, Object> rightSet= null; + Map<Object, Object> leftSet= null; if (ancestorChildren != null) { - ancestorSet= new HashMap(10); + ancestorSet= new HashMap<>(10); for (int i= 0; i < ancestorChildren.length; i++) { Object ancestorChild= ancestorChildren[i]; ancestorSet.put(ancestorChild, ancestorChild); @@ -266,7 +265,7 @@ public class Differencer { } if (rightChildren != null) { - rightSet= new HashMap(10); + rightSet= new HashMap<>(10); for (int i= 0; i < rightChildren.length; i++) { Object rightChild= rightChildren[i]; rightSet.put(rightChild, rightChild); @@ -275,7 +274,7 @@ public class Differencer { } if (leftChildren != null) { - leftSet= new HashMap(10); + leftSet= new HashMap<>(10); for (int i= 0; i < leftChildren.length; i++) { Object leftChild= leftChildren[i]; leftSet.put(leftChild, leftChild); @@ -283,12 +282,8 @@ public class Differencer { } } - Iterator e= allSet.iterator(); - while (e.hasNext()) { - Object keyChild= e.next(); - + for (Object keyChild : allSet) { if (pm != null) { - if (pm.isCanceled()) throw new OperationCanceledException(); @@ -533,7 +528,7 @@ public class Differencer { */ protected Object[] getChildren(Object input) { if (input instanceof IStructureComparator) - return ((IStructureComparator)input).getChildren(); + return ((IStructureComparator) input).getChildren(); return null; } @@ -549,7 +544,7 @@ public class Differencer { */ protected void updateProgress(IProgressMonitor progressMonitor, Object node) { if (node instanceof ITypedElement) { - String name= ((ITypedElement)node).getName(); + String name= ((ITypedElement) node).getName(); String fmt= Utilities.getString("Differencer.progressFormat"); //$NON-NLS-1$ String msg= MessageFormat.format(fmt, name ); progressMonitor.subTask(msg); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java index 58aa841f3..5a0601cc6 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java @@ -14,12 +14,24 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; -import org.eclipse.compare.*; +import org.eclipse.compare.IEditableContent; +import org.eclipse.compare.IEditableContentExtension; +import org.eclipse.compare.IEncodedStreamContentAccessor; +import org.eclipse.compare.ISharedDocumentAdapter; +import org.eclipse.compare.IStreamContentAccessor; +import org.eclipse.compare.ITypedElement; import org.eclipse.compare.contentmergeviewer.IDocumentRange; import org.eclipse.compare.internal.CompareUIPlugin; import org.eclipse.compare.internal.Utilities; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.text.*; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.BadPositionCategoryException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; import org.eclipse.swt.widgets.Shell; @@ -48,8 +60,8 @@ import org.eclipse.swt.widgets.Shell; * @see Differencer */ public class DocumentRangeNode - implements IDocumentRange, IStructureComparator, IEditableContent, IEncodedStreamContentAccessor, IAdaptable, IEditableContentExtension { - + implements IDocumentRange, IStructureComparator, IEditableContent, + IEncodedStreamContentAccessor, IAdaptable, IEditableContentExtension { private static final String UTF_16= "UTF-16"; //$NON-NLS-1$ private IDocument fBaseDocument; @@ -57,7 +69,7 @@ public class DocumentRangeNode private int fTypeCode; private String fID; private Position fAppendPosition; // a position where to insert a child textually - private ArrayList fChildren; + private ArrayList<DocumentRangeNode> fChildren; private final DocumentRangeNode fParent; /** @@ -113,6 +125,7 @@ public class DocumentRangeNode /* (non Javadoc) * see IDocumentRange.getDocument */ + @Override public IDocument getDocument() { return fBaseDocument; } @@ -120,6 +133,7 @@ public class DocumentRangeNode /* (non Javadoc) * see IDocumentRange.getRange */ + @Override public Position getRange() { return fRange; } @@ -161,13 +175,11 @@ public class DocumentRangeNode */ public void addChild(DocumentRangeNode node) { if (fChildren == null) - fChildren= new ArrayList(); + fChildren= new ArrayList<>(); fChildren.add(node); } - /* (non Javadoc) - * see IStructureComparator.getChildren - */ + @Override public Object[] getChildren() { if (fChildren != null) return fChildren.toArray(); @@ -243,6 +255,7 @@ public class DocumentRangeNode * @param other the object to compare this <code>DocumentRangeNode</code> against. * @return <code>true</code> if the <code>DocumentRangeNodes</code>are equal; <code>false</code> otherwise. */ + @Override public boolean equals(Object other) { if (other != null && other.getClass() == getClass()) { DocumentRangeNode tn= (DocumentRangeNode) other; @@ -255,6 +268,7 @@ public class DocumentRangeNode * Implementation based on <code>getID</code>. * @return a hash code for this object. */ + @Override public int hashCode() { return fID.hashCode(); } @@ -271,10 +285,10 @@ public class DocumentRangeNode if (ix >= 0) { for (int i= ix - 1; i >= 0; i--) { - DocumentRangeNode c1= (DocumentRangeNode) otherParent.fChildren.get(i); + DocumentRangeNode c1= otherParent.fChildren.get(i); int i2= fChildren.indexOf(c1); if (i2 >= 0) { - DocumentRangeNode c= (DocumentRangeNode) fChildren.get(i2); + DocumentRangeNode c= fChildren.get(i2); //System.out.println(" found corresponding: " + i2 + " " + c); Position p= c.fRange; @@ -289,10 +303,10 @@ public class DocumentRangeNode } for (int i= ix; i < otherParent.fChildren.size(); i++) { - DocumentRangeNode c1= (DocumentRangeNode) otherParent.fChildren.get(i); + DocumentRangeNode c1= otherParent.fChildren.get(i); int i2= fChildren.indexOf(c1); if (i2 >= 0) { - DocumentRangeNode c= (DocumentRangeNode) fChildren.get(i2); + DocumentRangeNode c= fChildren.get(i2); //System.out.println(" found corresponding: " + i2 + " " + c); Position p= c.fRange; //try { @@ -325,6 +339,7 @@ public class DocumentRangeNode /* (non Javadoc) * see IStreamContentAccessor.getContents */ + @Override public InputStream getContents() { String s; try { @@ -341,17 +356,15 @@ public class DocumentRangeNode * Otherwise return <code>true</code>. Subclasses may override. * @see org.eclipse.compare.IEditableContent#isEditable() */ + @Override public boolean isEditable() { if (fParent != null) return fParent.isEditable(); return true; } - /* (non Javadoc) - * see IEditableContent.replace - */ + @Override public ITypedElement replace(ITypedElement child, ITypedElement other) { - if (fParent == null) { // TODO: I don't believe this code does anything useful but just in case // I'm leaving it in but disabling it for the shared document case @@ -386,6 +399,7 @@ public class DocumentRangeNode * after the contents have been set. * @see org.eclipse.compare.IEditableContent#setContent(byte[]) */ + @Override public void setContent(byte[] content) { internalSetContents(content); nodeChanged(this); @@ -399,12 +413,9 @@ public class DocumentRangeNode */ protected void internalSetContents(byte[] content) { // By default, do nothing - } - /* (non-Javadoc) - * @see org.eclipse.compare.IStreamContentAccessor#getEncoding() - */ + @Override public String getCharset() { return UTF_16; } @@ -431,25 +442,22 @@ public class DocumentRangeNode * @see IAdaptable#getAdapter(Class) * @since 3.3 */ - public Object getAdapter(Class adapter) { + @Override + public <T> T getAdapter(Class<T> adapter) { if (adapter == ISharedDocumentAdapter.class && fParent != null) return fParent.getAdapter(adapter); return Platform.getAdapterManager().getAdapter(this, adapter); } - /* (non-Javadoc) - * @see org.eclipse.compare.IEditableContentExtension#isReadOnly() - */ + @Override public boolean isReadOnly() { if (fParent != null) return fParent.isReadOnly(); return false; } - /* (non-Javadoc) - * @see org.eclipse.compare.IEditableContentExtension#validateEdit(org.eclipse.swt.widgets.Shell) - */ + @Override public IStatus validateEdit(Shell shell) { if (fParent != null) return fParent.validateEdit(shell); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/IStructureComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/IStructureComparator.java index 4740bdadf..bbfd40dee 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/IStructureComparator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/IStructureComparator.java @@ -21,7 +21,6 @@ package org.eclipse.compare.structuremergeviewer; * @see Differencer */ public interface IStructureComparator { - /** * Returns an iterator for all children of this object or <code>null</code> * if there are no children. @@ -41,5 +40,6 @@ public interface IStructureComparator { * @return <code>true</code> if this object is the same as the other argument; <code>false</code> otherwise * @see java.lang.Object#equals */ + @Override boolean equals(Object other); } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java index c3a379ff9..c240a4533 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java @@ -13,7 +13,7 @@ package org.eclipse.compare.structuremergeviewer; import org.eclipse.compare.ISharedDocumentAdapter; import org.eclipse.compare.SharedDocumentAdapter; import org.eclipse.compare.internal.Utilities; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; @@ -27,7 +27,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider; * @since 3.3 */ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter { - private ISharedDocumentAdapter wrappedAdapter; /** @@ -50,31 +49,23 @@ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter { this.wrappedAdapter = wrappedAdapter; } - /* (non-Javadoc) - * @see org.eclipse.compare.ISharedDocumentAdapter#connect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput) - */ + @Override public void connect(IDocumentProvider provider, IEditorInput documentKey) throws CoreException { wrappedAdapter.connect(provider, documentKey); } - /* (non-Javadoc) - * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput) - */ + @Override public void disconnect(IDocumentProvider provider, IEditorInput documentKey) { wrappedAdapter.disconnect(provider, documentKey); } - /* (non-Javadoc) - * @see org.eclipse.compare.ISharedDocumentAdapter#getDocumentKey(java.lang.Object) - */ + @Override public IEditorInput getDocumentKey(Object element) { return wrappedAdapter.getDocumentKey(element); } - /* (non-Javadoc) - * @see org.eclipse.compare.ISharedDocumentAdapter#saveDocument(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput, org.eclipse.jface.text.IDocument, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ + @Override public void flushDocument(IDocumentProvider provider, IEditorInput documentKey, IDocument document, boolean overwrite) throws CoreException { wrappedAdapter.flushDocument(provider, documentKey, document, overwrite); @@ -88,9 +79,7 @@ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter { return wrappedAdapter; } - /* (non-Javadoc) - * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(java.lang.Object) - */ + @Override public void disconnect(Object element) { IEditorInput input = getDocumentKey(element); if (input == null) @@ -100,5 +89,4 @@ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter { return; disconnect(provider, input); } - } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureCreator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureCreator.java index f978ef0a2..e7fd54315 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureCreator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureCreator.java @@ -49,10 +49,7 @@ import org.eclipse.ui.texteditor.IDocumentProvider; * @since 3.3 */ public abstract class StructureCreator implements IStructureCreator2 { - - /* (non-Javadoc) - * @see org.eclipse.compare.structuremergeviewer.IStructureCreator#getStructure(java.lang.Object) - */ + @Override public IStructureComparator getStructure(Object input) { String contents= null; IDocument doc= CompareUI.getDocument(input); @@ -85,12 +82,12 @@ public abstract class StructureCreator implements IStructureCreator2 { } } - /* (non-Javadoc) - * @see org.eclipse.compare.structuremergeviewer.IStructureCreator2#createStructure(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) - */ - public IStructureComparator createStructure(final Object element, final IProgressMonitor monitor) throws CoreException { + @Override + public IStructureComparator createStructure(final Object element, + final IProgressMonitor monitor) throws CoreException { final IStructureComparator[] result = new IStructureComparator[] { null }; Runnable runnable = new Runnable() { + @Override public void run() { try { result[0]= internalCreateStructure(element, monitor); @@ -131,7 +128,7 @@ public abstract class StructureCreator implements IStructureCreator2 { } /** - * Create an {@link IStructureComparator} for the given element using the + * Creates an {@link IStructureComparator} for the given element using the * contents available in the given document. If the provided * {@link ISharedDocumentAdapter} is not <code>null</code> then the * {@link IStructureComparator} returned by this method must implement the @@ -163,7 +160,7 @@ public abstract class StructureCreator implements IStructureCreator2 { IProgressMonitor monitor) throws CoreException; /** - * Setup the newly created document as appropriate. Any document partitioners + * Sets up the newly created document as appropriate. Any document partitioners * should be added to a custom slot using the {@link IDocumentExtension3} interface * in case the document is shared via a file buffer. * @param document a document @@ -191,7 +188,7 @@ public abstract class StructureCreator implements IStructureCreator2 { } /** - * Return the partitioner to be associated with the document or + * Returns the partitioner to be associated with the document or * <code>null</code> is partitioning is not needed or if the subclass * overrode {@link #setupDocument(IDocument)} directly. * @return a partitioner @@ -201,7 +198,7 @@ public abstract class StructureCreator implements IStructureCreator2 { } /** - * Return the partitioning to which the partitioner returned from + * Returns the partitioning to which the partitioner returned from * {@link #getDocumentPartitioner()} is to be associated. Return <code>null</code> * only if partitioning is not needed or if the subclass * overrode {@link #setupDocument(IDocument)} directly. @@ -222,6 +219,7 @@ public abstract class StructureCreator implements IStructureCreator2 { * input, then the save is issued through the shared document adapter. * @see org.eclipse.compare.structuremergeviewer.IStructureCreator#save(org.eclipse.compare.structuremergeviewer.IStructureComparator, java.lang.Object) */ + @Override public void save(IStructureComparator node, Object input) { if (node instanceof IDocumentRange && input instanceof IEditableContent) { IDocument document= ((IDocumentRange)node).getDocument(); @@ -285,6 +283,7 @@ public abstract class StructureCreator implements IStructureCreator2 { private final ISharedDocumentAdapter wrapSharedDocumentAdapter(ISharedDocumentAdapter elementAdapter, final Object input, final IDocument document) { // We need to wrap the adapter so that the proper document key gets returned return new SharedDocumentAdapterWrapper(elementAdapter) { + @Override public IEditorInput getDocumentKey(Object element) { if (hasSameDocument(element)) { return super.getDocumentKey(input); @@ -313,6 +312,7 @@ public abstract class StructureCreator implements IStructureCreator2 { * @return the sub-structure element in the input for the given element * @throws CoreException if a parse error occurred */ + @Override public ITypedElement createElement(Object element, Object input, IProgressMonitor monitor) throws CoreException { String[] path= getPath(element, input); @@ -344,6 +344,7 @@ public abstract class StructureCreator implements IStructureCreator2 { * @param input the containing input * @return the sub-structure element in the input for the given element */ + @Override public IStructureComparator locate(Object element, Object input) { String[] path= getPath(element, input); if (path == null) @@ -358,7 +359,7 @@ public abstract class StructureCreator implements IStructureCreator2 { } /** - * Find the element at the given path in the given structure. + * Finds the element at the given path in the given structure. * This method is invoked from the {@link #createElement(Object, Object, IProgressMonitor)} * and {@link #locate(Object, Object)} methods to find the element for * the given path. @@ -401,7 +402,7 @@ public abstract class StructureCreator implements IStructureCreator2 { } /** - * Return the path of the element in the structure of it's containing input + * Returns the path of the element in the structure of it's containing input * or <code>null</code> if the element is not contained in the input. This method is * invoked from {@link #createElement(Object, Object, IProgressMonitor)} and * {@link #locate(Object, Object)} methods to determine @@ -416,9 +417,7 @@ public abstract class StructureCreator implements IStructureCreator2 { return null; } - /* (non-Javadoc) - * @see org.eclipse.compare.structuremergeviewer.IStructureCreator2#destroy(java.lang.Object) - */ + @Override public void destroy(Object object) { IDisposable disposable = getDisposable(object); if (disposable != null) @@ -464,9 +463,9 @@ public abstract class StructureCreator implements IStructureCreator2 { Object node2, char contributor2, boolean ignoreWhitespace, ICompareFilter[] compareFilters) { - List lines1 = LineReader.readLines(new BufferedReader(new StringReader( + List<String> lines1 = LineReader.readLines(new BufferedReader(new StringReader( getContents(node1, false)))); - List lines2 = LineReader.readLines(new BufferedReader(new StringReader( + List<String> lines2 = LineReader.readLines(new BufferedReader(new StringReader( getContents(node2, false)))); StringBuffer buffer1 = new StringBuffer(); diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java index 7df336d0c..a6520ec3d 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureDiffViewer.java @@ -12,17 +12,33 @@ package org.eclipse.compare.structuremergeviewer; import java.lang.reflect.InvocationTargetException; -import org.eclipse.compare.*; +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareUI; +import org.eclipse.compare.CompareViewerSwitchingPane; +import org.eclipse.compare.ICompareFilter; +import org.eclipse.compare.IContentChangeListener; +import org.eclipse.compare.IContentChangeNotifier; +import org.eclipse.compare.ITypedElement; import org.eclipse.compare.contentmergeviewer.IDocumentRange; -import org.eclipse.compare.internal.*; -import org.eclipse.core.runtime.*; +import org.eclipse.compare.internal.ChangeCompareFilterPropertyAction; +import org.eclipse.compare.internal.CompareMessages; +import org.eclipse.compare.internal.CompareUIPlugin; +import org.eclipse.compare.internal.Utilities; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.services.IDisposable; @@ -58,6 +74,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * A set of background tasks for updating the structure */ private IRunnableWithProgress diffTask = new IRunnableWithProgress() { + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(CompareMessages.StructureDiffViewer_0, 100); @@ -67,6 +84,7 @@ public class StructureDiffViewer extends DiffTreeViewer { }; private IRunnableWithProgress inputChangedTask = new IRunnableWithProgress() { + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(CompareMessages.StructureDiffViewer_1, 100); @@ -84,6 +102,7 @@ public class StructureDiffViewer extends DiffTreeViewer { private ITypedElement fInput; private IStructureComparator fStructureComparator; private IRunnableWithProgress refreshTask = new IRunnableWithProgress() { + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { refresh(monitor); @@ -204,11 +223,13 @@ public class StructureDiffViewer extends DiffTreeViewer { setAutoExpandLevel(3); fContentChangedListener= new IContentChangeListener() { + @Override public void contentChanged(IContentChangeNotifier changed) { StructureDiffViewer.this.contentChanged(changed); } }; fCompareInputChangeListener = new ICompareInputChangeListener() { + @Override public void compareInputChanged(ICompareInput input) { StructureDiffViewer.this.compareInputChanged(input, true); } @@ -245,6 +266,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * Reimplemented to get the descriptive title for this viewer from the <code>IStructureCreator</code>. * @return the viewer's name */ + @Override public String getTitle() { if (fStructureCreator != null) return fStructureCreator.getName(); @@ -257,6 +279,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * * @return the root of the diff tree produced by method <code>diff</code> */ + @Override protected Object getRoot() { return fRoot; } @@ -267,6 +290,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * and to feed them through the differencing engine. Note: for this viewer * the value from <code>getInput</code> is not identical to <code>getRoot</code>. */ + @Override protected void inputChanged(Object input, Object oldInput) { if (oldInput instanceof ICompareInput) { ICompareInput old = (ICompareInput) oldInput; @@ -281,6 +305,7 @@ public class StructureDiffViewer extends DiffTreeViewer { } } + @Override protected void initialSelection() { expandToLevel(2); } @@ -288,6 +313,7 @@ public class StructureDiffViewer extends DiffTreeViewer { /* (non Javadoc) * Overridden to unregister all listeners. */ + @Override protected void handleDispose(DisposeEvent event) { Object input = getInput(); if (input instanceof ICompareInput) { @@ -317,6 +343,7 @@ public class StructureDiffViewer extends DiffTreeViewer { // The compare configuration is nulled when the viewer is disposed if (cc != null) { BusyIndicator.showWhile(Display.getDefault(), new Runnable() { + @Override public void run() { try { inputChangedTask.run(new NullProgressMonitor()); @@ -385,7 +412,6 @@ public class StructureDiffViewer extends DiffTreeViewer { * @param changed the object that sent out the notification */ protected void contentChanged(final IContentChangeNotifier changed) { - if (fStructureCreator == null) return; @@ -418,6 +444,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * @deprecated Clients should override * {@link #preDiffHook(IStructureComparator, IStructureComparator, IStructureComparator, IProgressMonitor)} */ + @Deprecated protected void preDiffHook(IStructureComparator ancestor, IStructureComparator left, IStructureComparator right) { // we do nothing here } @@ -440,6 +467,7 @@ public class StructureDiffViewer extends DiffTreeViewer { */ protected void preDiffHook(final IStructureComparator ancestor, final IStructureComparator left, final IStructureComparator right, IProgressMonitor monitor) { syncExec(new Runnable() { + @Override public void run() { preDiffHook(ancestor, left, right); } @@ -470,16 +498,16 @@ public class StructureDiffViewer extends DiffTreeViewer { // could not get structure of one (or more) of the legs fRoot= null; message= CompareMessages.StructureDiffViewer_StructureError; - } else { // calculate difference of the two (or three) structures - if (fDifferencer == null) fDifferencer= new Differencer() { + @Override protected boolean contentsEqual(Object o1, char contributor1, Object o2, char contributor2) { return StructureDiffViewer.this.contentsEqual(o1, contributor1, o2, contributor2); } + @Override protected Object visit(Object data, int result, Object ancestor, Object left, Object right) { Object o= super.visit(data, result, ancestor, left, right); if (!getCompareConfiguration().isMirrored() && o instanceof DiffNode) @@ -498,11 +526,12 @@ public class StructureDiffViewer extends DiffTreeViewer { } } - if (Display.getCurrent() != null) + if (Display.getCurrent() != null) { refreshAfterDiff(message); - else { + } else { final String theMessage = message; Display.getDefault().asyncExec(new Runnable() { + @Override public void run() { refreshAfterDiff(theMessage); } @@ -533,6 +562,7 @@ public class StructureDiffViewer extends DiffTreeViewer { // A null compare configuration indicates that the viewer was disposed if (compareConfiguration != null) { compareConfiguration.getContainer().run(true, true, new IRunnableWithProgress() { + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(CompareMessages.StructureDiffViewer_2, 100); diffTask.run(new SubProgressMonitor(monitor, 100)); @@ -552,16 +582,18 @@ public class StructureDiffViewer extends DiffTreeViewer { private void handleFailedRefresh(final String message) { Runnable runnable = new Runnable() { + @Override public void run() { if (getControl().isDisposed()) return; refreshAfterDiff(message); } }; - if (Display.getCurrent() != null) + if (Display.getCurrent() != null) { runnable.run(); - else + } else { Display.getDefault().asyncExec(runnable); + } } /** @@ -577,6 +609,7 @@ public class StructureDiffViewer extends DiffTreeViewer { * {@link #postDiffHook(Differencer, IDiffContainer, IProgressMonitor)} * instead */ + @Deprecated protected void postDiffHook(Differencer differencer, IDiffContainer root) { // we do nothing here } @@ -599,6 +632,7 @@ public class StructureDiffViewer extends DiffTreeViewer { */ protected void postDiffHook(final Differencer differencer, final IDiffContainer root, IProgressMonitor monitor) { syncExec(new Runnable() { + @Override public void run() { postDiffHook(differencer, root); } @@ -616,18 +650,18 @@ public class StructureDiffViewer extends DiffTreeViewer { boolean ignoreWhiteSpace = Utilities.getBoolean( getCompareConfiguration(), CompareConfiguration.IGNORE_WHITESPACE, false); - ICompareFilter[] compareFilters = Utilities - .getCompareFilters(getCompareConfiguration()); + ICompareFilter[] compareFilters = + Utilities.getCompareFilters(getCompareConfiguration()); String s1, s2; if (compareFilters != null && compareFilters.length > 0 && fStructureCreator instanceof StructureCreator) { return ((StructureCreator) fStructureCreator).contentsEquals( o1, contributor1, o2, contributor2, ignoreWhiteSpace, compareFilters); - } else { - s1 = fStructureCreator.getContents(o1, ignoreWhiteSpace); - s2 = fStructureCreator.getContents(o2, ignoreWhiteSpace); } + + s1 = fStructureCreator.getContents(o1, ignoreWhiteSpace); + s2 = fStructureCreator.getContents(o2, ignoreWhiteSpace); if (s1 == null || s2 == null) return false; return s1.equals(s2); @@ -641,15 +675,14 @@ public class StructureDiffViewer extends DiffTreeViewer { * In this case they must call the inherited method. * @param event the property changed event that triggered the call to this method */ + @Override protected void propertyChange(PropertyChangeEvent event) { String key= event.getProperty(); if (key.equals(CompareConfiguration.IGNORE_WHITESPACE)) { diff(); - } else if (key - .equals(ChangeCompareFilterPropertyAction.COMPARE_FILTERS) - && getCompareConfiguration() - .getProperty( - ChangeCompareFilterPropertyAction.COMPARE_FILTERS_INITIALIZING) == null) { + } else if (key.equals(ChangeCompareFilterPropertyAction.COMPARE_FILTERS) + && getCompareConfiguration().getProperty( + ChangeCompareFilterPropertyAction.COMPARE_FILTERS_INITIALIZING) == null) { diff(); } else if (key.equals("ANCESTOR_STRUCTURE_REFRESH")) { //$NON-NLS-1$ fAncestorStructure.refresh(new NullProgressMonitor()); @@ -677,24 +710,27 @@ public class StructureDiffViewer extends DiffTreeViewer { * @param leftToRight if <code>true</code> the left side is copied to the right side. * If <code>false</code> the right side is copied to the left side */ + @Override protected void copySelected(boolean leftToRight) { super.copySelected(leftToRight); - if (fStructureCreator != null) + if (fStructureCreator != null) { fStructureCreator.save( leftToRight ? fRightStructure.getStructureComparator() : fLeftStructure.getStructureComparator(), leftToRight ? fRightStructure.getInput() : fLeftStructure.getInput()); + } } private void syncExec(final Runnable runnable) { if (getControl().isDisposed()) return; - if (Display.getCurrent() != null) + if (Display.getCurrent() != null) { runnable.run(); - else + } else { getControl().getDisplay().syncExec(() -> { if (!getControl().isDisposed()) runnable.run(); }); + } } } diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureRootNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureRootNode.java index 3ea3f04d5..57056b617 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureRootNode.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/StructureRootNode.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.compare.structuremergeviewer; -import org.eclipse.compare.*; +import org.eclipse.compare.IEditableContentExtension; +import org.eclipse.compare.ISharedDocumentAdapter; +import org.eclipse.compare.ITypedElement; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.text.IDocument; @@ -35,7 +37,6 @@ import org.eclipse.ui.services.IDisposable; * @since 3.3 */ public class StructureRootNode extends DocumentRangeNode implements IDisposable, ITypedElement { - /** * The integer constant (value <code>0</code>) that is used as the type code of the root node. * @see #getTypeCode() @@ -70,6 +71,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.ui.services.IDisposable#dispose() */ + @Override public void dispose() { if (fAdapter != null) { fAdapter.disconnect(fInput); @@ -84,9 +86,11 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, * @return the object adapted to the given class or <code>null</code> * @see IAdaptable#getAdapter(Class) */ - public Object getAdapter(Class adapter) { + @Override + @SuppressWarnings("unchecked") + public <T> T getAdapter(Class<T> adapter) { if (adapter == ISharedDocumentAdapter.class) { - return fAdapter; + return (T) fAdapter; } return super.getAdapter(adapter); } @@ -96,13 +100,12 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, * contents of a node have changed. * @param node the changed node */ + @Override protected void nodeChanged(DocumentRangeNode node) { fCreator.save(this, fInput); } - /* (non-Javadoc) - * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#replace(org.eclipse.compare.ITypedElement, org.eclipse.compare.ITypedElement) - */ + @Override public ITypedElement replace(ITypedElement child, ITypedElement other) { // TODO: I believe the parent implementation is flawed but didn't to remove // it in case I was missing something so I overrode it instead @@ -113,6 +116,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getImage() */ + @Override public Image getImage() { return null; } @@ -120,6 +124,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getName() */ + @Override public String getName() { return getId(); } @@ -127,6 +132,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.compare.ITypedElement#getType() */ + @Override public String getType() { return FOLDER_TYPE; } @@ -134,6 +140,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#isReadOnly() */ + @Override public boolean isReadOnly() { if (fInput instanceof IEditableContentExtension) { IEditableContentExtension ext = (IEditableContentExtension) fInput; @@ -145,6 +152,7 @@ public class StructureRootNode extends DocumentRangeNode implements IDisposable, /* (non-Javadoc) * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode#validateEdit(org.eclipse.swt.widgets.Shell) */ + @Override public IStatus validateEdit(Shell shell) { if (fInput instanceof IEditableContentExtension) { IEditableContentExtension ext = (IEditableContentExtension) fInput; |