Skip to content

Clean Code for ui/org.eclipse.pde.runtime #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/org.eclipse.pde.runtime/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %name
Bundle-SymbolicName: org.eclipse.pde.runtime; singleton:=true
Bundle-Version: 3.8.600.qualifier
Bundle-Version: 3.8.700.qualifier
Bundle-Activator: org.eclipse.pde.internal.runtime.PDERuntimePlugin
Bundle-Vendor: %provider-name
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@

public class MessageHelper {
public static String getResolutionFailureMessage(VersionConstraint unsatisfied) {
if (unsatisfied.isResolved())
if (unsatisfied.isResolved()) {
throw new IllegalArgumentException();
if (unsatisfied instanceof ImportPackageSpecification)
}
if (unsatisfied instanceof ImportPackageSpecification) {
return NLS.bind(PDERuntimeMessages.MessageHelper_missing_imported_package, toString(unsatisfied));
else if (unsatisfied instanceof BundleSpecification) {
if (((BundleSpecification) unsatisfied).isOptional())
} else if (unsatisfied instanceof BundleSpecification) {
if (((BundleSpecification) unsatisfied).isOptional()) {
return NLS.bind(PDERuntimeMessages.MessageHelper_missing_optional_required_bundle, toString(unsatisfied));
}
return NLS.bind(PDERuntimeMessages.MessageHelper_missing_required_bundle, toString(unsatisfied));
} else
} else {
return NLS.bind(PDERuntimeMessages.MessageHelper_missing_host, toString(unsatisfied));
}
}

private static String toString(VersionConstraint constraint) {
VersionRange versionRange = constraint.getVersionRange();
if (versionRange == null)
if (versionRange == null) {
return constraint.getName();
}
return constraint.getName() + '_' + versionRange;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ public class OverlayIcon extends CompositeImageDescriptor {

public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays) {
fBase = base;
if (fBase == null)
if (fBase == null) {
fBase = ImageDescriptor.getMissingImageDescriptor();
}
fOverlays = overlays;
fSize = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}

public OverlayIcon(ImageDescriptor base, ImageDescriptor[][] overlays, Point size) {
fBase = base;
if (fBase == null)
if (fBase == null) {
fBase = ImageDescriptor.getMissingImageDescriptor();
}
fOverlays = overlays;
fSize = size;
}

protected void drawBottomLeft(ImageDescriptor[] overlays) {
if (overlays == null)
if (overlays == null) {
return;
}
int length = overlays.length;
int x = 0;
for (int i = 0; i < 3; i++) {
Expand All @@ -59,8 +62,9 @@ protected void drawBottomLeft(ImageDescriptor[] overlays) {
}

protected void drawBottomRight(ImageDescriptor[] overlays) {
if (overlays == null)
if (overlays == null) {
return;
}
int length = overlays.length;
int x = getSize().x;
for (int i = 2; i >= 0; i--) {
Expand All @@ -78,23 +82,28 @@ protected void drawCompositeImage(int width, int height) {
drawImage(bg, 0, 0);

if (fOverlays != null) {
if (fOverlays.length > 0)
if (fOverlays.length > 0) {
drawTopRight(fOverlays[0]);
}

if (fOverlays.length > 1)
if (fOverlays.length > 1) {
drawBottomRight(fOverlays[1]);
}

if (fOverlays.length > 2)
if (fOverlays.length > 2) {
drawBottomLeft(fOverlays[2]);
}

if (fOverlays.length > 3)
if (fOverlays.length > 3) {
drawTopLeft(fOverlays[3]);
}
}
}

protected void drawTopLeft(ImageDescriptor[] overlays) {
if (overlays == null)
if (overlays == null) {
return;
}
int length = overlays.length;
int x = 0;
for (int i = 0; i < 3; i++) {
Expand All @@ -107,8 +116,9 @@ protected void drawTopLeft(ImageDescriptor[] overlays) {
}

protected void drawTopRight(ImageDescriptor[] overlays) {
if (overlays == null)
if (overlays == null) {
return;
}
int length = overlays.length;
int x = getSize().x;
for (int i = 2; i >= 0; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ public State getState() {
}

public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException) {
status = ((CoreException) e).getStatus();
} else if (e.getMessage() != null) {
status = Status.error(e.getMessage(), e);
}
if (status != null)
if (status != null) {
getDefault().getLog().log(status);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ private static ImageDescriptor create(String prefix, String name) {
}

public static Image get(String key) {
if (PLUGIN_REGISTRY == null)
if (PLUGIN_REGISTRY == null) {
initialize();
}
return PLUGIN_REGISTRY.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ public void run() {
private final ViewerFilter fActiveFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof ExtensionPoint)
if (element instanceof ExtensionPoint) {
element = Platform.getBundle(((ExtensionPoint) element).getNamespaceIdentifier());
else if (element instanceof Extension)
} else if (element instanceof Extension) {
element = Platform.getBundle(((Extension) element).getNamespaceIdentifier());
if (element instanceof Bundle)
}
if (element instanceof Bundle) {
return ((Bundle) element).getState() == Bundle.ACTIVE;
}
return true;
}
};
Expand Down Expand Up @@ -207,23 +209,27 @@ public IStatus run(IProgressMonitor monitor) {
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento);
if (memento == null)
if (memento == null) {
this.fMemento = XMLMemento.createWriteRoot("REGISTRYVIEW"); //$NON-NLS-1$
else
} else {
this.fMemento = memento;
}
initializeMemento();
}

private void initializeMemento() {
// show all bundles by default (i.e. not just activated ones)
if (fMemento.getString(SHOW_RUNNING_PLUGINS) == null)
if (fMemento.getString(SHOW_RUNNING_PLUGINS) == null) {
fMemento.putString(SHOW_RUNNING_PLUGINS, "false"); //$NON-NLS-1$
if (fMemento.getInteger(GROUP_BY) == null)
}
if (fMemento.getInteger(GROUP_BY) == null) {
fMemento.putInteger(GROUP_BY, BUNDLES);
}

// default to not showing advanced options to users
if (fMemento.getString(SHOW_ADVANCED_MODE) == null)
if (fMemento.getString(SHOW_ADVANCED_MODE) == null) {
fMemento.putString(SHOW_ADVANCED_MODE, "false"); //$NON-NLS-1$
}
}

@Override
Expand Down Expand Up @@ -286,17 +292,19 @@ public int compare(Viewer viewer, Object e1, Object e2) {
return c1.compareTo(c2);
}

if (e1 instanceof Folder && e2 instanceof Folder)
if (e1 instanceof Folder && e2 instanceof Folder) {
return ((Folder) e1).getId() - ((Folder) e2).getId();
}
if (e1 instanceof Bundle && e2 instanceof Bundle) {
e1 = ((Bundle) e1).getSymbolicName();
e2 = ((Bundle) e2).getSymbolicName();
}
return super.compare(viewer, e1, e2);
}
});
if (fShowPluginsAction.isChecked())
if (fShowPluginsAction.isChecked()) {
fTreeViewer.addFilter(fActiveFilter);
}

initializeModel();

Expand All @@ -317,8 +325,9 @@ private void hookDoubleClickAction() {
IStructuredSelection selection = fTreeViewer.getStructuredSelection();
if (selection.size() == 1) {
Object obj = selection.getFirstElement();
if (obj instanceof Bundle)
if (obj instanceof Bundle) {
ManifestEditor.openPluginEditor(((Bundle) obj).getSymbolicName());
}
}
});
}
Expand Down Expand Up @@ -355,13 +364,16 @@ private void fillContextMenu(IMenuManager manager) {
// check if we should enable advanced actions
if (fShowAdvancedOperationsAction.isChecked() && isBundleSelected()) {
// control bundle state actions
if (selectedBundlesStopped())
if (selectedBundlesStopped()) {
manager.add(fStartAction);
if (selectedBundlesStarted())
}
if (selectedBundlesStarted()) {
manager.add(fStopAction);
}

if (getSelectedBundles().size() == 1)
if (getSelectedBundles().size() == 1) {
manager.add(fDiagnoseAction);
}
}

manager.add(new Separator());
Expand All @@ -372,8 +384,9 @@ private void fillContextMenu(IMenuManager manager) {

@Override
public void saveState(IMemento memento) {
if (memento == null || fMemento == null || fTreeViewer == null)
if (memento == null || fMemento == null || fTreeViewer == null) {
return;
}
fMemento.putString(SHOW_RUNNING_PLUGINS, Boolean.toString(fShowPluginsAction.isChecked()));
fMemento.putBoolean(SHOW_ADVANCED_MODE, fShowAdvancedOperationsAction.isChecked());
memento.putMemento(fMemento);
Expand Down Expand Up @@ -530,8 +543,9 @@ public void updateTitle() {
}

protected Tree getUndisposedTree() {
if (fTreeViewer == null || fTreeViewer.getTree() == null || fTreeViewer.getTree().isDisposed())
if (fTreeViewer == null || fTreeViewer.getTree() == null || fTreeViewer.getTree().isDisposed()) {
return null;
}
return fTreeViewer.getTree();
}

Expand All @@ -555,8 +569,9 @@ public String getTitleSummary() {
break;
}

if (tree == null)
if (tree == null) {
return NLS.bind(PDERuntimeMessages.RegistryView_titleSummary, (new String[] { "0", "0", type })); //$NON-NLS-1$ //$NON-NLS-2$
}
return NLS.bind(PDERuntimeMessages.RegistryView_titleSummary, (new String[] {Integer.toString(tree.getItemCount()), Integer.toString(total), type}));
}

Expand Down Expand Up @@ -595,8 +610,9 @@ private boolean selectedBundlesStarted() {
List<Bundle> bundles = getSelectedBundles();
for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
Bundle bundle = it.next();
if (bundle.getState() != Bundle.ACTIVE)
if (bundle.getState() != Bundle.ACTIVE) {
return false;
}
}
return true;
}
Expand All @@ -608,8 +624,9 @@ private boolean selectedBundlesStopped() {
List<Bundle> bundles = getSelectedBundles();
for (Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
Bundle bundle = it.next();
if (bundle.getState() == Bundle.ACTIVE)
if (bundle.getState() == Bundle.ACTIVE) {
return false;
}
}
return true;
}
Expand All @@ -624,21 +641,25 @@ public void add(Object object) {
}

protected void add(Object parent, Object object) {
if (fTreeViewer.getTree().isDisposed())
if (fTreeViewer.getTree().isDisposed()) {
return;
}

if (fDrillDownAdapter.canGoHome())
if (fDrillDownAdapter.canGoHome()) {
return;
}
fTreeViewer.refresh();
updateTitle();
}

public void remove(Object object) {
if (fTreeViewer.getTree().isDisposed())
if (fTreeViewer.getTree().isDisposed()) {
return;
}

if (fDrillDownAdapter.canGoHome())
if (fDrillDownAdapter.canGoHome()) {
return;
}
fTreeViewer.refresh();
updateTitle();
}
Expand All @@ -648,8 +669,9 @@ private boolean filtersEnabled() {
}

private void deferredRefresh() {
if (refreshThread != null)
if (refreshThread != null) {
return;
}

long now = System.currentTimeMillis();
if (now - lastRefresh > REFRESH_DELAY) {
Expand All @@ -664,8 +686,9 @@ private void deferredRefresh() {
return;
}
refreshThread = null;
if (fTreeViewer.getTree().isDisposed())
if (fTreeViewer.getTree().isDisposed()) {
return;
}

fTreeViewer.getTree().getDisplay().asyncExec(() -> {
if (!fTreeViewer.getTree().isDisposed()) {
Expand All @@ -680,8 +703,9 @@ private void deferredRefresh() {
}

void refresh(Object[] objects) {
if (fTreeViewer.getTree().isDisposed())
if (fTreeViewer.getTree().isDisposed()) {
return;
}

if (filtersEnabled()) {
deferredRefresh();
Expand All @@ -694,8 +718,9 @@ void refresh(Object[] objects) {
}

void refresh(Object object) {
if (fTreeViewer.getTree().isDisposed())
if (fTreeViewer.getTree().isDisposed()) {
return;
}

if (filtersEnabled()) {
deferredRefresh();
Expand Down
Loading
Loading