Skip to content

Commit b431a28

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of bundles/org.eclipse.ui.workbench.texteditor
1 parent f27923b commit b431a28

File tree

102 files changed

+2167
-1209
lines changed

Some content is hidden

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

102 files changed

+2167
-1209
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/contentassist/ContentAssistHandler.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public class ContentAssistHandler {
5454
/**
5555
* The target control.
5656
*/
57-
private Control fControl;
57+
private final Control fControl;
5858
/**
5959
* The content assist subject adapter.
6060
*/
61-
private AbstractControlContentAssistSubjectAdapter fContentAssistSubjectAdapter;
61+
private final AbstractControlContentAssistSubjectAdapter fContentAssistSubjectAdapter;
6262
/**
6363
* The content assistant.
6464
*/
65-
private SubjectControlContentAssistant fContentAssistant;
65+
private final SubjectControlContentAssistant fContentAssistant;
6666
/**
6767
* The currently installed FocusListener, or <code>null</code> iff none installed.
6868
* This is also used as flag to tell whether content assist is enabled
@@ -132,13 +132,15 @@ public boolean isEnabled() {
132132
* @param enable enable content assist iff true
133133
*/
134134
public void setEnabled(boolean enable) {
135-
if (enable == isEnabled())
135+
if (enable == isEnabled()) {
136136
return;
137+
}
137138

138-
if (enable)
139+
if (enable) {
139140
enable();
140-
else
141+
} else {
141142
disable();
143+
}
142144
}
143145

144146
/**
@@ -149,8 +151,9 @@ private void enable() {
149151
fContentAssistant.install(fContentAssistSubjectAdapter);
150152
installCueLabelProvider();
151153
installFocusListener();
152-
if (fControl.isFocusControl())
154+
if (fControl.isFocusControl()) {
153155
activateHandler();
156+
}
154157
}
155158
}
156159

@@ -163,8 +166,9 @@ private void disable() {
163166
fContentAssistSubjectAdapter.setContentAssistCueProvider(null);
164167
fControl.removeFocusListener(fFocusListener);
165168
fFocusListener= null;
166-
if (fHandlerActivation != null)
169+
if (fHandlerActivation != null) {
167170
deactivateHandler();
171+
}
168172
}
169173
}
170174

@@ -177,8 +181,9 @@ private void installCueLabelProvider() {
177181
public String getText(Object element) {
178182
IBindingService bindingService= PlatformUI.getWorkbench().getAdapter(IBindingService.class);
179183
TriggerSequence[] activeBindings= bindingService.getActiveBindingsFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
180-
if (activeBindings.length == 0)
184+
if (activeBindings.length == 0) {
181185
return ContentAssistMessages.ContentAssistHandler_contentAssistAvailable;
186+
}
182187
return NLSUtility.format(ContentAssistMessages.ContentAssistHandler_contentAssistAvailableWithKeyBinding, activeBindings[0].format());
183188
}
184189
};
@@ -192,13 +197,15 @@ private void installFocusListener() {
192197
fFocusListener= new FocusListener() {
193198
@Override
194199
public void focusGained(final FocusEvent e) {
195-
if (fHandlerActivation == null)
200+
if (fHandlerActivation == null) {
196201
activateHandler();
202+
}
197203
}
198204
@Override
199205
public void focusLost(FocusEvent e) {
200-
if (fHandlerActivation != null)
206+
if (fHandlerActivation != null) {
201207
deactivateHandler();
208+
}
202209
}
203210
};
204211
fControl.addFocusListener(fFocusListener);
@@ -209,14 +216,16 @@ public void focusLost(FocusEvent e) {
209216
*/
210217
private void activateHandler() {
211218
IHandlerService handlerService= PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
212-
if (handlerService == null)
219+
if (handlerService == null) {
213220
return;
221+
}
214222

215223
IHandler handler= new AbstractHandler() {
216224
@Override
217225
public Object execute(ExecutionEvent event) throws ExecutionException {
218-
if (ContentAssistHandler.this.isEnabled()) // don't call AbstractHandler#isEnabled()!
226+
if (ContentAssistHandler.this.isEnabled()) { // don't call AbstractHandler#isEnabled()!
219227
fContentAssistant.showPossibleCompletions();
228+
}
220229
return null;
221230
}
222231
};
@@ -228,8 +237,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
228237
*/
229238
private void deactivateHandler() {
230239
IHandlerService handlerService= PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
231-
if (handlerService != null)
240+
if (handlerService != null) {
232241
handlerService.deactivateHandler(fHandlerActivation);
242+
}
233243
fHandlerActivation= null;
234244
}
235245
}

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/FindReplaceLogic.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class FindReplaceLogic implements IFindReplaceLogic {
5353

5454
private boolean isTargetSupportingRegEx;
5555
private boolean isTargetEditable;
56-
private Set<SearchOptions> searchOptions = new HashSet<>();
56+
private final Set<SearchOptions> searchOptions = new HashSet<>();
5757

5858
private String findString = ""; //$NON-NLS-1$
5959
private String replaceString = ""; //$NON-NLS-1$
@@ -465,11 +465,12 @@ public int findAndSelect(int offset) {
465465
* @return the selection after replacing, i.e. the inserted text
466466
*/
467467
private Point replaceSelection() {
468-
if (target instanceof IFindReplaceTargetExtension3)
468+
if (target instanceof IFindReplaceTargetExtension3) {
469469
((IFindReplaceTargetExtension3) target).replaceSelection(replaceString,
470470
isAvailableAndActive(SearchOptions.REGEX));
471-
else
471+
} else {
472472
target.replaceSelection(replaceString);
473+
}
473474

474475
return target.getSelection();
475476
}
@@ -575,8 +576,9 @@ public void updateTarget(IFindReplaceTarget newTarget, boolean canEditTarget) {
575576
this.isTargetEditable = canEditTarget;
576577

577578
if (this.target != newTarget) {
578-
if (this.target instanceof IFindReplaceTargetExtension)
579+
if (this.target instanceof IFindReplaceTargetExtension) {
579580
((IFindReplaceTargetExtension) this.target).endSession();
581+
}
580582

581583
this.target = newTarget;
582584
isTargetSupportingRegEx = newTarget instanceof IFindReplaceTargetExtension3;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/HistoryStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
* the nodes using the DialogSettings mechanism.
2727
*/
2828
public class HistoryStore {
29-
private IDialogSettings settingsManager;
30-
private int historySize;
31-
private String sectionName;
29+
private final IDialogSettings settingsManager;
30+
private final int historySize;
31+
private final String sectionName;
3232

3333
/**
3434
* @param settingsManager manager for DialogSettings

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
import org.eclipse.ui.texteditor.StatusTextEditor;
8484

8585
public class FindReplaceOverlay {
86-
private final class KeyboardShortcuts {
86+
private static final class KeyboardShortcuts {
8787
private static final List<KeyStroke> SEARCH_FORWARD = List.of( //
8888
KeyStroke.getInstance(SWT.CR), KeyStroke.getInstance(SWT.KEYPAD_CR));
8989
private static final List<KeyStroke> SEARCH_BACKWARD = List.of( //
@@ -154,7 +154,7 @@ private final class KeyboardShortcuts {
154154
private ControlDecoration searchBarDecoration;
155155
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;
156156

157-
private FocusListener targetActionActivationHandling = new FocusListener() {
157+
private final FocusListener targetActionActivationHandling = new FocusListener() {
158158
private DeactivateGlobalActionHandlers globalActionHandlerDeaction;
159159

160160
@Override
@@ -348,7 +348,7 @@ private void performSelectAll() {
348348
searchBar.storeHistory();
349349
}
350350

351-
private ControlListener targetMovementListener = ControlListener
351+
private final ControlListener targetMovementListener = ControlListener
352352
.controlResizedAdapter(__ -> asyncExecIfOpen(FindReplaceOverlay.this::updatePlacementAndVisibility));
353353

354354
private void asyncExecIfOpen(Runnable operation) {
@@ -361,12 +361,12 @@ private void asyncExecIfOpen(Runnable operation) {
361361
}
362362
}
363363

364-
private FocusListener targetFocusListener = FocusListener.focusGainedAdapter(__ -> {
364+
private final FocusListener targetFocusListener = FocusListener.focusGainedAdapter(__ -> {
365365
removeSearchScope();
366366
searchBar.storeHistory();
367367
});
368368

369-
private KeyListener closeOnTargetEscapeListener = KeyListener.keyPressedAdapter(c -> {
369+
private final KeyListener closeOnTargetEscapeListener = KeyListener.keyPressedAdapter(c -> {
370370
if (c.keyCode == SWT.ESC) {
371371
this.close();
372372
}
@@ -382,8 +382,9 @@ private IDialogSettings getDialogSettings() {
382382
IDialogSettings settings = PlatformUI
383383
.getDialogSettingsProvider(FrameworkUtil.getBundle(FindReplaceAction.class)).getDialogSettings();
384384
IDialogSettings dialogSettings = settings.getSection(FindReplaceAction.class.getClass().getName());
385-
if (dialogSettings == null)
385+
if (dialogSettings == null) {
386386
dialogSettings = settings.addNewSection(FindReplaceAction.class.getClass().getName());
387+
}
387388
return dialogSettings;
388389
}
389390

@@ -515,7 +516,7 @@ public void create() {
515516
* A composite with a fixed background color, not adapting to theming.
516517
*/
517518
private class FixedColorComposite extends Composite {
518-
private Color fixColor;
519+
private final Color fixColor;
519520

520521
public FixedColorComposite(Composite parent, int style, Color backgroundColor) {
521522
super(parent, style);

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/status/FindAllStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package org.eclipse.ui.internal.findandreplace.status;
1515

1616
public class FindAllStatus implements IFindReplaceStatus {
17-
private int selectCount;
17+
private final int selectCount;
1818

1919
public FindAllStatus(int selectCount) {
2020
this.selectCount = selectCount;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/status/FindStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public enum StatusCode {
2020
WRAPPED, READONLY,
2121
}
2222

23-
private StatusCode messageCode;
23+
private final StatusCode messageCode;
2424

2525
public FindStatus(StatusCode errorCode) {
2626
this.messageCode = errorCode;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/status/InvalidRegExStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class InvalidRegExStatus implements IFindReplaceStatus {
2323

24-
private PatternSyntaxException regExException;
24+
private final PatternSyntaxException regExException;
2525

2626
public InvalidRegExStatus(PatternSyntaxException regExException) {
2727
this.regExException = regExException;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/status/ReplaceAllStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package org.eclipse.ui.internal.findandreplace.status;
1515

1616
public class ReplaceAllStatus implements IFindReplaceStatus {
17-
private int replaceCount;
17+
private final int replaceCount;
1818

1919
public ReplaceAllStatus(int replaceCount) {
2020
this.replaceCount = replaceCount;

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/CompoundEditExitStrategy.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ public void preExecute(String commandId, ExecutionEvent event) {
109109
public void verifyKey(VerifyEvent event) {
110110
// any key press that is not a modifier combo ends the compound change
111111
final int maskWithoutShift= SWT.MODIFIER_MASK & ~SWT.SHIFT;
112-
if ((event.keyCode & SWT.MODIFIER_MASK) == 0 && (event.stateMask & maskWithoutShift) == 0)
112+
if ((event.keyCode & SWT.MODIFIER_MASK) == 0 && (event.stateMask & maskWithoutShift) == 0) {
113113
fireEndCompoundEdit();
114+
}
114115
}
115116

116117
}
@@ -130,8 +131,9 @@ public void verifyKey(VerifyEvent event) {
130131
* @param commandId the command id of the repeatable command
131132
*/
132133
public CompoundEditExitStrategy(String commandId) {
133-
if (commandId == null)
134+
if (commandId == null) {
134135
throw new NullPointerException("commandId"); //$NON-NLS-1$
136+
}
135137
fCommandIds= new String[] {commandId};
136138
}
137139

@@ -143,8 +145,9 @@ public CompoundEditExitStrategy(String commandId) {
143145
*/
144146
public CompoundEditExitStrategy(String[] commandIds) {
145147
for (int i= 0; i < commandIds.length; i++) {
146-
if (commandIds[i] == null)
148+
if (commandIds[i] == null) {
147149
throw new NullPointerException("commandIds[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$
150+
}
148151
}
149152
fCommandIds= new String[commandIds.length];
150153
System.arraycopy(commandIds, 0, fCommandIds, 0, commandIds.length);
@@ -158,8 +161,9 @@ public CompoundEditExitStrategy(String[] commandIds) {
158161
*/
159162
public void arm(ITextViewer viewer) {
160163
disarm();
161-
if (viewer == null)
164+
if (viewer == null) {
162165
throw new NullPointerException("editor"); //$NON-NLS-1$
166+
}
163167
fViewer= viewer;
164168
addListeners(fViewer);
165169
}
@@ -189,14 +193,16 @@ private void addListeners(ITextViewer viewer) {
189193
}
190194

191195
ICommandService commandService= PlatformUI.getWorkbench().getAdapter(ICommandService.class);
192-
if (commandService != null)
196+
if (commandService != null) {
193197
commandService.addExecutionListener(fEventListener);
198+
}
194199
}
195200

196201
private void removeListeners() {
197202
ICommandService commandService= PlatformUI.getWorkbench().getAdapter(ICommandService.class);
198-
if (commandService != null)
203+
if (commandService != null) {
199204
commandService.removeExecutionListener(fEventListener);
205+
}
200206

201207
if (fWidgetEventSource != null) {
202208
fWidgetEventSource.removeFocusListener(fEventListener);

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/FocusedInformationPresenter.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public class FocusedInformationPresenter extends InformationPresenter {
4747
*/
4848
public final static class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
4949

50-
private IRegion fHoverRegion;
51-
private Object fHoverInfo;
52-
private IInformationControlCreator fControlCreator;
50+
private final IRegion fHoverRegion;
51+
private final Object fHoverInfo;
52+
private final IInformationControlCreator fControlCreator;
5353

5454
public InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) {
5555
fHoverRegion= hoverRegion;
@@ -125,8 +125,9 @@ public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int
125125
Object hoverInfo;
126126
if (annotationHover instanceof IAnnotationHoverExtension extension) {
127127
ILineRange hoverLineRange= extension.getHoverLineRange(fSourceViewer, line);
128-
if (hoverLineRange == null)
128+
if (hoverLineRange == null) {
129129
return false;
130+
}
130131
final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
131132
hoverInfo= extension.getHoverInfo(fSourceViewer, hoverLineRange, maxVisibleLines);
132133
} else {
@@ -139,10 +140,11 @@ public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int
139140
String contentType= TextUtilities.getContentType(document, fSourceViewerConfiguration.getConfiguredDocumentPartitioning(fSourceViewer), offset, true);
140141

141142
IInformationControlCreator controlCreator= null;
142-
if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility
143+
if (annotationHover instanceof IInformationProviderExtension2) { // this is undocumented, but left here for backwards compatibility
143144
controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
144-
else if (annotationHover instanceof IAnnotationHoverExtension)
145+
} else if (annotationHover instanceof IAnnotationHoverExtension) {
145146
controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
147+
}
146148

147149
IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
148150

0 commit comments

Comments
 (0)