allow multiple patterns to be specified

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6223 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch committed 2008-06-17 22:29:24 +00:00
1 parent 586ea04522
commit ce359b0b40
1 file changed
+10 -8
@@ -3,6 +3,10 @@
*/
package net.sourceforge.pmd.lang.xpath;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
import org.jaxen.Context;
@@ -11,10 +15,6 @@ import org.jaxen.FunctionCallException;
import org.jaxen.SimpleFunctionContext;
import org.jaxen.XPathFunctionContext;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
// FIXME Can this function be extended to work on non-AST attributes?
public class MatchesFunction implements Function {
@@ -30,10 +30,12 @@ public class MatchesFunction implements Function {
List attributes = (List) args.get(0);
Attribute attr = (Attribute) attributes.get(0);
Pattern check = Pattern.compile((String) args.get(1));
Matcher matcher = check.matcher(attr.getValue());
if (matcher.find()) {
return context.getNodeSet();
for(int i = 1; i < args.size(); i++) {
Pattern check = Pattern.compile((String) args.get(i));
Matcher matcher = check.matcher(attr.getValue());
if (matcher.find()) {
return context.getNodeSet();
}
}
return Boolean.FALSE;
}