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


Java ASTNodes.isControlStatementBody方法代码示例

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


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

示例1: replaceSelectedExpressionWithTempDeclaration

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void replaceSelectedExpressionWithTempDeclaration() throws CoreException {
  ASTRewrite rewrite = fCURewrite.getASTRewrite();
  Expression selectedExpression =
      getSelectedExpression().getAssociatedExpression(); // whole expression selected

  Expression initializer = (Expression) rewrite.createMoveTarget(selectedExpression);
  ASTNode replacement =
      createTempDeclaration(initializer); // creates a VariableDeclarationStatement

  ExpressionStatement parent = (ExpressionStatement) selectedExpression.getParent();
  if (ASTNodes.isControlStatementBody(parent.getLocationInParent())) {
    Block block = rewrite.getAST().newBlock();
    block.statements().add(replacement);
    replacement = block;
  }
  rewrite.replace(
      parent,
      replacement,
      fCURewrite.createGroupDescription(
          RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable));
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:ExtractTempRefactoring.java

示例2: doAddLocal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private ASTRewrite doAddLocal() {
  Expression expression = ((ExpressionStatement) fNodeToAssign).getExpression();
  AST ast = fNodeToAssign.getAST();

  ASTRewrite rewrite = ASTRewrite.create(ast);

  createImportRewrite((CompilationUnit) fNodeToAssign.getRoot());

  String[] varNames = suggestLocalVariableNames(fTypeBinding, expression);
  for (int i = 0; i < varNames.length; i++) {
    addLinkedPositionProposal(KEY_NAME, varNames[i], null);
  }

  VariableDeclarationFragment newDeclFrag = ast.newVariableDeclarationFragment();
  newDeclFrag.setName(ast.newSimpleName(varNames[0]));
  newDeclFrag.setInitializer((Expression) rewrite.createCopyTarget(expression));

  Type type = evaluateType(ast);

  if (ASTNodes.isControlStatementBody(fNodeToAssign.getLocationInParent())) {
    Block block = ast.newBlock();
    block.statements().add(rewrite.createMoveTarget(fNodeToAssign));
    rewrite.replace(fNodeToAssign, block, null);
  }

  if (needsSemicolon(expression)) {
    VariableDeclarationStatement varStatement = ast.newVariableDeclarationStatement(newDeclFrag);
    varStatement.setType(type);
    rewrite.replace(expression, varStatement, null);
  } else {
    // trick for bug 43248: use an VariableDeclarationExpression and keep the ExpressionStatement
    VariableDeclarationExpression varExpression =
        ast.newVariableDeclarationExpression(newDeclFrag);
    varExpression.setType(type);
    rewrite.replace(expression, varExpression, null);
  }

  addLinkedPosition(rewrite.track(newDeclFrag.getName()), true, KEY_NAME);
  addLinkedPosition(rewrite.track(type), false, KEY_TYPE);
  setEndPosition(rewrite.track(fNodeToAssign)); // set cursor after expression statement

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

示例3: isNotInBlock

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean isNotInBlock(ASTNode parent) {
	ASTNode statement = parent.getParent();
	boolean isStatement = statement.getNodeType() != ASTNode.EXPRESSION_STATEMENT;
	ASTNode block = statement.getParent();
	boolean isBlock = block.getNodeType() == ASTNode.BLOCK || block.getNodeType() == ASTNode.SWITCH_STATEMENT;
	boolean isControlStatemenBody = ASTNodes.isControlStatementBody(statement.getLocationInParent());
	return isStatement || !(isBlock || isControlStatemenBody);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:9,代码来源:GetterSetterUtil.java

示例4: isNotInBlock

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean isNotInBlock(ASTNode parent) {
  ASTNode statement = parent.getParent();
  boolean isStatement = statement.getNodeType() != ASTNode.EXPRESSION_STATEMENT;
  ASTNode block = statement.getParent();
  boolean isBlock =
      block.getNodeType() == ASTNode.BLOCK || block.getNodeType() == ASTNode.SWITCH_STATEMENT;
  boolean isControlStatemenBody =
      ASTNodes.isControlStatementBody(statement.getLocationInParent());
  return isStatement || !(isBlock || isControlStatemenBody);
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:GetterSetterUtil.java

示例5: removeStatement

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void removeStatement(ASTRewrite rewrite, ASTNode statementNode, TextEditGroup group) {
  if (ASTNodes.isControlStatementBody(statementNode.getLocationInParent())) {
    rewrite.replace(statementNode, rewrite.getAST().newBlock(), group);
  } else {
    rewrite.remove(statementNode, group);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:UnusedCodeFix.java

示例6: removeVariableWithInitializer

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private void removeVariableWithInitializer(
    ASTRewrite rewrite, ASTNode initializerNode, ASTNode statementNode) {
  ArrayList<Expression> sideEffectNodes = new ArrayList<Expression>();
  initializerNode.accept(new SideEffectFinder(sideEffectNodes));
  int nSideEffects = sideEffectNodes.size();
  if (nSideEffects == 0) {
    if (ASTNodes.isControlStatementBody(statementNode.getLocationInParent())) {
      rewrite.replace(statementNode, rewrite.getAST().newBlock(), null);
    } else {
      rewrite.remove(statementNode, null);
    }
  } else {
    // do nothing yet
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:RemoveDeclarationCorrectionProposal.java

示例7: addRemoveIncludingConditionProposal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static void addRemoveIncludingConditionProposal(
    IInvocationContext context,
    ASTNode toRemove,
    ASTNode replacement,
    Collection<ICommandAccess> proposals) {
  Image image =
      JavaPluginImages.get(
          JavaPluginImages
              .IMG_TOOL_DELETE); // JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
  String label =
      CorrectionMessages
          .LocalCorrectionsSubProcessor_removeunreachablecode_including_condition_description;
  AST ast = toRemove.getAST();
  ASTRewrite rewrite = ASTRewrite.create(ast);
  ASTRewriteCorrectionProposal proposal =
      new ASTRewriteCorrectionProposal(
          label,
          context.getCompilationUnit(),
          rewrite,
          IProposalRelevance.REMOVE_UNREACHABLE_CODE_INCLUDING_CONDITION,
          image);

  if (replacement == null
      || replacement instanceof EmptyStatement
      || replacement instanceof Block && ((Block) replacement).statements().size() == 0) {
    if (ASTNodes.isControlStatementBody(toRemove.getLocationInParent())) {
      rewrite.replace(toRemove, toRemove.getAST().newBlock(), null);
    } else {
      rewrite.remove(toRemove, null);
    }

  } else if (toRemove instanceof Expression && replacement instanceof Expression) {
    Expression moved = (Expression) rewrite.createMoveTarget(replacement);
    Expression toRemoveExpression = (Expression) toRemove;
    Expression replacementExpression = (Expression) replacement;
    ITypeBinding explicitCast =
        ASTNodes.getExplicitCast(replacementExpression, toRemoveExpression);
    if (explicitCast != null) {
      CastExpression cast = ast.newCastExpression();
      if (NecessaryParenthesesChecker.needsParentheses(
          replacementExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
        ParenthesizedExpression parenthesized = ast.newParenthesizedExpression();
        parenthesized.setExpression(moved);
        moved = parenthesized;
      }
      cast.setExpression(moved);
      ImportRewrite imports = proposal.createImportRewrite(context.getASTRoot());
      ImportRewriteContext importRewriteContext =
          new ContextSensitiveImportRewriteContext(toRemove, imports);
      cast.setType(imports.addImport(explicitCast, ast, importRewriteContext));
      moved = cast;
    }
    rewrite.replace(toRemove, moved, null);

  } else {
    ASTNode parent = toRemove.getParent();
    ASTNode moveTarget;
    if ((parent instanceof Block || parent instanceof SwitchStatement)
        && replacement instanceof Block) {
      ListRewrite listRewrite = rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY);
      List<Statement> list = ((Block) replacement).statements();
      int lastIndex = list.size() - 1;
      moveTarget = listRewrite.createMoveTarget(list.get(0), list.get(lastIndex));
    } else {
      moveTarget = rewrite.createMoveTarget(replacement);
    }

    rewrite.replace(toRemove, moveTarget, null);
  }

  proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:che,代码行数:73,代码来源:LocalCorrectionsSubProcessor.java


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