use of java.util.regex.Pattern in project groovy by apache.
the class GroovyDocToolTest method testInnerEnumReference.
public void testInnerEnumReference() throws Exception {
List<String> srcList = new ArrayList<String>();
srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/InnerEnum.groovy");
srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/InnerClassProperty.groovy");
htmlTool.add(srcList);
MockOutputTool output = new MockOutputTool();
htmlTool.renderToOutput(output, MOCK_DIR);
String derivDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/InnerClassProperty.html");
Pattern p = Pattern.compile("<a(.+?)testfiles/InnerEnum.Enum.html'>(.+?)</a>");
Matcher m = p.matcher(derivDoc);
assertTrue(m.find());
assertEquals("There has to be a reference to class Enum", "Enum", m.group(2));
}
use of java.util.regex.Pattern in project groovy by apache.
the class Sql method nullify.
/**
* Hook to allow derived classes to override null handling.
* Default behavior is to replace ?'"? references with NULLish
*
* @param sql the SQL statement
* @return the modified SQL String
*/
protected String nullify(String sql) {
/*
* Some drivers (Oracle classes12.zip) have difficulty resolving data
* type if setObject(null). We will modify the query to pass 'null', 'is
* null', and 'is not null'
*/
//could be more efficient by compiling expressions in advance.
int firstWhere = findWhereKeyword(sql);
if (firstWhere >= 0) {
Pattern[] patterns = { Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)!=\\s{0,1}(\\s*)\\?'\"\\?(.*)"), Pattern.compile("(?is)^(.{" + firstWhere + "}.*?)<>\\s{0,1}(\\s*)\\?'\"\\?(.*)"), Pattern.compile("(?is)^(.{" + firstWhere + "}.*?[^<>])=\\s{0,1}(\\s*)\\?'\"\\?(.*)") };
String[] replacements = { "$1 is not $2null$3", "$1 is not $2null$3", "$1 is $2null$3" };
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(sql);
while (matcher.matches()) {
sql = matcher.replaceAll(replacements[i]);
matcher = patterns[i].matcher(sql);
}
}
}
return sql.replaceAll("\\?'\"\\?", "null");
}
use of java.util.regex.Pattern in project groovy by apache.
the class GroovyDocToolTest method testClassAliasing.
public void testClassAliasing() throws Exception {
List<String> srcList = new ArrayList<String>();
srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/Alias.groovy");
htmlTool.add(srcList);
MockOutputTool output = new MockOutputTool();
htmlTool.renderToOutput(output, MOCK_DIR);
String derivDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/Alias.html");
Pattern p = Pattern.compile("<a(.+?)java/util/ArrayList.html' title='ArrayList'>(.+?)</a>");
Matcher m = p.matcher(derivDoc);
assertTrue(m.find());
assertEquals("There has to be a reference to class ArrayList", "ArrayList", m.group(2));
}
use of java.util.regex.Pattern in project groovy by apache.
the class GroovyDocToolTest method testArrayPropertyLinkWithExternalReference.
public void testArrayPropertyLinkWithExternalReference() throws Exception {
List<String> srcList = new ArrayList<String>();
srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/PropertyLink.groovy");
srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/ArrayPropertyLink.groovy");
htmlTool.add(srcList);
MockOutputTool output = new MockOutputTool();
htmlTool.renderToOutput(output, MOCK_DIR);
String propertyLinkDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/PropertyLink.html");
Pattern p = Pattern.compile("<a(.+?)ArrayPropertyLink.html'>(.+?)</a>\\[\\]");
Matcher m = p.matcher(propertyLinkDoc);
assertTrue(m.find());
assertEquals("There has to be at least a single reference to the ArrayPropertyLink[]", "ArrayPropertyLink", m.group(2));
}
use of java.util.regex.Pattern in project groovy by apache.
the class InvokerHelper method matchRegex.
/**
* Find the right hand regex within the left hand string and return a matcher.
*
* @param left string to compare
* @param right regular expression to compare the string to
*/
public static boolean matchRegex(Object left, Object right) {
if (left == null || right == null)
return false;
Pattern pattern;
if (right instanceof Pattern) {
pattern = (Pattern) right;
} else {
pattern = Pattern.compile(toString(right));
}
String stringToCompare = toString(left);
Matcher matcher = pattern.matcher(stringToCompare);
RegexSupport.setLastMatcher(matcher);
return matcher.matches();
}
Aggregations