org/codehaus/groovy/ast/expr/RegexExpression.java

`RegexExpression.java`
`01 /* 02 * Copyright 2003-2007 the original author or authors. 03 * 04 * Licensed under the Apache License, Version 2.0 (the "License"); 05 * you may not use this file except in compliance with the License. 06 * You may obtain a copy of the License at 07 * 08 * http://www.apache.org/licenses/LICENSE-2.0 09 * 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. 15 */ 16 package org.codehaus.groovy.ast.expr; 17 18 import org.apache.log4j.Logger; 19 import org.codehaus.groovy.ast.ClassHelper; 20 import org.codehaus.groovy.ast.GroovyCodeVisitor; 21 22 import java.lang.reflect.Method; 23 24 /** 25 * Represents a regular expression of the form ~<double quoted string> which creates 26 * a regular expression. 27 * 28 * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> 29 * @version $Revision$ 30 */ 31 @Deprecated 32 public class RegexExpression extends Expression { 33 34 private static final Logger LOG = Logger.getLogger(RegexExpression.class); 35 36 private final Expression string; 37 38 public RegexExpression(Expression string) { 39 this.string = string; 40 super.setType(ClassHelper.PATTERN_TYPE); 41 } 42 43 public void visit(GroovyCodeVisitor visitor) { 44 45 // find the visitRegexExpression if it exists, ignore otherwise 46 try { 47 Method method = visitor.getClass().getMethod("visitRegexExpression", RegexExpression.class); 48 method.invoke(visitor, this); 49 } catch (NoSuchMethodException ignored) { 50 // no method is the most likely case 51 } catch (Exception e) { 52 LOG.error("An exception occurred dispatching to visitRegexExpression", e); 53 } 54 } 55 56 public Expression transformExpression(ExpressionTransformer transformer) { 57 Expression ret = new RegexExpression(transformer.transform(string)); 58 ret.setSourcePosition(this); 59 return ret; 60 } 61 62 public Expression getRegex() { 63 return string; 64 } 65 66 }`