Package com.puppetlabs.xtext.dommodel.formatter.comments.CommentProcessor

Examples of com.puppetlabs.xtext.dommodel.formatter.comments.CommentProcessor.CommentFormattingOptions


    assertEquals("Empty string should trim to single space", " ", CharSequences.trim("   ", 1, 1).toString());
  }

  @Test
  public void test_CommentProcessor() {
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 80);
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(0);
    CommentProcessor cp = new CommentProcessor();
    String source = "/* the\nquick\n     *brown\n * fox\n   \n\n*/ ";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
View Full Code Here


    assertEquals("Should produce expected result", expected, s.getText().toString());
  }

  @Test
  public void test_CommentProcessor_bannerfolding() {
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 24);
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(0);
    CommentProcessor cp = new CommentProcessor();

    String source = //
View Full Code Here

    assertEquals("Should produce expected result", expected, s.getText().toString());
  }

  @Test
  public void test_CommentProcessor_folding() {
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 24);
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(0);
    CommentProcessor cp = new CommentProcessor();

    String source = //
View Full Code Here

    assertEquals("Should produce expected result", expected, s.getText().toString());
  }

  @Test
  public void test_CommentProcessor_folding_indent() {
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 26);
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(0);
    CommentProcessor cp = new CommentProcessor();

    String source = //
View Full Code Here

  @Test
  public void test_CommentProcessor_Indented() {
    JavaLikeMLCommentContainer in = new ICommentContainerInformation.JavaLikeMLCommentContainer(2);
    CommentProcessor cp = new CommentProcessor();
    CommentFormattingOptions options = new CommentFormattingOptions(
      new ICommentFormatterAdvice.DefaultCommentAdvice(), 80);
    String source = "/* the\n  quick\n       *brown\n   * fox\n     \n  \n  */ ";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    // pad expected and result with 2 spaces to emulate the inserting of the result
View Full Code Here

    ICommentContainerInformation in = commentContext.create(Math.max(0, pos));
    CommentProcessor cpr = new CommentProcessor();
    CommentText comment = cpr.separateCommentFromContainer(textOfNodes(nodes), in, lineSeparator);

    // format in position 0 to measure it
    TextFlow formatted = cpr.formatComment(comment, pos0Context, new CommentFormattingOptions(
      advice, Integer.MAX_VALUE, trailing, maxTrailing), layoutContext);
    int w = formatted.getWidth();
    if(w <= available) {
      // yay, it will fit as a hanging comment, reformat for this position if the position is not
      // at an even indent multiple.
      int use = current - pos_effectiveIndent;
      if(use > 0) {
        // out = commentContext.create(use);
        formatted = cpr.formatComment(comment, commentContext.create(use), new CommentFormattingOptions(
          advice, Integer.MAX_VALUE, trailing, maxTrailing), layoutContext);
      }
      output.appendText(CharSequences.trimLeft(formatted.getText())); // , true);
    }
    else {
      // Did not fit un-wrapped

      // if output ends with a break, then current is at the leftmost position already, and moving it
      // is not an option. The position is also at an indent multiple, so no need to reposition the comment.
      //
      if(output.endsWithBreak() || output.isEmpty()) {

        // re-format for effective indent
        formatted = cpr.formatComment(
          //
          comment, //
          pos0Context, //
          new CommentFormattingOptions(advice, maxWidth - pos_effectiveIndent, trailing, maxTrailing),
          layoutContext);
      }
      else {
        // re-format for the available space (hanging at current position)
        formatted = cpr.formatComment(//
          comment, //
          commentContext.create(current - pos_effectiveIndent), //
          new CommentFormattingOptions(advice, available, trailing, maxTrailing), layoutContext);

        // if comment formatted for hanging at current does not fit the width (because it
        // has non-breakable content, or starts at an awkward position)
        // then reformat and move the comment to the effective indent.
        if(formatted.getWidth() > maxWidth - pos_effectiveIndent) {

          // ouch, not possible to format it as hanging at current position, must move it to the next line.
          output.appendBreak();

          // re-format for the effective indent position space
          formatted = cpr.formatComment(
            //
            comment, //
            pos0Context, //
            new CommentFormattingOptions(advice, maxWidth - pos_effectiveIndent, trailing, maxTrailing),
            layoutContext);
        }
      }
      output.appendText(CharSequences.trimLeft(formatted.getText())); // , true);
    }
View Full Code Here

                xtextDocument.get(0, xtextDocument.getLength()), "\n", offsetOfNode - 1));

          CommentText commentText = commentProcessor.separateCommentFromContainer(
            issueString, mlContainer.create(posOnLine), "\n");
          TextFlow result = commentProcessor.formatComment(
            commentText, hashContainer.create(posOnLine), new CommentFormattingOptions(
              commentConfigurationProvider.get().getFormatterAdvice(CommentType.SingleLine),
              Integer.MAX_VALUE, 0, 1), formattingContextFactory.create(state, FormattingOption.Format));

          if(!endsWithBreak)
            result.appendBreak();
View Full Code Here

TOP

Related Classes of com.puppetlabs.xtext.dommodel.formatter.comments.CommentProcessor.CommentFormattingOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.