Skip to content

Commit 01fc7f0

Browse files
eclipse-platform-botHeikoKlare
authored andcommitted
Perform clean code of bundles/org.eclipse.ui.browser
1 parent 2f6a390 commit 01fc7f0

28 files changed

+429
-250
lines changed

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorDialog.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ public BrowserDescriptorDialog(Shell parentShell) {
6767
protected void configureShell(Shell shell) {
6868
super.configureShell(shell);
6969

70-
if (isEdit)
70+
if (isEdit) {
7171
shell.setText(Messages.editExternalBrowser);
72-
else
72+
} else {
7373
shell.setText(Messages.createBrowser);
74+
}
7475
}
7576

7677
protected Text createText(Composite comp, String txt, final StringModifyListener listener, boolean multiLine) {
@@ -91,8 +92,9 @@ protected Text createText(Composite comp, String txt, final StringModifyListener
9192
});
9293
}
9394
// final Text text = SWTUtil.createMultilineText(comp, style);
94-
if (txt != null)
95+
if (txt != null) {
9596
text.setText(txt);
97+
}
9698

9799
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
98100
data.widthHint = 450;
@@ -104,8 +106,9 @@ protected Text createText(Composite comp, String txt, final StringModifyListener
104106
}
105107

106108
text.setLayoutData(data);
107-
if (listener != null)
109+
if (listener != null) {
108110
text.addModifyListener(e -> listener.valueChanged(text.getText()));
111+
}
109112
return text;
110113
}
111114

@@ -145,8 +148,9 @@ protected Control createDialogArea(Composite parent) {
145148
dialog.setFileName(fname);
146149
fname = dialog.open();
147150

148-
if (fname != null)
151+
if (fname != null) {
149152
browserLocationTextfield.setText(fname);
153+
}
150154
}));
151155

152156
SWTUtil.createLabel(composite, Messages.parameters).setFont(font);
@@ -184,11 +188,13 @@ protected void okPressed() {
184188
}
185189

186190
private void setOKButtonEnabled(boolean curIsEnabled) {
187-
if (okButton == null)
191+
if (okButton == null) {
188192
okButton = getButton(IDialogConstants.OK_ID);
193+
}
189194

190-
if (okButton != null)
195+
if (okButton != null) {
191196
okButton.setEnabled(curIsEnabled);
197+
}
192198
}
193199

194200
@Override
@@ -202,12 +208,14 @@ protected void validateFields() {
202208
boolean valid = true;
203209

204210
String name = browserNameTextfield.getText();
205-
if (name == null || name.trim().length() < 1)
211+
if (name == null || name.trim().length() < 1) {
206212
valid = false;
213+
}
207214

208215
String location = browserLocationTextfield.getText();
209-
if (location == null || location.trim().length() < 1)
216+
if (location == null || location.trim().length() < 1) {
210217
valid = false;
218+
}
211219

212220
setOKButtonEnabled(valid);
213221
}

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserDescriptorWorkingCopy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public BrowserDescriptorWorkingCopy(BrowserDescriptor browser) {
2828

2929
@Override
3030
public void setName(String name) {
31-
if (name == null)
31+
if (name == null) {
3232
throw new IllegalArgumentException();
33+
}
3334
this.name = name;
3435
}
3536

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserExt.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class BrowserExt implements IBrowserExt {
2626
private static final String ATTR_FACTORY_CLASS = "factoryclass"; //$NON-NLS-1$
2727

28-
private IConfigurationElement element;
28+
private final IConfigurationElement element;
2929

3030
private BrowserFactory delegate;
3131

@@ -50,8 +50,9 @@ public String getId() {
5050
@Override
5151
public String getName() {
5252
String label = element.getAttribute("name"); //$NON-NLS-1$
53-
if (label == null)
53+
if (label == null) {
5454
return "n/a"; //$NON-NLS-1$
55+
}
5556
return label;
5657
}
5758

@@ -68,8 +69,9 @@ public String getExecutable() {
6869
@Override
6970
public String getOS() {
7071
String os = element.getAttribute("os"); //$NON-NLS-1$
71-
if (os == null)
72+
if (os == null) {
7273
os = ""; //$NON-NLS-1$
74+
}
7375
return os;
7476
}
7577

@@ -92,8 +94,9 @@ public String[] getDefaultLocations() {
9294
protected BrowserFactory getDelegate() {
9395
if (delegate == null) {
9496
if (element.getAttribute(ATTR_FACTORY_CLASS) == null
95-
|| element.getAttribute(ATTR_FACTORY_CLASS).isEmpty())
97+
|| element.getAttribute(ATTR_FACTORY_CLASS).isEmpty()) {
9698
return null;
99+
}
97100

98101
try {
99102
delegate = (BrowserFactory) element
@@ -118,8 +121,9 @@ protected BrowserFactory getDelegate() {
118121
@Override
119122
public boolean isAvailable() {
120123
if (delegate == null && (element.getAttribute(ATTR_FACTORY_CLASS) == null
121-
|| element.getAttribute(ATTR_FACTORY_CLASS).isEmpty()))
124+
|| element.getAttribute(ATTR_FACTORY_CLASS).isEmpty())) {
122125
return true;
126+
}
123127

124128
try {
125129
return getDelegate().isAvailable();

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserLauncher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public BrowserLauncher() {
3232
public void open(IPath file) {
3333
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
3434
try {
35-
if (WebBrowserPreference.getBrowserChoice()== WebBrowserPreference.INTERNAL)
35+
if (WebBrowserPreference.getBrowserChoice()== WebBrowserPreference.INTERNAL) {
3636
support.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR,
3737
file.toPortableString(), null, null).openURL(file.toFile().toURI().toURL());
38-
else
38+
} else {
3939
support.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR,
4040
DefaultBrowserSupport.SHARED_ID, null, null).openURL(file.toFile().toURI().toURL());
41+
}
4142
}
4243
catch (MalformedURLException e) {
4344
// ignore

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserManager.java

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ public class BrowserManager extends Observable {
3636
protected List<IBrowserDescriptor> browsers;
3737
protected IBrowserDescriptor currentBrowser;
3838

39-
private IPreferenceChangeListener pcl;
39+
private final IPreferenceChangeListener pcl;
4040
protected boolean ignorePreferenceChanges = false;
4141

4242
protected static BrowserManager instance;
4343

4444
public static BrowserManager getInstance() {
45-
if (instance == null)
45+
if (instance == null) {
4646
instance = new BrowserManager();
47+
}
4748
return instance;
4849
}
4950

@@ -66,8 +67,9 @@ private BrowserManager() {
6667
}
6768

6869
protected static void safeDispose() {
69-
if (instance == null)
70+
if (instance == null) {
7071
return;
72+
}
7173
instance.dispose();
7274
}
7375

@@ -82,8 +84,9 @@ public IBrowserDescriptorWorkingCopy createExternalWebBrowser() {
8284
}
8385

8486
public List<IBrowserDescriptor> getWebBrowsers() {
85-
if (browsers == null)
87+
if (browsers == null) {
8688
loadBrowsers();
89+
}
8790
return new ArrayList<>(browsers);
8891
}
8992

@@ -101,8 +104,9 @@ public void loadBrowsers() {
101104
IMemento memento = XMLMemento.createReadRoot(reader);
102105

103106
IMemento system = memento.getChild("system"); //$NON-NLS-1$
104-
if (system != null && WebBrowserUtil.canUseSystemBrowser())
107+
if (system != null && WebBrowserUtil.canUseSystemBrowser()) {
105108
browsers.add(new SystemBrowserDescriptor());
109+
}
106110

107111
IMemento[] children = memento.getChildren("external"); //$NON-NLS-1$
108112
int size = children.length;
@@ -131,8 +135,9 @@ public void loadBrowsers() {
131135
saveBrowsers();
132136
}
133137

134-
if (currentBrowser == null && browsers.size() > 0)
138+
if (currentBrowser == null && browsers.size() > 0) {
135139
currentBrowser = browsers.get(0);
140+
}
136141
setChanged();
137142
notifyObservers();
138143
}
@@ -145,8 +150,7 @@ protected void saveBrowsers() {
145150
Iterator<IBrowserDescriptor> iterator = browsers.iterator();
146151
while (iterator.hasNext()) {
147152
Object obj = iterator.next();
148-
if (obj instanceof BrowserDescriptor) {
149-
BrowserDescriptor browser = (BrowserDescriptor) obj;
153+
if (obj instanceof BrowserDescriptor browser) {
150154
IMemento child = memento.createChild("external"); //$NON-NLS-1$
151155
browser.save(child);
152156
} else if (obj instanceof SystemBrowserDescriptor) {
@@ -194,49 +198,59 @@ protected void addDefaultBrowsers() {
194198

195199
// by default, if internal is there, that is current, else set the first
196200
// external one
197-
if (!browsers.isEmpty() && currentBrowser == null)
201+
if (!browsers.isEmpty() && currentBrowser == null) {
198202
currentBrowser = browsers.get(0);
203+
}
199204
}
200205

201206
protected void addBrowser(IBrowserDescriptor browser) {
202-
if (browsers == null)
207+
if (browsers == null) {
203208
loadBrowsers();
204-
if (!browsers.contains(browser))
209+
}
210+
if (!browsers.contains(browser)) {
205211
browsers.add(browser);
206-
if (browsers.size() == 1)
212+
}
213+
if (browsers.size() == 1) {
207214
setCurrentWebBrowser(browser);
215+
}
208216
}
209217

210218
protected void removeWebBrowser(IBrowserDescriptor browser) {
211-
if (browsers == null)
219+
if (browsers == null) {
212220
loadBrowsers();
221+
}
213222
browsers.remove(browser);
214223

215224
if (currentBrowser == null || currentBrowser.equals(browser)) {
216225
currentBrowser = null;
217-
if (browsers.size() > 0)
226+
if (browsers.size() > 0) {
218227
currentBrowser = browsers.get(0);
228+
}
219229
}
220230
}
221231

222232
public IBrowserDescriptor getCurrentWebBrowser() {
223-
if (browsers == null)
233+
if (browsers == null) {
224234
loadBrowsers();
235+
}
225236

226-
if (currentBrowser == null && browsers.size() > 0)
237+
if (currentBrowser == null && browsers.size() > 0) {
227238
return browsers.get(0);
239+
}
228240

229241
return currentBrowser;
230242
}
231243

232244
public void setCurrentWebBrowser(IBrowserDescriptor wb) {
233-
if (wb == null)
245+
if (wb == null) {
234246
throw new IllegalArgumentException();
247+
}
235248

236-
if (browsers.contains(wb))
249+
if (browsers.contains(wb)) {
237250
currentBrowser = wb;
238-
else
251+
} else {
239252
throw new IllegalArgumentException();
253+
}
240254
saveBrowsers();
241255
}
242256

bundles/org.eclipse.ui.browser/src/org/eclipse/ui/internal/browser/BrowserText.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class BrowserText {
3535
private String url;
3636

37-
private FallbackScrolledComposite scomp;
37+
private final FallbackScrolledComposite scomp;
3838

3939
private Label title;
4040

@@ -46,15 +46,15 @@ public class BrowserText {
4646

4747
protected Link link;
4848

49-
private BrowserViewer viewer;
49+
private final BrowserViewer viewer;
5050

5151
private Button button;
5252

5353
private Text exception;
5454

5555
private boolean expanded;
5656

57-
private Throwable ex;
57+
private final Throwable ex;
5858

5959
class ReflowScrolledComposite extends FallbackScrolledComposite {
6060
public ReflowScrolledComposite(Composite parent, int style) {
@@ -140,10 +140,11 @@ protected void toggleException() {
140140
}
141141

142142
private void updateButtonText() {
143-
if (expanded)
143+
if (expanded) {
144144
button.setText(Messages.BrowserText_button_collapse);
145-
else
145+
} else {
146146
button.setText(Messages.BrowserText_button_expand);
147+
}
147148
}
148149

149150
protected void updateWidth(Composite parent) {
@@ -158,14 +159,16 @@ protected void updateWidth(Composite parent) {
158159

159160
private void updateWidth(Control c, int width) {
160161
GridData gd = (GridData) c.getLayoutData();
161-
if (gd != null)
162+
if (gd != null) {
162163
gd.widthHint = width - 10;
164+
}
163165
}
164166

165167
protected void doOpenExternal() {
166168
IBrowserViewerContainer container = viewer.getContainer();
167-
if (container != null)
169+
if (container != null) {
168170
container.openInExternalBrowser(url);
171+
}
169172
}
170173

171174
public Control getControl() {

0 commit comments

Comments
 (0)