Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277248 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
76e199cbe4
11 changed files with 210 additions and 10 deletions
  1. +32
    -2
      src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java
  2. +15
    -0
      src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java
  3. +38
    -1
      src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java
  4. +15
    -0
      src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java
  5. +34
    -2
      src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java
  6. +15
    -0
      src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java
  7. +2
    -0
      src/main/org/apache/tools/ant/util/regexp/Regexp.java
  8. +6
    -0
      src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
  9. +17
    -1
      src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java
  10. +18
    -0
      src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
  11. +18
    -4
      src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java

+ 32
- 2
src/main/org/apache/tools/ant/util/regexp/JakartaOroMatcher.java View File

@@ -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.
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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 {
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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;



+ 15
- 0
src/main/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java View File

@@ -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;


+ 38
- 1
src/main/org/apache/tools/ant/util/regexp/JakartaRegexpMatcher.java View File

@@ -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.
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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.
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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;



+ 15
- 0
src/main/org/apache/tools/ant/util/regexp/JakartaRegexpRegexp.java View File

@@ -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);


+ 34
- 2
src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcher.java View File

@@ -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.
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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 {
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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;


+ 15
- 0
src/main/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java View File

@@ -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


+ 2
- 0
src/main/org/apache/tools/ant/util/regexp/Regexp.java View File

@@ -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;


+ 6
- 0
src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java View File

@@ -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;


+ 17
- 1
src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java View File

@@ -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.
*
* <p>Group 0 will be the full match, the rest are the
* parenthesized subexpressions</p>.
*
* @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;



+ 18
- 0
src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java View File

@@ -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 <code>String</code> value
* @return a <code>RegexpMatcher</code> 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 <code>String</code> value
* @exception BuildException if an error occurs
*/
protected void testAvailability(String className) throws BuildException {
try {
Class.forName(className);


+ 18
- 4
src/main/org/apache/tools/ant/util/regexp/RegexpUtil.java View File

@@ -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 <code>int</code> value
* @param flag an <code>int</code> 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 <code>int</code> value
* @param flag an <code>int</code> value
* @return the options with the flag unset
*/
public static int removeFlag(int options, int flag) {
return (options & (0xFFFFFFFF - flag));
}
}

Loading…
Cancel
Save