Java Code Examples for org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion#getFormattedText()
The following examples show how to use
org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion#getFormattedText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentFormatterFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override 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()); }
Example 2
Source File: FormatterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); }
Example 3
Source File: FormatterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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); }
Example 4
Source File: FormatterWindowsLinebreakTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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)); }
Example 5
Source File: AbstractFormatterTest.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
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); }
Example 6
Source File: AbstractFormattingTest.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * 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)); }