You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/23 08:20:48 UTC
[groovy] 02/03: GROOVY-10050: Add additional NamedParam annotations
in NioExtensions
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 4f14e19f89a83acc7b9ef061ea6b79772e3c6b27
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Apr 22 13:41:13 2021 +1000
GROOVY-10050: Add additional NamedParam annotations in NioExtensions
---
.../groovy/nio/extensions/NioExtensions.java | 64 ++++++++++++++++------
1 file changed, 47 insertions(+), 17 deletions(-)
diff --git a/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java b/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
index 733e540..1786fda 100644
--- a/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
+++ b/subprojects/groovy-nio/src/main/java/org/apache/groovy/nio/extensions/NioExtensions.java
@@ -24,6 +24,7 @@ import groovy.io.GroovyPrintWriter;
import groovy.lang.Closure;
import groovy.lang.MetaClass;
import groovy.lang.Writable;
+import groovy.transform.NamedParam;
import groovy.transform.stc.ClosureParams;
import groovy.transform.stc.FromString;
import groovy.transform.stc.PickFirstResolver;
@@ -66,9 +67,9 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
+import static java.lang.Boolean.FALSE;
import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE;
-import static org.codehaus.groovy.runtime.DefaultGroovyMethods.get;
/**
* This class defines new groovy methods for Readers, Writers, InputStreams and
@@ -887,7 +888,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #eachFile(Path, groovy.io.FileType, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void eachFile(final Path self, final Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException {
+ public static void eachFile(final Path self, final Closure closure) throws IOException {
eachFile(self, FileType.ANY, closure);
}
@@ -902,7 +903,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #eachFile(Path, groovy.io.FileType, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void eachDir(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException {
+ public static void eachDir(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException {
eachFile(self, FileType.DIRECTORIES, closure);
}
@@ -920,7 +921,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @throws IllegalArgumentException if the provided Path object does not represent a directory
* @since 2.3.0
*/
- public static void eachFileRecurse(final Path self, final FileType fileType, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException {
+ public static void eachFileRecurse(final Path self, final FileType fileType, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException {
// throws FileNotFoundException, IllegalArgumentException {
checkDir(self);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(self)) {
@@ -994,14 +995,29 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see groovy.io.FileType
* @since 2.3.0
*/
- public static void traverse(final Path self, final Map<String, Object> options, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure)
- throws IOException {
- // throws FileNotFoundException, IllegalArgumentException {
+ public static void traverse(
+ final Path self,
+ @NamedParam(value = "type", type = FileType.class)
+ @NamedParam(value = "preDir", type = Closure.class)
+ @NamedParam(value = "preRoot", type = Boolean.class)
+ @NamedParam(value = "postDir", type = Closure.class)
+ @NamedParam(value = "postRoot", type = Boolean.class)
+ @NamedParam(value = "visitRoot", type = Boolean.class)
+ @NamedParam(value = "maxDepth", type = Integer.class)
+ @NamedParam(value = "filter")
+ @NamedParam(value = "nameFilter")
+ @NamedParam(value = "excludeFilter")
+ @NamedParam(value = "excludeNameFilter")
+ @NamedParam(value = "sort", type = Closure.class)
+ final Map<String, Object> options,
+ @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path")
+ final Closure closure
+ ) throws IOException {
Number maxDepthNumber = DefaultGroovyMethods.asType(options.remove("maxDepth"), Number.class);
int maxDepth = maxDepthNumber == null ? -1 : maxDepthNumber.intValue();
- Boolean visitRoot = DefaultGroovyMethods.asType(get(options, "visitRoot", false), Boolean.class);
- Boolean preRoot = DefaultGroovyMethods.asType(get(options, "preRoot", false), Boolean.class);
- Boolean postRoot = DefaultGroovyMethods.asType(get(options, "postRoot", false), Boolean.class);
+ Boolean visitRoot = DefaultGroovyMethods.asType(options.getOrDefault("visitRoot", FALSE), Boolean.class);
+ Boolean preRoot = DefaultGroovyMethods.asType(options.getOrDefault("preRoot", FALSE), Boolean.class);
+ Boolean postRoot = DefaultGroovyMethods.asType(options.getOrDefault("postRoot", FALSE), Boolean.class);
final Closure pre = (Closure) options.get("preDir");
final Closure post = (Closure) options.get("postDir");
final FileType type = (FileType) options.get("type");
@@ -1090,8 +1106,22 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #traverse(Path, java.util.Map, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void traverse(final Path self, final Map<String, Object> options)
- throws IOException {
+ public static void traverse(
+ final Path self,
+ @NamedParam(value = "type", type = FileType.class)
+ @NamedParam(value = "preDir", type = Closure.class)
+ @NamedParam(value = "preRoot", type = Boolean.class)
+ @NamedParam(value = "postDir", type = Closure.class)
+ @NamedParam(value = "postRoot", type = Boolean.class)
+ @NamedParam(value = "visitRoot", type = Boolean.class)
+ @NamedParam(value = "maxDepth", type = Integer.class)
+ @NamedParam(value = "filter")
+ @NamedParam(value = "nameFilter")
+ @NamedParam(value = "excludeFilter")
+ @NamedParam(value = "excludeNameFilter")
+ @NamedParam(value = "sort", type = Closure.class)
+ final Map<String, Object> options
+ ) throws IOException {
final Closure visit = (Closure) options.remove("visit");
traverse(self, options, visit);
}
@@ -1170,7 +1200,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void eachFileRecurse(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException {
+ public static void eachFileRecurse(Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") Closure closure) throws IOException {
eachFileRecurse(self, FileType.ANY, closure);
}
@@ -1187,7 +1217,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #eachFileRecurse(Path, groovy.io.FileType, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void eachDirRecurse(final Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException { //throws FileNotFoundException, IllegalArgumentException {
+ public static void eachDirRecurse(final Path self, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException {
eachFileRecurse(self, FileType.DIRECTORIES, closure);
}
@@ -1269,7 +1299,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @see #eachFileMatch(Path, groovy.io.FileType, Object, groovy.lang.Closure)
* @since 2.3.0
*/
- public static void eachDirMatch(final Path self, final Object nameFilter, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException { // throws FileNotFoundException, IllegalArgumentException {
+ public static void eachDirMatch(final Path self, final Object nameFilter, @ClosureParams(value = SimpleType.class, options = "java.nio.file.Path") final Closure closure) throws IOException {
eachFileMatch(self, FileType.DIRECTORIES, nameFilter, closure);
}
@@ -1793,7 +1823,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @throws java.io.FileNotFoundException if the file is not found.
* @since 2.3.0
*/
- public static BufferedInputStream newInputStream(Path self) throws IOException { // throws FileNotFoundException {
+ public static BufferedInputStream newInputStream(Path self) throws IOException {
return new BufferedInputStream(Files.newInputStream(self));
}
@@ -1805,7 +1835,7 @@ public class NioExtensions extends DefaultGroovyMethodsSupport {
* @throws java.io.FileNotFoundException if the file is not found.
* @since 2.3.0
*/
- public static DataInputStream newDataInputStream(Path self) throws IOException { // throws FileNotFoundException {
+ public static DataInputStream newDataInputStream(Path self) throws IOException {
return new DataInputStream(Files.newInputStream(self));
}