KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > SwitchClauses


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.JavaCompiler;
28 import org.aspectj.compiler.base.CodeWriter;
29
30 /**
31  * @grammar case label: stmts
32  * @children SwitchClause clause
33  */

34
35 public class SwitchClauses extends ASTObject {
36
37     //BEGIN: Generated from @child and @property
38
protected int size;
39     public SwitchClause[] children;
40
41     public SwitchClauses(SourceLocation location, SwitchClause[] _children) {
42         super(location);
43         for(int i=0; i<_children.length; i++) {
44             if (_children[i] != null) _children[i].setParent(this);
45         }
46         children = _children;
47         size = _children.length;
48     }
49
50     public SwitchClauses(SourceLocation location) {
51         this(location, new SwitchClause[] {});
52     }
53
54     public SwitchClauses(SourceLocation location, SwitchClause child1) {
55         this(location, new SwitchClause[] {child1});
56     }
57
58     public SwitchClauses(SourceLocation location, SwitchClause child1, SwitchClause child2) {
59         this(location, new SwitchClause[] {child1, child2});
60     }
61
62     public SwitchClauses(SourceLocation location, SwitchClause child1, SwitchClause child2, SwitchClause child3) {
63         this(location, new SwitchClause[] {child1, child2, child3});
64     }
65
66     public ASTObject copyWalk(CopyWalker walker) {
67         final int N = size;
68         SwitchClause[] copiedChildren = new SwitchClause[N];
69         int newIndex = 0;
70         for(int oldIndex=0; oldIndex<N; oldIndex++) {
71             SwitchClause newChild = (SwitchClause)walker.process(children[oldIndex]);
72             if (newChild != null) copiedChildren[newIndex++] = newChild;
73         }
74         SwitchClauses ret = new SwitchClauses(getSourceLocation(),copiedChildren);
75         ret.size = newIndex;
76         ret.setSource(this);
77         return ret;
78     }
79
80     public ASTObject getChildAt(int childIndex) { return get(childIndex); }
81     public void setChildAt(int childIndex, ASTObject child) { set(childIndex, (SwitchClause)child); }
82     public String JavaDoc getChildNameAt(int childIndex) { return "clause"+childIndex; }
83
84     public int getChildCount() { return size; }
85     public int size() { return size; }
86
87     public SwitchClause get(int index) {
88         if (index >= size) throw new ArrayIndexOutOfBoundsException JavaDoc();
89         return children[index];
90     }
91
92     public void set(int index, SwitchClause child) {
93         if (index >= size) throw new ArrayIndexOutOfBoundsException JavaDoc();
94         children[index] = child;
95         child.setParent(this);
96     }
97
98     public void resize(int newSize) {
99         if (newSize > children.length) {
100             SwitchClause[] newChildren = new SwitchClause[children.length*2 + 1];
101             System.arraycopy(children, 0, newChildren, 0, children.length);
102             children = newChildren;
103         }
104         size = newSize;
105     }
106
107     public void addAll(SwitchClauses collection) {
108         addAll(size, collection);
109     }
110
111     public void addAll(int index, SwitchClauses collection) {
112         for(int i=0; i<collection.size(); i++) {
113             add(index+i, collection.get(i));
114         }
115     }
116
117     public void add(SwitchClause child) {
118         add(size, child);
119     }
120
121     public void add(int index, SwitchClause child) {
122         if (child == null) return;
123
124         if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException JavaDoc();
125
126         resize(size+1);
127
128         for(int moveIndex = size-1; moveIndex > index; moveIndex--) {
129             children[moveIndex] = children[moveIndex-1];
130         }
131
132         children[index] = child;
133         child.setParent(this);
134     }
135
136     public void remove(int index) {
137         if (index < 0 || index > size) throw new ArrayIndexOutOfBoundsException JavaDoc();
138
139         size -= 1;
140
141         for(int moveIndex = index; moveIndex < size; moveIndex++) {
142             children[moveIndex] = children[moveIndex+1];
143         }
144     }
145
146     public String JavaDoc getDefaultDisplayName() {
147         return "SwitchClauses()";
148     }
149
150     //END: Generated from @child and @property
151
}
152
153
154
Popular Tags