KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.IOException JavaDoc;
30
31 import java.util.Iterator JavaDoc;
32
33 /**
34   * @grammar catch*
35   * @children CatchClause clause
36   */

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