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;

Local variable declaration statement AST node type.

This kind of node collects several variable declaration fragments (VariableDeclarationFragment) into a statement (Statement), all sharing the same modifiers and base type.

For JLS2:
 VariableDeclarationStatement:
    { Modifier } Type VariableDeclarationFragment
        { , VariableDeclarationFragment } ;
 
For JLS3, the modifier flags were replaced by a list of modifier nodes (intermixed with annotations):
 VariableDeclarationStatement:
    { ExtendedModifier } Type VariableDeclarationFragment
        { , VariableDeclarationFragment } ;
 

Note: This type of node is a convenience of sorts. An equivalent way to represent the same statement is to use a VariableDeclarationExpression wrapped in an ExpressionStatement.

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

The "modifiers" structural property of this node type (type: java.lang.Integer) (JLS2 API only).

Since:
3.0
 
 	public static final SimplePropertyDescriptor MODIFIERS_PROPERTY =
 		new SimplePropertyDescriptor(VariableDeclarationStatement.class"modifiers"int.class); //$NON-NLS-1$
 
The "modifiers" structural property of this node type (element type: IExtendedModifier) (added in JLS3 API).

Since:
3.1
 
 		new ChildListPropertyDescriptor(VariableDeclarationStatement.class"modifiers"IExtendedModifier.class); //$NON-NLS-1$
 
The "type" structural property of this node type (child type: Type).

Since:
3.0
 
 	public static final ChildPropertyDescriptor TYPE_PROPERTY =
 		new ChildPropertyDescriptor(VariableDeclarationStatement.class"type"Type.class); //$NON-NLS-1$
 
The "fragments" structural property of this node type (element type: VariableDeclarationFragment).

Since:
3.0
 
 
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 propertyList = new ArrayList(4);
 		addProperty(propertyList);
 		addProperty(propertyList);
 		addProperty(propertyList);
		propertyList = new ArrayList(4);
		addProperty(propertyList);
	}

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 extended modifiers (element type: IExtendedModifier). Null in JLS2. Added in JLS3; defaults to an empty list (see constructor).

Since:
3.1
	private ASTNode.NodeList modifiers = null;

The modifier flagss; bit-wise or of Modifier flags. Defaults to none. Not used in JLS3.
	private int modifierFlags = .;

The base type; lazily initialized; defaults to an unspecified, legal type.
	private Type baseType = null;

The list of variable variable declaration fragments (element type: VariableDeclarationFragment). Defaults to an empty list.
Creates a new unparented local variable declaration statement node owned by the given AST. By default, the variable declaration has: no modifiers, an unspecified (but legal) type, and an empty list of variable declaration fragments (which is syntactically illegal).

N.B. This constructor is package-private.

Parameters:
ast the AST that is to own this node
		super(ast);
		if (ast.apiLevel >= .) {
		}
	}
	/* (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 int internalGetSetIntProperty(SimplePropertyDescriptor propertyboolean getint value) {
		if (property == ) {
			if (get) {
				return getModifiers();
else {
				return 0;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetIntProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
		if (property == ) {
			if (get) {
				return getType();
else {
				setType((Typechild);
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetChildProperty(propertygetchild);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
		if (property == ) {
			return modifiers();
		}
		if (property == ) {
			return fragments();
		}
		// allow default implementation to flag the error
		return super.internalGetChildListProperty(property);
	}
	/* (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) {
		result.copyLeadingComment(this);
		if (this.. == .) {
		}
		if (this.. >= .) {
			result.modifiers().addAll(ASTNode.copySubtrees(targetmodifiers()));
		}
		result.setType((TypegetType().clone(target));
		result.fragments().addAll(
			ASTNode.copySubtrees(targetfragments()));
		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) {
			// visit children in normal left to right reading order
			if (this.. >= .) {
				acceptChildren(visitorthis.);
			}
			acceptChild(visitorgetType());
		}
		visitor.endVisit(this);
	}

Returns the live ordered list of modifiers and annotations of this declaration (added in JLS3 API).

Note that the final modifier is the only meaningful modifier for local variable declarations.

Returns:
the live list of modifiers and annotations (element type: IExtendedModifier)
Throws:
java.lang.UnsupportedOperationException if this operation is used in a JLS2 AST
Since:
3.1
	public List modifiers() {
		// more efficient than just calling unsupportedIn2() to check
		if (this. == null) {
		}
		return this.;
	}

Returns the modifiers explicitly specified on this declaration.

In the JLS3 API, this method is a convenience method that computes these flags from modifiers().

Returns:
the bit-wise or of Modifier constants
See also:
Modifier
	public int getModifiers() {
		// more efficient than checking getAST().API_LEVEL
		if (this. == null) {
			// JLS2 behavior - bona fide property
			return this.;
else {
			// JLS3 behavior - convenience method
			// performance could be improved by caching computed flags
			// but this would require tracking changes to this.modifiers
			int computedModifierFlags = .;
			for (Iterator it = modifiers().iterator(); it.hasNext(); ) {
				Object x = it.next();
				if (x instanceof Modifier) {
					computedModifierFlags |= ((Modifierx).getKeyword().toFlagValue();
				}
			}
			return computedModifierFlags;
		}
	}

Sets the modifiers explicitly specified on this declaration (JLS2 API only).

Note that the final modifier is the only meaningful modifier for local variable declarations.

Deprecated:
In the JLS3 API, this method is replaced by modifiers() which contains a list of a Modifier nodes.
Parameters:
modifiers the given modifiers (bit-wise or of Modifier constants)
Throws:
java.lang.UnsupportedOperationException if this operation is used in an AST later than JLS2
See also:
Modifier
	public void setModifiers(int modifiers) {
	}

Internal synonym for deprecated method. Used to avoid deprecation warnings.

Since:
3.1
	/*package*/ final void internalSetModifiers(int pmodifiers) {
		this. = pmodifiers;
	}

Returns the base type declared in this variable declaration statement.

N.B. The individual child variable declaration fragments may specify additional array dimensions. So the type of the variable are not necessarily exactly this type.

Returns:
the base type
	public Type getType() {
		if (this. == null) {
			// lazy init must be thread-safe for readers
			synchronized (this) {
				if (this. == null) {
				}
			}
		}
		return this.;
	}

Sets the base type declared in this variable declaration statement to the given type.

Parameters:
type the new base type
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
	public void setType(Type type) {
		if (type == null) {
		}
		ASTNode oldChild = this.;
		preReplaceChild(oldChildtype);
		this. = type;
		postReplaceChild(oldChildtype);
	}

Returns the live list of variable declaration fragments in this statement. Adding and removing nodes from this list affects this node dynamically. All nodes in this list must be VariableDeclarationFragments; attempts to add any other type of node will trigger an exception.

Returns:
the live list of variable declaration fragments in this statement (element type: VariableDeclarationFragment)
	public List fragments() {
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		return super.memSize() + 4 * 4;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int treeSize() {
		return
			+ (this. == null ? 0 : this..listSize())
			+ (this. == null ? 0 : getType().treeSize())
	}
New to GrepCode? Check out our FAQ X