Package com.puppetlabs.xtext.dommodel

Examples of com.puppetlabs.xtext.dommodel.RegionMatch


      node, grammarAccess.getUnlessExpressionAccess().getThenStatementsExpressionListParserRuleCall_3_0());
    return false;
  }

  protected boolean _format(VerbatimTE o, StyleSet styleSet, IDomNode node, ITextFlow flow, ILayoutContext context) {
    RegionMatch match = intersect(node, context);
    if(match.isInside()) {
      if(match.isContained() && !context.isWhitespacePreservation())
        flow.appendText(o.getText(), true);
      else
        // output the part of the text that is inside the region as verbatim text
        flow.appendText(match.apply().getFirst(), true);
    }
    return true;
  }
View Full Code Here


    assertTrue(ws.containsAll(none));
  }

  @Test
  public void testRegionMatcher_after() {
    RegionMatch match = new RegionMatch("abc", 5, new TextRegion(3, 2));
    assertEquals("Should be AFTER", RegionMatch.IntersectionType.AFTER, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("", applied.getFirst().toString());
    assertEquals("", applied.getSecond().toString());
    assertEquals("abc", applied.getThird().toString());
  }
View Full Code Here

    assertEquals("abc", applied.getThird().toString());
  }

  @Test
  public void testRegionMatcher_before() {
    RegionMatch match = new RegionMatch("abc", 0, new TextRegion(3, 2));
    assertEquals("Should be BEFORE", RegionMatch.IntersectionType.BEFORE, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("", applied.getFirst().toString());
    assertEquals("abc", applied.getSecond().toString());
    assertEquals("", applied.getThird().toString());
  }
View Full Code Here

  }

  @Test
  public void testRegionMatcher_contained() {
    // left aligned in region
    RegionMatch match = new RegionMatch("abc", 0, new TextRegion(0, 5));
    assertEquals("Should be CONTAINED left", RegionMatch.IntersectionType.CONTAINED, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("abc", applied.getFirst().toString());
    assertEquals("", applied.getSecond().toString());
    assertEquals("", applied.getThird().toString());

    // "centered" in region
    match = new RegionMatch("abc", 2, new TextRegion(0, 6));
    assertEquals(
      "Should be CONTAINED centered", RegionMatch.IntersectionType.CONTAINED, match.getIntersectionType());
    applied = match.apply();
    assertEquals("abc", applied.getFirst().toString());
    assertEquals("", applied.getSecond().toString());
    assertEquals("", applied.getThird().toString());

    // right aligned in region
    match = new RegionMatch("abc", 2, new TextRegion(0, 5));
    assertEquals("Should be CONTAINED right", RegionMatch.IntersectionType.CONTAINED, match.getIntersectionType());
    applied = match.apply();
    assertEquals("abc", applied.getFirst().toString());
    assertEquals("", applied.getSecond().toString());
    assertEquals("", applied.getThird().toString());

  }
View Full Code Here

  }

  @Test
  public void testRegionMatcher_firstPartInside() {
    RegionMatch match = new RegionMatch("abc", 4, new TextRegion(0, 5));
    assertEquals(
      "Should be FIRSTPART_INSIDE", RegionMatch.IntersectionType.FIRSTPART_INSIDE, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("a", applied.getFirst().toString());
    assertEquals("", applied.getSecond().toString());
    assertEquals("bc", applied.getThird().toString());

  }
View Full Code Here

  }

  @Test
  public void testRegionMatcher_lastPartInside() {
    RegionMatch match = new RegionMatch("abc", 0, new TextRegion(2, 5));
    assertEquals(
      "Should be LASTPART_INSIDE", RegionMatch.IntersectionType.LASTPART_INSIDE, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("c", applied.getFirst().toString());
    assertEquals("ab", applied.getSecond().toString());
    assertEquals("", applied.getThird().toString());

  }
View Full Code Here

  }

  @Test
  public void testRegionMatcher_midPartInside() {
    RegionMatch match = new RegionMatch("abc", 0, new TextRegion(1, 1));
    assertEquals(
      "Should be MIDPART_INSIDE", RegionMatch.IntersectionType.MIDPART_INSIDE, match.getIntersectionType());
    Triple<CharSequence, CharSequence, CharSequence> applied = match.apply();
    assertEquals("b", applied.getFirst().toString());
    assertEquals("a", applied.getSecond().toString());
    assertEquals("c", applied.getThird().toString());

  }
View Full Code Here

    return format(null, dom, flow, context);
  }

  @Override
  public boolean format(StyleSet styleSet, IDomNode dom, ITextFlow flow, ILayoutContext context) {
    RegionMatch match = intersect(dom, context);
    if(match.isInside()) {
      if(match.isContained() && !context.isWhitespacePreservation()) {
        CommentType commentType = commentConfiguration.classify(dom);
        ICommentFormatterAdvice advice = commentConfiguration.getFormatterAdvice(commentType);
        if(!advice.enabled() || CommentType.Unknown == commentType) {
          flow.appendText(dom.getText(), true);
          return true;
        }
        ICommentContainerInformation commentContainer = commentConfiguration.getContainerInformation(commentType);
        List<IDomNode> collected = collectCommentSequence(dom, context, commentContainer);
        this.formatComment(styleSet, collected, flow, context, commentContainer, advice);
        for(IDomNode n : collected)
          context.markConsumed(n);
      }
      else
        // output the part of the text that is inside the region as verbatim text
        flow.appendText(match.apply().getFirst(), true);
    }

    return true;
  }
View Full Code Here

  @Named(COMMENT_LAYOUT_NAME)
  protected ILayout commentLayout;

  @Override
  protected void formatComment(StyleSet styleSet, IDomNode node, ITextFlow output, ILayoutContext context) {
    RegionMatch match = intersect(node, context);
    if(match.isInside()) {
      if(match.isContained() && !context.isWhitespacePreservation()) {
        Preconditions.checkState(
          commentLayout != null, "setCommentLayout(ILayout) must have been called first.");
        commentLayout.format(styleSet, node, output, context);
      }
      else
        // output the part of the text that is inside the region as verbatim text
        output.appendText(match.apply().getFirst(), true);
    }
  }
View Full Code Here

    }
  }

  @Override
  protected void formatToken(StyleSet styleSet, IDomNode node, ITextFlow output, ILayoutContext context) {
    RegionMatch match = intersect(node, context);
    if(match.isInside()) {
      if(match.isContained() && !context.isWhitespacePreservation())
        formatTokenInternal(styleSet, node, output, context);
      else
        // output the part of the text that is inside the region as verbatim text
        output.appendText(match.apply().getFirst(), true);
    }

  }
View Full Code Here

TOP

Related Classes of com.puppetlabs.xtext.dommodel.RegionMatch

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.