diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/CompositeManifestHeader.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/CompositeManifestHeader.java index 86865072c2..c1b82bd0a2 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/CompositeManifestHeader.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/CompositeManifestHeader.java @@ -14,9 +14,11 @@ package org.eclipse.pde.internal.core.text.bundle; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.Vector; import org.eclipse.osgi.util.ManifestElement; import org.eclipse.pde.core.IModelChangedEvent; @@ -32,7 +34,7 @@ public class CompositeManifestHeader extends ManifestHeader { private final boolean fSort; - protected ArrayList fManifestElements; + protected List fManifestElements; protected Map fElementMap; @@ -105,12 +107,12 @@ protected void addManifestElement(PDEManifestElement element) { addManifestElement(element, true); } - protected void addManifestElements(PDEManifestElement[] elements) { + protected void addManifestElements(List elements) { for (PDEManifestElement element : elements) { addManifestElement(element, false); } update(false); - fireStructureChanged(elements, IModelChangedEvent.INSERT); + fireStructureChanged(elements.toArray(PDEManifestElement[]::new), IModelChangedEvent.INSERT); } protected void addManifestElement(PDEManifestElement element, boolean update) { @@ -145,7 +147,7 @@ protected Object removeManifestElement(String name) { } } else if (fManifestElements != null) { for (int i = 0; i < fManifestElements.size(); i++) { - PDEManifestElement element = (PDEManifestElement) fManifestElements.get(i); + PDEManifestElement element = fManifestElements.get(i); if (name.equals(element.getValue())) { object = fManifestElements.remove(i); } @@ -183,8 +185,7 @@ public boolean hasElement(String name) { } if (fManifestElements != null) { - for (int i = 0; i < fManifestElements.size(); i++) { - PDEManifestElement element = (PDEManifestElement) fManifestElements.get(i); + for (PDEManifestElement element : fManifestElements) { if (name.equals(element.getValue())) { return true; } @@ -193,13 +194,9 @@ public boolean hasElement(String name) { return false; } - public Vector getElementNames() { + public List getElementNames() { PDEManifestElement[] elements = getElements(); - Vector vector = new Vector<>(elements.length); - for (PDEManifestElement element : elements) { - vector.add(element.getValue()); - } - return vector; + return Arrays.stream(elements).map(PDEManifestElement::getValue).toList(); } public void swap(int index1, int index2) { @@ -208,17 +205,14 @@ public void swap(int index1, int index2) { } int size = fManifestElements.size(); if (index1 >= 0 && index2 >= 0 && size > Math.max(index1, index2)) { - Object object1 = fManifestElements.get(index1); - Object object2 = fManifestElements.get(index2); - fManifestElements.set(index1, object2); - fManifestElements.set(index2, object1); + Collections.swap(fManifestElements, index1, index2); update(true); } } protected PDEManifestElement getElementAt(int index) { if (fManifestElements != null && fManifestElements.size() > index) { - return (PDEManifestElement) fManifestElements.get(index); + return fManifestElements.get(index); } return null; } @@ -228,7 +222,7 @@ protected PDEManifestElement getElementAt(int index) { */ public PDEManifestElement getPreviousElement(PDEManifestElement targetElement) { // Ensure we have elements - if (fSort == true) { + if (fSort) { return null; } else if (fManifestElements == null) { return null; @@ -247,9 +241,7 @@ public PDEManifestElement getPreviousElement(PDEManifestElement targetElement) { } // 1 <= index < size() // Get the previous element - PDEManifestElement previousElement = (PDEManifestElement) fManifestElements.get(targetIndex - 1); - - return previousElement; + return fManifestElements.get(targetIndex - 1); } /** @@ -257,7 +249,7 @@ public PDEManifestElement getPreviousElement(PDEManifestElement targetElement) { */ public PDEManifestElement getNextElement(PDEManifestElement targetElement) { // Ensure we have elements - if (fSort == true) { + if (fSort) { return null; } else if (fManifestElements == null) { return null; @@ -278,9 +270,7 @@ public PDEManifestElement getNextElement(PDEManifestElement targetElement) { } // 0 <= index < last element < size() // Get the next element - PDEManifestElement nextElement = (PDEManifestElement) fManifestElements.get(targetIndex + 1); - - return nextElement; + return fManifestElements.get(targetIndex + 1); } /** @@ -293,7 +283,7 @@ protected void addManifestElement(PDEManifestElement element, int index, boolean elementCount = fManifestElements.size(); } // 0 <= index <= size() - if (fSort == true) { + if (fSort) { return; } else if (index < 0) { return; @@ -334,29 +324,4 @@ public int indexOf(PDEManifestElement targetElement) { return fManifestElements.indexOf(targetElement); } - /** - * Method not applicable for headers that are sorted - */ - protected PDEManifestElement removeManifestElement(PDEManifestElement element, boolean update) { - if (fSort) { - return null; - } else if (fManifestElements == null) { - return null; - } else if (fManifestElements.isEmpty()) { - return null; - } - // Remove the element - boolean removed = fManifestElements.remove(element); - PDEManifestElement removedElement = null; - if (removed) { - removedElement = element; - } - // Fire event - if (update) { - update(false); - fireStructureChanged(removedElement, IModelChangedEvent.REMOVE); - } - return removedElement; - } - } diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/RequiredExecutionEnvironmentHeader.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/RequiredExecutionEnvironmentHeader.java index 8416dce7c2..532794add2 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/RequiredExecutionEnvironmentHeader.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/RequiredExecutionEnvironmentHeader.java @@ -17,7 +17,6 @@ import java.util.Arrays; import java.util.List; -import org.eclipse.jdt.launching.environments.IExecutionEnvironment; import org.eclipse.osgi.util.ManifestElement; import org.eclipse.pde.internal.core.ibundle.IBundle; @@ -42,22 +41,15 @@ public void addExecutionEnvironment(ExecutionEnvironment environment, int index) addManifestElement(environment, index, true); } - public void addExecutionEnvironments(Object[] envs) { - List list = new ArrayList<>(envs.length); - for (Object envObject : envs) { - ExecutionEnvironment env = null; - if (envObject instanceof ExecutionEnvironment ee) { - env = ee; - } else if (envObject instanceof IExecutionEnvironment ee) { - env = new ExecutionEnvironment(this, ee.getId()); - } - if (env != null && !hasElement(env.getName())) { - list.add(env); + public void addExecutionEnvironments(List eeIDs) { + List list = new ArrayList<>(eeIDs.size()); + for (String eeID : eeIDs) { + if (!hasElement(eeID)) { + list.add(new ExecutionEnvironment(this, eeID)); } } - if (!list.isEmpty()) { - addManifestElements(list.toArray(new ExecutionEnvironment[list.size()])); + addManifestElements(list); } } @@ -65,13 +57,6 @@ public ExecutionEnvironment removeExecutionEnvironment(String eeId) { return (ExecutionEnvironment) removeManifestElement(eeId); } - /** - * Remove operation performed using the actual object rather than its value - */ - public ExecutionEnvironment removeExecutionEnvironmentUnique(ExecutionEnvironment environment) { - return (ExecutionEnvironment) removeManifestElement(environment, true); - } - public List getEnvironments() { PDEManifestElement[] elements = getElements(); return Arrays.stream(elements).map(PDEManifestElement::getValue).toList(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java index 35595d1d7c..89b136379d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java @@ -17,7 +17,7 @@ import java.util.Arrays; import java.util.List; -import java.util.StringJoiner; +import java.util.Objects; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IncrementalProjectBuilder; @@ -298,24 +298,22 @@ private void handleAdd() { @SuppressWarnings("deprecation") private void addExecutionEnvironments(Object[] result) { + List ees = Arrays.stream(result).map(resultObject -> { + if (resultObject instanceof IExecutionEnvironment ee) { + return ee.getId(); + } else if (resultObject instanceof ExecutionEnvironment ee) { + return ee.getName(); + } + return null; + }).filter(Objects::nonNull).toList(); + IManifestHeader header = getHeader(); if (header == null) { - StringJoiner buffer = new StringJoiner("," + getLineDelimiter() + " "); //$NON-NLS-1$//$NON-NLS-2$ - for (Object resultObject : result) { - String id; - if (resultObject instanceof IExecutionEnvironment ee) { - id = ee.getId(); - } else if (resultObject instanceof ExecutionEnvironment ee) { - id = ee.getName(); - } else { - continue; - } - buffer.add(id); - } - getBundle().setHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, buffer.toString()); + String eeList = String.join("," + getLineDelimiter() + " ", ees); //$NON-NLS-1$//$NON-NLS-2$ + getBundle().setHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, eeList); } else { RequiredExecutionEnvironmentHeader ee = (RequiredExecutionEnvironmentHeader) header; - ee.addExecutionEnvironments(result); + ee.addExecutionEnvironments(ees); } } @@ -451,8 +449,9 @@ protected boolean canPaste(Object target, Object[] objects) { @Override protected void selectionChanged(IStructuredSelection selection) { getPage().getPDEEditor().setSelection(selection); - if (getPage().getModel().isEditable()) + if (getPage().getModel().isEditable()) { updateButtons(); + } } @Override