Skip to content

Commit

Permalink
[APITools] Various minor and local code clean-ups and simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Mar 16, 2024
1 parent 0849af2 commit 1cc0893
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 405 deletions.
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.api.tools.ui; singleton:=true
Bundle-Version: 1.3.300.qualifier
Bundle-Version: 1.3.400.qualifier
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Expand Down
Expand Up @@ -17,7 +17,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -84,9 +86,9 @@ protected boolean isDefaultBaseline(Object element) {

IApiBaselineManager manager = ApiPlugin.getDefault().getApiBaselineManager();

private static HashSet<String> removed = new HashSet<>(8);
private static Set<String> removed = new HashSet<>(8);
CheckboxTableViewer tableviewer = null;
ArrayList<IApiBaseline> backingcollection = new ArrayList<>(8);
List<IApiBaseline> backingcollection = new ArrayList<>(8);
String newdefault = null;
private Button newbutton = null;

Expand Down Expand Up @@ -271,8 +273,7 @@ protected void doEdit(final IApiBaseline baseline) {
* @return if the profile is the default or not
*/
protected boolean isDefault(Object element) {
if (element instanceof IApiBaseline) {
IApiBaseline profile = (IApiBaseline) element;
if (element instanceof IApiBaseline profile) {
if (newdefault == null) {
IApiBaseline def = ApiPlugin.getDefault().getApiBaselineManager().getDefaultApiBaseline();
if (def != null) {
Expand Down Expand Up @@ -378,7 +379,6 @@ private void findAndDeleteCompatibilityMarkers() {
}

}
return;
}

/**
Expand Down Expand Up @@ -429,11 +429,9 @@ protected void performDefaults() {
}
@Override
public void applyData(Object data) {
if (data instanceof Map) {
Map<?, ?> pageData = (Map<?, ?>) data;
if (data instanceof Map<?, ?> pageData) {
Object key = pageData.get(ApiErrorsWarningsPreferencePage.DATA_SELECT_OPTION_KEY);
if (key instanceof String) {
String option = (String) key;
if (key instanceof String option) {
if (option.equals(ApiBaselinePreferencePage.MISSING_BASELINE_OPTION)) {
block.selectOption(0);
}
Expand Down
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.pde.api.tools.ui.internal.preferences;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IMarker;
Expand Down Expand Up @@ -187,7 +188,7 @@ public String toString() {
*
* @return the new {@link Key} for the {@link ApiUIPlugin} preference store
*/
protected final static Key getApiToolsKey(String key) {
protected static final Key getApiToolsKey(String key) {
return new Key(ApiPlugin.PLUGIN_ID, key);
}

Expand Down Expand Up @@ -222,8 +223,7 @@ protected final static Key getApiToolsKey(String key) {
private final SelectionListener selectionlistener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.widget instanceof Combo) {
Combo combo = (Combo) e.widget;
if (e.widget instanceof Combo combo) {
ControlData data = (ControlData) combo.getData();
data.key.setStoredValue(fLookupOrder[0], combo.getText(), fManager);
fDirty = true;
Expand All @@ -236,11 +236,11 @@ public void widgetSelected(SelectionEvent e) {
* Listing of all of the {@link Combo}s added to the block
*/

private final ArrayList<Combo> fCombos = new ArrayList<>();
private final List<Combo> fCombos = new ArrayList<>();
/**
* Listing of the label in the block
*/
private final ArrayList<Label> fLabels = new ArrayList<>();
private final List<Label> fLabels = new ArrayList<>();

/**
* The context of settings locations to search for values in
Expand Down Expand Up @@ -323,7 +323,7 @@ public void performApply() {
private void save() {
if (fDirty) {
try {
ArrayList<Key> changes = new ArrayList<>();
List<Key> changes = new ArrayList<>();
collectChanges(fLookupOrder[0], changes);
filterOutChanges(changes);
if (changes.size() == 1 && changes.get(0).equals(KEY_MISSING_DEFAULT_API_PROFILE)) {
Expand All @@ -345,10 +345,8 @@ private void save() {
updateMissingBaselineMarkerSeverity(IMarker.SEVERITY_WARNING);
}
// if ignore to warning - calculate
if (original.equals(ApiPlugin.VALUE_IGNORE)) {
if (hasBaseline == false) {
createMissingBaselineMarker(IMarker.SEVERITY_WARNING);
}
if (original.equals(ApiPlugin.VALUE_IGNORE) && !hasBaseline) {
createMissingBaselineMarker(IMarker.SEVERITY_WARNING);
}

} else if (newval.equals(ApiPlugin.VALUE_ERROR)) {
Expand All @@ -357,17 +355,15 @@ private void save() {
updateMissingBaselineMarkerSeverity(IMarker.SEVERITY_ERROR);
}
// if ignore to warning - calculate
if (original.equals(ApiPlugin.VALUE_IGNORE)) {
if (hasBaseline == false) {
createMissingBaselineMarker(IMarker.SEVERITY_ERROR);
}
if (original.equals(ApiPlugin.VALUE_IGNORE) && !hasBaseline) {
createMissingBaselineMarker(IMarker.SEVERITY_ERROR);
}
}
fDirty = false;
return;
}
// code below probably redundant now
if (changes.size() > 0) {
if (!changes.isEmpty()) {
if (ApiBaselinePreferencePage.rebuildcount < 1) {
ApiBaselinePreferencePage.rebuildcount++;
fManager.applyChanges();
Expand All @@ -393,18 +389,16 @@ private void save() {
}

// Filter out redundant change
private void filterOutChanges(ArrayList<Key> changes) {
private void filterOutChanges(List<Key> changes) {
if (changes.size() == 2) {
Key k1 = changes.get(0);
String original1 = k1.getStoredValue(fLookupOrder[0], null);
String newval1 = k1.getStoredValue(fLookupOrder[0], fManager);
if (original1 == null && newval1 == null) {
changes.remove(0);
}
if (original1 != null && newval1 != null) {
if (original1.equals(newval1)) {
changes.remove(0);
}
if (original1 != null && newval1 != null && original1.equals(newval1)) {
changes.remove(0);
}
if (changes.size() == 2) {
Key k2 = changes.get(1);
Expand All @@ -413,18 +407,16 @@ private void filterOutChanges(ArrayList<Key> changes) {
if (original2 == null && newval2 == null) {
changes.remove(1);
}
if (original2 != null && newval2 != null) {
if (original2.equals(newval2)) {
changes.remove(1);
}
if (original2 != null && newval2 != null && original2.equals(newval2)) {
changes.remove(1);
}
}

}
}

private void updateMissingBaselineMarkerSeverity(int severity) {
ArrayList<IMarker> marker = findMissingBaselineMarker();
List<IMarker> marker = findMissingBaselineMarker();

for (IMarker iMarker : marker) {
try {
Expand All @@ -436,7 +428,7 @@ private void updateMissingBaselineMarkerSeverity(int severity) {
}

private void deleteMissingBaselineMarker() {
ArrayList<IMarker> marker = findMissingBaselineMarker();
List<IMarker> marker = findMissingBaselineMarker();
for (IMarker iMarker : marker) {
try {
iMarker.delete();
Expand Down Expand Up @@ -508,29 +500,26 @@ private void createMissingBaselineMarkerOnProject(IResource res, int valueWarnin
}
}

private ArrayList<IMarker> findMissingBaselineMarker() {
ArrayList<IMarker> markList = new ArrayList<>();
private List<IMarker> findMissingBaselineMarker() {
List<IMarker> markList = new ArrayList<>();
int missing_plugin = ApiProblemFactory.createProblemId(IApiProblem.CATEGORY_API_BASELINE,
IElementDescriptor.RESOURCE, IApiProblem.API_PLUGIN_NOT_PRESENT_IN_BASELINE, IApiProblem.NO_FLAGS);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
IMarker[] findMarkers = root.findMarkers(IApiMarkerConstants.DEFAULT_API_BASELINE_PROBLEM_MARKER, false,
IResource.DEPTH_ZERO);
for (IMarker iMarker : findMarkers) {
markList.add(iMarker);
}
Collections.addAll(markList, findMarkers);
} catch (CoreException e) {
ApiPlugin.log(e);
}
IProject[] apiProjects = Util.getApiProjects();
if (apiProjects == null) {
return markList;
}
for (IProject iProject : apiProjects) {
IMarker[] findMarkers;
for (IProject project : apiProjects) {
try {
findMarkers = iProject.findMarkers(IApiMarkerConstants.DEFAULT_API_BASELINE_PROBLEM_MARKER, false,
IResource.DEPTH_ZERO);
IMarker[] findMarkers = project.findMarkers(IApiMarkerConstants.DEFAULT_API_BASELINE_PROBLEM_MARKER,
false, IResource.DEPTH_ZERO);
for (IMarker iMarker : findMarkers) {
int id = ApiProblemFactory.getProblemId(iMarker);
if (id == missing_plugin) {
Expand Down Expand Up @@ -639,13 +628,10 @@ public static Key[] getAllKeys() {
public void selectOption(int index) {
if (fCombos.get(index) != null && !fCombos.get(index).isDisposed()) {
fCombos.get(index).setFocus();
if (fLabels.get(index) != null && !(fLabels.get(index).isDisposed())) {
if (org.eclipse.jface.util.Util.isMac()) {
if (fLabels.get(index) != null) {
highlight(fCombos.get(index).getParent(), fLabels.get(index), fCombos.get(index),
ConfigurationBlock.HIGHLIGHT_FOCUS);
}
}
Label label = fLabels.get(index);
if (label != null && !label.isDisposed() && org.eclipse.jface.util.Util.isMac()) {
highlight(fCombos.get(index).getParent(), label, fCombos.get(index),
ConfigurationBlock.HIGHLIGHT_FOCUS);
}
}
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionException;
Expand Down Expand Up @@ -585,10 +586,10 @@ public void widgetSelected(SelectionEvent e) {
ControlData data = (ControlData) widget.getData();
Key key = data.getKey();
String newValue = null;
if (widget instanceof Button) {
newValue = data.getValue(((Button) widget).getSelection());
} else if (widget instanceof Combo) {
newValue = data.getValue(((Combo) widget).getSelectionIndex());
if (widget instanceof Button button) {
newValue = data.getValue(button.getSelection());
} else if (widget instanceof Combo combo) {
newValue = data.getValue(combo.getSelectionIndex());
} else {
return;
}
Expand Down Expand Up @@ -677,22 +678,22 @@ public void widgetSelected(SelectionEvent e) {
/**
* Listing of all of the {@link ExpandableComposite}s in the block
*/
private final ArrayList<ExpandableComposite> fExpComps = new ArrayList<>();
private final List<ExpandableComposite> fExpComps = new ArrayList<>();

/**
* Listing of all of the {@link Combo}s added to the block
*/
private final ArrayList<Combo> fCombos = new ArrayList<>();
private final List<Combo> fCombos = new ArrayList<>();

/**
* Map of combo and label
*/
private final HashMap<Combo, Label> fComboLabelMap = new HashMap<>();
private final Map<Combo, Label> fComboLabelMap = new HashMap<>();

/**
* Listing of all of the {@link Button} with SWT.check added to the block
*/
private final ArrayList<Button> fCheckBoxes = new ArrayList<>();
private final List<Button> fCheckBoxes = new ArrayList<>();

/**
* Control used inside the system library ee group
Expand Down Expand Up @@ -1241,8 +1242,7 @@ public void expansionStateChanged(ExpansionEvent e) {
* Returns the scrolling parent for the given ExpandibleComposite object
*/
ScrolledComposite getScrollingParent(Object obj) {
if (obj instanceof ExpandableComposite) {
ExpandableComposite ecomp = (ExpandableComposite) obj;
if (obj instanceof ExpandableComposite ecomp) {
Composite parent = ecomp.getParent();
while (parent != null && !(parent instanceof ScrolledComposite)) {
parent = parent.getParent();
Expand All @@ -1251,8 +1251,8 @@ ScrolledComposite getScrollingParent(Object obj) {
return (ScrolledComposite) parent;
}
}
if (obj instanceof ScrolledComposite) {
return (ScrolledComposite) obj;
if (obj instanceof ScrolledComposite scrolledComposite) {
return scrolledComposite;
}
return null;
}
Expand Down Expand Up @@ -1299,9 +1299,9 @@ public void performApply() {
private void save() {
if (fDirty) {
try {
ArrayList<Key> changes = new ArrayList<>();
List<Key> changes = new ArrayList<>();
collectChanges(fLookupOrder[0], changes);
if (changes.size() > 0) {
if (!changes.isEmpty()) {
if (fRebuildcount < 1) {
fRebuildcount++;
fManager.applyChanges();
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -106,7 +107,7 @@ protected Control createContents(Composite parent) {
link.setFont(comp.getFont());
link.setText(PreferenceMessages.ApiErrorsWarningsPreferencePage_1);
link.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
HashSet<IJavaProject> set = new HashSet<>();
Set<IJavaProject> set = new HashSet<>();
try {
IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
IProject project = null;
Expand All @@ -125,7 +126,7 @@ protected Control createContents(Composite parent) {
}
ProjectSelectionDialog psd = new ProjectSelectionDialog(getShell(), set);
if (psd.open() == IDialogConstants.OK_ID) {
HashMap<String, Boolean> data = new HashMap<>();
Map<String, Boolean> data = new HashMap<>();
data.put(NO_LINK, Boolean.TRUE);
PreferencesUtil.createPropertyDialogOn(getShell(), ((IJavaProject) psd.getFirstResult()).getProject(),
IApiToolsConstants.ID_ERRORS_WARNINGS_PROP_PAGE,
Expand Down
Expand Up @@ -281,9 +281,9 @@ public void performApply() {
*/
private void save() {
try {
ArrayList<Key> changes = new ArrayList<>();
List<Key> changes = new ArrayList<>();
collectChanges(fLookupOrder[0], changes);
if (changes.size() > 0) {
if (!changes.isEmpty()) {
fManager.applyChanges();
}

Expand Down

0 comments on commit 1cc0893

Please sign in to comment.