下面列出了org.eclipse.jdt.core.dom.ForStatement#getExpression ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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;
}
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);
}
@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());
}
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;
}
@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());
}