Skip to content

Commit 6e6590a

Browse files
eclipse-pde-botlaeubi
authored andcommitted
Perform clean code of ui/org.eclipse.pde.bnd.ui
1 parent 4e00417 commit 6e6590a

36 files changed

+329
-182
lines changed

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/Central.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public static IFile getWorkspaceBuildFile() throws Exception {
8585
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace()
8686
.getRoot();
8787
IProject cnf = wsroot.getProject(Workspace.CNFDIR);
88-
if (cnf == null || !cnf.isAccessible())
88+
if (cnf == null || !cnf.isAccessible()) {
8989
return null;
90+
}
9091
return cnf.getFile(Workspace.BUILDFILE);
9192
}
9293

@@ -107,8 +108,9 @@ private static File getWorkspaceDirectory() throws CoreException {
107108

108109
IProject cnfProject = eclipseWorkspace.getProject(Workspace.CNFDIR);
109110
if (cnfProject.exists()) {
110-
if (!cnfProject.isOpen())
111+
if (!cnfProject.isOpen()) {
111112
cnfProject.open(null);
113+
}
112114
return cnfProject.getLocation()
113115
.toFile()
114116
.getParentFile();
@@ -137,10 +139,12 @@ public static boolean hasWorkspaceDirectory() {
137139
}
138140

139141
public static boolean isChangeDelta(IResourceDelta delta) {
140-
if (IResourceDelta.MARKERS == delta.getFlags())
142+
if (IResourceDelta.MARKERS == delta.getFlags()) {
141143
return false;
142-
if ((delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED)) == 0)
144+
}
145+
if ((delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED)) == 0) {
143146
return false;
147+
}
144148
return true;
145149
}
146150

@@ -188,8 +192,9 @@ public static IPath toPath(File file, Workspace workspace) throws Exception {
188192
try {
189193
String workspacePath = workspace.getBase().getAbsolutePath();
190194
String absolutePath = absolute.getPath();
191-
if (absolutePath.startsWith(workspacePath))
195+
if (absolutePath.startsWith(workspacePath)) {
192196
return new Path(absolutePath.substring(workspacePath.length()));
197+
}
193198
return null;
194199
} catch (Exception e) {
195200
throw Exceptions.duck(e);
@@ -224,8 +229,9 @@ public static void refresh(IPath path) {
224229
IResource r = ResourcesPlugin.getWorkspace()
225230
.getRoot()
226231
.findMember(path);
227-
if (r != null)
232+
if (r != null) {
228233
return;
234+
}
229235

230236
IPath p = (IPath) path.clone();
231237
while (p.segmentCount() > 0) {
@@ -255,8 +261,9 @@ public static void refreshPlugins(Workspace workspace) throws Exception {
255261
if (rp.refresh()) {
256262
changed = true;
257263
File root = rp.getRoot();
258-
if (root != null)
264+
if (root != null) {
259265
refreshedFiles.add(root);
266+
}
260267
if (rp instanceof RepositoryPlugin) {
261268
repoChanged = true;
262269
}
@@ -339,9 +346,10 @@ public static void refreshFile(File file, IProgressMonitor monitor, boolean deri
339346

340347
public static void refresh(Project p) throws Exception {
341348
IJavaProject jp = getJavaProject(p);
342-
if (jp != null)
349+
if (jp != null) {
343350
jp.getProject()
344351
.refreshLocal(IResource.DEPTH_INFINITE, null);
352+
}
345353
}
346354

347355

@@ -369,8 +377,9 @@ public static boolean isBndProject(IProject project) {
369377
*/
370378

371379
public static IResource toResource(File file) {
372-
if (file == null)
380+
if (file == null) {
373381
return null;
382+
}
374383

375384
IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
376385
.getRoot();
@@ -477,10 +486,11 @@ public static boolean refreshFiles(Reporter reporter, Collection<File> files, IP
477486
Central.refreshFile(t, monitor, derived);
478487
} catch (CoreException e) {
479488
errors.incrementAndGet();
480-
if (reporter != null)
489+
if (reporter != null) {
481490
reporter.error("failed to refresh %s : %s", t, Exceptions.causes(e));
482-
else
491+
} else {
483492
throw Exceptions.duck(e);
493+
}
484494
}
485495
});
486496
return errors.get() == 0;

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/EditorUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public static boolean saveEditorIfDirty(final IEditorPart editor, String dialogT
5252
public static final IFormPart findPartByClass(IManagedForm form, Class<? extends IFormPart> clazz) {
5353
IFormPart[] parts = form.getParts();
5454
for (IFormPart part : parts) {
55-
if (clazz.isInstance(part))
55+
if (clazz.isInstance(part)) {
5656
return part;
57+
}
5758
}
5859
return null;
5960
}

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/FileExtensionFilter.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ public FileExtensionFilter(String[] extensions, boolean caseInsensitive) {
3737
this.extensions = new String[extensions.length];
3838

3939
for (int i = 0; i < extensions.length; i++) {
40-
if (extensions[i].length() > 0 && extensions[i].charAt(0) == '.')
40+
if (extensions[i].length() > 0 && extensions[i].charAt(0) == '.') {
4141
this.extensions[i] = extensions[i];
42-
else
42+
} else {
4343
this.extensions[i] = "." + extensions[i];
44+
}
4445

45-
if (caseInsensitive)
46+
if (caseInsensitive) {
4647
this.extensions[i] = this.extensions[i].toLowerCase();
48+
}
4749
}
4850
}
4951

@@ -78,24 +80,28 @@ public FileExtensionFilter(String extension) {
7880
public boolean select(Viewer viewer, Object parent, Object element) {
7981
if (element instanceof IFile) {
8082
String fileName = ((IFile) element).getName();
81-
if (caseInsensitive)
83+
if (caseInsensitive) {
8284
fileName = fileName.toLowerCase(Locale.ENGLISH);
85+
}
8386
for (String extension : this.extensions) {
84-
if (fileName.endsWith(extension))
87+
if (fileName.endsWith(extension)) {
8588
return true;
89+
}
8690
}
8791
return false;
8892
}
8993

90-
if (element instanceof IProject && !((IProject) element).isOpen())
94+
if (element instanceof IProject && !((IProject) element).isOpen()) {
9195
return false;
96+
}
9297

9398
if (element instanceof IContainer) {
9499
try {
95100
IResource[] resources = ((IContainer) element).members();
96101
for (IResource element2 : resources) {
97-
if (select(viewer, parent, element2))
102+
if (select(viewer, parent, element2)) {
98103
return true;
104+
}
99105
}
100106
} catch (CoreException e) {}
101107
}

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/FilterPanelPart.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ public class FilterPanelPart {
5858
newFilter);
5959
};
6060
if (display.getThread() == Thread
61-
.currentThread())
61+
.currentThread()) {
6262
update.run();
63-
else
63+
} else {
6464
display.asyncExec(update);
65+
}
6566
};
6667
private ScheduledFuture<?> scheduledFilterUpdate = null;
6768

@@ -81,8 +82,9 @@ public Control createControl(Composite parent, int marginWidth, int marginHeight
8182
txtFilter.setMessage("Enter search string");
8283

8384
// INITIAL PROPERTIES
84-
if (filter != null)
85+
if (filter != null) {
8586
txtFilter.setText(filter);
87+
}
8688

8789
// LAYOUT
8890
GridLayout layout = new GridLayout(2, false);
@@ -97,8 +99,9 @@ public Control createControl(Composite parent, int marginWidth, int marginHeight
9799
public void widgetDefaultSelected(SelectionEvent ev) {
98100
try {
99101
scheduledFilterLock.lock();
100-
if (scheduledFilterUpdate != null)
102+
if (scheduledFilterUpdate != null) {
101103
scheduledFilterUpdate.cancel(true);
104+
}
102105
} finally {
103106
scheduledFilterLock.unlock();
104107
}
@@ -110,8 +113,9 @@ public void widgetDefaultSelected(SelectionEvent ev) {
110113
txtFilter.addModifyListener(ev -> {
111114
try {
112115
scheduledFilterLock.lock();
113-
if (scheduledFilterUpdate != null)
116+
if (scheduledFilterUpdate != null) {
114117
scheduledFilterUpdate.cancel(true);
118+
}
115119
scheduledFilterUpdate = scheduler.schedule(updateFilterTask, SEARCH_DELAY, TimeUnit.MILLISECONDS);
116120
} finally {
117121
scheduledFilterLock.unlock();
@@ -135,8 +139,9 @@ public void setFilter(String filter) {
135139
}
136140

137141
public void setFocus() {
138-
if (txtFilter != null && !txtFilter.isDisposed())
142+
if (txtFilter != null && !txtFilter.isDisposed()) {
139143
txtFilter.setFocus();
144+
}
140145
}
141146

142147
public void addPropertyChangeListener(PropertyChangeListener listener) {

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/LabelParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ public LabelParser(String labelExpression) {
139139

140140
Matcher m = LABEL_PATTERN.matcher(labelExpression);
141141
if (m.matches()) {
142-
if (m.group(1) != null)
142+
if (m.group(1) != null) {
143143
enabled = false;
144+
}
144145

145-
if (m.group(2) != null)
146+
if (m.group(2) != null) {
146147
checked = true;
148+
}
147149

148150
label = m.group(3);
149151

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/ResourceUtils.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public final class ResourceUtils {
4545

4646
public static Capability getIdentityCapability(Resource resource) throws IllegalArgumentException {
4747
List<Capability> caps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
48-
if (caps.isEmpty())
48+
if (caps.isEmpty()) {
4949
throw new IllegalArgumentException("Resource has no identity");
50+
}
5051
if (caps.size() > 1) {
5152
// Remove the alias identity "system.bundle"
5253
List<Capability> filtered = new ArrayList<>(caps.size());
@@ -60,28 +61,32 @@ public static Capability getIdentityCapability(Resource resource) throws Illegal
6061
}
6162
caps = filtered;
6263

63-
if (caps.size() > 1)
64+
if (caps.size() > 1) {
6465
throw new IllegalArgumentException("Resource has multiple identity capabilities: " + ids);
66+
}
6567
}
6668
return caps.get(0);
6769
}
6870

6971
public static String getIdentity(Capability identityCapability) throws IllegalArgumentException {
7072
String id = (String) identityCapability.getAttributes()
7173
.get(IdentityNamespace.IDENTITY_NAMESPACE);
72-
if (id == null)
74+
if (id == null) {
7375
throw new IllegalArgumentException("Resource identity capability has missing identity attribute");
76+
}
7477
return id;
7578
}
7679

7780
public static Version getVersion(Capability identityCapability) throws IllegalArgumentException {
7881
Object versionObj = identityCapability.getAttributes()
7982
.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
80-
if (versionObj instanceof Version)
83+
if (versionObj instanceof Version) {
8184
return (Version) versionObj;
85+
}
8286

83-
if (versionObj == null || versionObj instanceof String)
87+
if (versionObj == null || versionObj instanceof String) {
8488
return Version.parseVersion((String) versionObj);
89+
}
8590

8691
throw new IllegalArgumentException(
8792
"Resource identity capability has version attribute with incorrect type: " + versionObj.getClass());
@@ -98,8 +103,9 @@ public static Version getVersion(Resource resource) throws IllegalArgumentExcept
98103
public static Capability getContentCapability(Resource resource) throws IllegalArgumentException {
99104
List<Capability> caps = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE);
100105

101-
if (caps.isEmpty())
106+
if (caps.isEmpty()) {
102107
throw new IllegalArgumentException("Resource has no content");
108+
}
103109

104110
// A resource may have multiple capabilities and this is acceptable
105111
// according to the specification
@@ -109,14 +115,16 @@ public static Capability getContentCapability(Resource resource) throws IllegalA
109115
Capability firstCap = null;
110116
for (Capability c : caps) {
111117

112-
if (firstCap == null)
118+
if (firstCap == null) {
113119
firstCap = c;
120+
}
114121

115122
Object url = c.getAttributes()
116123
.get("url");
117124

118-
if (url == null)
125+
if (url == null) {
119126
continue;
127+
}
120128

121129
String urlString = String.valueOf(url);
122130

@@ -134,15 +142,18 @@ public static Capability getContentCapability(Resource resource) throws IllegalA
134142
public static URI getURI(Capability contentCapability) {
135143
Object uriObj = contentCapability.getAttributes()
136144
.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
137-
if (uriObj == null)
145+
if (uriObj == null) {
138146
throw new IllegalArgumentException("Resource content capability has missing URL attribute");
147+
}
139148

140-
if (uriObj instanceof URI)
149+
if (uriObj instanceof URI) {
141150
return (URI) uriObj;
151+
}
142152

143153
try {
144-
if (uriObj instanceof URL)
154+
if (uriObj instanceof URL) {
145155
return ((URL) uriObj).toURI();
156+
}
146157

147158
if (uriObj instanceof String) {
148159
try {
@@ -170,24 +181,25 @@ public static URI getURI(Capability contentCapability) {
170181
public static String getVersionAttributeForNamespace(String ns) {
171182
String name;
172183

173-
if (IdentityNamespace.IDENTITY_NAMESPACE.equals(ns))
184+
if (IdentityNamespace.IDENTITY_NAMESPACE.equals(ns)) {
174185
name = IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE;
175-
else if (BundleNamespace.BUNDLE_NAMESPACE.equals(ns))
186+
} else if (BundleNamespace.BUNDLE_NAMESPACE.equals(ns)) {
176187
name = AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE;
177-
else if (HostNamespace.HOST_NAMESPACE.equals(ns))
188+
} else if (HostNamespace.HOST_NAMESPACE.equals(ns)) {
178189
name = AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE;
179-
else if (PackageNamespace.PACKAGE_NAMESPACE.equals(ns))
190+
} else if (PackageNamespace.PACKAGE_NAMESPACE.equals(ns)) {
180191
name = PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE;
181-
else if (ServiceNamespace.SERVICE_NAMESPACE.equals(ns))
192+
} else if (ServiceNamespace.SERVICE_NAMESPACE.equals(ns)) {
182193
name = null;
183-
else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(ns))
194+
} else if (ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE.equals(ns)) {
184195
name = ExecutionEnvironmentNamespace.CAPABILITY_VERSION_ATTRIBUTE;
185-
else if (ExtenderNamespace.EXTENDER_NAMESPACE.equals(ns))
196+
} else if (ExtenderNamespace.EXTENDER_NAMESPACE.equals(ns)) {
186197
name = ExtenderNamespace.CAPABILITY_VERSION_ATTRIBUTE;
187-
else if (ContractNamespace.CONTRACT_NAMESPACE.equals(ns))
198+
} else if (ContractNamespace.CONTRACT_NAMESPACE.equals(ns)) {
188199
name = ContractNamespace.CAPABILITY_VERSION_ATTRIBUTE;
189-
else
200+
} else {
190201
name = null;
202+
}
191203

192204
return name;
193205
}

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/SWTUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ public interface OverrideEnablement {
3737
public static void recurseEnable(boolean enable, Control control) {
3838
Object data = control.getData();
3939
boolean en = enable;
40-
if (data != null && data instanceof OverrideEnablement)
40+
if (data != null && data instanceof OverrideEnablement) {
4141
en = ((OverrideEnablement) data).override(en);
42-
else {
42+
} else {
4343
data = control.getData(OVERRIDE_ENABLEMENT);
44-
if (data != null && data instanceof OverrideEnablement)
44+
if (data != null && data instanceof OverrideEnablement) {
4545
en = ((OverrideEnablement) data).override(en);
46+
}
4647
}
4748
control.setEnabled(en);
4849
if (control instanceof Composite) {

0 commit comments

Comments
 (0)