Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2012 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 java.util.List;

Import declaration AST node type. For JLS2:
 ImportDeclaration:
    import Name [ . * ] ;
 
For JLS3, static was added:
 ImportDeclaration:
    import [ static ] Name [ . * ] ;
 

Since:
2.0
Noinstantiate:
This class is not intended to be instantiated by clients.
 
 public class ImportDeclaration extends ASTNode {

The "name" structural property of this node type (child type: Name).

Since:
3.0
 
 	public static final ChildPropertyDescriptor NAME_PROPERTY =
 		new ChildPropertyDescriptor(ImportDeclaration.class"name"Name.class); //$NON-NLS-1$
 
The "onDemand" structural property of this node type (type: java.lang.Boolean).

Since:
3.0
 
 	public static final SimplePropertyDescriptor ON_DEMAND_PROPERTY =
 		new SimplePropertyDescriptor(ImportDeclaration.class"onDemand"boolean.class); //$NON-NLS-1$
 
The "static" structural property of this node type (type: java.lang.Boolean) (added in JLS3 API).

Since:
3.1
 
 	public static final SimplePropertyDescriptor STATIC_PROPERTY =
 		new SimplePropertyDescriptor(ImportDeclaration.class"static"boolean.class); //$NON-NLS-1$
 
A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.

Since:
3.0
 
 	private static final List PROPERTY_DESCRIPTORS_2_0;

A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.

Since:
3.1
 
 	private static final List PROPERTY_DESCRIPTORS_3_0;
 
 	static {
 		List properyList = new ArrayList(3);
 		createPropertyList(ImportDeclaration.classproperyList);
 		addProperty(properyList);
 
 		properyList = new ArrayList(4);
 		createPropertyList(ImportDeclaration.classproperyList);
 		addProperty(properyList);
 		addProperty(properyList);
 	}

Returns a list of structural property descriptors for this node type. Clients must not modify the result.

Parameters:
apiLevel the API level; one of the AST.JLS* constants
Returns:
a list of property descriptors (element type: StructuralPropertyDescriptor)
Since:
3.0
 
 	public static List propertyDescriptors(int apiLevel) {
 		if (apiLevel == .) {
else {
		}
	}

The import name; lazily initialized; defaults to a unspecified, legal Java identifier.
	private Name importName = null;

On demand versus single type import; defaults to single type import.
	private boolean onDemand = false;

Static versus regular; defaults to regular import. Added in JLS3; not used in JLS2.

Since:
3.1
	private boolean isStatic = false;

Creates a new AST node for an import declaration owned by the given AST. The import declaration initially is a regular (non-static) single type import for an unspecified, but legal, Java type name.

N.B. This constructor is package-private; all subclasses must be declared in the same package; clients are unable to declare additional subclasses.

Parameters:
ast the AST that is to own this node
		super(ast);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final List internalStructuralPropertiesForType(int apiLevel) {
		return propertyDescriptors(apiLevel);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final boolean internalGetSetBooleanProperty(SimplePropertyDescriptor propertyboolean getboolean value) {
		if (property == ) {
			if (get) {
				return isOnDemand();
else {
				return false;
			}
		}
		if (property == ) {
			if (get) {
				return isStatic();
else {
				setStatic(value);
				return false;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetBooleanProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
		if (property == ) {
			if (get) {
				return getName();
else {
				setName((Namechild);
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetChildProperty(propertygetchild);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final int getNodeType0() {
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	ASTNode clone0(AST target) {
		ImportDeclaration result = new ImportDeclaration(target);
		if (this.. >= .) {
		}
		result.setName((NamegetName().clone(target));
		return result;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final boolean subtreeMatch0(ASTMatcher matcherObject other) {
		// dispatch to correct overloaded match method
		return matcher.match(thisother);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	void accept0(ASTVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		if (visitChildren) {
			acceptChild(visitorgetName());
		}
		visitor.endVisit(this);
	}

Returns the name imported by this declaration.

For a regular on-demand import, this is the name of a package. For a static on-demand import, this is the qualified name of a type. For a regular single-type import, this is the qualified name of a type. For a static single-type import, this is the qualified name of a static member of a type.

Returns:
the imported name node
	public Name getName()  {
		if (this. == null) {
			// lazy init must be thread-safe for readers
			synchronized (this) {
				if (this. == null) {
							new SimpleName(this.), new SimpleName(this.));
				}
			}
		}
		return this.;
	}

Sets the name of this import declaration to the given name.

For a regular on-demand import, this is the name of a package. For a static on-demand import, this is the qualified name of a type. For a regular single-type import, this is the qualified name of a type. For a static single-type import, this is the qualified name of a static member of a type.

Parameters:
name the new import name
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
	public void setName(Name name) {
		if (name == null) {
		}
		ASTNode oldChild = this.;
		preReplaceChild(oldChildname);
		this. = name;
		postReplaceChild(oldChildname);
	}

Returns whether this import declaration is an on-demand or a single-type import.

Returns:
true if this is an on-demand import, and false if this is a single type import
	public boolean isOnDemand() {
		return this.;
	}

Sets whether this import declaration is an on-demand or a single-type import.

Parameters:
onDemand true if this is an on-demand import, and false if this is a single type import
	public void setOnDemand(boolean onDemand) {
		this. = onDemand;
	}

Returns whether this import declaration is a static import (added in JLS3 API).

Returns:
true if this is a static import, and false if this is a regular import
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public boolean isStatic() {
		return this.;
	}

Sets whether this import declaration is a static import (added in JLS3 API).

Parameters:
isStatic true if this is a static import, and false if this is a regular import
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public void setStatic(boolean isStatic) {
		this. = isStatic;
	}

Resolves and returns the binding for the package, type, field, or method named in this import declaration.

The name specified in a non-static single-type import can resolve to a type (only). The name specified in a non-static on-demand import can itself resolve to either a package or a type. For static imports (introduced in JLS3), the name specified in a static on-demand import can itself resolve to a type (only). The name specified in a static single import can resolve to a type, field, or method; in cases where the name could be resolved to more than one element with that name (for example, two methods both named "max", or a method and a field), this method returns one of the plausible bindings.

Note that bindings are generally unavailable unless requested when the AST is being built.

Returns:
a package, type, field, or method binding, or null if the binding cannot be resolved
		return this..getBindingResolver().resolveImport(this);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		return  + 3 * 4;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int treeSize() {
		return
			+ (this. == null ? 0 : getName().treeSize());
	}
New to GrepCode? Check out our FAQ X