Skip to content
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

Clean Code for ds/org.eclipse.pde.ds.ui #1648

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 ds/org.eclipse.pde.ds.ui/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: %pluginName
Bundle-SymbolicName: org.eclipse.pde.ds.ui;singleton:=true
Bundle-Version: 1.4.0.qualifier
Bundle-Version: 1.4.100.qualifier
Bundle-Activator: org.eclipse.pde.internal.ds.ui.Activator
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.30.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.20.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ public static void logException(Throwable e, final String title,
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException)
if (e instanceof CoreException) {
status = ((CoreException) e).getStatus();
else {
if (message == null)
} else {
if (message == null) {
message = e.getMessage();
if (message == null)
}
if (message == null) {
message = e.toString();
}
status = Status.error(message, e);
}
ResourcesPlugin.getPlugin().getLog().log(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public class SWTUtil {
public static Display getStandardDisplay() {
Display display;
display = Display.getCurrent();
if (display == null)
if (display == null) {
display = Display.getDefault();
}
return display;
}

Expand All @@ -59,18 +60,24 @@ public static Display getStandardDisplay() {
* @return the shell for the given widget
*/
public static Shell getShell(Widget widget) {
if (widget instanceof Control)
if (widget instanceof Control) {
return ((Control) widget).getShell();
if (widget instanceof Caret)
}
if (widget instanceof Caret) {
return ((Caret) widget).getParent().getShell();
if (widget instanceof DragSource)
}
if (widget instanceof DragSource) {
return ((DragSource) widget).getControl().getShell();
if (widget instanceof DropTarget)
}
if (widget instanceof DropTarget) {
return ((DropTarget) widget).getControl().getShell();
if (widget instanceof Menu)
}
if (widget instanceof Menu) {
return ((Menu) widget).getParent().getShell();
if (widget instanceof ScrollBar)
}
if (widget instanceof ScrollBar) {
return ((ScrollBar) widget).getParent().getShell();
}

return null;
}
Expand All @@ -79,8 +86,9 @@ public static Shell getShell(Widget widget) {
* Returns a width hint for a button control.
*/
public static int getButtonWidthHint(Button button) {
if (button.getFont().equals(JFaceResources.getDefaultFont()))
if (button.getFont().equals(JFaceResources.getDefaultFont())) {
button.setFont(JFaceResources.getDialogFont());
}
PixelConverter converter = new PixelConverter(button);
int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public static Image getImage(String key, int flags) {
if ((flags & F_DYNAMIC) != 0) {
Image o = Activator.getDefault().getImageRegistry().get(
key + OVR_DYNAMIC);
if (o != null)
if (o != null) {
return o;
}
Image i = new DecorationOverlayIcon(image, SharedImages
.getImageDescriptor(OVR_DYNAMIC),
IDecoration.TOP_RIGHT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public DSHyperlinkDetector(PDESourcePage page) {
@Override
protected IHyperlink[] detectAttributeHyperlink(IDocumentAttributeNode attr) {
String attrValue = attr.getAttributeValue();
if (attrValue.length() == 0)
if (attrValue.length() == 0) {
return null;
}

if (!(attr.getEnclosingElement() instanceof IDSObject)) {
return null;
}
IDSObject node = (IDSObject) attr.getEnclosingElement();

if (node == null || !node.getModel().isEditable())
if (node == null || !node.getModel().isEditable()) {
return null;
}

IRegion linkRegion = new Region(attr.getValueOffset(), attr
.getValueLength());
Expand Down Expand Up @@ -96,8 +98,9 @@ protected IHyperlink[] detectAttributeHyperlink(IDocumentAttributeNode attr) {
// declarations?
}

if (link[0] != null)
if (link[0] != null) {
return link;
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public String getText(Object obj) {
return getObjectText((IDSObject) obj);
}

if (obj instanceof IFormPage)
if (obj instanceof IFormPage) {
return ((IFormPage) obj).getTitle();
}

return super.getText(obj);
}
Expand All @@ -49,8 +50,9 @@ public String getObjectText(IDSObject obj) {
if (obj.getType() == IDSConstants.TYPE_REFERENCE) {
IDSReference reference = (IDSReference) obj;
if (reference.getName() == null
|| reference.getName().length() == 0)
|| reference.getName().length() == 0) {
return reference.getReferenceInterface();
}
}
return obj.getName();
}
Expand All @@ -62,9 +64,10 @@ public Image getImage(Object obj) {
}

// TODO consider changing this
if (obj instanceof IFormPage)
if (obj instanceof IFormPage) {
return PDEPlugin.getDefault().getLabelProvider().get(
PDEPluginImages.DESC_PAGE_OBJ);
}

return super.getImage(obj);
}
Expand All @@ -83,9 +86,10 @@ private Image getObjectImage(IDSObject obj) {
int flags = 0;

if (reference == null || reference.getReferencePolicy() == null
|| reference.getReferenceCardinality() == null)
|| reference.getReferenceCardinality() == null) {
return SharedImages
.getImage(SharedImages.DESC_REFERENCE, flags);
}

if (reference.getReferencePolicy().equals(
IDSConstants.VALUE_REFERENCE_POLICY_DYNAMIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ protected void setPartName(String partName) {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (IHyperlinkDetector.class.equals(adapter))
if (IHyperlinkDetector.class.equals(adapter)) {
return (T) new DSHyperlinkDetector(this);
}
return super.getAdapter(adapter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {

@Override
public void dispose() {
if (fContentAssistProcessor != null)
if (fContentAssistProcessor != null) {
fContentAssistProcessor.dispose();
}
super.dispose();
}

@Override
public ITextHover getTextHover(ISourceViewer sourceViewer,
String contentType) {
if (fTextHover == null && fSourcePage != null)
if (fTextHover == null && fSourcePage != null) {
fTextHover = new DSTextHover(fSourcePage);
}
return fTextHover;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ public DSTextHover(PDESourcePage sourcePage) {
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
int offset = hoverRegion.getOffset();
IDocumentRange range = fSourcePage.getRangeElement(offset, true);
if (range instanceof IDocumentTextNode)
if (range instanceof IDocumentTextNode) {
return checkTranslatedValue((IDocumentTextNode) range);
if (!(range instanceof IDSObject))
}
if (!(range instanceof IDSObject)) {
return null;
}

return ((IDSObject) range).getName();

}

private String checkTranslatedValue(IDocumentTextNode node) {
String value = node.getText();
if (value.startsWith("%")) //$NON-NLS-1$
if (value.startsWith("%")) { //$NON-NLS-1$
return ((IPluginObject) node.getEnclosingElement())
.getResourceString(value);
.getResourceString(value);
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public DSTypeSelectionExtension(IDSModel model) {
@Override
public ITypeInfoFilterExtension getFilterExtension() {
IDSService service = fModel.getDSComponent().getService();
if (service != null)
if (service != null) {
return new TypeInfoFilterExtension(service.getProvidedServices());
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ public void browseButtonSelected(FormEntry entry) {

@Override
public void linkEntered(HyperlinkEvent e) {
if (actionBars == null)
if (actionBars == null) {
return;
}
IStatusLineManager mng = actionBars.getStatusLineManager();
mng.setMessage(e.getLabel());
}

@Override
public void linkExited(HyperlinkEvent e) {
if (actionBars == null)
if (actionBars == null) {
return;
}
IStatusLineManager mng = actionBars.getStatusLineManager();
mng.setMessage(null);
}
Expand Down
Loading
Loading