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


Java EnhancedForStatement.setBody方法代码示例

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


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

示例1: generateForEachRewrite

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate a <code>foreach</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 generateForEachRewrite(AST ast) {

  EnhancedForStatement loopStatement = ast.newEnhancedForStatement();

  ASTRewrite rewrite = ASTRewrite.create(ast);
  ITypeBinding loopOverType = extractElementType(ast);

  // generate name proposals and add them to the variable declaration
  SimpleName forDeclarationName =
      resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), null, true);

  SingleVariableDeclaration forLoopInitializer = ast.newSingleVariableDeclaration();
  forLoopInitializer.setType(
      getImportRewrite()
          .addImport(
              loopOverType,
              ast,
              new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
  forLoopInitializer.setName(forDeclarationName);

  loopStatement.setParameter(forLoopInitializer);
  loopStatement.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));

  Block forLoopBody = ast.newBlock();
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

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

示例2: convert

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
@Override
protected Statement convert(CompilationUnitRewrite cuRewrite, TextEditGroup group, LinkedProposalModel positionGroups) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	ImportRewrite importRewrite= cuRewrite.getImportRewrite();

	ForStatement forStatement= getForStatement();

	IJavaProject javaProject= ((CompilationUnit)forStatement.getRoot()).getJavaElement().getJavaProject();
	String[] proposals= getVariableNameProposals(fArrayAccess.resolveTypeBinding(), javaProject);

	String parameterName;
	if (fElementDeclaration != null) {
		parameterName= fElementDeclaration.getName().getIdentifier();
	} else {
		parameterName= proposals[0];
	}

	LinkedProposalPositionGroup pg= positionGroups.getPositionGroup(parameterName, true);
	if (fElementDeclaration != null)
		pg.addProposal(parameterName, null, 10);
	for (int i= 0; i < proposals.length; i++) {
		pg.addProposal(proposals[i], null, 10);
	}

	AST ast= forStatement.getAST();
	EnhancedForStatement result= ast.newEnhancedForStatement();

	SingleVariableDeclaration parameterDeclaration= createParameterDeclaration(parameterName, fElementDeclaration, fArrayAccess, forStatement, importRewrite, rewrite, group, pg, fMakeFinal);
	result.setParameter(parameterDeclaration);

	result.setExpression((Expression)rewrite.createCopyTarget(fArrayAccess));

	convertBody(forStatement.getBody(), fIndexBinding, fArrayBinding, parameterName, rewrite, group, pg);
	result.setBody(getBody(cuRewrite, group, positionGroups));

	positionGroups.setEndPosition(rewrite.track(result));

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

示例3: convert

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
@Override
protected Statement convert(
    CompilationUnitRewrite cuRewrite, TextEditGroup group, LinkedProposalModel positionGroups)
    throws CoreException {
  ASTRewrite rewrite = cuRewrite.getASTRewrite();
  ImportRewrite importRewrite = cuRewrite.getImportRewrite();

  ForStatement forStatement = getForStatement();

  IJavaProject javaProject =
      ((CompilationUnit) forStatement.getRoot()).getJavaElement().getJavaProject();
  String[] proposals = getVariableNameProposals(fArrayAccess.resolveTypeBinding(), javaProject);

  String parameterName;
  if (fElementDeclaration != null) {
    parameterName = fElementDeclaration.getName().getIdentifier();
  } else {
    parameterName = proposals[0];
  }

  LinkedProposalPositionGroup pg = positionGroups.getPositionGroup(parameterName, true);
  if (fElementDeclaration != null) pg.addProposal(parameterName, null, 10);
  for (int i = 0; i < proposals.length; i++) {
    pg.addProposal(proposals[i], null, 10);
  }

  AST ast = forStatement.getAST();
  EnhancedForStatement result = ast.newEnhancedForStatement();

  SingleVariableDeclaration parameterDeclaration =
      createParameterDeclaration(
          parameterName,
          fElementDeclaration,
          fArrayAccess,
          forStatement,
          importRewrite,
          rewrite,
          group,
          pg,
          fMakeFinal);
  result.setParameter(parameterDeclaration);

  result.setExpression((Expression) rewrite.createCopyTarget(fArrayAccess));

  convertBody(
      forStatement.getBody(), fIndexBinding, fArrayBinding, parameterName, rewrite, group, pg);
  result.setBody(getBody(cuRewrite, group, positionGroups));

  positionGroups.setEndPosition(rewrite.track(result));

  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:53,代码来源:ConvertForLoopOperation.java

示例4: generateForEachRewrite

import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
/**
 * Helper to generate a <code>foreach</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 generateForEachRewrite(AST ast) {

	EnhancedForStatement loopStatement= ast.newEnhancedForStatement();

	ASTRewrite rewrite= ASTRewrite.create(ast);
	ITypeBinding loopOverType= extractElementType(ast);

	// generate name proposals and add them to the variable declaration
	SimpleName forDeclarationName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), null, true);

	SingleVariableDeclaration forLoopInitializer= ast.newSingleVariableDeclaration();
	forLoopInitializer.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
	forLoopInitializer.setName(forDeclarationName);

	loopStatement.setParameter(forLoopInitializer);
	loopStatement.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));

	Block forLoopBody= ast.newBlock();
	forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

	loopStatement.setBody(forLoopBody);

	rewrite.replace(fCurrentNode, loopStatement, null);

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


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