Java 类org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion 实例源码

项目:xtext-core    文件:FormatterTest.java   
protected void assertFormattedNM(String expected, String model, int offset, int lengt) throws Exception {
    EObject m = getModel(model);
    ICompositeNode node = NodeModelUtils.getNode(m).getRootNode();
    // System.out.println(EmfFormatter.objToStr(node));
    IFormattedRegion r = getNodeModelFormatter().format(node, offset, lengt);
    String actual = model.substring(0, r.getOffset()) + r.getFormattedText()
            + model.substring(r.getLength() + r.getOffset());
    assertEquals(expected, actual);
}
项目:xtext-core    文件:FormatterTest.java   
@Test public void testBug471212() throws Exception {
    String model = "test wrappingdt f\nb kw1";
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    AccessibleFormatter formatter = get(AccessibleFormatter.class);
    formatter.setNodeModelStreamer(get(BrokenStreamer.class));
    IFormattedRegion region = formatter.format(node, 0, model.length());
    String actual = region.getFormattedText();
    assertEquals(model, actual);
    assertEqualTokenStreams(model);
    assertPreserved(model);
}
项目:xtext-core    文件:FormatterWindowsLinebreakTest.java   
@Override
protected void assertFormattedNM(String expected, final String modelP, int offset, int length) throws Exception {
    if(length != modelP.length() && offset != 0)
        return;
    String model = convertLineBreaks(modelP);
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    // System.out.println(EmfFormatter.objToStr(node));
    IFormattedRegion r = getNodeModelFormatter().format(node, 0, model.length());
    String actual = model.substring(0, r.getOffset()) + r.getFormattedText()
            + model.substring(r.getLength() + r.getOffset());
    assertEquals(revealLineBreaks(convertLineBreaks(expected)), revealLineBreaks(actual));
}
项目:bts    文件:ContentFormatterFactory.java   
public ReplaceRegion exec(XtextResource state) throws Exception {
    IParseResult parseResult = state.getParseResult();
    if (parseResult == null)
        return null;
    IFormattedRegion r = formatter.format(parseResult.getRootNode(), region.getOffset(), region.getLength());
    return new ReplaceRegion(r.getOffset(), r.getLength(), r.getFormattedText());
}
项目:dsl-devkit    文件:AbstractFormatterTest.java   
protected void assertFormattedNM(final String expected, final String model, final int offset, final int length) throws IOException {
  ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
  IFormattedRegion r = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
  String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
  Assert.assertEquals(expected, actual);
}
项目:dsl-devkit    文件:AbstractFormattingTest.java   
/**
 * Test formatting based on the NodeModel.
 *
 * @param model
 *          the model to check
 * @param input
 *          String representing a serialized model
 * @param expected
 *          Expected formatted String
 * @param offset
 *          Offset from which to start formatting
 * @param length
 *          Length of region to format
 */
private void assertFormattedNodeModel(final EObject model, final String input, final String expected, final int offset, final int length) {
  ICompositeNode node = NodeModelUtils.getNode(model).getRootNode();
  IFormattedRegion region = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
  String actual = input.substring(0, offset) + region.getFormattedText() + input.substring(length + offset);
  Assert.assertEquals(expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
}