KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > ast > GenTypeNames


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.crosscuts.ast;
26 import org.aspectj.compiler.base.ast.*;
27
28 import org.aspectj.compiler.base.JavaCompiler;
29 import org.aspectj.compiler.base.CodeWriter;
30 import java.io.IOException JavaDoc;
31
32 /**
33  * @grammar name (, name)*
34  * @children GenTypeName name
35  */

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