KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
28
29 /**
30   * @grammar (import*)
31   * @children Import import
32   */

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