Skip to content

Instantly share code, notes, and snippets.

@paulk-asert
Created May 28, 2015 11:17
Show Gist options
  • Save paulk-asert/ed2f25035f621248ced8 to your computer and use it in GitHub Desktop.
Save paulk-asert/ed2f25035f621248ced8 to your computer and use it in GitHub Desktop.
Index: src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252
===================================================================
--- src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java (revision 03d9c2673947d44cd01cf1e3ec5bf32459e0b39c)
+++ src/main/org/codehaus/groovy/runtime/IOGroovyMethods.java (revision )
@@ -25,6 +25,7 @@
import groovy.transform.stc.ClosureParams;
import groovy.transform.stc.FirstParam;
import groovy.transform.stc.FromString;
+import groovy.transform.stc.PickFirstResolver;
import groovy.transform.stc.SimpleType;
import org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper;
@@ -554,7 +555,7 @@
* @see java.lang.String#split(java.lang.String)
* @since 1.6.8
*/
- public static <T> T splitEachLine(Reader self, Pattern pattern, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException {
+ public static <T> T splitEachLine(Reader self, Pattern pattern, @ClosureParams(value=FromString.class,options={"List<String>","String[]"},conflictResolutionStrategy=PickFirstResolver.class) Closure<T> closure) throws IOException {
BufferedReader br;
T result = null;
@@ -570,7 +571,7 @@
break;
} else {
List vals = Arrays.asList(pattern.split(line));
- result = closure.call(vals);
+ result = closure.call(hasSingleStringArg(closure) ? vals.get(0) : vals);
}
}
Reader temp = self;
@@ -581,6 +582,12 @@
closeWithWarning(self);
closeWithWarning(br);
}
+ }
+
+ private static boolean hasSingleStringArg(Closure c) {
+ if (c.getMaximumNumberOfParameters() != 1) return false;
+ String typeName = c.getParameterTypes()[0].getName();
+ return typeName.equals("java.lang.String");
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment