Skip to content

Commit de7a9c4

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of team/bundles/org.eclipse.compare.win32
1 parent a3ca975 commit de7a9c4

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ private static OleAutomation getAutomationProperty(OleAutomation auto, String na
7979
Variant varResult = getVariantProperty(auto, name);
8080
try {
8181
OleAutomation automation = varResult.getAutomation();
82-
if (automation != null)
82+
if (automation != null) {
8383
return automation;
84+
}
8485
} finally {
8586
varResult.dispose();
8687
}
@@ -92,8 +93,9 @@ private static OleAutomation getAutomationResult(OleAutomation auto, String comm
9293
if (varResult != null) {
9394
try {
9495
OleAutomation result = varResult.getAutomation();
95-
if (result != null)
96+
if (result != null) {
9697
return result;
98+
}
9799
} finally {
98100
varResult.dispose();
99101
}
@@ -106,8 +108,9 @@ private static OleAutomation getAutomationResult(OleAutomation auto, String comm
106108
if (varResult != null) {
107109
try {
108110
OleAutomation result = varResult.getAutomation();
109-
if (result != null)
111+
if (result != null) {
110112
return result;
113+
}
111114
} finally {
112115
varResult.dispose();
113116
}
@@ -134,7 +137,9 @@ private static int property(OleAutomation auto, OleAutomation reference, String
134137
if (ids != null) {
135138
return ids[0];
136139
}
137-
if(reference == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ;
140+
if(reference == null) {
141+
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name)) ;
142+
}
138143

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

147152
private static int property(OleAutomation auto, String name) {
148153
int[] ids = auto.getIDsOfNames(new String[] { name });
149-
if (ids == null) throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
154+
if (ids == null) {
155+
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_4, name));
156+
}
150157
return ids[0];
151158
}
152159

@@ -205,8 +212,9 @@ public void createWorkingCopy(String baseDocument, String revisedDocument, Strin
205212
OleAutomation activeDocument = getActiveDocument(application);
206213
try {
207214
Variant varResult = invoke(activeDocument, document, "SaveAs", workingCopy); //$NON-NLS-1$
208-
if (varResult == null)
215+
if (varResult == null) {
209216
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_6, workingCopy));
217+
}
210218
varResult.dispose();
211219
} finally {
212220
closeDocument(activeDocument, document);
@@ -251,8 +259,9 @@ private void closeDocument(OleAutomation document, OleAutomation reference) {
251259
private void compareDocument(OleAutomation document, String baseDocument, String revisedDocument) {
252260
// Compare to the second document: compare = destination.Compare(p1)
253261
Variant varResult = invoke(document, "Compare", baseDocument); //$NON-NLS-1$
254-
if (varResult == null)
262+
if (varResult == null) {
255263
throw new SWTException(NLS.bind(CompareWin32Messages.WordComparison_9, baseDocument, revisedDocument));
264+
}
256265
varResult.dispose();
257266
}
258267

@@ -361,7 +370,9 @@ private void disposeSite() {
361370
}
362371

363372
public void saveAsDocument(String doc) {
364-
if (site == null || site.isDisposed()) return;
373+
if (site == null || site.isDisposed()) {
374+
return;
375+
}
365376
if (inplace) {
366377
site.deactivateInPlaceClient();
367378
site.save(new File(doc), true);
@@ -415,8 +426,9 @@ public boolean isDirty() {
415426
*/
416427
protected void initializeWorkbenchMenus(IWorkbenchWindow window) {
417428
//If there was an OLE Error or nothing has been created yet
418-
if (frame == null || frame.isDisposed())
429+
if (frame == null || frame.isDisposed()) {
419430
return;
431+
}
420432
// Get the browser menu bar. If one does not exist then
421433
// create it.
422434
Shell shell = frame.getShell();
@@ -434,13 +446,14 @@ protected void initializeWorkbenchMenus(IWorkbenchWindow window) {
434446
for (int i = 0; i < menuBar.getItemCount(); i++) {
435447
MenuItem item = menuBar.getItem(i);
436448
String id = ""; //$NON-NLS-1$
437-
if (item.getData() instanceof IMenuManager)
449+
if (item.getData() instanceof IMenuManager) {
438450
id = ((IMenuManager) item.getData()).getId();
439-
if (id.equals(IWorkbenchActionConstants.M_FILE))
451+
}
452+
if (id.equals(IWorkbenchActionConstants.M_FILE)) {
440453
fileMenu[0] = item;
441-
else if (id.equals(IWorkbenchActionConstants.M_WINDOW))
454+
} else if (id.equals(IWorkbenchActionConstants.M_WINDOW)) {
442455
windowMenu[0] = item;
443-
else {
456+
} else {
444457
if (window.isApplicationMenu(id)) {
445458
containerItems.addElement(item);
446459
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ private static void initAction(IAction a, ResourceBundle bundle, String prefix)
164164
}
165165

166166
ImageDescriptor id= getImageDescriptor(dPath); // we set the disabled image first (see PR 1GDDE87)
167-
if (id != null)
167+
if (id != null) {
168168
a.setDisabledImageDescriptor(id);
169+
}
169170
id= getImageDescriptor(ePath);
170171
if (id != null) {
171172
a.setImageDescriptor(id);
@@ -176,8 +177,9 @@ private static void initAction(IAction a, ResourceBundle bundle, String prefix)
176177
private static ImageDescriptor getImageDescriptor(String relativePath) {
177178
IPath path= IPath.fromOSString("$nl$/icons/full/").append(relativePath);
178179
URL url= FileLocator.find(Activator.getDefault().getBundle(), path, null);
179-
if (url == null)
180+
if (url == null) {
180181
return null;
182+
}
181183
return ImageDescriptor.createFromURL(url);
182184
}
183185

@@ -205,8 +207,9 @@ private Composite createComposite(Composite parent) {
205207
}
206208

207209
private void updateEnablements() {
208-
if (saveAction != null)
210+
if (saveAction != null) {
209211
saveAction.setEnabled(isDirty());
212+
}
210213
inplaceAction.setChecked(wordArea.isInplace());
211214
inplaceAction.setEnabled(wordArea.isOpen());
212215
}
@@ -358,8 +361,7 @@ private String getTextDescription() {
358361
if (saveAction != null &&hasResultFile()) {
359362
IEditableContent saveTarget = getSaveTarget();
360363
String name = CompareWin32Messages.WordMergeViewer_3;
361-
if (saveTarget instanceof ITypedElement) {
362-
ITypedElement te = (ITypedElement) saveTarget;
364+
if (saveTarget instanceof ITypedElement te) {
363365
name = te.getName();
364366
}
365367
try {
@@ -391,8 +393,9 @@ private void updateDirtyFlag() {
391393
final Runnable dirtyFlagUpdater = new Runnable() {
392394
@Override
393395
public void run() {
394-
if (wordArea.getFrame().isDisposed())
396+
if (wordArea.getFrame().isDisposed()) {
395397
return;
398+
}
396399
boolean dirty = wordArea.isDirty();
397400
if (hasResultFile()) {
398401
try {

0 commit comments

Comments
 (0)