Examples of TextFlow


Examples of com.puppetlabs.xtext.textflow.TextFlow

   *
   * @see org.eclipse.xtext.serializer.ISerializer#serialize(org.eclipse.emf.ecore.EObject, org.eclipse.xtext.resource.SaveOptions)
   */
  @Override
  public String serialize(EObject obj, SaveOptions options) {
    ITextFlow.WithText tokenStringBuffer = new TextFlow(formattingContext);
    try {
      serialize(obj, tokenStringBuffer, options);
    }
    catch(IOException e) {
      throw new RuntimeException(e);
    }
    return getString(tokenStringBuffer.getText());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

   *
   * @see org.eclipse.xtext.serializer.ISerializer#serialize(org.eclipse.emf.ecore.EObject, java.io.Writer, org.eclipse.xtext.resource.SaveOptions)
   */
  @Override
  public void serialize(EObject obj, Writer writer, SaveOptions options) throws IOException {
    serialize(obj, new TextFlow(writer, formattingContext), options);
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

          if(DomModelUtils.isWhitespace(nextLeaf))
            nextLeaf.getStyles().add(StyleSet.withStyles(styles.oneLineBreak()));
        }
        else if(ge == hashAccess.getKeyLiteralNameOrStringParserRuleCall_0_0()) {
          DelegatingLayoutContext keyContext = new DelegatingLayoutContext(context);
          TextFlow keyFlow = new TextFlow(keyContext);
          ArrayList<IDomNode> children = Lists.newArrayList(n.getChildren());
          for(Iterator<IDomNode> subitor = children.iterator(); subitor.hasNext();) {
            IDomNode x = subitor.next();
            NodeType t = x.getNodeType();
            if(t == NodeType.ACTION || t == NodeType.WHITESPACE) {
              subitor.remove();
              continue;
            }
            break; // first non whitespace or action
          }
          feeder.sequence(children, keyFlow, context);
          previousKeyWidth = keyFlow.getWidthOfLastLine();
          cluster.add(previousKeyWidth);
          System.out.println("node= [" + keyFlow.getText() + "] width = " + previousKeyWidth);
        }
        else if(ge == hashAccess.getEqualsSignGreaterThanSignKeyword_1()) {
          operatorNodes.put(n, previousKeyWidth);
        }
      }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

              continuedFlow.getIndentSize();
        }
        // used to measure output of formatted case values
        // adjust its width to available width (and do not mark items consumed in the given context)
        DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
        TextFlow measuredFlow = new TextFlow(innerContext);
        // visit all nodes in case until the colon is hit, and format the output to the measured flow
        IDomNode colonNode = feeder.sequence(n, measuredFlow, innerContext, caseColonPredicate);
        if(doCompaction && !n.getStyleClassifiers().contains(StatementStyle.COMPACTABLE))
          allCompactable = false;

        colonNodes.add(colonNode);

        // collect the width of the last case's values
        int lastLineWidth = measuredFlow.getWidthOfLastLine();
        if(!firstCaseSeen) {
          // the space before the first case triggers case expression indentation of 1, this must be adjusted
          lastLineWidth -= measuredFlow.getIndentSize();
        }
        clusters.add(lastLineWidth);
        widths.add(lastLineWidth);
        firstCaseSeen = true;
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

    for(int i = 0; i < colonNodes.size(); i++) {
      IDomNode p = colonNodes.get(i).getParent();
      IDomNode statements = DomModelUtils.nodeForGrammarElement(
        p, grammarAccess.getCaseAccess().getStatementsExpressionListParserRuleCall_4_0());
      DelegatingLayoutContext caseStatementContext = new DelegatingLayoutContext(context, remainingWidths.get(i));
      TextFlow caseStatementFlow = new TextFlow(caseStatementContext);
      if(statements != null)
        feeder.sequence(
          statements, caseStatementFlow, caseStatementContext, new SkipInitialWhitespacePredicate(),
          alwaysFalse);
      // only 1 line high and did not overflow
      if(!(caseStatementFlow.getHeight() <= 1 && caseStatementFlow.getWidthOfLastLine() <= remainingWidths.get(i))) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

    boolean containsAppend = false;

    // while siblings are assignments, starting with the current one
    for(IDomNode aeNode = node; aeNode != null && includeInSequence(aeNode); aeNode = aeNode.getNextSibling()) {
      DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
      TextFlow measuredFlow = new TextFlow(innerContext);

      // iterate to format the LHS expression and measure, and find the = sign (which gets padded)
      Iterator<IDomNode> itor = aeNode.treeIterator();
      while(itor.hasNext()) {
        IDomNode n = itor.next();
        // forward until assignment expression =, or +=
        if(!(n.getGrammarElement() == theAssignmentExpression || n.getGrammarElement() == theAppendExpression))
          continue;

        // Measure assignment expression
        feeder.sequence(n, measuredFlow, innerContext, new FirstLeafWithTextAndTheRest(), untilTheEnd);

        // forward to = or += sign
        while(itor.hasNext()) {
          n = itor.next();
          if(n.getGrammarElement() == theEqualSign || n.getGrammarElement() == thePlusEqualSign)
            break;
        }
        if(n.getGrammarElement() == thePlusEqualSign)
          containsAppend = true;

        if(!itor.hasNext())
          break; // WAT, nothing after the '=', give up on this assignment, try to align the others

        // If assignment node already has a width, it was processed by a preceding assignment
        // and we were done a long time ago...
        //
        WidthStyle widthStyle = n.getStyles().getStyle(WidthStyle.class, n);
        if(widthStyle != null)
          return false;

        equalSignNodes.add(n);

        // collect the width of the last selector entry's values
        int lastLineWidth = measuredFlow.getWidthOfLastLine();
        clusters.add(lastLineWidth);
        widths.add(lastLineWidth);
        break;
      }
    }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

              continuedFlow.getIndentSize();
        }
        // used to measure output of formatted selector entry values
        // adjust its width to available width (and do not mark items consumed in the given context)
        DelegatingLayoutContext innerContext = new DelegatingLayoutContext(context, availableWidth);
        TextFlow measuredFlow = new TextFlow(innerContext);
        // visit all nodes in case until the colon is hit, and format the output to the measured flow
        IDomNode fatCommaNode = feeder.sequence(n, measuredFlow, innerContext, caseFatCommaPredicate);

        fatCommaNodes.add(fatCommaNode);

        // collect the width of the last selector entry's values
        int lastLineWidth = measuredFlow.getWidthOfLastLine();
        if(!firstSelectoEntrySeen) {
          // the space before the first entry triggers selector expression indentation of 1, this must be adjusted
          lastLineWidth -= measuredFlow.getIndentSize();
        }
        clusters.add(lastLineWidth);
        widths.add(lastLineWidth);
        firstSelectoEntrySeen = true;
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.TextFlow

      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

Examples of com.puppetlabs.xtext.textflow.TextFlow

        + " * 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

Examples of com.puppetlabs.xtext.textflow.TextFlow

        + " * 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
TOP
Copyright © 2018 www.massapi.com. 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.