KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.aspectj.compiler.base.cst.*;
30
31 import java.util.Iterator JavaDoc;
32
33 /**
34   * @grammar (name, )*
35   * @children TypeD typeD
36   */

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