Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RegexExpression |
|
| 1.5;1.5 |
1 | /* | |
2 | * Copyright 2003-2007 the original author or authors. | |
3 | * | |
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 | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
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 | */ | |
30 | @Deprecated | |
31 | public class RegexExpression extends Expression { | |
32 | ||
33 | 0 | private static final Logger LOG = Logger.getLogger(RegexExpression.class); |
34 | ||
35 | private final Expression string; | |
36 | ||
37 | 0 | public RegexExpression(Expression string) { |
38 | 0 | this.string = string; |
39 | 0 | super.setType(ClassHelper.PATTERN_TYPE); |
40 | 0 | } |
41 | ||
42 | public void visit(GroovyCodeVisitor visitor) { | |
43 | ||
44 | // find the visitRegexExpression if it exists, ignore otherwise | |
45 | try { | |
46 | 0 | Method method = visitor.getClass().getMethod("visitRegexExpression", RegexExpression.class); |
47 | 0 | method.invoke(visitor, this); |
48 | 0 | } catch (NoSuchMethodException ignored) { |
49 | // no method is the most likely case | |
50 | 0 | }catch (Exception e) { |
51 | 0 | LOG.error("An exception occurred dispatching to visitRegexExpression", e); |
52 | 0 | } |
53 | 0 | } |
54 | ||
55 | public Expression transformExpression(ExpressionTransformer transformer) { | |
56 | 0 | Expression ret = new RegexExpression(transformer.transform(string)); |
57 | 0 | ret.setSourcePosition(this); |
58 | 0 | return ret; |
59 | } | |
60 | ||
61 | public Expression getRegex() { | |
62 | 0 | return string; |
63 | } | |
64 | ||
65 | } |