当前位置: 首页>>代码示例>>Java>>正文


Java ForStatement.setExpression方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.ForStatement.setExpression方法的典型用法代码示例。如果您正苦于以下问题:Java ForStatement.setExpression方法的具体用法?Java ForStatement.setExpression怎么用?Java ForStatement.setExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.ForStatement的用法示例。


在下文中一共展示了ForStatement.setExpression方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateIteratorBasedForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an iterator based <code>for</code> loop to iterate over an {@link Iterable}.
 *
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);
  ForStatement loopStatement = ast.newForStatement();

  ITypeBinding loopOverType = extractElementType(ast);

  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));

  MethodInvocation loopExpression = ast.newMethodInvocation();
  loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
  SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
  loopExpression.setExpression(expressionName);

  loopStatement.setExpression(loopExpression);

  Block forLoopBody = ast.newBlock();
  Assignment assignResolvedVariable =
      getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
  forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:GenerateForLoopAssistProposal.java

示例2: generateIndexBasedForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
 * implementation.
 *
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);

  ForStatement loopStatement = ast.newForStatement();
  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

  MethodInvocation listSizeExpression = ast.newMethodInvocation();
  listSizeExpression.setName(ast.newSimpleName("size")); // $NON-NLS-1$
  Expression listExpression = (Expression) rewrite.createCopyTarget(fCurrentExpression);
  listSizeExpression.setExpression(listExpression);

  loopStatement.setExpression(
      getLinkedInfixExpression(
          rewrite,
          loopVariableName.getIdentifier(),
          listSizeExpression,
          InfixExpression.Operator.LESS));
  loopStatement
      .updaters()
      .add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

  Block forLoopBody = ast.newBlock();
  forLoopBody
      .statements()
      .add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
  loopStatement.setBody(forLoopBody);
  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:41,代码来源:GenerateForLoopAssistProposal.java

示例3: generateForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over an array.
 * 
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateForRewrite(AST ast) {
	ASTRewrite rewrite= ASTRewrite.create(ast);

	ForStatement loopStatement= ast.newForStatement();
	SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$
	loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

	FieldAccess getArrayLengthExpression= ast.newFieldAccess();
	getArrayLengthExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
	getArrayLengthExpression.setName(ast.newSimpleName("length")); //$NON-NLS-1$

	loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), getArrayLengthExpression, InfixExpression.Operator.LESS));
	loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

	Block forLoopBody= ast.newBlock();
	forLoopBody.statements().add(ast.newExpressionStatement(getForBodyAssignment(rewrite, loopVariableName)));
	forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
	loopStatement.setBody(forLoopBody);
	rewrite.replace(fCurrentNode, loopStatement, null);

	return rewrite;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:GenerateForLoopAssistProposal.java

示例4: generateIndexBasedForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
 * implementation.
 * 
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
	ASTRewrite rewrite= ASTRewrite.create(ast);

	ForStatement loopStatement= ast.newForStatement();
	SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$
	loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

	MethodInvocation listSizeExpression= ast.newMethodInvocation();
	listSizeExpression.setName(ast.newSimpleName("size")); //$NON-NLS-1$
	Expression listExpression= (Expression) rewrite.createCopyTarget(fCurrentExpression);
	listSizeExpression.setExpression(listExpression);

	loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), listSizeExpression, InfixExpression.Operator.LESS));
	loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

	Block forLoopBody= ast.newBlock();
	forLoopBody.statements().add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
	forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
	loopStatement.setBody(forLoopBody);
	rewrite.replace(fCurrentNode, loopStatement, null);

	return rewrite;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:GenerateForLoopAssistProposal.java

示例5: generateForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an index based <code>for</code> loop to iterate over an array.
 *
 * @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
 * @return an applicable {@link ASTRewrite} instance
 */
private ASTRewrite generateForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);

  ForStatement loopStatement = ast.newForStatement();
  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getForInitializer(ast, loopVariableName));

  FieldAccess getArrayLengthExpression = ast.newFieldAccess();
  getArrayLengthExpression.setExpression(
      (Expression) rewrite.createCopyTarget(fCurrentExpression));
  getArrayLengthExpression.setName(ast.newSimpleName("length")); // $NON-NLS-1$

  loopStatement.setExpression(
      getLinkedInfixExpression(
          rewrite,
          loopVariableName.getIdentifier(),
          getArrayLengthExpression,
          InfixExpression.Operator.LESS));
  loopStatement
      .updaters()
      .add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));

  Block forLoopBody = ast.newBlock();
  forLoopBody
      .statements()
      .add(ast.newExpressionStatement(getForBodyAssignment(rewrite, loopVariableName)));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
  loopStatement.setBody(forLoopBody);
  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:GenerateForLoopAssistProposal.java

示例6: generateIteratorBasedForRewrite

import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate an iterator based <code>for</code> loop to iterate over an
 * {@link Iterable}.
 * 
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
	ASTRewrite rewrite= ASTRewrite.create(ast);
	ForStatement loopStatement= ast.newForStatement();

	ITypeBinding loopOverType= extractElementType(ast);

	SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); //$NON-NLS-1$
	loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));

	MethodInvocation loopExpression= ast.newMethodInvocation();
	loopExpression.setName(ast.newSimpleName("hasNext")); //$NON-NLS-1$
	SimpleName expressionName= ast.newSimpleName(loopVariableName.getIdentifier());
	addLinkedPosition(rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
	loopExpression.setExpression(expressionName);

	loopStatement.setExpression(loopExpression);

	Block forLoopBody= ast.newBlock();
	Assignment assignResolvedVariable= getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
	forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
	forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

	loopStatement.setBody(forLoopBody);

	rewrite.replace(fCurrentNode, loopStatement, null);

	return rewrite;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:GenerateForLoopAssistProposal.java


注:本文中的org.eclipse.jdt.core.dom.ForStatement.setExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。