Skip to content

Commit

Permalink
Apply new JDT clean-up "Convert while loops to enhanced for loops"
Browse files Browse the repository at this point in the history
... without "Only if loop variable used" option being activated.

And manually remove now unused imports, which the clean-up does not yet
detect (a JDT issue is already created).

Don't apply clean-up to embedded OSGi and Felix sources.
  • Loading branch information
HannesWell committed Jul 20, 2022
1 parent 2d5d4d0 commit a1a9eaf
Show file tree
Hide file tree
Showing 40 changed files with 157 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ private String getHelp(String commandName) {
}

addHeader(Messages.console_help_app_commands_header, sb);
Iterator<Entry<String, String[]>> i = commandsHelp.entrySet().iterator();
while (i.hasNext()) {
Entry<String, String[]> entry = i.next();
for (Entry<String, String[]> entry : commandsHelp.entrySet()) {
String command = entry.getKey();
String[] attributes = entry.getValue();
addCommand(command, attributes, sb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -72,8 +71,7 @@ public synchronized Dictionary getProperties() {
}

if (newProps != null) {
for (Iterator it = newProps.keySet().iterator(); it.hasNext();) {
Object key = it.next();
for (Object key : newProps.keySet()) {
result.put(key, newProps.get(key));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider;
Expand Down Expand Up @@ -77,8 +76,7 @@ public synchronized Dictionary getProperties() {
}

if (newProps != null) {
for (Iterator it = newProps.keySet().iterator(); it.hasNext();) {
Object key = it.next();
for (Object key : newProps.keySet()) {
result.put(key, newProps.get(key));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.osgi.service.urlconversion.URLConverter;
Expand Down Expand Up @@ -114,8 +113,8 @@ synchronized public void uninstallBundle(Bundle b) throws BundleException {
if (bundles == null)
return;
if (bundles.containsValue(b)) {
for (Iterator it = bundles.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
for (Object element : bundles.entrySet()) {
Map.Entry entry = (Map.Entry) element;
if (entry.getValue().equals(b)) {
bundles.remove(entry.getKey());
break;
Expand All @@ -129,8 +128,8 @@ synchronized public Bundle[] uninstallAllBundles() throws BundleException {
if (bundles == null)
return null;
ArrayList result = new ArrayList(bundles.size());
for (Iterator iter = bundles.values().iterator(); iter.hasNext();) {
Bundle bundle = (Bundle) iter.next();
for (Object element : bundles.values()) {
Bundle bundle = (Bundle) element;
try {
bundle.uninstall();
} catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -2925,8 +2924,7 @@ private static void assertEqualElements(String message, List list1, List list2)
fail(message);
}
List tmp = new ArrayList(list2);
for (Iterator it = list1.iterator(); it.hasNext();) {
Object el = it.next();
for (Object el : list1) {
if (!tmp.contains(el)) {
fail(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void open() {
}
}
if (extensions != null) {
for (int i = 0; i < extensions.length; ++i) {
listener.added(extensions[i]);
for (IExtension extension : extensions) {
listener.added(extension);
}
}
}
Expand All @@ -93,8 +93,8 @@ public void close() {
extensions = this.getExtensions();
extensionCache.clear();
}
for (int i = 0; i < extensions.length; ++i) {
listener.removed(extensions[i]);
for (IExtension extension : extensions) {
listener.removed(extension);
}
}

Expand All @@ -119,8 +119,7 @@ public synchronized IExtension[] getExtensions() {
class RegistryChangeListener implements IRegistryChangeListener {
public void registryChanged(IRegistryChangeEvent event) {
IExtensionDelta[] deltas = event.getExtensionDeltas(namespace, simpleIdentifier);
for (int i = 0; i < deltas.length; ++i) {
IExtensionDelta delta = deltas[i];
for (IExtensionDelta delta : deltas) {
IExtension extension = delta.getExtension();
switch (delta.getKind()) {
case IExtensionDelta.ADDED :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public void stop() {

public void added(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement serviceSelectorElement = elements[i];
for (IConfigurationElement serviceSelectorElement : elements) {
if (!SERVICESELECTOR.equals(serviceSelectorElement.getName()))
continue;

Expand Down Expand Up @@ -105,8 +104,7 @@ public void added(IExtension extension) {
break;
}

for (int i = 0; i < elements.length; i++) {
IConfigurationElement filterElement = elements[i];
for (IConfigurationElement filterElement : elements) {
if (!FILTER.equals(filterElement.getName()))
continue;

Expand All @@ -117,9 +115,9 @@ public void added(IExtension extension) {

Dictionary<String, String> initparams = new Hashtable<>();
IConfigurationElement[] initParams = filterElement.getChildren(INIT_PARAM);
for (int j = 0; j < initParams.length; ++j) {
String paramName = initParams[j].getAttribute(PARAM_NAME);
String paramValue = initParams[j].getAttribute(PARAM_VALUE);
for (IConfigurationElement initParam : initParams) {
String paramName = initParam.getAttribute(PARAM_NAME);
String paramValue = initParam.getAttribute(PARAM_VALUE);
initparams.put(paramName, paramValue);
}

Expand All @@ -142,8 +140,7 @@ public void added(IExtension extension) {

public void removed(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement filterElement = elements[i];
for (IConfigurationElement filterElement : elements) {
Filter filter = registered.remove(filterElement);
if (filter != null)
httpRegistryManager.removeFilterContribution(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ public Bundle getBundle(String symbolicName) {
if (bundles == null)
return null;
//Return the first bundle that is not installed or uninstalled
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
return bundles[i];
for (Bundle bundle : bundles) {
if ((bundle.getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
return bundle;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public void stop() {

public void added(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement serviceSelectorElement = elements[i];
for (IConfigurationElement serviceSelectorElement : elements) {
if (!SERVICESELECTOR.equals(serviceSelectorElement.getName()))
continue;

Expand Down Expand Up @@ -99,8 +98,7 @@ public void added(IExtension extension) {
break;
}

for (int i = 0; i < elements.length; i++) {
IConfigurationElement resourceElement = elements[i];
for (IConfigurationElement resourceElement : elements) {
if (!RESOURCE.equals(resourceElement.getName()))
continue;

Expand All @@ -127,8 +125,7 @@ public void added(IExtension extension) {

public void removed(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement resourceElement = elements[i];
for (IConfigurationElement resourceElement : elements) {
if (registered.remove(resourceElement)) {
String alias = resourceElement.getAttribute(ALIAS);
httpRegistryManager.removeContribution(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void stop() {

public void added(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement serviceSelectorElement = elements[i];
for (IConfigurationElement serviceSelectorElement : elements) {
if (!SERVICESELECTOR.equals(serviceSelectorElement.getName()))
continue;

Expand Down Expand Up @@ -106,8 +105,7 @@ public void added(IExtension extension) {
break;
}

for (int i = 0; i < elements.length; i++) {
IConfigurationElement servletElement = elements[i];
for (IConfigurationElement servletElement : elements) {
if (!SERVLET.equals(servletElement.getName()))
continue;

Expand All @@ -118,9 +116,9 @@ public void added(IExtension extension) {

Dictionary<String, String> initparams = new Hashtable<>();
IConfigurationElement[] initParams = servletElement.getChildren(INIT_PARAM);
for (int j = 0; j < initParams.length; ++j) {
String paramName = initParams[j].getAttribute(PARAM_NAME);
String paramValue = initParams[j].getAttribute(PARAM_VALUE);
for (IConfigurationElement initParam : initParams) {
String paramName = initParam.getAttribute(PARAM_NAME);
String paramValue = initParam.getAttribute(PARAM_VALUE);
initparams.put(paramName, paramValue);
}

Expand All @@ -143,8 +141,7 @@ public void added(IExtension extension) {

public void removed(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement servletElement = elements[i];
for (IConfigurationElement servletElement : elements) {
if (registered.remove(servletElement)) {
String alias = servletElement.getAttribute(ALIAS);
httpRegistryManager.removeContribution(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -229,14 +228,12 @@ else if (String[].class.isInstance(property)) {
}
else if (Collection.class.isInstance(property)) {
List<String> list = new ArrayList<>();
for (@SuppressWarnings("rawtypes")
Iterator i = ((Collection)property).iterator(); i.hasNext();) {
for (Object o : ((Collection) property)) {

Object o = i.next();
if (String.class.isInstance(o)) {
list.add((String)o);
}
if (String.class.isInstance(o)) {
list.add((String)o);
}
}
return list;
}
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,12 @@ private String assembleEndpoint(String protocol, String host, String port, Strin
}

private void processRegistrations() {
Iterator<Entry<ProxyServlet, Object>> iterator =
registrations.entrySet().iterator();
BundleContext currentContext = context;
if (currentContext == null) {
return;
}

while (iterator.hasNext()) {
Entry<ProxyServlet, Object> entry = iterator.next();
for (Entry<ProxyServlet, Object> entry : registrations.entrySet()) {
ProxyServlet proxyServlet = entry.getKey();
Object value = entry.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public class ServletRegistration extends EndpointRegistration<ServletDTO> {
static {
ServiceLoader<MultipartSupportFactory> loader = ServiceLoader.load(MultipartSupportFactory.class);

Iterator<MultipartSupportFactory> iterator = loader.iterator();

while (iterator.hasNext()) {
for (MultipartSupportFactory element : loader) {
try {
factory = iterator.next();
factory = element;
break;
}
catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ public void filterSingletonCollisions(BundleCapability singleton, Collection<Bun
private void debugEntry(BundleRevision requirer, Collection<BundleCapability> candidates, boolean singleton) {
System.out.println((singleton ? "Singleton" : "Requirer: ") + requirer.getSymbolicName() + "_" + requirer.getVersion() + "[" + getBundleId(requirer) + "]"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println(" Candidates: "); //$NON-NLS-1$
Iterator<BundleCapability> i = candidates.iterator();
while (i.hasNext()) {
BundleCapability c = i.next();
for (BundleCapability c : candidates) {
String namespace = c.getNamespace();
if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
BundleRevision providerRevision = c.getRevision();
Expand All @@ -157,9 +155,7 @@ private void debugEntry(BundleRevision requirer, Collection<BundleCapability> ca

private void debugExit(BundleRevision requirer, Collection<BundleCapability> candidates) {
System.out.println(" Filtered candidates: "); //$NON-NLS-1$
Iterator<BundleCapability> i = candidates.iterator();
while (i.hasNext()) {
BundleCapability c = i.next();
for (BundleCapability c : candidates) {
String namespace = c.getNamespace();
if (BundleRevision.PACKAGE_NAMESPACE.equals(namespace)) {
BundleRevision providerRevision = c.getRevision();
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.registry/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.equinox.registry;singleton:=true
Bundle-Version: 3.11.100.qualifier
Bundle-Version: 3.11.200.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.core.internal.adapter;x-internal:=true,
org.eclipse.core.internal.registry;x-friends:="org.eclipse.core.runtime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private ConfigurationElement loadConfigurationElementAndChildren(DataInputStream
if (depth + 1 > maxDepth)
return ce;

for (int i = 0; i < children.length; i++) {
for (int child : children) {
ConfigurationElement tmp = loadConfigurationElementAndChildren(currentStream, extraIs, depth + 1, maxDepth, objectManager, namespaceOwnerId);
objectManager.add(tmp, holdObjects);
}
Expand Down
Loading

0 comments on commit a1a9eaf

Please sign in to comment.