Examples of TextRegion


Examples of org.eclipse.xtext.util.TextRegion

  }

  @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

Examples of org.eclipse.xtext.util.TextRegion

  }

  @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());
View Full Code Here

Examples of org.eclipse.xtext.util.TextRegion

  }

  @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());
View Full Code Here

Examples of org.eclipse.xtext.util.TextRegion

  }

  @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());
View Full Code Here

Examples of org.eclipse.xtext.util.TextRegion

      try {
        resourceScope.enter(state);
        // EObject context = getContext(state.getContents().get(0));
        IDomNode root = getSerializer().serializeToDom(state.getContents().get(0), false);
        org.eclipse.xtext.util.ReplaceRegion r = getFormatter().format(
          root, new TextRegion(region.getOffset(), region.getLength()), //
          getFormattingContextFactory().create(state, FormattingOption.Format), errors);
        ReplaceRegion replaceRegion = new ReplaceRegion(r.getOffset(), r.getLength(), r.getText());
        try {
          if(replaceRegion != null) {
View Full Code Here

Examples of org.eclipse.xtext.util.TextRegion

      // Serialize everything to DOM
      IDomNode root = serializeToDom(obj.eResource().getContents().get(0), true, commentReconciliator);

      // Find the node for the modified object, we need to format the region it occupies.
      IDomNode replacementNode = DomModelUtils.findNodeForSemanticObject(root, obj);
      TextRegion regionToFormat = new TextRegion(replacementNode.getOffset(), replacementNode.getLength());

      // Override temporarily to have formatting turned on
      // GAH - this is just ridiculous internal DSL junk to set a single boolean
      options = SaveOptions.newBuilder().format().getOptions();
      ReplaceRegion r = domFormatter.format(
View Full Code Here

Examples of org.eclipse.xtext.util.TextRegion

    String code = code1 + code2 + code3;
    XtextResource r = getResourceFromString(code);
    String s = serializeFormatted(r.getContents().get(0));
    assertEquals("formatting should produce wanted result", code, s);

    s = serializeFormatted(r.getContents().get(0), new TextRegion(10, 47));
    assertEquals("formatting should produce wanted result", code2, s);

  }
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.