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

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

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

Block.getParent介绍

暂无

代码示例

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

@Override
  public boolean visit(Block node) {
    if (!(node.getParent() instanceof LambdaExpression)) {
      searchNode(node, contents, label, textedits);
    }
    return true;
  }
});

代码示例来源:origin: mono/sharpen

boolean isBlockInsideBlock (Block node) {
  return node.getParent() instanceof Block;
}

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

public final boolean visit(final Block block) {
    Assert.isNotNull(block);
    if (declarations && block.getParent() instanceof MethodDeclaration)
      return false;
    return super.visit(block);
  }
};

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

public final boolean visit(final Block block) {
    Assert.isNotNull(block);
    if (declarations && block.getParent() instanceof MethodDeclaration)
      return false;
    return super.visit(block);
  }
};

代码示例来源:origin: JnRouvignac/AutoRefactor

private boolean match0(final Block node, final Statement other) {
    if ((node.getParent() instanceof IfStatement
        || node.getParent() instanceof ForStatement
        || node.getParent() instanceof EnhancedForStatement
        || node.getParent() instanceof WhileStatement
        || node.getParent() instanceof DoStatement)
        && node.statements().size() == 1) {
      return safeSubtreeMatch(node.statements().get(0), other)
          || super.match(node, other);
    }

    return super.match(node, other);
  }
}

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

try (BufferedReader bufferedReader = new BufferedReader(reader)) {
   Block block = new Block();
   String line, previousIndents = "";
   while (null != (line = bufferedReader.readLine()) {
     Matcher m = Pattern.compile("^(\\s+)").matcher(line);
     if (m.find()) {
       String indents = m.group(1);
       if (previousIndents.equals(indents)) {
          // update current block
       } else if (indents.length() > previousIndents.length()) {
          // start a new block
          Block newBlock = new Block();
          newBlock.setParent(block);
          block.getChildren().add(newBlock);
          block = newBlock;
       } else {
          // current block finished, return to parent
          block = block.getParent();
       }
       previousIndents = indents;
     }
   } 
 }
 catch (IOException ioEx) {
   throw new ParseException(ioEx);
 }

代码示例来源:origin: JnRouvignac/AutoRefactor

@Override
public boolean visit(Block node) {
  final List<Statement> stmts = statements(node);
  if (stmts.size() == 1
      && stmts.get(0) instanceof Block) {
    replaceBlock((Block) stmts.get(0));
    return DO_NOT_VISIT_SUBTREE;
  } else if (node.getParent() instanceof Block) {
    final Set<String> ifVariableNames = getLocalVariableIdentifiers(node, false);
    final Set<String> followingVariableNames = new HashSet<String>();
    for (final Statement statement : getNextSiblings(node)) {
      followingVariableNames.addAll(getLocalVariableIdentifiers(statement, true));
    }
    if (!ifVariableNames.removeAll(followingVariableNames)) {
      replaceBlock(node);
      return DO_NOT_VISIT_SUBTREE;
    }
  }
  return VISIT_SUBTREE;
}

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

@Override
public boolean visit(Block node) {
  if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node))
    return true;
  List<Statement> statements = node.statements();
  for (Statement statement : statements) {
    if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
      breakLineBefore(statement);
  }
  if (node.getParent().getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  ASTNode parent = node.getParent();
  if (parent instanceof MethodDeclaration)
    return true; // braces have been handled in #visit(MethodDeclaration)
  String bracePosition = this.options.brace_position_for_block;
  if (parent instanceof SwitchStatement) {
    List<Statement> siblings = ((SwitchStatement) parent).statements();
    int blockPosition = siblings.indexOf(node);
    boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase);
    if (isFirstInCase)
      bracePosition = this.options.brace_position_for_block_in_case;
  } else if (parent instanceof LambdaExpression) {
    bracePosition = this.options.brace_position_for_lambda_body;
  }
  handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block,
      this.options.insert_new_line_in_empty_block);
  return true;
}

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

@Override
public boolean visit(Block node) {
  if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node))
    return true;
  List<Statement> statements = node.statements();
  for (Statement statement : statements) {
    if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
      breakLineBefore(statement);
  }
  if (node.getParent().getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  ASTNode parent = node.getParent();
  if (parent instanceof MethodDeclaration)
    return true; // braces have been handled in #visit(MethodDeclaration)
  String bracePosition = this.options.brace_position_for_block;
  if (parent instanceof SwitchStatement) {
    List<Statement> siblings = ((SwitchStatement) parent).statements();
    int blockPosition = siblings.indexOf(node);
    boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase);
    if (isFirstInCase)
      bracePosition = this.options.brace_position_for_block_in_case;
  } else if (parent instanceof LambdaExpression) {
    bracePosition = this.options.brace_position_for_lambda_body;
  }
  handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block,
      this.options.insert_new_line_in_empty_block);
  return true;
}

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

public boolean isGuardClause(Block node) {
  if (node.statements().size() != 1)
    return false;
  ASTNode parent = node.getParent();
  if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null)
    return false;
  Object statement = node.statements().get(0);
  if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement))
    return false;
  // guard clause cannot start with a comment
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565
  int openBraceIndex = firstIndexIn(node, TokenNameLBRACE);
  return !get(openBraceIndex + 1).isComment();
}

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

public boolean isGuardClause(Block node) {
  if (node.statements().size() != 1)
    return false;
  ASTNode parent = node.getParent();
  if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null)
    return false;
  Object statement = node.statements().get(0);
  if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement))
    return false;
  // guard clause cannot start with a comment
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565
  int openBraceIndex = firstIndexIn(node, TokenNameLBRACE);
  return !get(openBraceIndex + 1).isComment();
}

代码示例来源:origin: io.spring.javaformat/spring-javaformat-formatter-eclipse

@Override
public boolean visit(Block node) {
  if (this.options.keep_guardian_clause_on_one_line && this.tm.isGuardClause(node))
    return true;
  List<Statement> statements = node.statements();
  for (Statement statement : statements) {
    if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
      breakLineBefore(statement);
  }
  if (node.getParent().getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  ASTNode parent = node.getParent();
  if (parent instanceof MethodDeclaration)
    return true; // braces have been handled in #visit(MethodDeclaration)
  String bracePosition = this.options.brace_position_for_block;
  if (parent instanceof SwitchStatement) {
    List<Statement> siblings = ((SwitchStatement) parent).statements();
    int blockPosition = siblings.indexOf(node);
    boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase);
    if (isFirstInCase)
      bracePosition = this.options.brace_position_for_block_in_case;
  } else if (parent instanceof LambdaExpression) {
    bracePosition = this.options.brace_position_for_lambda_body;
  }
  handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block,
      this.options.insert_new_line_in_empty_block);
  return true;
}

代码示例来源:origin: io.spring.javaformat/spring-javaformat-formatter-eclipse

public boolean isGuardClause(Block node) {
  if (node.statements().size() != 1)
    return false;
  ASTNode parent = node.getParent();
  if (!(parent instanceof IfStatement) || ((IfStatement) parent).getElseStatement() != null)
    return false;
  Object statement = node.statements().get(0);
  if (!(statement instanceof ReturnStatement) && !(statement instanceof ThrowStatement))
    return false;
  // guard clause cannot start with a comment
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=58565
  int openBraceIndex = firstIndexIn(node, TokenNameLBRACE);
  return !get(openBraceIndex + 1).isComment();
}

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

@Override
public boolean visit(Block node) {
  List<Statement> statements = node.statements();
  for (Statement statement : statements) {
    if (this.options.put_empty_statement_on_new_line || !(statement instanceof EmptyStatement))
      breakLineBefore(statement);
  }
  ASTNode parent = node.getParent();
  if (parent.getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  if (parent instanceof MethodDeclaration)
    return true; // braces have been handled in #visit(MethodDeclaration)
  String bracePosition = this.options.brace_position_for_block;
  if (parent instanceof SwitchStatement) {
    List<Statement> siblings = ((SwitchStatement) parent).statements();
    int blockPosition = siblings.indexOf(node);
    boolean isFirstInCase = blockPosition > 0 && (siblings.get(blockPosition - 1) instanceof SwitchCase);
    if (isFirstInCase)
      bracePosition = this.options.brace_position_for_block_in_case;
  } else if (parent instanceof LambdaExpression) {
    bracePosition = this.options.brace_position_for_lambda_body;
  }
  handleBracedCode(node, null, bracePosition, this.options.indent_statements_compare_to_block);
  return true;
}

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

/**
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Block)
 */
public boolean visit(Block node) {
  if (visit(node, false)) {
    if (node.statements().isEmpty() && node.getParent().getNodeType() == ASTNode.METHOD_DECLARATION) {
      // in case of an empty method, set the breakpoint on the last line of the empty block.
      fLineLocation= lineNumber(node.getStartPosition() + node.getLength() - 1);
      fLocationFound= true;
      fLocationType= LOCATION_LINE;
      fTypeName= computeTypeName(node);
      return false;
    }
    return true;
  }
  return false;
}

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

return null;
ASTNode parent= block.getParent();
if (!(parent instanceof Statement))
  return null;

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

@Override
public boolean visit(Block node) {
  handleSemicolon(node.statements());
  ASTNode parent = node.getParent();
  if (parent.getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  if (parent instanceof MethodDeclaration)
    return true; // spaces handled in #visit(MethodDeclaration)
  handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
  if (this.options.insert_space_after_closing_brace_in_block
      && (parent instanceof Statement || parent instanceof CatchClause)) {
    int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
    this.tm.get(closeBraceIndex).spaceAfter();
  }
  return true;
}

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

@Override
public boolean visit(Block node) {
  handleSemicolon(node.statements());
  ASTNode parent = node.getParent();
  if (parent.getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  if (parent instanceof MethodDeclaration)
    return true; // spaces handled in #visit(MethodDeclaration)
  handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
  if (this.options.insert_space_after_closing_brace_in_block
      && (parent instanceof Statement || parent instanceof CatchClause)) {
    int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
    this.tm.get(closeBraceIndex).spaceAfter();
  }
  return true;
}

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

@Override
public boolean visit(Block node) {
  handleSemicolon(node.statements());
  ASTNode parent = node.getParent();
  if (parent.getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  if (parent instanceof MethodDeclaration)
    return true; // spaces handled in #visit(MethodDeclaration)
  handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
  if (this.options.insert_space_after_closing_brace_in_block
      && (parent instanceof Statement || parent instanceof CatchClause)) {
    int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
    this.tm.get(closeBraceIndex).spaceAfter();
  }
  return true;
}

代码示例来源:origin: io.spring.javaformat/spring-javaformat-formatter-eclipse

@Override
public boolean visit(Block node) {
  handleSemicolon(node.statements());
  ASTNode parent = node.getParent();
  if (parent.getLength() == 0)
    return true; // this is a fake block created by parsing in statements mode
  if (parent instanceof MethodDeclaration)
    return true; // spaces handled in #visit(MethodDeclaration)
  handleToken(node, TokenNameLBRACE, this.options.insert_space_before_opening_brace_in_block, false);
  if (this.options.insert_space_after_closing_brace_in_block
      && (parent instanceof Statement || parent instanceof CatchClause)) {
    int closeBraceIndex = this.tm.lastIndexIn(node, TokenNameRBRACE);
    this.tm.get(closeBraceIndex).spaceAfter();
  }
  return true;
}

相关文章