scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java | 5 - scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java | 19 ++---- scripting/java/com/sun/star/script/framework/container/Parcel.java | 14 ++--- scripting/java/com/sun/star/script/framework/container/ParcelContainer.java | 28 +++------- scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java | 5 + scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java | 21 ++----- scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java | 7 +- 7 files changed, 38 insertions(+), 61 deletions(-)
New commits: commit e41cc6898abe5f46a98085c1a42608cca7813317 Author: rbuj <robert....@gmail.com> Date: Fri Sep 5 12:31:14 2014 +0200 scripting: Enhanced For-Loops Change-Id: Ib5e59a8c153e7d788c14153fa3b94c8b2d0a068c Reviewed-on: https://gerrit.libreoffice.org/11292 Reviewed-by: David Tardon <dtar...@redhat.com> Tested-by: David Tardon <dtar...@redhat.com> diff --git a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java index 71cfbe7..0e5c721 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java @@ -118,9 +118,8 @@ public class ParcelBrowseNode extends PropertySet String[] names = parcel.getElementNames(); browsenodes = new ArrayList<XBrowseNode>( names.length ); - for ( int index = 0; index < names.length; index++ ) - { - browsenodes.add( new ScriptBrowseNode( provider, parcel, names[ index ] )); + for (String name : names) { + browsenodes.add(new ScriptBrowseNode(provider, parcel, name)); } } else diff --git a/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java index fc6a6d4..7e7c938 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java @@ -99,25 +99,20 @@ public class ProviderBrowseNode extends PropertySet LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " + container ); String[] parcels = container.getElementNames(); browsenodes = new ArrayList<XBrowseNode>( parcels.length ); - for ( int index = 0; index < parcels.length; index++ ) - { - try - { - XBrowseNode node = new ParcelBrowseNode( provider, container, parcels[ index ] ); + for (String parcel : parcels) { + try { + XBrowseNode node = new ParcelBrowseNode(provider, container, parcel); browsenodes.add( node ); - } - catch ( Exception e ) - { - LogUtils.DEBUG("*** Failed to create parcel node for " + parcels[ index ] ); + } catch (Exception e) { + LogUtils.DEBUG("*** Failed to create parcel node for " + parcel); LogUtils.DEBUG( e.toString() ); } } ParcelContainer[] packageContainers = container.getChildContainers(); LogUtils.DEBUG("**** For container named " + container.getName() + " with root path " + container.getParcelContainerDir() + " has " + packageContainers.length + " child containers " ); - for ( int i = 0; i < packageContainers.length; i++ ) - { - XBrowseNode node = new PkgProviderBrowseNode( provider, packageContainers[ i ], m_xCtx ); + for (ParcelContainer packageContainer : packageContainers) { + XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer, m_xCtx); browsenodes.add( node ); } } diff --git a/scripting/java/com/sun/star/script/framework/container/Parcel.java b/scripting/java/com/sun/star/script/framework/container/Parcel.java index e9c3bfe..ba269ac 100644 --- a/scripting/java/com/sun/star/script/framework/container/Parcel.java +++ b/scripting/java/com/sun/star/script/framework/container/Parcel.java @@ -62,7 +62,7 @@ public class Parcel implements XNameContainer public java.lang.Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { LogUtils.DEBUG("** Parcel.getByName for " + aName ); - ScriptEntry script = null; + ScriptEntry thescript = null; try { if ( m_descriptor != null && hasElements() ) @@ -70,11 +70,9 @@ public class Parcel implements XNameContainer ScriptEntry[] scripts = m_descriptor.getScriptEntries(); if ( scripts.length != 0 ) { - for ( int index = 0; index < scripts.length; index++ ) - { - if ( scripts[ index ].getLanguageName().equals( aName ) ) - { - script = scripts[ index ]; + for (ScriptEntry script : scripts) { + if (script.getLanguageName().equals(aName)) { + thescript = script; break; } } @@ -86,12 +84,12 @@ public class Parcel implements XNameContainer { throw new com.sun.star.lang.WrappedTargetException( e.toString() ); } - if ( script == null ) + if ( thescript == null ) { LogUtils.DEBUG("No script for " + aName ); throw new com.sun.star.container.NoSuchElementException("No script named " + aName ); } - ScriptMetaData data = new ScriptMetaData( this, script, null ); + ScriptMetaData data = new ScriptMetaData( this, thescript, null ); LogUtils.DEBUG("returning date for " + aName ); return data; diff --git a/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java b/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java index 92e7a5b..38b7dff 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java @@ -121,17 +121,13 @@ public class ParcelContainer implements XNameAccess * @return child <tt>ParcelContainer</tt> or {@code null} if none * found. */ - - public ParcelContainer getChildContainer( String key ) + public ParcelContainer getChildContainer(String key) { ParcelContainer result = null; - Iterator<ParcelContainer> iter = childContainers.iterator(); - while ( iter.hasNext() ) + for (ParcelContainer c : childContainers) { - ParcelContainer c = iter.next(); String location = ScriptMetaData.getLocationPlaceHolder( c.containerUrl, c.getName()); - if ( key.equals( location ) ) { result = c; @@ -151,14 +147,11 @@ public class ParcelContainer implements XNameAccess * @return child <tt>ParcelContainer</tt> or {@code null} if none * found. */ - public ParcelContainer getChildContainerForURL( String containerUrl ) { ParcelContainer result = null; - Iterator<ParcelContainer> iter = childContainers.iterator(); - while ( iter.hasNext() ) + for (ParcelContainer c : childContainers) { - ParcelContainer c = iter.next(); if ( containerUrl.equals( c.containerUrl ) ) { result = c; @@ -294,6 +287,7 @@ public class ParcelContainer implements XNameAccess } return containerUrl; } + public Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, WrappedTargetException { Parcel parcel = null; @@ -301,11 +295,8 @@ public class ParcelContainer implements XNameAccess { if ( hasElements() ) { - Iterator<Parcel> iter = parcels.iterator(); - while ( iter.hasNext() ) + for (Parcel parcelToCheck : parcels) { - Parcel parcelToCheck = iter.next(); - if ( parcelToCheck.getName().equals( aName ) ) { parcel = parcelToCheck; @@ -324,6 +315,7 @@ public class ParcelContainer implements XNameAccess } return parcel; } + public String[] getElementNames() { if ( hasElements() ) @@ -375,18 +367,18 @@ public class ParcelContainer implements XNameAccess LogUtils.DEBUG( getParcelContainerDir() + " is a folder " ); String[] children = m_xSFA.getFolderContents( getParcelContainerDir(), true ); parcels = new ArrayList<Parcel>(children.length); - for ( int i = 0; i < children.length; i++) + for (String child : children) { - LogUtils.DEBUG("Processing " + children[ i ] ); + LogUtils.DEBUG("Processing " + child); try { - loadParcel( children[ i ] ); + loadParcel(child); } catch (java.lang.Exception e) { // print an error message and move on to // the next parcel - LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + children[i] + ": " + e.getMessage() ); + LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + child + ": " + e.getMessage()); } } } diff --git a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java index 8f39afd..e94e0de 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java @@ -221,8 +221,9 @@ public class ParcelDescriptor { public void setScriptEntries(ScriptEntry[] scripts) { clearEntries(); - for (int i = 0; i < scripts.length; i++) - addScriptEntry(scripts[i]); + for (ScriptEntry script : scripts) { + addScriptEntry(script); + } } public void setScriptEntries(Iterator<ScriptEntry> scripts) { diff --git a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java index d281b92..657e7dc 100644 --- a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java @@ -140,24 +140,17 @@ public class UnoPkgContainer extends ParcelContainer if ( db != null ) { String[] packages = db.getDeployedPackages( language ); - - for ( int i=0; i<packages.length;i++) - { - try - { - processUnoPackage( packages[i], language ); - } - catch ( com.sun.star.lang.IllegalArgumentException ila) - { - LogUtils.DEBUG("Failed to process " + packages[i] + " for " + language); + for (String thepackage : packages) { + try { + processUnoPackage(thepackage, language); + } catch (com.sun.star.lang.IllegalArgumentException ila) { + LogUtils.DEBUG("Failed to process " + thepackage + " for " + language); LogUtils.DEBUG(" Reason: " + ila ); - } - catch( Exception e ) - { + } catch (Exception e) { // TODO proper exception or do we wish // to ignore errors here LogUtils.DEBUG("Something very wrong!!!!!"); - LogUtils.DEBUG("Failed to process " + packages[i] + " for " + language); + LogUtils.DEBUG("Failed to process " + thepackage + " for " + language); LogUtils.DEBUG(" Reason: " + e ); } } diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index c1ca79f..1520f3f 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -282,12 +282,11 @@ public class ScriptEditorForBeanShell JPanel p = new JPanel(); p.setLayout(new FlowLayout()); - for (int i = 0; i < labels.length; i++) { - JButton b = new JButton(labels[i]); + for (String label : labels) { + JButton b = new JButton(label); b.addActionListener(this); p.add(b); - - if (labels[i].equals("Save") && filename == null) { + if (label.equals("Save") && filename == null) { b.setEnabled(false); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits