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 java.util.LinkedList;
19  
20  /**
21   * Represents an inner class declaration
22   * 
23   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
24   * @version $Revision: 20583 $
25   */
26  public class InnerClassNode extends ClassNode {
27  
28      private ClassNode outerClass;
29      private VariableScope scope;
30      private boolean anonymous;
31  
32      /**
33       * @param name is the full name of the class
34       * @param modifiers the modifiers, @see org.objectweb.asm.Opcodes
35       * @param superClass the base class name - use "java.lang.Object" if no direct base class
36       */
37      public InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass) {
38          this(outerClass, name, modifiers, superClass, ClassHelper.EMPTY_TYPE_ARRAY, MixinNode.EMPTY_ARRAY);
39      }
40  
41      /**
42       * @param name is the full name of the class
43       * @param modifiers the modifiers, @see org.objectweb.asm.Opcodes
44       * @param superClass the base class name - use "java.lang.Object" if no direct base class
45       */
46      public InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins) {
47          super(name, modifiers, superClass, interfaces, mixins);
48          this.outerClass = outerClass;
49  
50          if (outerClass.innerClasses == null)
51              outerClass.innerClasses = new LinkedList<InnerClassNode> ();
52          outerClass.innerClasses.add(this);
53      }
54  
55      public ClassNode getOuterClass() {
56          return outerClass;
57      }
58  
59      /**
60       * @return the field node on the outer class or null if this is not an inner class
61       */
62      public FieldNode getOuterField(String name) {
63          return outerClass.getDeclaredField(name);
64      }
65      
66      public VariableScope getVariableScope() {
67          return scope;        
68      }
69      
70      public void setVariableScope(VariableScope scope) {
71          this.scope = scope;
72      }
73  
74      public boolean isAnonymous() {
75          return anonymous;
76      }
77  
78      public void setAnonymous(boolean anonymous) {
79          this.anonymous = anonymous;
80      }
81  }