Start line:  
End line:  

Snippet Preview

Snippet HTML Code

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

Infix expression AST node type.
 InfixExpression:
    Expression InfixOperator Expression { InfixOperator Expression }
 

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

Infix operators (typesafe enumeration).
 InfixOperator:
    * TIMES
    /  DIVIDE
    %  REMAINDER
    +  PLUS
    -  MINUS
    <<  LEFT_SHIFT
    >>  RIGHT_SHIFT_SIGNED
    >>>  RIGHT_SHIFT_UNSIGNED
    <  LESS
    >  GREATER
    <=  LESS_EQUALS
    >=  GREATER_EQUALS
    ==  EQUALS
    !=  NOT_EQUALS
    ^  XOR
    &  AND
    |  OR
    &&  CONDITIONAL_AND
    ||  CONDITIONAL_OR
 
 
 	public static class Operator {

The token for the operator.
 
 		private String token;

Creates a new infix operator with the given token.

Note: this constructor is private. The only instances ever created are the ones for the standard operators.

Parameters:
token the character sequence for the operator
 
 		private Operator(String token) {
 			this. = token;
 		}

Returns the character sequence for the operator.

Returns:
the character sequence for the operator
 
 		public String toString() {
 			return this.;
 		}

Multiplication "*" operator.
 
 		public static final Operator TIMES = new Operator("*");//$NON-NLS-1$
 		
Division "/" operator.
 
 		public static final Operator DIVIDE = new Operator("/");//$NON-NLS-1$
 		
Remainder "%" operator.
 
 		public static final Operator REMAINDER = new Operator("%");//$NON-NLS-1$
 		
Addition (or string concatenation) "+" operator.
 
 		public static final Operator PLUS = new Operator("+");//$NON-NLS-1$
 		
Subtraction "-" operator.
 
 		public static final Operator MINUS = new Operator("-");//$NON-NLS-1$
 		
Left shift "<<" operator.
 
 		public static final Operator LEFT_SHIFT = new Operator("<<");//$NON-NLS-1$
 		
Signed right shift ">>" operator.
 
 		public static final Operator RIGHT_SHIFT_SIGNED = new Operator(">>");//$NON-NLS-1$
 		
Unsigned right shift ">>>" operator.
 
		public static final Operator RIGHT_SHIFT_UNSIGNED =
			new Operator(">>>");//$NON-NLS-1$
Less than "<" operator.
		public static final Operator LESS = new Operator("<");//$NON-NLS-1$
Greater than ">" operator.
		public static final Operator GREATER = new Operator(">");//$NON-NLS-1$
Less than or equals "<=" operator.
		public static final Operator LESS_EQUALS = new Operator("<=");//$NON-NLS-1$
Greater than or equals "&gt=;" operator.
		public static final Operator GREATER_EQUALS = new Operator(">=");//$NON-NLS-1$
Equals "==" operator.
		public static final Operator EQUALS = new Operator("==");//$NON-NLS-1$
Not equals "!=" operator.
		public static final Operator NOT_EQUALS = new Operator("!=");//$NON-NLS-1$
Exclusive OR "^" operator.
		public static final Operator XOR = new Operator("^");//$NON-NLS-1$
Inclusive OR "|" operator.
		public static final Operator OR = new Operator("|");//$NON-NLS-1$
AND "&" operator.
		public static final Operator AND = new Operator("&");//$NON-NLS-1$
Conditional OR "||" operator.
		public static final Operator CONDITIONAL_OR = new Operator("||");//$NON-NLS-1$
Conditional AND "&&" operator.
		public static final Operator CONDITIONAL_AND = new Operator("&&");//$NON-NLS-1$
Map from token to operator (key type: String; value type: Operator).
		private static final Map CODES;
		static {
			 = new HashMap(20);
			Operator[] ops = {
				};
			for (int i = 0; i < ops.lengthi++) {
				.put(ops[i].toString(), ops[i]);
			}
		}

Returns the infix operator corresponding to the given string, or null if none.

toOperator is the converse of toString: that is, Operator.toOperator(op.toString()) == op for all operators op.

Parameters:
token the character sequence for the operator
Returns:
the infix operator, or null if none
		public static Operator toOperator(String token) {
			return (Operator.get(token);
		}
	}

The "leftOperand" structural property of this node type (child type: Expression).

Since:
3.0
		new ChildPropertyDescriptor(InfixExpression.class"leftOperand"Expression.class); //$NON-NLS-1$
The "operator" structural property of this node type (type: InfixExpression.Operator).

Since:
3.0
		new SimplePropertyDescriptor(InfixExpression.class"operator"InfixExpression.Operator.class); //$NON-NLS-1$
The "rightOperand" structural property of this node type (child type: Expression).

Since:
3.0
		new ChildPropertyDescriptor(InfixExpression.class"rightOperand"Expression.class); //$NON-NLS-1$
The "extendedOperands" structural property of this node type (element type: Expression).

Since:
3.0
		new ChildListPropertyDescriptor(InfixExpression.class"extendedOperands"Expression.class); //$NON-NLS-1$
A list of property descriptors (element type: StructuralPropertyDescriptor), or null if uninitialized.
	private static final List PROPERTY_DESCRIPTORS;
	static {
		List properyList = new ArrayList(5);
		createPropertyList(InfixExpression.classproperyList);
	}

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) {
	}

The infix operator; defaults to InfixExpression.Operator.PLUS.
The left operand; lazily initialized; defaults to an unspecified, but legal, simple name.
	private Expression leftOperand = null;

The right operand; lazily initialized; defaults to an unspecified, but legal, simple name.
	private Expression rightOperand = null;

The list of extended operand expressions (element type: Expression). Lazily initialized; defaults to an empty list.
	private ASTNode.NodeList extendedOperands = null;

Creates a new AST node for an infix expression owned by the given AST. By default, the node has unspecified (but legal) operator, left and right operands, and an empty list of additional operands.

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 Object internalGetSetObjectProperty(SimplePropertyDescriptor propertyboolean getObject value) {
		if (property == ) {
			if (get) {
				return getOperator();
else {
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetObjectProperty(propertygetvalue);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor propertyboolean getASTNode child) {
		if (property == ) {
			if (get) {
				return getLeftOperand();
else {
				return null;
			}
		}
		if (property == ) {
			if (get) {
				return getRightOperand();
else {
				return null;
			}
		}
		// allow default implementation to flag the error
		return super.internalGetSetChildProperty(propertygetchild);
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
		if (property == ) {
		}
		// 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) {
		InfixExpression result = new InfixExpression(target);
		if (this. != null) {
			// be careful not to trigger lazy creation of list
				ASTNode.copySubtrees(targetextendedOperands()));
		}
		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. != null) {
				// be careful not to trigger lazy creation of list
			}
		}
		visitor.endVisit(this);
	}

Returns the operator of this infix expression.

Returns:
the infix operator
		return this.;
	}

Sets the operator of this infix expression.

Parameters:
operator the infix operator
Throws:
java.lang.IllegalArgumentException if the argument is incorrect
	public void setOperator(InfixExpression.Operator operator) {
		if (operator == null) {
		}
		this. = operator;
	}

Returns the left operand of this infix expression.

Returns:
the left operand node
		if (this.  == null) {
			// lazy init must be thread-safe for readers
			synchronized (this) {
				if (this. == null) {
					this.new SimpleName(this.);
				}
			}
		}
		return this.;
	}

Sets the left operand of this infix expression.

Parameters:
expression the left operand node
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
  • a cycle in would be created
	public void setLeftOperand(Expression expression) {
		if (expression == null) {
		}
		ASTNode oldChild = this.;
		preReplaceChild(oldChildexpression);
		this. = expression;
		postReplaceChild(oldChildexpression);
	}

Returns the right operand of this infix expression.

Returns:
the right operand node
		if (this.  == null) {
			// lazy init must be thread-safe for readers
			synchronized (this) {
				if (this.  == null) {
					this.new SimpleName(this.);
				}
			}
		}
		return this.;
	}

Sets the right operand of this infix expression.

Parameters:
expression the right operand node
Throws:
java.lang.IllegalArgumentException if:
  • the node belongs to a different AST
  • the node already has a parent
  • a cycle in would be created
	public void setRightOperand(Expression expression) {
		if (expression == null) {
		}
		ASTNode oldChild = this.;
		preReplaceChild(oldChildexpression);
		this. = expression;
		postReplaceChild(oldChildexpression);
	}

Returns where there are any extended operands.

Returns:
true if there are one or more extended operands, and false if there are no extended operands
	public boolean hasExtendedOperands() {
		return
			(this. != null) && this..size() > 0;
	}

Returns the live list of extended operands.

The extended operands is the preferred way of representing deeply nested expressions of the form L op R op R2 op R3... where the same operator appears between all the operands (the most common case being lengthy string concatenation expressions). Using the extended operands keeps the trees from getting too deep; this decreases the risk is running out of thread stack space at runtime when traversing such trees. ((a + b) + c) + d would be translated to: leftOperand: a rightOperand: b extendedOperands: {c, d} operator: +

Returns:
the live list of extended operands (element type: Expression)
	public List extendedOperands() {
		if (this. == null) {
			// lazily initialize
		}
		return this.;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int memSize() {
		// treat Operator as free
		return  + 4 * 4;
	}
	/* (omit javadoc for this method)
	 * Method declared on ASTNode.
	 */
	int treeSize() {
		return
			+ (this. == null ? 0 : getLeftOperand().treeSize())
			+ (this. == null ? 0 : getRightOperand().treeSize())
			+ (this. == null ? 0 : this..listSize());
	}
New to GrepCode? Check out our FAQ X