From 76e199cbe4aaabf0cfdcf3bc59f3fa10e8944bb5 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Fri, 17 Dec 2004 19:46:04 +0000 Subject: [PATCH] checkstyle git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277248 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/util/regexp/JakartaOroMatcher.java | 34 +++++++++++++++- .../ant/util/regexp/JakartaOroRegexp.java | 15 +++++++ .../ant/util/regexp/JakartaRegexpMatcher.java | 39 ++++++++++++++++++- .../ant/util/regexp/JakartaRegexpRegexp.java | 15 +++++++ .../ant/util/regexp/Jdk14RegexpMatcher.java | 36 ++++++++++++++++- .../ant/util/regexp/Jdk14RegexpRegexp.java | 15 +++++++ .../apache/tools/ant/util/regexp/Regexp.java | 2 + .../tools/ant/util/regexp/RegexpFactory.java | 6 +++ .../tools/ant/util/regexp/RegexpMatcher.java | 18 ++++++++- .../ant/util/regexp/RegexpMatcherFactory.java | 18 +++++++++ .../tools/ant/util/regexp/RegexpUtil.java | 22 +++++++++-- 11 files changed, 210 insertions(+), 10 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java b/src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java index e35ea3459..45c2a676a 100644 --- a/src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java +++ b/src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java @@ -34,11 +34,15 @@ public class JakartaOroMatcher implements RegexpMatcher { protected final Perl5Compiler compiler = new Perl5Compiler(); protected final Perl5Matcher matcher = new Perl5Matcher(); + /** + * Constructor for JakartaOroMatcher. + */ public JakartaOroMatcher() { } /** * Set the regexp pattern from the String description. + * @param pattern the pattern to match */ public void setPattern(String pattern) { this.pattern = pattern; @@ -46,6 +50,7 @@ public class JakartaOroMatcher implements RegexpMatcher { /** * Get a String representation of the regexp pattern + * @return the pattern */ public String getPattern() { return this.pattern; @@ -53,6 +58,9 @@ public class JakartaOroMatcher implements RegexpMatcher { /** * Get a compiled representation of the regexp pattern + * @param options the options + * @return the compiled pattern + * @throws BuildException on error */ protected Pattern getCompiledPattern(int options) throws BuildException { @@ -66,7 +74,10 @@ public class JakartaOroMatcher implements RegexpMatcher { } /** - * Does the given argument match the pattern? + * Does the given argument match the pattern using default options? + * @param argument the string to match against + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String argument) throws BuildException { return matches(argument, MATCH_DEFAULT); @@ -74,6 +85,10 @@ public class JakartaOroMatcher implements RegexpMatcher { /** * Does the given argument match the pattern? + * @param input the string to match against + * @param options the regex options to use + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String input, int options) throws BuildException { @@ -82,10 +97,15 @@ public class JakartaOroMatcher implements RegexpMatcher { } /** - * Returns a Vector of matched groups found in the argument. + * Returns a Vector of matched groups found in the argument + * using default options. * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param argument the string to match against + * @return the vector of groups + * @throws BuildException on error */ public Vector getGroups(String argument) throws BuildException { return getGroups(argument, MATCH_DEFAULT); @@ -96,6 +116,11 @@ public class JakartaOroMatcher implements RegexpMatcher { * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param input the string to match against + * @param options the regex options to use + * @return the vector of groups + * @throws BuildException on error */ public Vector getGroups(String input, int options) throws BuildException { @@ -116,6 +141,11 @@ public class JakartaOroMatcher implements RegexpMatcher { return v; } + /** + * Convert the generic options to the regex compiler specific options. + * @param options the generic options + * @return the specific options + */ protected int getCompilerOptions(int options) { int cOptions = Perl5Compiler.DEFAULT_MASK; diff --git a/src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java b/src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java index e2ab7482a..510975837 100644 --- a/src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java +++ b/src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java @@ -28,10 +28,19 @@ import org.apache.tools.ant.BuildException; */ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { + /** Constructor for JakartaOroRegexp */ public JakartaOroRegexp() { super(); } + /** + * Perform a substitution on the regular expression. + * @param input The string to substitute on + * @param argument The string which defines the substitution + * @param options The list of options for the match and replace. + * @return the result of the operation + * @throws BuildException on error + */ public String substitute(String input, String argument, int options) throws BuildException { // translate \1 to $1 so that the Perl5Substitution will work @@ -71,6 +80,12 @@ public class JakartaOroRegexp extends JakartaOroMatcher implements Regexp { getSubsOptions(options)); } + /** + * Convert ant regexp substitution option to oro options. + * + * @param options the ant regexp options + * @return the oro substition options + */ protected int getSubsOptions(int options) { boolean replaceAll = RegexpUtil.hasFlag(options, REPLACE_ALL); int subsOptions = 1; diff --git a/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java b/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java index 86e58039e..1616340a1 100644 --- a/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java +++ b/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java @@ -32,6 +32,7 @@ public class JakartaRegexpMatcher implements RegexpMatcher { /** * Set the regexp pattern from the String description. + * @param pattern the pattern to match */ public void setPattern(String pattern) { this.pattern = pattern; @@ -39,11 +40,19 @@ public class JakartaRegexpMatcher implements RegexpMatcher { /** * Get a String representation of the regexp pattern + * @return the pattern */ public String getPattern() { return pattern; } + /** + * Compile the pattern. + * + * @param options the ant regexp options + * @return a compiled pattern + * @exception BuildException if an error occurs + */ protected RE getCompiledPattern(int options) throws BuildException { int cOptions = getCompilerOptions(options); @@ -58,6 +67,9 @@ public class JakartaRegexpMatcher implements RegexpMatcher { /** * Does the given argument match the pattern? + * @param argument the string to match against + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String argument) throws BuildException { return matches(argument, MATCH_DEFAULT); @@ -65,6 +77,10 @@ public class JakartaRegexpMatcher implements RegexpMatcher { /** * Does the given argument match the pattern? + * @param input the string to match against + * @param options the regex options to use + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String input, int options) throws BuildException { @@ -76,15 +92,31 @@ public class JakartaRegexpMatcher implements RegexpMatcher { } /** - * Returns a Vector of matched groups found in the argument. + * Returns a Vector of matched groups found in the argument + * using default options. * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param argument the string to match against + * @return the vector of groups + * @throws BuildException on error */ public Vector getGroups(String argument) throws BuildException { return getGroups(argument, MATCH_DEFAULT); } + /** + * Returns a Vector of matched groups found in the argument. + * + *

Group 0 will be the full match, the rest are the + * parenthesized subexpressions

. + * + * @param input the string to match against + * @param options the regex options to use + * @return the vector of groups + * @throws BuildException on error + */ public Vector getGroups(String input, int options) throws BuildException { RE reg = getCompiledPattern(options); @@ -104,6 +136,11 @@ public class JakartaRegexpMatcher implements RegexpMatcher { return v; } + /** + * Convert the generic options to the regex compiler specific options. + * @param options the generic options + * @return the specific options + */ protected int getCompilerOptions(int options) { int cOptions = RE.MATCH_NORMAL; diff --git a/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java b/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java index 4c3f1f89d..f858fddd7 100644 --- a/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java +++ b/src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java @@ -27,10 +27,17 @@ import org.apache.tools.ant.BuildException; public class JakartaRegexpRegexp extends JakartaRegexpMatcher implements Regexp { + /** Constructor for JakartaRegexpRegexp */ public JakartaRegexpRegexp() { super(); } + /** + * Convert ant regexp substitution option to apache regex options. + * + * @param options the ant regexp options + * @return the apache regex substition options + */ protected int getSubsOptions(int options) { int subsOptions = RE.REPLACE_FIRSTONLY; if (RegexpUtil.hasFlag(options, REPLACE_ALL)) { @@ -39,6 +46,14 @@ public class JakartaRegexpRegexp extends JakartaRegexpMatcher return subsOptions; } + /** + * Perform a substitution on the regular expression. + * @param input The string to substitute on + * @param argument The string which defines the substitution + * @param options The list of options for the match and replace. + * @return the result of the operation + * @throws BuildException on error + */ public String substitute(String input, String argument, int options) throws BuildException { Vector v = getGroups(input, options); diff --git a/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java b/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java index 21a6cbe6a..cad5354ce 100644 --- a/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java +++ b/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java @@ -32,11 +32,13 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { private String pattern; + /** Constructor for JakartaOroRegexp */ public Jdk14RegexpMatcher() { } /** * Set the regexp pattern from the String description. + * @param pattern the pattern to match */ public void setPattern(String pattern) { this.pattern = pattern; @@ -44,11 +46,19 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { /** * Get a String representation of the regexp pattern + * @return the pattern + * @throws BuildException on error */ public String getPattern() { return pattern; } + /** + * Get a compiled representation of the regexp pattern + * @param options the options + * @return the compiled pattern + * @throws BuildException on error + */ protected Pattern getCompiledPattern(int options) throws BuildException { int cOptions = getCompilerOptions(options); @@ -61,7 +71,10 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { } /** - * Does the given argument match the pattern? + * Does the given argument match the pattern using default options? + * @param argument the string to match against + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String argument) throws BuildException { return matches(argument, MATCH_DEFAULT); @@ -69,6 +82,10 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { /** * Does the given argument match the pattern? + * @param input the string to match against + * @param options the regex options to use + * @return true if the pattern matches + * @throws BuildException on error */ public boolean matches(String input, int options) throws BuildException { @@ -81,10 +98,15 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { } /** - * Returns a Vector of matched groups found in the argument. + * Returns a Vector of matched groups found in the argument + * using default options. * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param argument the string to match against + * @return the vector of groups + * @throws BuildException on error */ public Vector getGroups(String argument) throws BuildException { return getGroups(argument, MATCH_DEFAULT); @@ -95,6 +117,11 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param input the string to match against + * @param options the regex options to use + * @return the vector of groups + * @throws BuildException on error */ public Vector getGroups(String input, int options) throws BuildException { @@ -116,6 +143,11 @@ public class Jdk14RegexpMatcher implements RegexpMatcher { return v; } + /** + * Convert the generic options to the regex compiler specific options. + * @param options the generic options + * @return the specific options + */ protected int getCompilerOptions(int options) { // be strict about line separator int cOptions = Pattern.UNIX_LINES; diff --git a/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java b/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java index bb6a064c8..eb9eab8af 100644 --- a/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java +++ b/src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java @@ -27,10 +27,17 @@ import org.apache.tools.ant.BuildException; */ public class Jdk14RegexpRegexp extends Jdk14RegexpMatcher implements Regexp { + /** Constructor for Jdk14RegexpRegexp */ public Jdk14RegexpRegexp() { super(); } + /** + * Convert ant regexp substitution option to jdk1.4 options. + * + * @param options the ant regexp options + * @return the jdk14 substition options + */ protected int getSubsOptions(int options) { int subsOptions = REPLACE_FIRST; if (RegexpUtil.hasFlag(options, REPLACE_ALL)) { @@ -39,6 +46,14 @@ public class Jdk14RegexpRegexp extends Jdk14RegexpMatcher implements Regexp { return subsOptions; } + /** + * Perform a substitution on the regular expression. + * @param input The string to substitute on + * @param argument The string which defines the substitution + * @param options The list of options for the match and replace. + * @return the result of the operation + * @throws BuildException on error + */ public String substitute(String input, String argument, int options) throws BuildException { // translate \1 to $(1) so that the Matcher will work diff --git a/src/main/org/apache/tools/ant/util/regexp/Regexp.java b/src/main/org/apache/tools/ant/util/regexp/Regexp.java index 102bbb061..9f7270e7d 100644 --- a/src/main/org/apache/tools/ant/util/regexp/Regexp.java +++ b/src/main/org/apache/tools/ant/util/regexp/Regexp.java @@ -41,6 +41,8 @@ public interface Regexp extends RegexpMatcher { * @param argument The string which defines the substitution * @param options The list of options for the match and replace. See the * MATCH_ and REPLACE_ constants above. + * @return the result of the operation + * @throws BuildException on error */ String substitute(String input, String argument, int options) throws BuildException; diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java index 7204996dd..033a5d054 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java @@ -27,11 +27,15 @@ import org.apache.tools.ant.Project; * @version $Revision$ */ public class RegexpFactory extends RegexpMatcherFactory { + + /** Constructor for RegexpFactory */ public RegexpFactory() { } /*** * Create a new regular expression matcher instance. + * @return the matcher instance + * @throws BuildException on error */ public Regexp newRegexp() throws BuildException { return (Regexp) newRegexp(null); @@ -41,6 +45,8 @@ public class RegexpFactory extends RegexpMatcherFactory { * Create a new regular expression matcher instance. * * @param p Project whose ant.regexp.regexpimpl property will be used. + * @return the matcher instance + * @throws BuildException on error */ public Regexp newRegexp(Project p) throws BuildException { String systemDefault = null; diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java index e11bff69c..282ef0329 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java @@ -50,24 +50,36 @@ public interface RegexpMatcher { /** * Set the regexp pattern from the String description. + * @param pattern the pattern to match + * @throws BuildException on error */ void setPattern(String pattern) throws BuildException; /** * Get a String representation of the regexp pattern + * @return the pattern + * @throws BuildException on error */ String getPattern() throws BuildException; /** * Does the given argument match the pattern? + * @param argument the string to match against + * @return true if the pattern matches + * @throws BuildException on error */ boolean matches(String argument) throws BuildException; /** - * Returns a Vector of matched groups found in the argument. + * Returns a Vector of matched groups found in the argument + * using default options. * *

Group 0 will be the full match, the rest are the * parenthesized subexpressions

. + * + * @param argument the string to match against + * @return the vector of groups + * @throws BuildException on error */ Vector getGroups(String argument) throws BuildException; @@ -77,6 +89,8 @@ public interface RegexpMatcher { * @param input The string to check for a match * @param options The list of options for the match. See the * MATCH_ constants above. + * @return true if the pattern matches + * @throws BuildException on error */ boolean matches(String input, int options) throws BuildException; @@ -86,6 +100,8 @@ public interface RegexpMatcher { * @param input The string to check for a match * @param options The list of options for the match. See the * MATCH_ constants above. + * @return the vector of groups + * @throws BuildException on error */ Vector getGroups(String input, int options) throws BuildException; diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java index 530320cff..6d4f7d287 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java @@ -32,11 +32,14 @@ import org.apache.tools.ant.Project; */ public class RegexpMatcherFactory { + /** Constructor for RegexpMatcherFactory. */ public RegexpMatcherFactory() { } /*** * Create a new regular expression instance. + * @return the matcher + * @throws BuildException on error */ public RegexpMatcher newRegexpMatcher() throws BuildException { return newRegexpMatcher(null); @@ -46,6 +49,8 @@ public class RegexpMatcherFactory { * Create a new regular expression instance. * * @param p Project whose ant.regexp.regexpimpl property will be used. + * @return the matcher + * @throws BuildException on error */ public RegexpMatcher newRegexpMatcher(Project p) throws BuildException { @@ -86,6 +91,13 @@ public class RegexpMatcherFactory { throw new BuildException("No supported regular expression matcher found"); } + /** + * Create an instance of a matcher from a classname. + * + * @param className a String value + * @return a RegexpMatcher value + * @exception BuildException if an error occurs + */ protected RegexpMatcher createInstance(String className) throws BuildException { try { @@ -96,6 +108,12 @@ public class RegexpMatcherFactory { } } + /** + * Test if a particular class is available to be used. + * + * @param className a String value + * @exception BuildException if an error occurs + */ protected void testAvailability(String className) throws BuildException { try { Class.forName(className); diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java b/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java index 01ea71f7a..dea822832 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java @@ -17,18 +17,32 @@ package org.apache.tools.ant.util.regexp; /*** - * Regular expression utilities class which handles flag operations + * Regular expression utilities class which handles flag operations. * */ -public class RegexpUtil { +public final class RegexpUtil { private RegexpUtil() { } - public static final boolean hasFlag(int options, int flag) { + /** + * Check the options has a particular flag set. + * + * @param options an int value + * @param flag an int value + * @return true if the flag is set + */ + public static boolean hasFlag(int options, int flag) { return ((options & flag) > 0); } - public static final int removeFlag(int options, int flag) { + /** + * Remove a particular flag from an int value contains the option flags. + * + * @param options an int value + * @param flag an int value + * @return the options with the flag unset + */ + public static int removeFlag(int options, int flag) { return (options & (0xFFFFFFFF - flag)); } }