2
* Copyright 2003-2007 the original author or authors.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package org.codehaus.groovy.ast.expr;
18
import org.apache.log4j.Logger;
19
import org.codehaus.groovy.ast.ClassHelper;
20
import org.codehaus.groovy.ast.GroovyCodeVisitor;
22
import java.lang.reflect.Method;
25
* Represents a regular expression of the form ~<double quoted string> which creates
26
* a regular expression.
28
* @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
31
public class RegexExpression extends Expression {
33
private static final Logger LOG = Logger.getLogger(RegexExpression.class);
35
private final Expression string;
37
public RegexExpression(Expression string) {
39
super.setType(ClassHelper.PATTERN_TYPE);
42
public void visit(GroovyCodeVisitor visitor) {
44
// find the visitRegexExpression if it exists, ignore otherwise
46
Method method = visitor.getClass().getMethod("visitRegexExpression", RegexExpression.class);
47
method.invoke(visitor, this);
48
} catch (NoSuchMethodException ignored) {
49
// no method is the most likely case
50
}catch (Exception e) {
51
LOG.error("An exception occurred dispatching to visitRegexExpression", e);
55
public Expression transformExpression(ExpressionTransformer transformer) {
56
Expression ret = new RegexExpression(transformer.transform(string));
57
ret.setSourcePosition(this);
61
public Expression getRegex() {
b'\\ No newline at end of file'