/**
   * Tries to find node that is direct or indirect previous node of the given node.
   *
   * <p>E.g. there is a possible use-case:
   *
   * <pre>
   *                     n1
   *                  /    \
   *                n21    n22
   *                 |      |
   *                n31    n32
   * </pre>
   *
   * Let's assume that target node is <code>'n32'</code>. 'n31' is assumed to be returned from this
   * method then.
   *
   * <p><b>Note:</b> current method avoids going too deep if found node type is the same as start
   * node type
   *
   * @return direct or indirect previous node of the given one having target type if possible;
   *     <code>null</code> otherwise
   */
  private static boolean findPreviousNode(
      AlignmentInColumnsConfig config,
      ASTNode from,
      IElementType targetType,
      boolean processFrom,
      boolean processParent,
      NodeProcessor processor) {
    if (from == null) return false;

    for (ASTNode prev = processFrom ? from : from.getTreePrev();
        prev != null;
        prev = prev.getTreePrev()) {
      IElementType prevType = prev.getElementType();
      if (prevType == targetType) {
        if (processor.targetTypeFound(prev)) return true;
      } else if (config.getWhiteSpaceTokenTypes().contains(prevType)) {
        if (processor.whitespaceFound(prev)) return true;
      }

      if (findPreviousNode(config, prev.getLastChildNode(), targetType, true, false, processor))
        return true;
    }

    if (processParent) {
      for (ASTNode parent = from.getTreeParent(); parent != null; parent = parent.getTreeParent()) {
        if (findPreviousNode(config, parent, targetType, false, false, processor)) return true;
      }
    }
    return false;
  }
  @Test(expected = RuntimeException.class)
  public void shouldRethrowExceptionWhileLoggin() {
    given(nodeProcessor.processNode(astNode)).willThrow(new RuntimeException("Ouch!"));
    given(astNode.getLineno()).willThrow(new IllegalArgumentException("Ouchy!"));

    instrumenter.visit(astNode);
  }
  @Test(expected = RuntimeException.class)
  public void shouldRethrowExceptionIfNoLog() {
    ReflectionUtils.setField(instrumenter, "log", null);
    given(nodeProcessor.processNode(astNode)).willThrow(new RuntimeException("Ouch!"));

    instrumenter.visit(astNode);
  }
  /** {@inheritDoc} */
  public boolean accept(Node aNode) {
    final boolean accepted = delegate.accept(aNode);
    if (accepted) {
      acceptedNodes.add(aNode);
    }

    return accepted;
  }
  @Test
  public void shouldLogException() {
    RuntimeException exception = new RuntimeException("Ouch!");
    given(nodeProcessor.processNode(astNode)).willThrow(exception);
    given(astNode.getLineno()).willReturn(7);

    instrumenter.visit(astNode);

    verify(logger).log(SEVERE, "Error on line 7 of /dir/file.js", exception);
  }
 /** {@inheritDoc} */
 public void process(Node aNode) {
   delegate.process(aNode);
 }
Пример #7
0
 /**
  * This method is called when all nodes have been processed and PathEntity is created. {@link
  * net.minecraft.world.pathfinder.WalkNodeProcessor WalkNodeProcessor} uses this to change its
  * field {@link net.minecraft.world.pathfinder.WalkNodeProcessor#avoidsWater avoidsWater}
  */
 public void postProcess() {
   super.postProcess();
 }
Пример #8
0
 public void initProcessor(IBlockAccess iblockaccessIn, Entity entityIn) {
   super.initProcessor(iblockaccessIn, entityIn);
 }