diff options
author | Carsten Hammer | 2019-07-05 18:40:11 +0000 |
---|---|---|
committer | Carsten Hammer | 2019-07-14 18:50:29 +0000 |
commit | fd878b586ff648618c875415d228f507bea4944d (patch) | |
tree | d227593c46cbe6ebb1662d952abccabad65d6592 | |
parent | 8e6a88f76a60bb864d67ea61beb461e5a29a846c (diff) | |
download | rt.equinox.bundles-fd878b586ff648618c875415d228f507bea4944d.tar.gz rt.equinox.bundles-fd878b586ff648618c875415d228f507bea4944d.tar.xz rt.equinox.bundles-fd878b586ff648618c875415d228f507bea4944d.zip |
Use jdk 5 for-each-loop (jasper, metatype, preferences)
Replace most simple uses of Iterator with a corresponding for-each-loop.
Also add missing braces on loops as necessary.
Change-Id: I0dcaa50a43e0ff3b450f386dfa856d75bdcb6cba
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
23 files changed, 186 insertions, 159 deletions
diff --git a/bundles/org.eclipse.equinox.jsp.jasper.registry/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.jsp.jasper.registry/META-INF/MANIFEST.MF index 95552c956..0d5089c1a 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper.registry/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.jsp.jasper.registry/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: %bundleName Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.equinox.jsp.jasper.registry -Bundle-Version: 1.1.200.qualifier +Bundle-Version: 1.1.300.qualifier Bundle-Activator: org.eclipse.equinox.internal.jsp.jasper.registry.Activator Import-Package: org.eclipse.equinox.jsp.jasper, org.osgi.framework;version="1.3.0", diff --git a/bundles/org.eclipse.equinox.jsp.jasper.registry/pom.xml b/bundles/org.eclipse.equinox.jsp.jasper.registry/pom.xml index ddd9775d2..26925e3e3 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper.registry/pom.xml +++ b/bundles/org.eclipse.equinox.jsp.jasper.registry/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.jsp.jasper.registry</artifactId> - <version>1.1.200-SNAPSHOT</version> + <version>1.1.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.jsp.jasper.registry/src/org/eclipse/equinox/internal/jsp/jasper/registry/Activator.java b/bundles/org.eclipse.equinox.jsp.jasper.registry/src/org/eclipse/equinox/internal/jsp/jasper/registry/Activator.java index 2795f1ec7..c60048139 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper.registry/src/org/eclipse/equinox/internal/jsp/jasper/registry/Activator.java +++ b/bundles/org.eclipse.equinox.jsp.jasper.registry/src/org/eclipse/equinox/internal/jsp/jasper/registry/Activator.java @@ -46,9 +46,9 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer<Pack 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; diff --git a/bundles/org.eclipse.equinox.jsp.jasper/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.jsp.jasper/META-INF/MANIFEST.MF index 632ef22bc..326fe7f5a 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.jsp.jasper/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: %bundleName Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.equinox.jsp.jasper -Bundle-Version: 1.1.200.qualifier +Bundle-Version: 1.1.300.qualifier Bundle-Activator: org.eclipse.equinox.internal.jsp.jasper.Activator Import-Package: javax.servlet;version="[2.4, 5.0)", javax.servlet.annotation;version="[2.6, 5.0)";resolution:=optional, diff --git a/bundles/org.eclipse.equinox.jsp.jasper/pom.xml b/bundles/org.eclipse.equinox.jsp.jasper/pom.xml index d2cc9766b..cfff99aee 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper/pom.xml +++ b/bundles/org.eclipse.equinox.jsp.jasper/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.jsp.jasper</artifactId> - <version>1.1.200-SNAPSHOT</version> + <version>1.1.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/Activator.java b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/Activator.java index 991bcda4a..fc04bc222 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/Activator.java +++ b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/Activator.java @@ -90,11 +90,12 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer<Pack throw new IllegalStateException("Not started"); //$NON-NLS-1$ ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages("org.apache.jasper.servlet"); //$NON-NLS-1$ - for (int i = 0; i < exportedPackages.length; i++) { - Bundle[] importingBundles = exportedPackages[i].getImportingBundles(); - for (int j = 0; j < importingBundles.length; j++) { - if (thisBundle.equals(importingBundles[j])) - return exportedPackages[i].getExportingBundle(); + for (ExportedPackage exportedPackage : exportedPackages) { + Bundle[] importingBundles = exportedPackage.getImportingBundles(); + for (Bundle importingBundle : importingBundles) { + if (thisBundle.equals(importingBundle)) { + return exportedPackage.getExportingBundle(); + } } } return null; diff --git a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/JspClassLoader.java b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/JspClassLoader.java index aa63205f9..d809abf8b 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/JspClassLoader.java +++ b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/internal/jsp/jasper/JspClassLoader.java @@ -73,8 +73,8 @@ public class JspClassLoader extends URLClassLoader { addBundleClassPathJars(bundle); Bundle[] fragments = Activator.getFragments(bundle); if (fragments != null) { - for (int i = 0; i < fragments.length; i++) { - addBundleClassPathJars(fragments[i]); + for (Bundle fragment : fragments) { + addBundleClassPathJars(fragment); } } } diff --git a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/jsp/jasper/JspServlet.java b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/jsp/jasper/JspServlet.java index 3f85dd9a9..7dd8e35c9 100644 --- a/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/jsp/jasper/JspServlet.java +++ b/bundles/org.eclipse.equinox.jsp.jasper/src/org/eclipse/equinox/jsp/jasper/JspServlet.java @@ -221,8 +221,7 @@ public class JspServlet extends HttpServlet { private static Map<Method, Method> createContextToHandlerMethods() { Map<Method, Method> methods = new HashMap<>(); Method[] handlerMethods = ServletContextAdaptor.class.getDeclaredMethods(); - for (int i = 0; i < handlerMethods.length; i++) { - Method handlerMethod = handlerMethods[i]; + for (Method handlerMethod : handlerMethods) { String name = handlerMethod.getName(); Class<?>[] parameterTypes = handlerMethod.getParameterTypes(); try { diff --git a/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF index 8b6a6e62a..1c605cb36 100644 --- a/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.metatype/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Bundle-ManifestVersion: 2 Bundle-Name: %bundleName -Bundle-Version: 1.5.0.qualifier +Bundle-Version: 1.5.100.qualifier Bundle-SymbolicName: org.eclipse.equinox.metatype Bundle-Activator: org.eclipse.equinox.metatype.impl.Activator Import-Package: javax.xml.parsers, diff --git a/bundles/org.eclipse.equinox.metatype/pom.xml b/bundles/org.eclipse.equinox.metatype/pom.xml index eddd5b26f..817596148 100644 --- a/bundles/org.eclipse.equinox.metatype/pom.xml +++ b/bundles/org.eclipse.equinox.metatype/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,7 +19,7 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.metatype</artifactId> - <version>1.5.0-SNAPSHOT</version> + <version>1.5.100-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <build> <plugins> diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java index e5019dd59..baaa8f890 100644 --- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java +++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeProviderTracker.java @@ -48,10 +48,11 @@ public class MetaTypeProviderTracker implements EquinoxMetaTypeInformation { return new String[0]; // return none if not active MetaTypeProviderWrapper[] wrappers = getMetaTypeProviders(); ArrayList<String> results = new ArrayList<String>(); - for (int i = 0; i < wrappers.length; i++) { + for (MetaTypeProviderWrapper wrapper : wrappers) { // return only the correct type of pids (regular or factory) - if (factory == wrappers[i].factory) - results.add(wrappers[i].pid); + if (factory == wrapper.factory) { + results.add(wrapper.pid); + } } return results.toArray(new String[results.size()]); } @@ -73,10 +74,11 @@ public class MetaTypeProviderTracker implements EquinoxMetaTypeInformation { if (_bundle.getState() != Bundle.ACTIVE) return null; // return none if not active MetaTypeProviderWrapper[] wrappers = getMetaTypeProviders(); - for (int i = 0; i < wrappers.length; i++) { - if (id.equals(wrappers[i].pid)) + for (MetaTypeProviderWrapper wrapper : wrappers) { + if (id.equals(wrapper.pid)) { // found a matching pid now call the actual provider - return wrappers[i].getObjectClassDefinition(id, locale); + return wrapper.getObjectClassDefinition(id, locale); + } } return null; } @@ -87,13 +89,15 @@ public class MetaTypeProviderTracker implements EquinoxMetaTypeInformation { MetaTypeProviderWrapper[] wrappers = getMetaTypeProviders(); ArrayList<String> locales = new ArrayList<String>(); // collect all the unique locales from all providers we found - for (int i = 0; i < wrappers.length; i++) { - String[] wrappedLocales = wrappers[i].getLocales(); + for (MetaTypeProviderWrapper wrapper : wrappers) { + String[] wrappedLocales = wrapper.getLocales(); if (wrappedLocales == null) continue; - for (int j = 0; j < wrappedLocales.length; j++) - if (!locales.contains(wrappedLocales[j])) - locales.add(wrappedLocales[j]); + for (String wrappedLocale : wrappedLocales) { + if (!locales.contains(wrappedLocale)) { + locales.add(wrappedLocale); + } + } } return locales.toArray(new String[locales.size()]); } diff --git a/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF index a04bfb507..ab39a8700 100644 --- a/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.preferences/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.preferences; singleton:=true -Bundle-Version: 3.7.400.qualifier +Bundle-Version: 3.7.500.qualifier Bundle-Activator: org.eclipse.core.internal.preferences.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.preferences/pom.xml b/bundles/org.eclipse.equinox.preferences/pom.xml index ae14cd1ce..d23977b14 100644 --- a/bundles/org.eclipse.equinox.preferences/pom.xml +++ b/bundles/org.eclipse.equinox.preferences/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.preferences</artifactId> - <version>3.7.400-SNAPSHOT</version> + <version>3.7.500-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ConfigurationPreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ConfigurationPreferences.java index 534eda7f8..87f8accc1 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ConfigurationPreferences.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ConfigurationPreferences.java @@ -114,8 +114,9 @@ public class ConfigurationPreferences extends EclipsePreferences { if (baseLocation == null) return; String[] names = computeChildren(baseLocation); - for (int i = 0; i < names.length; i++) - addChild(names[i], null); + for (String n : names) { + addChild(n, null); + } } } finally { initialized = true; diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java index 45cad1ec8..f47b4e947 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java @@ -116,8 +116,9 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { if (!visitor.visit(this)) return; IEclipsePreferences[] toVisit = getChildren(true); - for (int i = 0; i < toVisit.length; i++) - toVisit[i].accept(visitor); + for (IEclipsePreferences p : toVisit) { + p.accept(visitor); + } } protected IEclipsePreferences addChild(String childName, IEclipsePreferences child) { @@ -200,8 +201,9 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { keys = properties.keys(); } //don't synchronize remove call because it calls listeners - for (int i = 0; i < keys.length; i++) - remove(keys[i]); + for (String key : keys) { + remove(key); + } makeDirty(); } @@ -214,9 +216,9 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { File file = dir.toFile(); File[] totalFiles = file.listFiles(); if (totalFiles != null) { - for (int i = 0; i < totalFiles.length; i++) { - if (totalFiles[i].isFile()) { - String filename = totalFiles[i].getName(); + for (File totalFile : totalFiles) { + if (totalFile.isFile()) { + String filename = totalFile.getName(); if (filename.endsWith(extension)) { String shortName = filename.substring(0, filename.length() - extension.length()); result.add(shortName); @@ -326,8 +328,8 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { } // recursively add the child information IEclipsePreferences[] childNodes = getChildren(true); - for (int i = 0; i < childNodes.length; i++) { - EclipsePreferences child = (EclipsePreferences) childNodes[i]; + for (IEclipsePreferences childNode : childNodes) { + EclipsePreferences child = (EclipsePreferences) childNode; String fullPath = addSeparator ? prefix + PATH_SEPARATOR + child.name() : child.name(); child.convertToProperties(result, fullPath); } @@ -411,8 +413,9 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { // if this node or a parent is not the load level, then flush the children if (loadLevel == null) { String[] childrenNames = childrenNames(); - for (int i = 0; i < childrenNames.length; i++) - node(childrenNames[i]).flush(); + for (String childrenName : childrenNames) { + node(childrenName).flush(); + } return null; } @@ -497,8 +500,8 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { protected IEclipsePreferences[] getChildren(boolean create) { ArrayList<IEclipsePreferences> result = new ArrayList<>(); String[] names = internalChildNames(); - for (int i = 0; i < names.length; i++) { - IEclipsePreferences child = getChild(names[i], null, create); + for (String n : names) { + IEclipsePreferences child = getChild(n, null, create); if (child != null) result.add(child); } @@ -966,8 +969,9 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { // clear all the property values. do it "the long way" so // everyone gets notification String[] keys = keys(); - for (int i = 0; i < keys.length; i++) - remove(keys[i]); + for (String key : keys) { + remove(key); + } // don't remove the global root or the scope root from the // parent but remove all its children if (parent != null && !(parent instanceof RootPreferences)) { @@ -976,13 +980,14 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { parent.removeNode(this); } IEclipsePreferences[] childNodes = getChildren(false); - for (int i = 0; i < childNodes.length; i++) + for (IEclipsePreferences childNode : childNodes) { try { - childNodes[i].removeNode(); - } catch (IllegalStateException e) { + childNode.removeNode(); + }catch (IllegalStateException e) { // ignore since we only get this exception if we have already // been removed. no work to do. } + } } /* @@ -1088,9 +1093,11 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { } temp.shareStrings(pool); IEclipsePreferences[] myChildren = getChildren(false); - for (int i = 0; i < myChildren.length; i++) - if (myChildren[i] instanceof EclipsePreferences) - ((EclipsePreferences) myChildren[i]).shareStrings(pool); + for (IEclipsePreferences child : myChildren) { + if (child instanceof EclipsePreferences) { + ((EclipsePreferences) child).shareStrings(pool); + } + } } /* @@ -1219,12 +1226,12 @@ public class EclipsePreferences implements IEclipsePreferences, IScope { buffer.append(node); buffer.append('\n'); String[] keys = node.keys(); - for (int i = 0; i < keys.length; i++) { + for (String key : keys) { buffer.append(node.absolutePath()); buffer.append(PATH_SEPARATOR); - buffer.append(keys[i]); + buffer.append(key); buffer.append('='); - buffer.append(node.get(keys[i], "*default*")); //$NON-NLS-1$ + buffer.append(node.get(key, "*default*")); //$NON-NLS-1$ buffer.append('\n'); } return true; diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ImmutableMap.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ImmutableMap.java index 15d485379..1e7164a54 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ImmutableMap.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/ImmutableMap.java @@ -98,9 +98,11 @@ public abstract class ImmutableMap implements Cloneable { return EMPTY_STRING_ARRAY; String[] result = new String[elementSize]; int next = 0; - for (int i = 0; i < keyTable.length; i++) - if (keyTable[i] != null) - result[next++] = keyTable[i]; + for (String key : keyTable) { + if (key != null) { + result[next++] = key; + } + } return result; } diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/InstancePreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/InstancePreferences.java index 16ba5495d..5f4fa881e 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/InstancePreferences.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/InstancePreferences.java @@ -210,8 +210,9 @@ public class InstancePreferences extends EclipsePreferences { try { synchronized (this) { String[] names = computeChildren(getBaseLocation()); - for (int i = 0; i < names.length; i++) - addChild(names[i], null); + for (String n : names) { + addChild(n, null); + } } } finally { initialized = true; diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/LookupOrder.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/LookupOrder.java index 1befa95ce..f3af741f9 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/LookupOrder.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/LookupOrder.java @@ -24,9 +24,11 @@ public class LookupOrder { private String[] order; LookupOrder(String[] order) { - for (int i = 0; i < order.length; i++) - if (order[i] == null) + for (String o : order) { + if (o == null) { throw new IllegalArgumentException(); + } + } this.order = order; } diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/OSGiPreferencesServiceManager.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/OSGiPreferencesServiceManager.java index 1e99b0b2d..13bfe2511 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/OSGiPreferencesServiceManager.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/OSGiPreferencesServiceManager.java @@ -51,17 +51,17 @@ public class OSGiPreferencesServiceManager implements ServiceFactory<org.osgi.se //get list of currently installed bundles Bundle[] allBundles = context.getBundles(); Set<String> bundleQualifiers = new TreeSet<>(); - for (int i = 0; i < allBundles.length; i++) { - bundleQualifiers.add(getQualifier(allBundles[i])); + for (Bundle allBundle : allBundles) { + bundleQualifiers.add(getQualifier(allBundle)); } //get list of bundles we created prefs for String[] prefsBundles = prefBundles.keys(); //remove prefs nodes for bundles that are no longer installed - for (int i = 0; i < prefsBundles.length; i++) { - if (!bundleQualifiers.contains(prefsBundles[i])) { - removePrefs(prefsBundles[i]); + for (String prefsBundle : prefsBundles) { + if (!bundleQualifiers.contains(prefsBundle)) { + removePrefs(prefsBundle); } } diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceServiceRegistryHelper.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceServiceRegistryHelper.java index cfdb4ab3a..ab9f46b88 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceServiceRegistryHelper.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferenceServiceRegistryHelper.java @@ -115,13 +115,13 @@ public class PreferenceServiceRegistryHelper implements IRegistryChangeListener return null; } boolean foundInitializer = false; - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length; j++) - if (ELEMENT_INITIALIZER.equals(elements[j].getName())) { - if (name.equals(elements[j].getContributor().getName())) { + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if (ELEMENT_INITIALIZER.equals(element.getName())) { + if (name.equals(element.getContributor().getName())) { if (EclipsePreferences.DEBUG_PREFERENCE_GENERAL) { - IExtension theExtension = elements[j].getDeclaringExtension(); + IExtension theExtension = element.getDeclaringExtension(); String extensionNamespace = theExtension.getContributor().getName(); Bundle underlyingBundle = PreferencesOSGiUtils.getDefault().getBundle(extensionNamespace); String ownerName; @@ -131,11 +131,12 @@ public class PreferenceServiceRegistryHelper implements IRegistryChangeListener ownerName = extensionNamespace; PrefsMessages.message("Running default preference customization as defined by: " + ownerName); //$NON-NLS-1$ } - runInitializer(elements[j]); + runInitializer(element); // don't return yet in case we have multiple initializers registered foundInitializer = true; } } + } } if (foundInitializer) return null; @@ -201,11 +202,13 @@ public class PreferenceServiceRegistryHelper implements IRegistryChangeListener if (modifyListeners == null) { modifyListeners = new ListenerList<>(); IExtension[] extensions = getPrefExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length; j++) - if (ELEMENT_MODIFIER.equalsIgnoreCase(elements[j].getName())) - addModifyListener(elements[j]); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if (ELEMENT_MODIFIER.equalsIgnoreCase(element.getName())) { + addModifyListener(element); + } + } } } return modifyListeners; @@ -244,11 +247,13 @@ public class PreferenceServiceRegistryHelper implements IRegistryChangeListener */ private void initializeScopes() { IExtension[] extensions = getPrefExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int j = 0; j < elements.length; j++) - if (ELEMENT_SCOPE.equalsIgnoreCase(elements[j].getName())) - scopeAdded(elements[j]); + for (IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for (IConfigurationElement element : elements) { + if (ELEMENT_SCOPE.equalsIgnoreCase(element.getName())) { + scopeAdded(element); + } + } } } @@ -263,17 +268,18 @@ public class PreferenceServiceRegistryHelper implements IRegistryChangeListener if (deltas.length == 0) return; - // dynamically adjust the registered scopes - for (int i = 0; i < deltas.length; i++) { - IConfigurationElement[] elements = deltas[i].getExtension().getConfigurationElements(); - for (int j = 0; j < elements.length; j++) { - switch (deltas[i].getKind()) { - case IExtensionDelta.ADDED : - if (ELEMENT_SCOPE.equalsIgnoreCase(elements[j].getName())) - scopeAdded(elements[j]); + // dynamically adjust the registered scopes + for (IExtensionDelta delta : deltas) { + IConfigurationElement[] elements = delta.getExtension().getConfigurationElements(); + for (IConfigurationElement element : elements) { + switch (delta.getKind()) { + case IExtensionDelta.ADDED: + if (ELEMENT_SCOPE.equalsIgnoreCase(element.getName())) { + scopeAdded(element); + } break; - case IExtensionDelta.REMOVED : - String scope = elements[j].getAttribute(ATTRIBUTE_NAME); + case IExtensionDelta.REMOVED: + String scope = element.getAttribute(ATTRIBUTE_NAME); if (scope != null) scopeRemoved(scope); break; diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesOSGiUtils.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesOSGiUtils.java index 15d279aab..a412341b9 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesOSGiUtils.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesOSGiUtils.java @@ -142,9 +142,9 @@ public class PreferencesOSGiUtils { 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; diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java index e6a195305..7a114ccc1 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/PreferencesService.java @@ -156,19 +156,17 @@ public class PreferencesService implements IPreferencesService { // the list for properties to remove List<String> propsToRemove = new ArrayList<>(); - for (int i = 0; i < globalNode.keys().length; i++) { - propsToRemove.add(globalNode.keys()[i]); + for (String key : globalNode.keys()) { + propsToRemove.add(key); } if (keys.length > 0) { String key = null; - for (int i = 0; i < keys.length; i++) { - key = keys[i]; - + for (String k : keys) { + key = k; // preferences that are not in the applied node // will be removed propsToRemove.remove(key); - // intern strings we import because some people // in their property change listeners use identity // instead of equals. See bug 20193 and 20534. @@ -305,16 +303,15 @@ public class PreferencesService implements IPreferencesService { return false; String path = absolutePath.length() <= baseLength ? EMPTY_STRING : EclipsePreferences.makeRelative(absolutePath.substring(baseLength)); // check the excludes list to see if this node should be considered - for (int i = 0; i < excludesList.length; i++) { - String exclusion = EclipsePreferences.makeRelative(excludesList[i]); + for (String exclude : excludesList) { + String exclusion = EclipsePreferences.makeRelative(exclude); if (path.startsWith(exclusion)) return false; } boolean needToAddVersion = InstanceScope.SCOPE.equals(scope); // check the excludes list for each preference String[] keys = node.keys(); - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; + for (String key : keys) { boolean ignore = false; for (int j = 0; !ignore && j < excludesList.length; j++) if (EclipsePreferences.encodePath(path, key).startsWith(EclipsePreferences.makeRelative(excludesList[j]))) @@ -357,16 +354,18 @@ public class PreferencesService implements IPreferencesService { */ void copyFromTo(Preferences source, Preferences destination, String[] keys, int depth) throws BackingStoreException { String[] keysToCopy = keys == null ? source.keys() : keys; - for (int i = 0; i < keysToCopy.length; i++) { - String value = source.get(keysToCopy[i], null); - if (value != null) - destination.put(keysToCopy[i], value); + for (String key : keysToCopy) { + String value = source.get(key, null); + if (value != null) { + destination.put(key, value); + } } if (depth == 0) return; String[] children = source.childrenNames(); - for (int i = 0; i < children.length; i++) - copyFromTo(source.node(children[i]), destination.node(children[i]), keys, depth); + for (String child : children) { + copyFromTo(source.node(child), destination.node(child), keys, depth); + } } public WeakReference<Object> applyRuntimeDefaults(String name, WeakReference<Object> pluginReference) { @@ -464,8 +463,7 @@ public class PreferencesService implements IPreferencesService { public String get(String key, String defaultValue, Preferences[] nodes) { if (nodes == null) return defaultValue; - for (int i = 0; i < nodes.length; i++) { - Preferences node = nodes[i]; + for (Preferences node : nodes) { if (node != null) { String result = node.get(key, null); if (result != null) @@ -597,8 +595,7 @@ public class PreferencesService implements IPreferencesService { String[] order = getLookupOrder(qualifier, key); final String childPath = EclipsePreferences.makeRelative(EclipsePreferences.decodePath(key)[0]); final ArrayList<Preferences> result = new ArrayList<>(); - for (int i = 0; i < order.length; i++) { - final String scopeString = order[i]; + for (String scopeString : order) { AtomicReference<IllegalStateException> error = new AtomicReference<>(); SafeRunner.run(new ISafeRunnable() { @@ -703,8 +700,9 @@ public class PreferencesService implements IPreferencesService { */ private void internalApply(IEclipsePreferences tree, IPreferenceFilter[] filters) throws BackingStoreException { ArrayList<IEclipsePreferences> trees = new ArrayList<>(); - for (int i = 0; i < filters.length; i++) - trees.add(trimTree(tree, filters[i])); + for (IPreferenceFilter filter : filters) { + trees.add(trimTree(tree, filter)); + } // merge the union of the matching filters IEclipsePreferences toApply = mergeTrees(trees.toArray(new IEclipsePreferences[trees.size()])); @@ -731,8 +729,9 @@ public class PreferencesService implements IPreferencesService { */ private void internalExport(IEclipsePreferences node, IPreferenceFilter filters[], OutputStream output) throws BackingStoreException, CoreException { ArrayList<IEclipsePreferences> trees = new ArrayList<>(); - for (int i = 0; i < filters.length; i++) - trees.add(trimTree(node, filters[i])); + for (IPreferenceFilter filter : filters) { + trees.add(trimTree(node, filter)); + } IEclipsePreferences toExport = mergeTrees(trees.toArray(new IEclipsePreferences[trees.size()])); exportPreferences(toExport, output, (String[]) null); } @@ -747,8 +746,7 @@ public class PreferencesService implements IPreferencesService { throw new IllegalArgumentException(); String treePath = tree.absolutePath(); // see if this node is applicable by going over all our scopes - for (int i = 0; i < scopes.length; i++) { - String scope = scopes[i]; + for (String scope : scopes) { Map<String, PreferenceFilterEntry[]> mapping = filter.getMapping(scope); // if the mapping is null then we match everything if (mapping == null) { @@ -763,8 +761,7 @@ public class PreferencesService implements IPreferencesService { continue; } // iterate over the list of declared nodes - for (Iterator<String> iter = mapping.keySet().iterator(); iter.hasNext();) { - String nodePath = iter.next(); + for (String nodePath : mapping.keySet()) { String nodeFullPath = '/' + scope + '/' + nodePath; // if this subtree isn't in a hierarchy we are interested in, then go to the next one if (!nodeFullPath.startsWith(treePath)) @@ -789,14 +786,17 @@ public class PreferencesService implements IPreferencesService { return true; } else { // otherwise check to see if we have any applicable keys - for (int j = 0; j < entries.length; j++) { - if (entries[j] == null) + for (PreferenceFilterEntry entry : entries) { + if (entry == null) { continue; - if (entries[j].getMatchType() == null) { - if (child.get(entries[j].getKey(), null) != null) + } + if (entry.getMatchType() == null) { + if (child.get(entry.getKey(), null) != null) { return true; - } else if (internalMatchesWithMatchType(entries[j], child.keys())) + } + } else if (internalMatchesWithMatchType(entry, child.keys())) { return true; + } } } } @@ -810,9 +810,11 @@ public class PreferencesService implements IPreferencesService { */ private IPreferenceFilter[] internalMatches(IEclipsePreferences tree, IPreferenceFilter[] filters) throws BackingStoreException { ArrayList<IPreferenceFilter> result = new ArrayList<>(); - for (int i = 0; i < filters.length; i++) - if (internalMatches(tree, filters[i])) - result.add(filters[i]); + for (IPreferenceFilter filter : filters) { + if (internalMatches(tree, filter)) { + result.add(filter); + } + } return result.toArray(new IPreferenceFilter[result.size()]); } @@ -826,9 +828,10 @@ public class PreferencesService implements IPreferencesService { String matchType = entry.getMatchType(); if (!matchType.equalsIgnoreCase(MATCH_TYPE_PREFIX)) return false; - for (int i = 0; i < keys.length; i++) { - if (keys[i].startsWith(key)) + for (String k : keys) { + if (k.startsWith(key)) { return true; + } } return false; } @@ -870,8 +873,9 @@ public class PreferencesService implements IPreferencesService { return true; } }; - for (int i = 0; i < trees.length; i++) - trees[i].accept(visitor); + for (IEclipsePreferences tree : trees) { + tree.accept(visitor); + } return result; } @@ -974,9 +978,8 @@ public class PreferencesService implements IPreferencesService { if (scopes == null) throw new IllegalArgumentException(); String treePath = tree.absolutePath(); - // see if this node is applicable by going over all our scopes - for (int i = 0; i < scopes.length; i++) { - String scope = scopes[i]; + // see if this node is applicable by going over all our scopes + for (String scope : scopes) { Map<String, PreferenceFilterEntry[]> mapping = filter.getMapping(scope); // if the mapping is null then copy everything if the scope matches if (mapping == null) { @@ -989,8 +992,7 @@ public class PreferencesService implements IPreferencesService { continue; } // iterate over the list of declared nodes - for (Iterator<String> iter = mapping.keySet().iterator(); iter.hasNext();) { - String nodePath = iter.next(); + for (String nodePath : mapping.keySet()) { String nodeFullPath = '/' + scope + '/' + nodePath; // if this subtree isn't in a hierarchy we are interested in, then go to the next one if (!nodeFullPath.startsWith(treePath)) @@ -1011,9 +1013,10 @@ public class PreferencesService implements IPreferencesService { String[] keys = null; if (entries != null) { ArrayList<String> list = new ArrayList<>(); - for (int j = 0; j < entries.length; j++) { - if (entries[j] != null) - addMatchedKeys(list, entries[j], child.keys()); + for (PreferenceFilterEntry entry : entries) { + if (entry != null) { + addMatchedKeys(list, entry, child.keys()); + } } keys = list.toArray(new String[list.size()]); } @@ -1037,9 +1040,10 @@ public class PreferencesService implements IPreferencesService { if (keys == null) return; String key = entry.getKey(); - for (int i = 0; i < keys.length; i++) { - if (matchType.equals(MATCH_TYPE_PREFIX) && keys[i].startsWith(key)) - list.add(keys[i]); + for (String k : keys) { + if (matchType.equals(MATCH_TYPE_PREFIX) && k.startsWith(key)) { + list.add(k); + } } } diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/RootPreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/RootPreferences.java index 2b1198d6c..5df59ec8f 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/RootPreferences.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/RootPreferences.java @@ -36,10 +36,10 @@ public class RootPreferences extends EclipsePreferences { // flush all children BackingStoreException exception = null; String[] names = childrenNames(); - for (int i = 0; i < names.length; i++) { + for (String n : names) { try { - node(names[i]).flush(); - } catch (BackingStoreException e) { + node(n).flush(); + }catch (BackingStoreException e) { // store the first exception we get and still try and flush // the rest of the children. if (exception == null) @@ -114,10 +114,10 @@ public class RootPreferences extends EclipsePreferences { // sync all children BackingStoreException exception = null; String[] names = childrenNames(); - for (int i = 0; i < names.length; i++) { + for (String n : names) { try { - node(names[i]).sync(); - } catch (BackingStoreException e) { + node(n).sync(); + }catch (BackingStoreException e) { // store the first exception we get and still try and sync // the rest of the children. if (exception == null) |