KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > JavaElementRequestor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jdt.core.IField;
16 import org.eclipse.jdt.core.IInitializer;
17 import org.eclipse.jdt.core.IMethod;
18 import org.eclipse.jdt.core.IPackageFragment;
19 import org.eclipse.jdt.core.IType;
20
21 /**
22  * @see IJavaElementRequestor
23  */

24
25 public class JavaElementRequestor implements IJavaElementRequestor {
26     /**
27      * True if this requestor no longer wants to receive
28      * results from its <code>IRequestorNameLookup</code>.
29      */

30     protected boolean fCanceled= false;
31     
32     /**
33      * A collection of the resulting fields, or <code>null</code>
34      * if no field results have been received.
35      */

36     protected ArrayList JavaDoc fFields= null;
37
38     /**
39      * A collection of the resulting initializers, or <code>null</code>
40      * if no initializer results have been received.
41      */

42     protected ArrayList JavaDoc fInitializers= null;
43
44     /**
45      * A collection of the resulting member types, or <code>null</code>
46      * if no member type results have been received.
47      */

48     protected ArrayList JavaDoc fMemberTypes= null;
49
50     /**
51      * A collection of the resulting methods, or <code>null</code>
52      * if no method results have been received.
53      */

54     protected ArrayList JavaDoc fMethods= null;
55
56     /**
57      * A collection of the resulting package fragments, or <code>null</code>
58      * if no package fragment results have been received.
59      */

60     protected ArrayList JavaDoc fPackageFragments= null;
61
62     /**
63      * A collection of the resulting types, or <code>null</code>
64      * if no type results have been received.
65      */

66     protected ArrayList JavaDoc fTypes= null;
67
68     /**
69      * Empty arrays used for efficiency
70      */

71     protected static IField[] fgEmptyFieldArray= new IField[0];
72     protected static IInitializer[] fgEmptyInitializerArray= new IInitializer[0];
73     protected static IType[] fgEmptyTypeArray= new IType[0];
74     protected static IPackageFragment[] fgEmptyPackageFragmentArray= new IPackageFragment[0];
75     protected static IMethod[] fgEmptyMethodArray= new IMethod[0];
76 /**
77  * @see IJavaElementRequestor
78  */

79 public void acceptField(IField field) {
80     if (fFields == null) {
81         fFields= new ArrayList JavaDoc();
82     }
83     fFields.add(field);
84 }
85 /**
86  * @see IJavaElementRequestor
87  */

88 public void acceptInitializer(IInitializer initializer) {
89     if (fInitializers == null) {
90         fInitializers= new ArrayList JavaDoc();
91     }
92     fInitializers.add(initializer);
93 }
94 /**
95  * @see IJavaElementRequestor
96  */

97 public void acceptMemberType(IType type) {
98     if (fMemberTypes == null) {
99         fMemberTypes= new ArrayList JavaDoc();
100     }
101     fMemberTypes.add(type);
102 }
103 /**
104  * @see IJavaElementRequestor
105  */

106 public void acceptMethod(IMethod method) {
107     if (fMethods == null) {
108         fMethods = new ArrayList JavaDoc();
109     }
110     fMethods.add(method);
111 }
112 /**
113  * @see IJavaElementRequestor
114  */

115 public void acceptPackageFragment(IPackageFragment packageFragment) {
116     if (fPackageFragments== null) {
117         fPackageFragments= new ArrayList JavaDoc();
118     }
119     fPackageFragments.add(packageFragment);
120 }
121 /**
122  * @see IJavaElementRequestor
123  */

124 public void acceptType(IType type) {
125     if (fTypes == null) {
126         fTypes= new ArrayList JavaDoc();
127     }
128     fTypes.add(type);
129 }
130 /**
131  * @see IJavaElementRequestor
132  */

133 public IField[] getFields() {
134     if (fFields == null) {
135         return fgEmptyFieldArray;
136     }
137     int size = fFields.size();
138     IField[] results = new IField[size];
139     fFields.toArray(results);
140     return results;
141 }
142 /**
143  * @see IJavaElementRequestor
144  */

145 public IInitializer[] getInitializers() {
146     if (fInitializers == null) {
147         return fgEmptyInitializerArray;
148     }
149     int size = fInitializers.size();
150     IInitializer[] results = new IInitializer[size];
151     fInitializers.toArray(results);
152     return results;
153 }
154 /**
155  * @see IJavaElementRequestor
156  */

157 public IType[] getMemberTypes() {
158     if (fMemberTypes == null) {
159         return fgEmptyTypeArray;
160     }
161     int size = fMemberTypes.size();
162     IType[] results = new IType[size];
163     fMemberTypes.toArray(results);
164     return results;
165 }
166 /**
167  * @see IJavaElementRequestor
168  */

169 public IMethod[] getMethods() {
170     if (fMethods == null) {
171         return fgEmptyMethodArray;
172     }
173     int size = fMethods.size();
174     IMethod[] results = new IMethod[size];
175     fMethods.toArray(results);
176     return results;
177 }
178 /**
179  * @see IJavaElementRequestor
180  */

181 public IPackageFragment[] getPackageFragments() {
182     if (fPackageFragments== null) {
183         return fgEmptyPackageFragmentArray;
184     }
185     int size = fPackageFragments.size();
186     IPackageFragment[] results = new IPackageFragment[size];
187     fPackageFragments.toArray(results);
188     return results;
189 }
190 /**
191  * @see IJavaElementRequestor
192  */

193 public IType[] getTypes() {
194     if (fTypes== null) {
195         return fgEmptyTypeArray;
196     }
197     int size = fTypes.size();
198     IType[] results = new IType[size];
199     fTypes.toArray(results);
200     return results;
201 }
202 /**
203  * @see IJavaElementRequestor
204  */

205 public boolean isCanceled() {
206     return fCanceled;
207 }
208 /**
209  * Reset the state of this requestor.
210  */

211 public void reset() {
212     fCanceled = false;
213     fFields = null;
214     fInitializers = null;
215     fMemberTypes = null;
216     fMethods = null;
217     fPackageFragments = null;
218     fTypes = null;
219 }
220 /**
221  * Sets the #isCanceled state of this requestor to true or false.
222  */

223 public void setCanceled(boolean b) {
224     fCanceled= b;
225 }
226 }
227
Popular Tags