Skip to content

Commit 0cb8d47

Browse files
Perform clean code of team/bundles/org.eclipse.compare.win32
1 parent 47871af commit 0cb8d47

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

team/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/AbstractMergeViewer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ public void setSelection(ISelection selection, boolean reveal) {
101101
}
102102

103103
protected boolean isOneSided() {
104-
if (input instanceof ICompareInput) {
105-
ICompareInput ci = (ICompareInput) input;
104+
if (input instanceof ICompareInput ci) {
106105
int type = ci.getKind() & Differencer.CHANGE_TYPE_MASK;
107106
return type != Differencer.CHANGE;
108107
}
@@ -111,14 +110,16 @@ protected boolean isOneSided() {
111110

112111
protected File getFileForSingleSide() throws CoreException {
113112
File file = getFileForLeft();
114-
if (file != null && file.exists())
113+
if (file != null && file.exists()) {
115114
return file;
115+
}
116116
return getFileForRight();
117117
}
118118

119119
protected File getFileForRight() throws CoreException {
120-
if (rightFile != null)
120+
if (rightFile != null) {
121121
return rightFile;
122+
}
122123
ICompareInput ci = getCompareInput();
123124
if (ci != null) {
124125
ITypedElement right = ci.getRight();
@@ -133,8 +134,9 @@ protected File getFileForRight() throws CoreException {
133134
}
134135

135136
protected File getFileForLeft() throws CoreException {
136-
if (leftFile != null)
137+
if (leftFile != null) {
137138
return leftFile;
139+
}
138140
ICompareInput ci = getCompareInput();
139141
if (ci != null) {
140142
ITypedElement left = ci.getLeft();
@@ -149,8 +151,9 @@ protected File getFileForLeft() throws CoreException {
149151
}
150152

151153
protected File getResultFile() throws IOException {
152-
if (resultFile != null)
154+
if (resultFile != null) {
153155
return resultFile;
156+
}
154157
resultFile = File.createTempFile("merge", ".doc"); //$NON-NLS-1$ //$NON-NLS-2$
155158
resultFile.deleteOnExit();
156159
// Need to delete the file so that clients will know that the files doesn't exist yet
@@ -163,8 +166,7 @@ protected boolean hasResultFile() {
163166
}
164167

165168
private File cacheContents(ITypedElement element) throws CoreException {
166-
if (element instanceof IStreamContentAccessor) {
167-
IStreamContentAccessor sca = (IStreamContentAccessor) element;
169+
if (element instanceof IStreamContentAccessor sca) {
168170
InputStream contents = sca.getContents();
169171
if (contents != null) {
170172
try {
@@ -216,15 +218,13 @@ protected File getLocalFile(ITypedElement left) throws CoreException {
216218
}
217219

218220
protected IFile getEclipseFile(Object element) {
219-
if (element instanceof IResourceProvider) {
220-
IResourceProvider rp = (IResourceProvider) element;
221+
if (element instanceof IResourceProvider rp) {
221222
IResource resource = rp.getResource();
222223
if (resource.getType() == IResource.FILE) {
223224
return (IFile)resource;
224225
}
225226
}
226-
if (element instanceof IAdaptable) {
227-
IAdaptable a = (IAdaptable) element;
227+
if (element instanceof IAdaptable a) {
228228
Object result = a.getAdapter(IResource.class);
229229
if (result == null) {
230230
result = a.getAdapter(IFile.class);

team/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordComparison.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@
1818

1919
import org.eclipse.jface.action.IMenuManager;
2020
import org.eclipse.osgi.util.NLS;
21-
import org.eclipse.swt.SWT;
22-
import org.eclipse.swt.SWTException;
23-
import org.eclipse.swt.ole.win32.OLE;
24-
import org.eclipse.swt.ole.win32.OleAutomation;
25-
import org.eclipse.swt.ole.win32.OleClientSite;
26-
import org.eclipse.swt.ole.win32.OleFrame;
27-
import org.eclipse.swt.ole.win32.Variant;
28-
import org.eclipse.swt.widgets.Composite;
29-
import org.eclipse.swt.widgets.Menu;
30-
import org.eclipse.swt.widgets.MenuItem;
31-
import org.eclipse.swt.widgets.Shell;
3221
import org.eclipse.ui.IWorkbenchActionConstants;
3322
import org.eclipse.ui.IWorkbenchWindow;
3423

@@ -79,8 +68,9 @@ private static OleAutomation getAutomationProperty(OleAutomation auto, String na
7968
Variant varResult = getVariantProperty(auto, name);
8069
try {
8170
OleAutomation automation = varResult.getAutomation();
82-
if (automation != null)
71+
if (automation != null) {
8372
return automation;
73+
}
8474
} finally {
8575
varResult.dispose();
8676
}
@@ -92,8 +82,9 @@ private static OleAutomation getAutomationResult(OleAutomation auto, String comm
9282
if (varResult != null) {
9383
try {
9484
OleAutomation result = varResult.getAutomation();
95-
if (result != null)
85+
if (result != null) {
9686
return result;
87+
}
9788
} finally {
9889
varResult.dispose();
9990
}
@@ -106,8 +97,9 @@ private static OleAutomation getAutomationResult(OleAutomation auto, String comm
10697
if (varResult != null) {
10798
try {
10899
OleAutomation result = varResult.getAutomation();
109-
if (result != null)
100+
if (result != null) {
110101
return result;
102+
}
111103
} finally {
112104
varResult.dispose();
113105
}
@@ -134,7 +126,9 @@ private static int property(OleAutomation auto, OleAutomation reference, String
134126
if (ids != null) {
135127
return ids[0];
136128
}
137-
if(reference == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ;
129+
if(reference == null) {
130+
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ;
131+
}
138132

139133
// the property was not retrieved at that point, try to get it from the reference object
140134
ids = reference.getIDsOfNames(new String[] { name });
@@ -146,7 +140,9 @@ private static int property(OleAutomation auto, OleAutomation reference, String
146140

147141
private static int property(OleAutomation auto, String name) {
148142
int[] ids = auto.getIDsOfNames(new String[] { name });
149-
if (ids == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
143+
if (ids == null) {
144+
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
145+
}
150146
return ids[0];
151147
}
152148

@@ -205,8 +201,9 @@ public void createWorkingCopy(String baseDocument, String revisedDocument, Strin
205201
OleAutomation activeDocument = getActiveDocument(application);
206202
try {
207203
Variant varResult = invoke(activeDocument, document, "SaveAs", workingCopy); //$NON-NLS-1$
208-
if (varResult == null)
204+
if (varResult == null) {
209205
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_6, workingCopy));
206+
}
210207
varResult.dispose();
211208
} finally {
212209
closeDocument(activeDocument, document);
@@ -251,8 +248,9 @@ private void closeDocument(OleAutomation document, OleAutomation reference) {
251248
private void compareDocument(OleAutomation document, String baseDocument, String revisedDocument) {
252249
// Compare to the second document: compare = destination.Compare(p1)
253250
Variant varResult = invoke(document, "Compare", baseDocument); //$NON-NLS-1$
254-
if (varResult == null)
251+
if (varResult == null) {
255252
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_9, baseDocument, revisedDocument));
253+
}
256254
varResult.dispose();
257255
}
258256

@@ -361,7 +359,9 @@ private void disposeSite() {
361359
}
362360

363361
public void saveAsDocument(String doc) {
364-
if (site == null || site.isDisposed()) return;
362+
if (site == null || site.isDisposed()) {
363+
return;
364+
}
365365
if (inplace) {
366366
site.deactivateInPlaceClient();
367367
site.save(new File(doc), true);
@@ -415,8 +415,9 @@ public boolean isDirty() {
415415
*/
416416
protected void initializeWorkbenchMenus(IWorkbenchWindow window) {
417417
//If there was an OLE Error or nothing has been created yet
418-
if (frame == null || frame.isDisposed())
418+
if (frame == null || frame.isDisposed()) {
419419
return;
420+
}
420421
// Get the browser menu bar. If one does not exist then
421422
// create it.
422423
Shell shell = frame.getShell();
@@ -434,13 +435,14 @@ protected void initializeWorkbenchMenus(IWorkbenchWindow window) {
434435
for (int i = 0; i < menuBar.getItemCount(); i++) {
435436
MenuItem item = menuBar.getItem(i);
436437
String id = ""; //$NON-NLS-1$
437-
if (item.getData() instanceof IMenuManager)
438+
if (item.getData() instanceof IMenuManager) {
438439
id = ((IMenuManager) item.getData()).getId();
439-
if (id.equals(IWorkbenchActionConstants.M_FILE))
440+
}
441+
if (id.equals(IWorkbenchActionConstants.M_FILE)) {
440442
fileMenu[0] = item;
441-
else if (id.equals(IWorkbenchActionConstants.M_WINDOW))
443+
} else if (id.equals(IWorkbenchActionConstants.M_WINDOW)) {
442444
windowMenu[0] = item;
443-
else {
445+
} else {
444446
if (window.isApplicationMenu(id)) {
445447
containerItems.addElement(item);
446448
}

team/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordMergeViewer.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@
4848
import org.eclipse.jface.util.PropertyChangeEvent;
4949
import org.eclipse.jface.util.SafeRunnable;
5050
import org.eclipse.osgi.util.NLS;
51-
import org.eclipse.swt.SWT;
52-
import org.eclipse.swt.SWTException;
53-
import org.eclipse.swt.custom.BusyIndicator;
54-
import org.eclipse.swt.layout.GridData;
55-
import org.eclipse.swt.widgets.Composite;
56-
import org.eclipse.swt.widgets.Control;
57-
import org.eclipse.swt.widgets.Display;
58-
import org.eclipse.swt.widgets.FileDialog;
59-
import org.eclipse.swt.widgets.Label;
6051
import org.eclipse.ui.IWorkbenchPart;
6152
import org.eclipse.ui.forms.widgets.FormToolkit;
6253
import org.eclipse.ui.part.PageBook;
@@ -164,8 +155,9 @@ private static void initAction(IAction a, ResourceBundle bundle, String prefix)
164155
}
165156

166157
ImageDescriptor id= getImageDescriptor(dPath); // we set the disabled image first (see PR 1GDDE87)
167-
if (id != null)
158+
if (id != null) {
168159
a.setDisabledImageDescriptor(id);
160+
}
169161
id= getImageDescriptor(ePath);
170162
if (id != null) {
171163
a.setImageDescriptor(id);
@@ -176,8 +168,9 @@ private static void initAction(IAction a, ResourceBundle bundle, String prefix)
176168
private static ImageDescriptor getImageDescriptor(String relativePath) {
177169
IPath path= IPath.fromOSString("$nl$/icons/full/").append(relativePath);
178170
URL url= FileLocator.find(Activator.getDefault().getBundle(), path, null);
179-
if (url == null)
171+
if (url == null) {
180172
return null;
173+
}
181174
return ImageDescriptor.createFromURL(url);
182175
}
183176

@@ -205,8 +198,9 @@ private Composite createComposite(Composite parent) {
205198
}
206199

207200
private void updateEnablements() {
208-
if (saveAction != null)
201+
if (saveAction != null) {
209202
saveAction.setEnabled(isDirty());
203+
}
210204
inplaceAction.setChecked(wordArea.isInplace());
211205
inplaceAction.setEnabled(wordArea.isOpen());
212206
}
@@ -358,8 +352,7 @@ private String getTextDescription() {
358352
if (saveAction != null &&hasResultFile()) {
359353
IEditableContent saveTarget = getSaveTarget();
360354
String name = CompareWin32Messages.WordMergeViewer_3;
361-
if (saveTarget instanceof ITypedElement) {
362-
ITypedElement te = (ITypedElement) saveTarget;
355+
if (saveTarget instanceof ITypedElement te) {
363356
name = te.getName();
364357
}
365358
try {
@@ -391,8 +384,9 @@ private void updateDirtyFlag() {
391384
final Runnable dirtyFlagUpdater = new Runnable() {
392385
@Override
393386
public void run() {
394-
if (wordArea.getFrame().isDisposed())
387+
if (wordArea.getFrame().isDisposed()) {
395388
return;
389+
}
396390
boolean dirty = wordArea.isDirty();
397391
if (hasResultFile()) {
398392
try {

team/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/WordViewerCreator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.eclipse.compare.CompareConfiguration;
1717
import org.eclipse.compare.IViewerCreator;
1818
import org.eclipse.jface.viewers.Viewer;
19-
import org.eclipse.swt.widgets.Composite;
2019

2120
/**
2221
* Factory registered with the <code>org.eclipse.compare.contentMergeViewers</code>

0 commit comments

Comments
 (0)