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;
17  
18  import org.codehaus.groovy.ast.expr.Expression;
19  import org.codehaus.groovy.ast.stmt.Statement;
20  import org.objectweb.asm.Opcodes;
21  
22  /**
23   * Represents a property (member variable, a getter and setter)
24   *
25   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
26   * @version $Revision: 20583 $
27   */
28  public class PropertyNode extends AnnotatedNode implements Opcodes, Variable {
29  
30      private FieldNode field;
31  
32      private Statement getterBlock;
33      private Statement setterBlock;
34      private final int modifiers;
35      private boolean closureShare = false;
36  
37      public PropertyNode(
38              String name, int modifiers, ClassNode type, ClassNode owner,
39              Expression initialValueExpression, Statement getterBlock,
40              Statement setterBlock) {
41          this(new FieldNode(name, modifiers & ACC_STATIC, type, owner, initialValueExpression), modifiers, getterBlock, setterBlock);
42      }
43  
44      public PropertyNode(FieldNode field, int modifiers, Statement getterBlock, Statement setterBlock) {
45          this.field = field;
46          this.modifiers = modifiers;
47          this.getterBlock = getterBlock;
48          this.setterBlock = setterBlock;
49      }
50  
51      public Statement getGetterBlock() {
52          return getterBlock;
53      }
54  
55      public Expression getInitialExpression() {
56          return field.getInitialExpression();
57      }
58  
59      public void setGetterBlock(Statement getterBlock) {
60          this.getterBlock = getterBlock;
61      }
62  
63      public void setSetterBlock(Statement setterBlock) {
64          this.setterBlock = setterBlock;
65      }
66  
67      public int getModifiers() {
68          return modifiers;
69      }
70  
71      public String getName() {
72          return field.getName();
73      }
74  
75      public Statement getSetterBlock() {
76          return setterBlock;
77      }
78  
79      public ClassNode getType() {
80          return field.getType();
81      }
82  
83      public void setType(ClassNode t) {
84          field.setType(t);
85      }
86  
87      public FieldNode getField() {
88          return field;
89      }
90  
91      public void setField(FieldNode fn) {
92          field = fn;
93      }
94  
95      public boolean isPrivate() {
96          return (modifiers & ACC_PRIVATE) != 0;
97      }
98  
99      public boolean isPublic() {
100         return (modifiers & ACC_PUBLIC) != 0;
101     }
102 
103     public boolean isStatic() {
104         return (modifiers & ACC_STATIC) != 0;
105     }
106 
107     public boolean hasInitialExpression() {
108         return field.hasInitialExpression();
109     }
110 
111     public boolean isInStaticContext() {
112         return field.isInStaticContext();
113     }
114 
115     public boolean isDynamicTyped() {
116         return field.isDynamicTyped();
117     }
118 
119     public boolean isClosureSharedVariable() {
120         return false;
121     }
122 
123     public void setClosureSharedVariable(boolean inClosure) {
124         closureShare = inClosure;
125     }
126 
127     public ClassNode getOriginType() {
128         return getType();
129     }
130 }