Examples of MeasuredTextFlow


Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

    assertSampleFlowMetrics(flow);
  }

  @Test
  public void test_TextFlowOneLineNoBreak() {
    MeasuredTextFlow flow = this.getInjector().getInstance(TextFlow.class);
    flow.appendText("123");
    assertFlowOneLineNoBreak(flow);
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

  }

  @Test
  public void test_TextLinewrap() {
    // default is 132 characters before a wrap and 0 wrap indent
    MeasuredTextFlow flow = this.getInjector().getInstance(TextFlow.class);
    Fixed stars = new CharSequences.Fixed('*', 22);
    for(int i = 0; i < 24; i++) {
      flow.appendText(stars);
      flow.appendSpaces(0);
    }
    assertEquals(4, flow.getHeight());
    assertEquals(132, flow.getWidth());

    flow = this.getInjector().getInstance(TextFlow.class);
    for(int i = 0; i < 24; i++) {
      flow.appendText(stars);
      flow.appendSpaces(1);
    }
    assertEquals(5, flow.getHeight());
    assertEquals(115, flow.getWidth());
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

    assertEquals(115, flow.getWidth());
  }

  @Test
  public void test_TextRecordingEmpty() {
    MeasuredTextFlow flow = this.getInjector().getInstance(TextFlowRecording.class);
    assertFalse("ends with break", flow.endsWithBreak());
    assertEquals("Height", 0, flow.getHeight());
    assertEquals("Last used indent", 0, flow.getLastUsedIndentation());
    assertEquals("Current indent", 0, flow.getIndentation());
    assertEquals("Width", 0, flow.getWidth());
    assertEquals("Width of last line", 0, flow.getWidthOfLastLine());
    assertTrue("Empty", flow.isEmpty());

  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

  DomNodeLayoutFeeder feeder;

  public boolean fitsOnSameLine(IDomNode node, AbstractElement startGrammarElement,
      AbstractElement untilGrammarElement, ITextFlow flow, ILayoutContext context) {
    DelegatingLayoutContext dlc = new DelegatingLayoutContext(context);
    MeasuredTextFlow continuedFlow = new MeasuredTextFlow((MeasuredTextFlow) flow);

    // advance to first token to measure (there may be pending whitespace to newline output at the start of the node).
    if(startGrammarElement != null)
      for(IDomNode n : node.getChildren()) {
        if(n.getGrammarElement() == startGrammarElement)
          break;
        feeder.sequence(n, continuedFlow, dlc);
      }
    // take start measure
    // if flow is empty the first output char will give it height 1
    int h0 = Math.max(1, continuedFlow.getHeight());
    for(IDomNode n : node.getChildren()) {
      feeder.sequence(n, continuedFlow, dlc);
      if(untilGrammarElement != null && n.getGrammarElement() == untilGrammarElement)
        break;
    }
    int h1 = continuedFlow.getHeight();
    // if output causes break (height increases), or at edge (the '{' will not fit).
    return h1 <= h0 && continuedFlow.getWidthOfLastLine() < continuedFlow.getPreferredMaxWidth();
  }
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

    stream.appendBreaks(1);

    // process cases
    int width = 0;
    for(Case c : o.getCases()) {
      MeasuredTextFlow inner = new MeasuredTextFlow(formattingContext);
      Iterator<Expression> itor = c.getValues().iterator();
      while(itor.hasNext()) {
        doFormat(itor.next(), inner);
        if(itor.hasNext()) {
          inner.appendText(",");
          inner.appendSpace();
        }
      }
      width = inner.getWidth();
    }
    for(Case c : o.getCases()) {
      int before = stream.size();
      Iterator<Expression> itor = c.getValues().iterator();
      while(itor.hasNext()) {
View Full Code Here

Examples of com.puppetlabs.xtext.textflow.MeasuredTextFlow

    // Simply skip entries that can be very wide/unknown - format the rest
    // TODO: Set "folding" in the stream to allow nested List/hash to fold
    //
    int width = 0;
    for(Expression e : o.getParameters()) {
      MeasuredTextFlow inner = new MeasuredTextFlow(formattingContext);
      // if e is not a SelectorEntry, it is really a syntax error, but do something reasonable
      doFormat(e instanceof SelectorEntry
          ? ((SelectorEntry) e).getLeftExpr()
          : e, inner);
      width = inner.getWidth();
    }
    for(Expression e : o.getParameters()) {
      if(e instanceof SelectorEntry == false) {
        doFormat(e, stream);
        stream.appendBreaks(1);
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.