You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/05/16 13:16:02 UTC

[groovy] branch GROOVY_3_0_X updated: Trivial refactoring: 'for' loop replaceable with enhanced 'for' loop

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 003ec5b  Trivial refactoring: 'for' loop replaceable with enhanced 'for' loop
003ec5b is described below

commit 003ec5b2c46e3e6d8c7587799616d38171056d0c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat May 16 20:46:58 2020 +0800

    Trivial refactoring: 'for' loop replaceable with enhanced 'for' loop
    
    (cherry picked from commit c3075611638f46e2b4e3e81450e144ef7b30b49e)
---
 .../org/codehaus/groovy/ant/CompileTaskSupport.java |  3 +--
 .../java/org/codehaus/groovy/ant/GroovycTask.java   | 21 ++++++++++-----------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
index 85e6ec4..35d0e60 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
@@ -142,8 +142,7 @@ public abstract class CompileTaskSupport
         Path path = getClasspath();
         if (path != null) {
             final String[] filePaths = path.list();
-            for (int i = 0; i < filePaths.length; i++) {
-                String filePath = filePaths[i];
+            for (String filePath : filePaths) {
                 gcl.addClasspath(filePath);
             }
         }
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/GroovycTask.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/GroovycTask.java
index a02015f..e108527 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/GroovycTask.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/GroovycTask.java
@@ -58,9 +58,9 @@ public class GroovycTask
         int count = 0;
         String[] list = src.list();
 
-        for (int i = 0; i < list.length; i++) {
-            File basedir = getProject().resolveFile(list[i]);
-            
+        for (String s : list) {
+            File basedir = getProject().resolveFile(s);
+
             if (!basedir.exists()) {
                 throw new BuildException("Source directory does not exist: " + basedir, getLocation());
             }
@@ -71,24 +71,23 @@ public class GroovycTask
             if (force) {
                 log.debug("Forcefully including all files from: " + basedir);
 
-                for (int j=0; j < includes.length; j++) {
-                    File file = new File(basedir, includes[j]);
-                    log.debug("    "  + file);
+                for (String include : includes) {
+                    File file = new File(basedir, include);
+                    log.debug("    " + file);
 
                     compilation.addSource(file);
                     count++;
                 }
-            }
-            else {
+            } else {
                 log.debug("Including changed files from: " + basedir);
 
                 SourceFileScanner sourceScanner = new SourceFileScanner(this);
                 File[] files = sourceScanner.restrictAsFiles(includes, basedir, destdir, mapper);
 
-                for (int j=0; j < files.length; j++) {
-                    log.debug("    "  + files[j]);
+                for (File file : files) {
+                    log.debug("    " + file);
 
-                    compilation.addSource(files[j]);
+                    compilation.addSource(file);
                     count++;
                 }
             }