KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.compiler.base.cst.Name;
32
33 /**
34  * @grammar name (.name)*
35  * @children NamePattern name
36  */

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