1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import java.util.ArrayList;
15 import net.sourceforge.phpdt.core.IField;
16 import net.sourceforge.phpdt.core.IMethod;
17 import net.sourceforge.phpdt.core.IPackageFragment;
18 import net.sourceforge.phpdt.core.IType;
21 * @see IJavaElementRequestor
24 public class JavaElementRequestor implements IJavaElementRequestor {
26 * True if this requestor no longer wants to receive results from its
27 * <code>IRequestorNameLookup</code>.
29 protected boolean fCanceled = false;
32 * A collection of the resulting fields, or <code>null</code> if no field
33 * results have been received.
35 protected ArrayList fFields = null;
38 * A collection of the resulting initializers, or <code>null</code> if no
39 * initializer results have been received.
41 protected ArrayList fInitializers = null;
44 * A collection of the resulting member types, or <code>null</code> if no
45 * member type results have been received.
47 protected ArrayList fMemberTypes = null;
50 * A collection of the resulting methods, or <code>null</code> if no
51 * method results have been received.
53 protected ArrayList fMethods = null;
56 * A collection of the resulting package fragments, or <code>null</code>
57 * if no package fragment results have been received.
59 protected ArrayList fPackageFragments = null;
62 * A collection of the resulting types, or <code>null</code> if no type
63 * results have been received.
65 protected ArrayList fTypes = null;
68 * Empty arrays used for efficiency
70 protected static IField[] fgEmptyFieldArray = new IField[0];
72 // protected static IInitializer[] fgEmptyInitializerArray= new
74 protected static IType[] fgEmptyTypeArray = new IType[0];
76 protected static IPackageFragment[] fgEmptyPackageFragmentArray = new IPackageFragment[0];
78 protected static IMethod[] fgEmptyMethodArray = new IMethod[0];
81 * @see IJavaElementRequestor
83 public void acceptField(IField field) {
84 if (fFields == null) {
85 fFields = new ArrayList();
91 * @see IJavaElementRequestor
93 // public void acceptInitializer(IInitializer initializer) {
94 // if (fInitializers == null) {
95 // fInitializers= new ArrayList();
97 // fInitializers.add(initializer);
100 * @see IJavaElementRequestor
102 public void acceptMemberType(IType type) {
103 if (fMemberTypes == null) {
104 fMemberTypes = new ArrayList();
106 fMemberTypes.add(type);
110 * @see IJavaElementRequestor
112 public void acceptMethod(IMethod method) {
113 if (fMethods == null) {
114 fMethods = new ArrayList();
116 fMethods.add(method);
120 * @see IJavaElementRequestor
122 public void acceptPackageFragment(IPackageFragment packageFragment) {
123 if (fPackageFragments == null) {
124 fPackageFragments = new ArrayList();
126 fPackageFragments.add(packageFragment);
130 * @see IJavaElementRequestor
132 public void acceptType(IType type) {
133 if (fTypes == null) {
134 fTypes = new ArrayList();
140 * @see IJavaElementRequestor
142 public IField[] getFields() {
143 if (fFields == null) {
144 return fgEmptyFieldArray;
146 int size = fFields.size();
147 IField[] results = new IField[size];
148 fFields.toArray(results);
153 * @see IJavaElementRequestor
155 // public IInitializer[] getInitializers() {
156 // if (fInitializers == null) {
157 // return fgEmptyInitializerArray;
159 // int size = fInitializers.size();
160 // IInitializer[] results = new IInitializer[size];
161 // fInitializers.toArray(results);
165 * @see IJavaElementRequestor
167 public IType[] getMemberTypes() {
168 if (fMemberTypes == null) {
169 return fgEmptyTypeArray;
171 int size = fMemberTypes.size();
172 IType[] results = new IType[size];
173 fMemberTypes.toArray(results);
178 * @see IJavaElementRequestor
180 public IMethod[] getMethods() {
181 if (fMethods == null) {
182 return fgEmptyMethodArray;
184 int size = fMethods.size();
185 IMethod[] results = new IMethod[size];
186 fMethods.toArray(results);
191 * @see IJavaElementRequestor
193 public IPackageFragment[] getPackageFragments() {
194 if (fPackageFragments == null) {
195 return fgEmptyPackageFragmentArray;
197 int size = fPackageFragments.size();
198 IPackageFragment[] results = new IPackageFragment[size];
199 fPackageFragments.toArray(results);
204 * @see IJavaElementRequestor
206 public IType[] getTypes() {
207 if (fTypes == null) {
208 return fgEmptyTypeArray;
210 int size = fTypes.size();
211 IType[] results = new IType[size];
212 fTypes.toArray(results);
217 * @see IJavaElementRequestor
219 public boolean isCanceled() {
224 * Reset the state of this requestor.
226 public void reset() {
229 fInitializers = null;
232 fPackageFragments = null;
237 * Sets the #isCanceled state of this requestor to true or false.
239 public void setCanceled(boolean b) {