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

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


      ICommentContainerInformation in = (nodes.size() == 1 && nodes.get(0).getGrammarElement() == ga.getML_COMMENTRule())
          ? commentConfiguration.getContainerInformation(CommentType.Multiline)
          : (commentConfiguration.getContainerInformation(CommentType.SingleLine));

      CommentProcessor cpr = new CommentProcessor();
      CommentText comment = cpr.separateCommentFromContainer(result, in, "\n"); // TODO: cheating on line separator
      return new RubyDocProcessor().asHTML(comment.getLines());

    }
    return null;
  }
View Full Code Here


  @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);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    String expected = "/* the\n * quick\n * brown\n * fox\n */ ";
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

  @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 = //
    "/*******************************************\n"//
        + "* 0123456789 0123456789 0123456789 0123456789\n"//
        + "* abc\n" //
        + "* 0123456789 0123456789 0123456789 0123456789\n"//
        + "*/";
    String expected = //
    "/***********************\n"//
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

  @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 = //
    "/* 0123456789 0123456789 0123456789 0123456789\n"//
        + "* abc\n" //
        + "* 0123456789 0123456789 0123456789 0123456789\n"//
        + "*/";
    String expected = //
    "/* 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";

    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
View Full Code Here

  @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 = //
    "/*   0123456789 0123456789 0123456789 0123456789\n"//
        + "* abc\n" //
        + "* 0123456789 0123456789 0123456789 0123456789\n"//
        + "*/";
    String expected = //
    "/*   0123456789 0123456789\n *   0123456789 0123456789\n"//
        + " * abc\n" //
        + " * 0123456789 0123456789\n * 0123456789 0123456789\n"//
        + " */";
    IFormattingContext fmtCtx = get(IFormattingContext.class);
    TextFlow s = cp.formatComment(source, in, in, options, fmtCtx);
    assertEquals("Should produce expected result", expected, s.getText().toString());
  }
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
    // (makes comparison look nicer if test fails)
    String expected = "  /* the\n   * quick\n   * brown\n   * fox\n   */ ";
    assertEquals("Should produce expected result", expected, "  " + CharSequences.trimLeft(s.getText()).toString());
  }
View Full Code Here

        try {

          String issueString = xtextDocument.get(issue.getOffset(), issue.getLength());
          final boolean endsWithBreak = issue.getData() != null && issue.getData().length == 1 &&
              "true".equals(issue.getData()[0]);
          CommentProcessor commentProcessor = new CommentProcessor();
          JavaLikeMLCommentContainer mlContainer = new ICommentContainerInformation.JavaLikeMLCommentContainer();
          HashSLCommentContainer hashContainer = new ICommentContainerInformation.HashSLCommentContainer();
          int offsetOfNode = issue.getOffset();

          int posOnLine = offsetOfNode -
              Math.max(0, 1 + CharSequences.lastIndexOf(
                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)
View Full Code Here

TOP

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

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.