Skip to content

Clean Code for ui/org.eclipse.pde.ui #1663

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 1 commit into from
Mar 11, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,17 @@ public String getObjectText(IPluginBase pluginBase) {

String text;

if (version != null && version.length() > 0)
if (version != null && version.length() > 0) {
text = name + ' ' + formatVersion(pluginBase.getVersion());
else
} else {
text = name;
}
if (SYSTEM_BUNDLE.equals(pluginBase.getId())) {
text += getSystemBundleInfo();
}
if (pluginBase.getModel() != null && !pluginBase.getModel().isInSync())
if (pluginBase.getModel() != null && !pluginBase.getModel().isInSync()) {
text += " " + PDEUIMessages.PluginModelManager_outOfSync; //$NON-NLS-1$
}
return text;
}

Expand All @@ -225,12 +227,14 @@ public String getObjectText(IPluginExtensionPoint point) {

public String getObjectText(ImportObject obj) {
String version = obj.getImport().getVersion();
if (version != null && version.length() > 0)
if (version != null && version.length() > 0) {
version = formatVersion(version);
}

String text = isFullNameModeEnabled() ? obj.toString() : preventNull(obj.getId());
if (SYSTEM_BUNDLE.equals(obj.getId()))
if (SYSTEM_BUNDLE.equals(obj.getId())) {
return text + getSystemBundleInfo();
}
return version == null || version.length() == 0 ? text : text + " " + version; //$NON-NLS-1$
}

Expand All @@ -239,10 +243,11 @@ public String getObjectText(IProductPlugin obj) {
String name = obj.getId();
String version = obj.getVersion();
String text;
if (version != null && version.length() > 0)
if (version != null && version.length() > 0) {
text = name + ' ' + formatVersion(obj.getVersion());
else
} else {
text = name;
}
return preventNull(text);
}

Expand Down Expand Up @@ -285,15 +290,17 @@ public String getObjectText(ISchemaObject obj) {
int maxOccurs = rso.getMaxOccurs();
int minOccurs = rso.getMinOccurs();
if (maxOccurs != 1 || minOccurs != 1) {
if (isRTL() && SWTUtil.isBidi())
if (isRTL() && SWTUtil.isBidi()) {
text.append('\u200f');
}
text.append(" ("); //$NON-NLS-1$
text.append(minOccurs);
text.append(" - "); //$NON-NLS-1$
if (unbounded)
if (unbounded) {
text.append('*');
else
} else {
text.append(maxOccurs);
}
text.append(')');
}
}
Expand All @@ -312,10 +319,11 @@ public String getObjectText(FeaturePlugin obj) {

String text;

if (version != null && version.length() > 0)
if (version != null && version.length() > 0) {
text = name + ' ' + formatVersion(version);
else
} else {
text = name;
}
return preventNull(text);
}

Expand All @@ -338,8 +346,9 @@ public String getObjectText(FeatureImport obj) {
public String getObjectText(IFeatureModel obj, boolean showVersion) {
IFeature feature = obj.getFeature();
String name = (isFullNameModeEnabled()) ? feature.getTranslatableLabel() : feature.getId();
if (!showVersion)
if (!showVersion) {
return preventNull(name);
}
return preventNull(name) + ' ' + formatVersion(feature.getVersion());

}
Expand All @@ -357,8 +366,9 @@ public String getObjectText(IProductFeature obj) {
if (obj.isRootInstallMode()) {
name += " (root)"; //$NON-NLS-1$
}
if (VersionUtil.isEmptyVersion(obj.getVersion()))
if (VersionUtil.isEmptyVersion(obj.getVersion())) {
return name;
}
return name + ' ' + formatVersion(obj.getVersion());
}

Expand All @@ -376,19 +386,22 @@ private String getObjectText(IProductModel obj) {

public String getObjectText(ISiteFeature obj) {
IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(obj.getId(), obj.getVersion() != null ? obj.getVersion() : ICoreConstants.DEFAULT_VERSION);
if (model != null)
if (model != null) {
return getObjectText(model);
}
String url = obj.getURL();
if (url != null)
if (url != null) {
return url;
}
return preventNull(obj.getId());
}

public String getObjectText(ISiteBundle obj) {
IPluginModelBase modelBase = PluginRegistry.findModel(obj.getId(), obj.getVersion(),
VersionMatchRule.COMPATIBLE);
if (modelBase != null)
if (modelBase != null) {
return getObjectText(modelBase.getPluginBase());
}
return preventNull(obj.getId());
}

Expand All @@ -413,8 +426,9 @@ public String getObjectText(PackageObject obj) {

public String getObjectText(ISiteCategory obj) {
ISiteCategoryDefinition def = obj.getDefinition();
if (def != null)
if (def != null) {
return preventNull(def.getLabel());
}
return preventNull(obj.getName());
}

Expand Down Expand Up @@ -484,8 +498,9 @@ public Image getImage(Object obj) {
}
if (obj instanceof IFeatureModel) {
int flags = 0;
if (((IFeatureModel) obj).getUnderlyingResource() == null)
if (((IFeatureModel) obj).getUnderlyingResource() == null) {
flags |= F_EXTERNAL;
}
return get(PDEPluginImages.DESC_FEATURE_OBJ, flags);
}
if (obj instanceof IFeatureChild) {
Expand Down Expand Up @@ -571,18 +586,21 @@ public Image getObjectImage(IPlugin plugin, boolean checkEnabled, boolean javaSe
IPluginModelBase model = plugin.getPluginModel();
int flags = getModelFlags(model);

if (javaSearch)
if (javaSearch) {
flags |= F_JAVA;
}
ImageDescriptor desc = PDEPluginImages.DESC_PLUGIN_OBJ;
if (checkEnabled && model.isEnabled() == false)
if (checkEnabled && model.isEnabled() == false) {
desc = PDEPluginImages.DESC_EXT_PLUGIN_OBJ;
}
return get(desc, flags);
}

private int getModelFlags(IPluginModelBase model) {
int flags = 0;
if (!(model.isLoaded() && model.isInSync()))
if (!(model.isLoaded() && model.isInSync())) {
flags = F_ERROR;
}
IResource resource = model.getUnderlyingResource();
if (resource == null) {
flags |= F_EXTERNAL;
Expand Down Expand Up @@ -613,23 +631,27 @@ private Image getObjectImage(IFragment fragment) {
public Image getObjectImage(IFragment fragment, boolean checkEnabled, boolean javaSearch) {
IPluginModelBase model = fragment.getPluginModel();
int flags = getModelFlags(model);
if (javaSearch)
if (javaSearch) {
flags |= F_JAVA;
}
ImageDescriptor desc = PDEPluginImages.DESC_FRAGMENT_OBJ;
if (checkEnabled && !model.isEnabled())
if (checkEnabled && !model.isEnabled()) {
desc = PDEPluginImages.DESC_EXT_FRAGMENT_OBJ;
}
return get(desc, flags);
}

private Image getObjectImage(ImportObject iobj) {
int flags = 0;
IPluginImport iimport = iobj.getImport();
if (!iobj.isResolved())
if (!iobj.isResolved()) {
flags = iimport.isOptional() ? F_WARNING : F_ERROR;
else if (iimport.isReexported())
} else if (iimport.isReexported()) {
flags = F_EXPORT;
if (iimport.isOptional())
}
if (iimport.isOptional()) {
flags |= F_OPTIONAL;
}
IPlugin plugin = iobj.getPlugin();
if (plugin != null) {
IPluginModelBase model = plugin.getPluginModel();
Expand All @@ -656,8 +678,9 @@ private Image getObjectImage(IPluginElement obj) {
ISchemaElement schemaElement = schema.findElement(obj.getName());
// Only label an element if either the element is deprecated or it actually specifies a deprecated attribute;
// We don't want to mislabel non-deprecated elements with no deprecated attributes.
if (schemaElement != null && (schemaElement.isDeprecated() || hasDeprecatedAttributes(obj, schemaElement)))
if (schemaElement != null && (schemaElement.isDeprecated() || hasDeprecatedAttributes(obj, schemaElement))) {
flags |= F_WARNING;
}
}
}
return get(getRequiredPluginImageDescriptor(obj), flags);
Expand All @@ -682,8 +705,9 @@ protected ImageDescriptor getRequiredPluginImageDescriptor(IPluginImport iobj) {

private Image getObjectImage(IPluginImport obj) {
int flags = 0;
if (obj.isReexported())
if (obj.isReexported()) {
flags |= F_EXPORT;
}
return get(getRequiredPluginImageDescriptor(obj), flags);
}

Expand All @@ -710,8 +734,9 @@ private Image getObjectImage(IPluginExtensionPoint point) {

private Image getObjectImage(ISchemaElement element) {
int flags = 0;
if (element instanceof ISchemaObjectReference && ((ISchemaObjectReference) element).getReferencedObject() == null)
if (element instanceof ISchemaObjectReference && ((ISchemaObjectReference) element).getReferencedObject() == null) {
flags |= F_ERROR;
}
ImageDescriptor desc = element instanceof ISchemaObjectReference ? PDEPluginImages.DESC_XML_ELEMENT_REF_OBJ : PDEPluginImages.DESC_GEL_SC_OBJ;
return get(desc, flags);
}
Expand All @@ -721,16 +746,21 @@ private Image getObjectImage(ISchemaAttribute att) {
String type = att.getType().getName();
int use = att.getUse();
int flags = 0;
if (use == ISchemaAttribute.OPTIONAL)
if (use == ISchemaAttribute.OPTIONAL) {
flags = 0; //|= F_OPTIONAL;
if (kind == IMetaAttribute.JAVA)
}
if (kind == IMetaAttribute.JAVA) {
return get(PDEPluginImages.DESC_ATT_CLASS_OBJ, flags);
if (kind == IMetaAttribute.RESOURCE)
}
if (kind == IMetaAttribute.RESOURCE) {
return get(PDEPluginImages.DESC_ATT_FILE_OBJ, flags);
if (kind == IMetaAttribute.IDENTIFIER)
}
if (kind == IMetaAttribute.IDENTIFIER) {
return get(PDEPluginImages.DESC_ATT_ID_OBJ, flags);
if (type.equals(ISchemaAttribute.TYPES[ISchemaAttribute.BOOL_IND]))
}
if (type.equals(ISchemaAttribute.TYPES[ISchemaAttribute.BOOL_IND])) {
return get(PDEPluginImages.DESC_ATT_BOOLEAN_OBJ, flags);
}

return get(PDEPluginImages.DESC_ATT_STRING_OBJ);
}
Expand All @@ -753,24 +783,27 @@ private Image getObjectImage(IFeaturePlugin plugin) {
int flags = 0;
if (((FeaturePlugin) plugin).getPluginBase() == null) {
int cflag = CompilerFlags.getFlag(null, CompilerFlags.F_UNRESOLVED_PLUGINS);
if (cflag == CompilerFlags.ERROR)
if (cflag == CompilerFlags.ERROR) {
flags = F_ERROR;
else if (cflag == CompilerFlags.WARNING)
} else if (cflag == CompilerFlags.WARNING) {
flags = F_WARNING;
}
}
if (plugin.isFragment())
if (plugin.isFragment()) {
return get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
}
return get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
}

private Image getObjectImage(IFeatureChild feature) {
int flags = 0;
if (((FeatureChild) feature).getReferencedFeature() == null) {
int cflag = CompilerFlags.getFlag(null, CompilerFlags.F_UNRESOLVED_FEATURES);
if (cflag == CompilerFlags.ERROR)
if (cflag == CompilerFlags.ERROR) {
flags = F_ERROR;
else if (cflag == CompilerFlags.WARNING)
} else if (cflag == CompilerFlags.WARNING) {
flags = F_WARNING;
}
}
return get(PDEPluginImages.DESC_FEATURE_OBJ, flags);
}
Expand All @@ -779,15 +812,17 @@ private Image getObjectImage(IProductFeature feature) {
int flags = 0;
String version = feature.getVersion().length() > 0 ? feature.getVersion() : ICoreConstants.DEFAULT_VERSION;
IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(feature.getId(), version);
if (model == null)
if (model == null) {
flags = F_ERROR;
}
return get(PDEPluginImages.DESC_FEATURE_OBJ, flags);
}

private Image getObjectImage(IFeatureData data) {
int flags = 0;
if (!data.exists())
if (!data.exists()) {
flags = F_ERROR;
}
ImageDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(data.getId());
return get(desc, flags);
}
Expand All @@ -801,13 +836,15 @@ private Image getObjectImage(IFeatureImport obj) {
if (type == IFeatureImport.FEATURE) {
base = PDEPluginImages.DESC_FEATURE_OBJ;
IFeature feature = iimport.getFeature();
if (feature == null)
if (feature == null) {
flags = F_ERROR;
}
} else {
base = PDEPluginImages.DESC_REQ_PLUGIN_OBJ;
IPlugin plugin = iimport.getPlugin();
if (plugin == null)
if (plugin == null) {
flags = F_ERROR;
}
}

return get(base, flags);
Expand All @@ -816,8 +853,9 @@ private Image getObjectImage(IFeatureImport obj) {
private Image getObjectImage(IFeatureInfo info) {
int flags = 0;
String text = info.getDescription();
if (text != null)
if (text != null) {
text = text.trim();
}
if (text != null && text.length() > 0) {
// complete
flags = F_EDIT;
Expand Down Expand Up @@ -855,8 +893,9 @@ public Image getObjectImage(ExportPackageObject obj) {
if (obj.isInternal()) {
flags = F_INTERNAL;
// if internal with at least one friend
if (obj.getFriends().length > 0)
if (obj.getFriends().length > 0) {
flags = F_FRIEND;
}
}
ImageDescriptor desc = JavaUI.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_PACKAGE);
return get(desc, flags);
Expand Down Expand Up @@ -914,11 +953,12 @@ private static boolean isRTL() {
public static String formatVersion(String versionRange) {
boolean isBasicVersion = versionRange == null || versionRange.length() == 0 || Character.isDigit(versionRange.charAt(0));
if (isBasicVersion) {
if (SWTUtil.isBidi())
if (SWTUtil.isBidi()) {
// The versionRange is a single version. Since parenthesis is neutral, it direction is determined by leading and following character.
// Since leading character is Arabic and following character is Latin, the parenthesis will take default (proper) direction.
// Must have the following character be the Latin character to ensure version is formatted as Latin (LTR)
return "\u200f(\u200e" + versionRange + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
return "(" + versionRange + ')'; //$NON-NLS-1$
} else if (isRTL() && SWTUtil.isBidi()) {
// when running RTL and formatting a versionRange, we need to break up the String to make sure it is properly formatted.
Expand Down
Loading
Loading