View Javadoc
Minimize
Table

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.codehaus.groovy.ast.ClassNode;
19  import org.codehaus.groovy.ast.FieldNode;
20  import org.codehaus.groovy.ast.GroovyCodeVisitor;
21  
22  /**
23   * Represents a field access such as the expression "this.foo".
24   * 
25   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
26   * @version $Revision: 20953 $
27   */
28  public class FieldExpression extends Expression {
29  
30      private final FieldNode field;
31      private boolean useRef;
32      
33      public FieldExpression(FieldNode field) {
34          this.field = field;
35      }
36      
37      public void visit(GroovyCodeVisitor visitor) {
38          visitor.visitFieldExpression(this);
39      }
40  
41      public Expression transformExpression(ExpressionTransformer transformer) {
42          return this;
43      }
44      
45      public String getFieldName() {
46          return field.getName();
47      }
48  
49      public FieldNode getField() {
50          return field;
51      }
52  
53      public String getText() {
54          return "this." + field.getName();
55      }
56  
57      public boolean isDynamicTyped() {
58          return field.isDynamicTyped();
59      }
60  
61      public void setType(ClassNode type) {
62          super.setType(type);
63          field.setType(type);
64      }
65      
66      public ClassNode getType() {
67          return field.getType();
68      }
69      
70      public void setUseReferenceDirectly(boolean useRef) {
71          this.useRef = useRef;        
72      }
73      
74      public boolean isUseReferenceDirectly() {
75          return useRef;
76      }
77      
78      public String toString() {
79          return "field("+getType()+" "+getFieldName()+")";
80      }
81  }