Skip to content

Commit 33aa102

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of bundles/org.eclipse.ui.editors
1 parent 11aace0 commit 33aa102

File tree

86 files changed

+2078
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2078
-1255
lines changed

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/DefaultEncodingSupport.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,22 @@ public void initialize(StatusTextEditor textEditor) {
8181
if (ResourcesPlugin.PREF_ENCODING.equals(event.getKey())) {
8282
// null means: use default
8383
Runnable runnable= () -> setEncoding(null, false);
84-
if (Display.getCurrent() != null)
84+
if (Display.getCurrent() != null) {
8585
runnable.run();
86-
else {
86+
} else {
8787
// Post runnable into UI thread
8888
Shell shell;
89-
if (fTextEditor != null)
89+
if (fTextEditor != null) {
9090
shell= fTextEditor.getSite().getShell();
91-
else
91+
} else {
9292
shell= getActiveWorkbenchShell();
93+
}
9394
Display display;
94-
if (shell != null)
95+
if (shell != null) {
9596
display= shell.getDisplay();
96-
else
97+
} else {
9798
display= Display.getDefault();
99+
}
98100
display.asyncExec(runnable);
99101
}
100102
}
@@ -139,10 +141,11 @@ protected void setEncoding(String encoding, boolean overwrite) {
139141
Runnable encodingSetter=
140142
() -> fTextEditor.doRevertToSaved();
141143
Display display= fTextEditor.getSite().getShell().getDisplay();
142-
if (display != null && !display.isDisposed())
144+
if (display != null && !display.isDisposed()) {
143145
BusyIndicator.showWhile(display, encodingSetter);
144-
else
146+
} else {
145147
encodingSetter.run();
148+
}
146149
}
147150
}
148151
}
@@ -180,11 +183,13 @@ public String getDefaultEncoding() {
180183
public String getStatusHeader(IStatus status) {
181184
Throwable t= status.getException();
182185

183-
if (t instanceof CharConversionException)
186+
if (t instanceof CharConversionException) {
184187
return TextEditorMessages.Editor_error_unreadable_encoding_header;
188+
}
185189

186-
if (t instanceof UnsupportedEncodingException)
190+
if (t instanceof UnsupportedEncodingException) {
187191
return TextEditorMessages.Editor_error_unsupported_encoding_header;
192+
}
188193

189194
return null;
190195
}
@@ -198,11 +203,13 @@ public String getStatusHeader(IStatus status) {
198203
public String getStatusBanner(IStatus status) {
199204
Throwable t= status.getException();
200205

201-
if (t instanceof CharConversionException)
206+
if (t instanceof CharConversionException) {
202207
return TextEditorMessages.Editor_error_unreadable_encoding_banner;
208+
}
203209

204-
if (t instanceof UnsupportedEncodingException)
210+
if (t instanceof UnsupportedEncodingException) {
205211
return TextEditorMessages.Editor_error_unsupported_encoding_banner;
212+
}
206213

207214
return null;
208215

@@ -219,18 +226,21 @@ public String getStatusMessage(IStatus status) {
219226
if (t instanceof CharConversionException || t instanceof UnsupportedEncodingException) {
220227

221228
String encoding= getEncoding();
222-
if (encoding == null)
229+
if (encoding == null) {
223230
encoding= getDefaultEncoding();
231+
}
224232

225233
if (t instanceof CharConversionException) {
226-
if (encoding != null)
234+
if (encoding != null) {
227235
return NLSUtility.format(TextEditorMessages.Editor_error_unreadable_encoding_message_arg, encoding);
236+
}
228237
return TextEditorMessages.Editor_error_unreadable_encoding_message;
229238
}
230239

231240
if (t instanceof UnsupportedEncodingException) {
232-
if (encoding != null)
241+
if (encoding != null) {
233242
return NLSUtility.format(TextEditorMessages.Editor_error_unsupported_encoding_message_arg, encoding);
243+
}
234244
return TextEditorMessages.Editor_error_unsupported_encoding_message;
235245
}
236246
}
@@ -247,8 +257,9 @@ public String getStatusMessage(IStatus status) {
247257
* @since 3.1
248258
*/
249259
public boolean isEncodingError(IStatus status) {
250-
if (status == null || status.getSeverity() != IStatus.ERROR)
260+
if (status == null || status.getSeverity() != IStatus.ERROR) {
251261
return false;
262+
}
252263

253264
Throwable t= status.getException();
254265
return t instanceof CharConversionException || t instanceof UnsupportedEncodingException;
@@ -265,11 +276,13 @@ public boolean isEncodingError(IStatus status) {
265276
*/
266277
public void createStatusEncodingChangeControl(Composite parent, final IStatus status) {
267278
final IAction action= fTextEditor.getAction(ITextEditorActionConstants.CHANGE_ENCODING);
268-
if (action instanceof TextEditorAction textEditorAction)
279+
if (action instanceof TextEditorAction textEditorAction) {
269280
textEditorAction.update();
281+
}
270282

271-
if (action == null || !action.isEnabled())
283+
if (action == null || !action.isEnabled()) {
272284
return;
285+
}
273286

274287
Shell shell= parent.getShell();
275288
Display display= shell.getDisplay();
@@ -301,8 +314,9 @@ public void widgetSelected(SelectionEvent e) {
301314
*/
302315
private static Shell getActiveWorkbenchShell() {
303316
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
304-
if (window != null)
305-
return window.getShell();
317+
if (window != null) {
318+
return window.getShell();
319+
}
306320

307321
return null;
308322
}

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/DocumentReader.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DocumentReader extends Reader {
4343
private static class DocumentCharSequence implements CharSequence {
4444

4545
/** Document */
46-
private IDocument fDocument;
46+
private final IDocument fDocument;
4747

4848
/**
4949
* Initialize with the sequence of characters in the given
@@ -104,7 +104,7 @@ public void documentChanged(DocumentEvent event) {
104104
private volatile CharSequence fCharSequence;
105105

106106
/** Document length. */
107-
private int fLength;
107+
private final int fLength;
108108

109109
/** The current offset. */
110110
private int fOffset= 0;
@@ -142,12 +142,14 @@ public void close() throws IOException {
142142
*/
143143
private void handleDocumentAboutToBeChanged() {
144144
IDocument document= fDocument;
145-
if (fCharSequence == null || document == null)
145+
if (fCharSequence == null || document == null) {
146146
return;
147+
}
147148
String content= document.get();
148149
synchronized (this) {
149-
if (fCharSequence == null)
150+
if (fCharSequence == null) {
150151
return;
152+
}
151153
fCharSequence= content;
152154
}
153155
releaseDocument();
@@ -157,8 +159,9 @@ private void handleDocumentAboutToBeChanged() {
157159
* Removes the document listener.
158160
*/
159161
private synchronized void releaseDocument() {
160-
if (fDocument != null)
162+
if (fDocument != null) {
161163
fDocument.removeDocumentListener(fDocumentListener);
164+
}
162165
fDocument= null;
163166
fDocumentListener= null;
164167
}
@@ -167,10 +170,12 @@ private synchronized void releaseDocument() {
167170
public int read(char[] cbuf, int off, int len) throws IOException {
168171
int i= 0;
169172
try {
170-
for (; i < len && fOffset < fLength; i++)
173+
for (; i < len && fOffset < fLength; i++) {
171174
cbuf[off + i]= fCharSequence.charAt(fOffset++);
172-
if (i > 0)
175+
}
176+
if (i > 0) {
173177
return i;
178+
}
174179

175180
return -1;
176181
} catch (NullPointerException x) {

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/EditorsUI.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,19 @@ public static HyperlinkDetectorRegistry getHyperlinkDetectorRegistry() {
235235
* @since 3.3
236236
*/
237237
public static final String getTooltipAffordanceString() {
238-
if (!getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE))
238+
if (!getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE)) {
239239
return null;
240+
}
240241

241242
IBindingService bindingService= PlatformUI.getWorkbench().getAdapter(IBindingService.class);
242-
if (bindingService == null)
243+
if (bindingService == null) {
243244
return null;
245+
}
244246

245247
String keySequence= bindingService.getBestActiveBindingFormattedFor(ITextEditorActionDefinitionIds.SHOW_INFORMATION);
246-
if (keySequence == null)
248+
if (keySequence == null) {
247249
return ""; //$NON-NLS-1$
250+
}
248251

249252
return NLSUtility.format(TextEditorMessages.Editor_toolTip_affordance, keySequence);
250253
}

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/editors/text/FileBufferOperationAction.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ public void selectionChanged(IAction action, ISelection selection) {
9191
Iterator<?> e= structuredSelection.iterator();
9292
while (e.hasNext()) {
9393
Object element= e.next();
94-
if (element instanceof IResource)
94+
if (element instanceof IResource) {
9595
fResources.add(element);
96-
else if (element instanceof IAdaptable adaptable) {
96+
} else if (element instanceof IAdaptable adaptable) {
9797
Object adapter= adaptable.getAdapter(IResource.class);
98-
if (adapter instanceof IResource)
98+
if (adapter instanceof IResource) {
9999
fResources.add(adapter);
100+
}
100101
}
101102
}
102103
}
@@ -108,9 +109,9 @@ else if (element instanceof IAdaptable adaptable) {
108109
if (workbenchPart instanceof IEditorPart editorPart) {
109110
IEditorInput input= editorPart.getEditorInput();
110111
Object adapter= input.getAdapter(IResource.class);
111-
if (adapter instanceof IResource)
112+
if (adapter instanceof IResource) {
112113
fResources.add(adapter);
113-
else {
114+
} else {
114115
adapter= input.getAdapter(ILocationProvider.class);
115116
if (adapter instanceof ILocationProvider provider) {
116117
fLocation= provider.getPath(input);
@@ -125,8 +126,9 @@ else if (element instanceof IAdaptable adaptable) {
125126
}
126127

127128
protected final IWorkbenchWindow getWorkbenchWindow() {
128-
if (fWindow == null)
129+
if (fWindow == null) {
129130
fWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
131+
}
130132
return fWindow;
131133
}
132134

@@ -139,10 +141,12 @@ protected final Shell getShell() {
139141
public void run(IAction action) {
140142
if (fResources != null && !fResources.isEmpty()) {
141143
IFile[] files= collectFiles(fResources.toArray(new IResource[fResources.size()]));
142-
if (files != null && files.length > 0)
144+
if (files != null && files.length > 0) {
143145
doRun(files, null, fFileBufferOperation);
144-
} else if (isAcceptableLocation(fLocation))
146+
}
147+
} else if (isAcceptableLocation(fLocation)) {
145148
doRun(null, fLocation, fFileBufferOperation);
149+
}
146150
}
147151

148152
/**
@@ -155,8 +159,9 @@ public void run(IAction action) {
155159
protected IFile[] collectFiles(IResource[] resources) {
156160
Set<IResource> files= new HashSet<>();
157161
for (IResource resource : resources) {
158-
if ((IResource.FILE & resource.getType()) > 0)
162+
if ((IResource.FILE & resource.getType()) > 0) {
159163
files.add(resource);
164+
}
160165
}
161166
return files.toArray(new IFile[files.size()]);
162167
}
@@ -175,8 +180,9 @@ protected IStatus run(IProgressMonitor monitor) {
175180
if (files != null) {
176181
ticks-= 30;
177182
locations= generateLocations(files, subMonitor.split(30));
178-
} else
183+
} else {
179184
locations= new IPath[] { location };
185+
}
180186

181187
if (locations != null && locations.length > 0) {
182188
FileBufferOperationRunner runner= new FileBufferOperationRunner(FileBuffers.getTextFileBufferManager(), getShell());
@@ -203,8 +209,9 @@ protected final IPath[] generateLocations(IFile[] files, IProgressMonitor progre
203209
Set<IPath> locations= new HashSet<>();
204210
for (IFile file : files) {
205211
IPath fullPath = file.getFullPath();
206-
if (isAcceptableLocation(fullPath))
212+
if (isAcceptableLocation(fullPath)) {
207213
locations.add(fullPath);
214+
}
208215
progressMonitor.worked(1);
209216
}
210217
return locations.toArray(new IPath[locations.size()]);

0 commit comments

Comments
 (0)