org.eclipse.jdt.core.dom.Block.statements()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.eclipse.jdt.core.dom.Block.statements()方法的一些代码示例,展示了Block.statements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.statements()方法的具体详情如下:
包路径:org.eclipse.jdt.core.dom.Block
类名称:Block
方法名:statements

Block.statements介绍

[英]The list of statements (element type: Statement). Defaults to an empty list.
[中]语句列表(元素类型:语句)。默认为空列表。

代码示例

代码示例来源:origin: stackoverflow.com

block.statements().add(e);

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private static boolean hasStopAsLastExecutableStatement(Statement lastStatement) {
  if (lastStatement instanceof ReturnStatement || lastStatement instanceof BreakStatement) {
    return true;
  }
  if (lastStatement instanceof Block) {
    Block block= (Block) lastStatement;
    lastStatement= (Statement) block.statements().get(block.statements().size() - 1);
    return hasStopAsLastExecutableStatement(lastStatement);
  }
  return false;
}

代码示例来源:origin: wala/WALA

/**
 * Visit all the statements in the block and return an arraylist of the statements. Some statements
 * (VariableDeclarationStatements) may expand to more than one CAstNode.
 */
private ArrayList<CAstNode> createBlock(Block n, WalkContext context) {
 ArrayList<CAstNode> stmtNodes = new ArrayList<>();
 for (ASTNode s : (Iterable<ASTNode>) n.statements())
  visitNodeOrNodes(s, context, stmtNodes);
 return stmtNodes;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

public boolean visit(Block node) {
  this.fBuffer.append("{");//$NON-NLS-1$
  for (Iterator it= node.statements().iterator(); it.hasNext();) {
    Statement s= (Statement) it.next();
    s.accept(this);
  }
  this.fBuffer.append("}");//$NON-NLS-1$
  return false;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

public boolean isLastStatementReturn() {
  List statements= fDeclaration.getBody().statements();
  if (statements.size() == 0)
    return false;
  return statements.get(statements.size() - 1) instanceof ReturnStatement;
}

代码示例来源:origin: org.jibx/jibx-tools

/**
   * Append a constructed statement.
   *
   * @param stmt Statement Builder Base
   */
  public void addStatement(StatementBuilderBase stmt) {
    m_block.statements().add(stmt.getStatement());
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
  if (property == STATEMENTS_PROPERTY) {
    return statements();
  }
  // allow default implementation to flag the error
  return super.internalGetChildListProperty(property);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

private List<IRegion> getStatementRanges() {
  fMarkerMode= STATEMENT_MODE;
  List<IRegion> result= new ArrayList<>(1);
  List<Statement> statements= fDeclaration.getBody().statements();
  int size= statements.size();
  if (size == 0)
    return result;
  result.add(createRange(statements, size - 1));
  return result;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

private List<IRegion> getReturnStatementRanges() {
  fMarkerMode= RETURN_STATEMENT_MODE;
  List<IRegion> result= new ArrayList<>(1);
  List<Statement> statements= fDeclaration.getBody().statements();
  int size= statements.size();
  if (size <= 1)
    return result;
  result.add(createRange(statements, size - 2));
  return result;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

protected void addElement(Object element, Block block) {
  if (element instanceof String)
    fBuffer.append((String)element);
  if (element instanceof Expression) {
    flushBuffer(block);
    block.statements().add(fAst.newExpressionStatement(createMethodInvocation(fBuilderVariableName, APPEND_METHOD_NAME, (Expression)element)));
  }
}

代码示例来源:origin: org.jibx/jibx-tools

/**
 * Append a statement returning the value of an expression.
 *
 * @param expr expression
 */
public void addReturnExpression(ExpressionBuilderBase expr) {
  ReturnStatement ret = m_ast.newReturnStatement();
  ret.setExpression(expr.getExpression());
  m_block.statements().add(ret);
}

代码示例来源:origin: org.jibx/jibx-tools

/**
 * Append a 'switch' statement using a local variable or field name as the switch value.
 *
 * @param name Switch statement name
 * @return statement builder
 */
public SwitchBuilder addSwitch(String name) {
  SwitchBuilder builder = new SwitchBuilder(m_source, m_ast.newSimpleName(name));
  m_block.statements().add(builder.getStatement());
  return builder;
}

代码示例来源:origin: org.jibx/jibx-tools

/**
 * Append a 'switch' statement using a constructed expression as the switch value.
 *
 * @param expr Expression Builder
 * @return statement builder
 */
public SwitchBuilder addSwitch(ExpressionBuilderBase expr) {
  SwitchBuilder builder = new SwitchBuilder(m_source, expr.getExpression());
  m_block.statements().add(builder.getStatement());
  return builder;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

protected void flushBuffer(Block target) {
  if (fBuffer.length() > 0) {
    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(fBuffer.toString());
    if (target == null)
      target= toStringMethod.getBody();
    target.statements().add(fAst.newExpressionStatement(createMethodInvocation(fBuilderVariableName, APPEND_METHOD_NAME, literal)));
    fBuffer.setLength(0);
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private static SuperConstructorInvocation getSuperConstructorCallNode(IMethod constructor, CompilationUnit cuNode) throws JavaModelException {
    Assert.isTrue(constructor.isConstructor());
    MethodDeclaration constructorNode= ASTNodeSearchUtil.getMethodDeclarationNode(constructor, cuNode);
    Assert.isTrue(constructorNode.isConstructor());
    Block body= constructorNode.getBody();
    Assert.isNotNull(body);
    List statements= body.statements();
    if (! statements.isEmpty() && statements.get(0) instanceof SuperConstructorInvocation)
      return (SuperConstructorInvocation)statements.get(0);
    return null;
  }
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

@Override
public void endVisit(Block node) {
  super.endVisit(node);
  clearAccessMode(accessFlowInfo(node), node.statements());
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

@Override
public void endVisit(Block node) {
  super.endVisit(node);
  clearAccessMode(accessFlowInfo(node), node.statements());
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
  ASTRewrite rewrite= cuRewrite.getASTRewrite();
  Block block= (Block)fStatement.getStructuralProperty(fChild);
  Statement statement= (Statement)block.statements().get(0);
  Statement moveTarget= (Statement)rewrite.createMoveTarget(statement);
  TextEditGroup group= createTextEditGroup(FixMessages.ControlStatementsFix_removeBrackets_proposalDescription, cuRewrite);
  rewrite.set(fStatement, fChild, moveTarget, group);
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

@Override
public void endVisit(Block node) {
  if (skipNode(node)) {
    return;
  }
  BlockFlowInfo info = createBlock();
  setFlowInfo(node, info);
  process(info, node.statements());
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

protected ASTNode createBody(BodyDeclaration bd) throws JavaModelException {
  MethodDeclaration methodDeclaration= (MethodDeclaration) bd;
  final MethodInvocation invocation= getAst().newMethodInvocation();
  invocation.setName(getAst().newSimpleName(getNewElementName()));
  invocation.setExpression(createSimpleTargetAccessExpression(methodDeclaration));
  fNeededInsertion= createArgumentList(methodDeclaration, invocation.arguments(), new VisibilityAdjustingArgumentFactory(getAst(), fRewrites, fAdjustments));
  final Block block= getAst().newBlock();
  block.statements().add(createMethodInvocation(methodDeclaration, invocation));
  if (!fSourceRewrite.getCu().equals(fTargetType.getCompilationUnit()))
    fSourceRewrite.getImportRemover().registerRemovedNode(methodDeclaration.getBody());
  return block;
}

相关文章