@Override
 public boolean visit(MethodDeclaration node) {
   Block body = node.getBody();
   if (body == null) return false;
   Selection selection = getSelection();
   int nodeStart = body.getStartPosition();
   int nodeExclusiveEnd = nodeStart + body.getLength();
   // if selection node inside of the method body ignore method
   if (!(nodeStart < selection.getOffset() && selection.getExclusiveEnd() < nodeExclusiveEnd))
     return false;
   return super.visit(node);
 }
  @Override
  public boolean visit(LambdaExpression node) {
    Selection selection = getSelection();
    int selectionStart = selection.getOffset();
    int selectionExclusiveEnd = selection.getExclusiveEnd();
    int lambdaStart = node.getStartPosition();
    int lambdaExclusiveEnd = lambdaStart + node.getLength();
    ASTNode body = node.getBody();
    int bodyStart = body.getStartPosition();
    int bodyExclusiveEnd = bodyStart + body.getLength();

    boolean isValidSelection = false;
    if ((body instanceof Block)
        && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
      // if selection is inside lambda body's block
      isValidSelection = true;
    } else if (body instanceof Expression) {
      try {
        TokenScanner scanner = new TokenScanner(fCUnit);
        int arrowExclusiveEnd =
            scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
        if (selectionStart >= arrowExclusiveEnd) {
          isValidSelection = true;
        }
      } catch (CoreException e) {
        // ignore
      }
    }
    if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
      // if selection covers the lambda node
      isValidSelection = true;
    }

    if (!isValidSelection) {
      return false;
    }
    return super.visit(node);
  }