org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRequestor.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (download) (annotate)
Sat Mar 7 01:08:09 2009 UTC (8 months, 3 weeks ago) by oliviert
Branch: MAIN
CVS Tags: v_943, v_942, v_974_R35x, v_969_R35x, v_A03, v_A02, v_A01, v_A00, v_A07, v_A06, v_A05, v_A04, v_A09, v_A08, v_968_R35x, v_958, v_959, v_950, v_951, v_952, v_953, v_954, v_955, v_956, v_957, v_971_R35x, v_978_R35x, v_961, v_960, v_963, v_962, v_964_R35x, v_977_R35x, R3_5, v_A18, v_A19, v_A14, v_A15, v_A16, v_A10, v_A11, v_A12, v_A13, v_966_R35x, v_970_R35x, v_A21, v_A20, v_A23, v_A22, v_975_R35x, v_976_R35x, v_967_R35x, v_965_R35x, v_A21d, v_A21a, jsr308_A22, v_972_R35x, v_949, v_948, v_947, v_946, v_945, v_944, R3_5_1, v_A17b, v_A17c, v_973_R35x, HEAD
Branch point for: JSR_308, R3_5_maintenance
Changes since 1.14: +1 -1 lines
HEAD - Fix copyrights
/*******************************************************************************
 * Copyright (c) 2005, 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.core.dom;

import org.eclipse.jdt.core.ICompilationUnit;

/**
 * An AST requestor handles ASTs for compilation units passed to
 * <code>ASTParser.createASTs</code>.
 * <p>
 * <code>ASTRequestor.acceptAST</code> is called for each of the
 * compilation units passed to <code>ASTParser.createASTs</code>.
 * After all the compilation units have been processed,
 * <code>ASTRequestor.acceptBindings</code> is called for each
 * of the binding keys passed to <code>ASTParser.createASTs</code>.
 * </p>
 * <p>
 * This class is intended to be subclassed by clients.
 * AST requestors are serially reusable, but neither reentrant nor
 * thread-safe.
 * </p>
 *
 * @see ASTParser#createASTs(ICompilationUnit[], String[], ASTRequestor, org.eclipse.core.runtime.IProgressMonitor)
 * @since 3.1
 */
public abstract class ASTRequestor {

	/**
	 * The compilation unit resolver used to resolve bindings, or
	 * <code>null</code> if none. Note that this field is non-null
	 * only within the dynamic scope of a call to
	 * <code>ASTParser.createASTs</code>.
	 */
	CompilationUnitResolver compilationUnitResolver = null;

	/**
	 * Creates a new instance.
	 */
	protected ASTRequestor() {
		// do nothing
	}

	/**
	 * Accepts an AST corresponding to the compilation unit.
	 * That is, <code>ast</code> is an AST for <code>source</code>.
	 * <p>
	 * The default implementation of this method does nothing.
	 * Clients should override to process the resulting AST.
	 * </p>
	 *
	 * @param source the compilation unit the ast is coming from
	 * @param ast the requested abtract syntax tree
	 */
	public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
		// do nothing
	}

	/**
	 * Accepts a binding corresponding to the binding key.
	 * That is, <code>binding</code> is the binding for
	 * <code>bindingKey</code>; <code>binding</code> is <code>null</code>
	 * if the key cannot be resolved.
	 * <p>
	 * The default implementation of this method does nothing.
	 * Clients should override to process the resulting binding.
	 * </p>
	 *
	 * @param bindingKey the key of the requested binding
	 * @param binding the requested binding, or <code>null</code> if none
	 */
	public void acceptBinding(String bindingKey, IBinding binding) {
		// do nothing
	}

	/**
	 * Resolves bindings for the given binding keys.
	 * The given binding keys must have been obtained earlier
	 * using {@link IBinding#getKey()}.
	 * <p>
	 * If a binding key cannot be resolved, <code>null</code> is put in the resulting array.
	 * Bindings can only be resolved in the dynamic scope of a <code>ASTParser.createASTs</code>,
	 * and only if <code>ASTParser.resolveBindings(true)</code> was specified.
	 * </p>
	 * <p>
	 * Caveat: During an <code>acceptAST</code> callback, there are implementation
	 * limitations concerning the look up of binding keys representing local elements.
	 * In some cases, the binding is unavailable, and <code>null</code> will be returned.
	 * This is only an issue during an <code>acceptAST</code> callback, and only
	 * when the binding key represents a local element (e.g., local variable,
	 * local class, method declared in anonymous class). There is no such limitation
	 * outside of <code>acceptAST</code> callbacks, or for top-level types and their
	 * members even within <code>acceptAST</code> callbacks.
	 * </p>
	 *
	 * @param bindingKeys the binding keys to look up
	 * @return a list of bindings paralleling the <code>bindingKeys</code> parameter,
	 * with <code>null</code> entries for keys that could not be resolved
	 */
	public final IBinding[] createBindings(String[] bindingKeys) {
		int length = bindingKeys.length;
		IBinding[] result = new IBinding[length];
		for (int i = 0; i < length; i++) {
			result[i] = null;
			if (this.compilationUnitResolver != null) {
				result[i] = this.compilationUnitResolver.createBinding(bindingKeys[i]);
			}
		}
		return result;
	}
}