From f2c89e45ac5a02aa9b186c28e2163cfe52cf67ec Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:36:01 -0300 Subject: [PATCH] Linting and documentation --- .../codemodder/IncludesExcludesPattern.java | 19 ++++++++++++++----- .../java/io/codemodder/RegexFileChanger.java | 3 --- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/framework/codemodder-base/src/main/java/io/codemodder/IncludesExcludesPattern.java b/framework/codemodder-base/src/main/java/io/codemodder/IncludesExcludesPattern.java index a7f8c8db0..00b802b78 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/IncludesExcludesPattern.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/IncludesExcludesPattern.java @@ -7,10 +7,11 @@ public interface IncludesExcludesPattern { /** - * Returns an IncludesExcludes file matcher that matches files following the patterns against a - * root folder. + * Returns an IncludesExcludes file matcher that matches files following the patterns specified + * patterns. The patterns must follow the java's {@link java.nio.file.PathMatcher} specification + * and are treated as relative paths with regard to the repository root. */ - public IncludesExcludes getRootedMatcher(final Path root); + IncludesExcludes getRootedMatcher(final Path root); class Default implements IncludesExcludesPattern { @@ -34,9 +35,12 @@ public IncludesExcludes getRootedMatcher(final Path root) { } } + /** An includes/excludes pattern that matches java files. */ final class JavaMatcherSingleton { private static IncludesExcludesPattern singleton; + private JavaMatcherSingleton() {} + public static IncludesExcludesPattern getInstance() { if (singleton == null) { singleton = @@ -47,9 +51,12 @@ public static IncludesExcludesPattern getInstance() { } } + /** An includes/excludes pattern that matches any files. */ final class AnySingleton { private static IncludesExcludesPattern singleton; + private AnySingleton() {} + public static IncludesExcludesPattern getInstance() { if (singleton == null) { singleton = new IncludesExcludesPattern.Default(Set.of("**"), Collections.emptySet()); @@ -58,11 +65,13 @@ public static IncludesExcludesPattern getInstance() { } } - public static IncludesExcludesPattern getJavaMatcher() { + /** Returns an includes/excludes pattern that matches any java files. */ + static IncludesExcludesPattern getJavaMatcher() { return JavaMatcherSingleton.getInstance(); } - public static IncludesExcludesPattern getAnyMatcher() { + /** Returns an includes/excludes pattern that matches any files. */ + static IncludesExcludesPattern getAnyMatcher() { return AnySingleton.getInstance(); } } diff --git a/framework/codemodder-base/src/main/java/io/codemodder/RegexFileChanger.java b/framework/codemodder-base/src/main/java/io/codemodder/RegexFileChanger.java index 31f2e86bc..092627b04 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/RegexFileChanger.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/RegexFileChanger.java @@ -4,11 +4,9 @@ import java.io.LineNumberReader; import java.io.StringReader; import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; @@ -33,7 +31,6 @@ protected RegexFileChanger( } protected RegexFileChanger( - final Predicate fileMatcher, final Pattern pattern, final boolean removeEmptyLeftoverLines, final List dependenciesRequired,