Java Code Examples for org.eclipse.jdt.core.dom.ForStatement#getExpression()

The following examples show how to use org.eclipse.jdt.core.dom.ForStatement#getExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public boolean visit(ForStatement node) {
	int position = 0;
	if(node.getExpression() != null){
		position = node.getExpression().getStartPosition();
	} else if(node.initializers() != null && node.initializers().size() > 0){
		position = ((ASTNode)node.initializers().get(0)).getStartPosition();
	} else if(node.updaters() != null && node.updaters().size() > 0){
		position = ((ASTNode)node.updaters().get(0)).getStartPosition();
	}
	int start = _unit.getLineNumber(position);
	if(start == _extendedLine){
		_extendedStatement = node;
		return false;
	}
	return true;
}
 
Example 2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final ForStatement it) {
  this.appendToBuffer("for (");
  this.visitAll(it.initializers());
  this.appendToBuffer("; ");
  Expression _expression = it.getExpression();
  boolean _tripleNotEquals = (_expression != null);
  if (_tripleNotEquals) {
    it.getExpression().accept(this);
  }
  this.appendToBuffer("; ");
  this.visitAll(it.updaters());
  this.appendToBuffer(") ");
  it.getBody().accept(this);
  return false;
}
 
Example 3
Source File: ConditionalLoop.java    From JDeodorant with MIT License 5 votes vote down vote up
public ConditionalLoop(ForStatement forStatement) {
	super(forStatement);
	this.condition                 = forStatement.getExpression();
	Statement loopBody             = forStatement.getBody();
	List<Expression> forUpdaters   = forStatement.updaters();
	this.conditionControlVariables = generateConditionControlVariables(this.condition, loopBody, forUpdaters);
}
 
Example 4
Source File: ForStatementWriter.java    From juniversal with MIT License 5 votes vote down vote up
@Override
public void write(ForStatement forStatement) {
    matchAndWrite("for");

    copySpaceAndComments();
    matchAndWrite("(");

    writeCommaDelimitedNodes(forStatement.initializers());

    copySpaceAndComments();
    matchAndWrite(";");

    Expression forExpression = forStatement.getExpression();
    if (forExpression != null) {
        copySpaceAndComments();
        writeNode(forStatement.getExpression());
    }

    copySpaceAndComments();
    matchAndWrite(";");

    writeCommaDelimitedNodes(forStatement.updaters());

    copySpaceAndComments();
    matchAndWrite(")");

    copySpaceAndComments();
    writeNode(forStatement.getBody());
}
 
Example 5
Source File: ConvertForLoopOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean validateExpression(ForStatement statement) {
	Expression expression= statement.getExpression();
	if (!(expression instanceof InfixExpression))
		return false;

	InfixExpression infix= (InfixExpression)expression;

	Expression left= infix.getLeftOperand();
	Expression right= infix.getRightOperand();
	if (left instanceof SimpleName && right instanceof SimpleName) {
		IVariableBinding lengthBinding= fLengthBinding;
		if (lengthBinding == null)
			return false;

		IBinding leftBinding= ((SimpleName)left).resolveBinding();
		IBinding righBinding= ((SimpleName)right).resolveBinding();

		if (fIndexBinding.equals(leftBinding)) {
			return lengthBinding.equals(righBinding);
		} else if (fIndexBinding.equals(righBinding)) {
			return lengthBinding.equals(leftBinding);
		}

		return false;
	} else if (left instanceof SimpleName) {
		if (!fIndexBinding.equals(((SimpleName)left).resolveBinding()))
			return false;

		if (!Operator.LESS.equals(infix.getOperator()))
			return false;

		return validateLengthQuery(right);
	} else if (right instanceof SimpleName) {
		if (!fIndexBinding.equals(((SimpleName)right).resolveBinding()))
			return false;

		if (!Operator.GREATER.equals(infix.getOperator()))
			return false;

		return validateLengthQuery(left);
	}

	return false;
}
 
Example 6
Source File: ForStatementWriter.java    From juniversal with MIT License 4 votes vote down vote up
@Override
public void write(ForStatement forStatement) {
    matchAndWrite("for");

    copySpaceAndComments();
    matchAndWrite("(");

    copySpaceAndComments();
    boolean first = true;
    for (Object initializerExpressionObject : forStatement.initializers()) {
        Expression initializerExpression = (Expression) initializerExpressionObject;

        if (!first) {
            matchAndWrite(",");
            copySpaceAndComments();
        }

        writeNode(initializerExpression);
        copySpaceAndComments();

        first = false;
    }

    matchAndWrite(";");

    copySpaceAndComments();
    Expression forExpression = forStatement.getExpression();
    if (forExpression != null) {
        writeNode(forStatement.getExpression());
        copySpaceAndComments();
    }

    matchAndWrite(";");

    copySpaceAndComments();
    first = true;
    for (Object updaterExpressionObject : forStatement.updaters()) {
        Expression updaterExpression = (Expression) updaterExpressionObject;

        if (!first) {
            matchAndWrite(",");
            copySpaceAndComments();
        }

        writeNode(updaterExpression);
        copySpaceAndComments();

        first = false;
    }

    matchAndWrite(")");

    copySpaceAndComments();
    writeNode(forStatement.getBody());
}