org.eclipse.xtext.formatting.INodeModelFormatter Java Examples
The following examples show how to use
org.eclipse.xtext.formatting.INodeModelFormatter.
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: AnotherFormatterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void loadModel() { try { final ParseHelper<Root> parseHelper = this.getInjector().<ParseHelper<Root>>getInstance(Key.<ParseHelper<Root>>get(new TypeLiteral<ParseHelper<Root>>() { })); final INodeModelFormatter formatter = this.getInjector().<INodeModelFormatter>getInstance(INodeModelFormatter.class); StringConcatenation _builder = new StringConcatenation(); _builder.append("test sample {"); _builder.newLine(); _builder.append("// just a comment"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final Root root = parseHelper.parse(_builder); Assert.assertNotNull(root); final EList<Resource.Diagnostic> errors = root.eResource().getErrors(); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("Unexpected errors: "); String _join = IterableExtensions.join(errors, ", "); _builder_1.append(_join); Assert.assertTrue(_builder_1.toString(), errors.isEmpty()); Resource _eResource = root.eResource(); ICompositeNode rootNode = ((XtextResource) _eResource).getParseResult().getRootNode(); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("test sample {"); _builder_2.newLine(); _builder_2.newLine(); _builder_2.append("// just a comment"); _builder_2.newLine(); _builder_2.append("}"); final String expected = _builder_2.toString(); INodeModelFormatter.IFormattedRegion formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength()); Assert.assertEquals(expected, formattedRegion.getFormattedText()); formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength()); Assert.assertEquals(expected, formattedRegion.getFormattedText()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: FormatFragment.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** {@inheritDoc} */ @Override public Set<Binding> getGuiceBindingsRt(final Grammar grammar) { final BindFactory bindFactory = new BindFactory(); bindFactory.addTypeToType(IFormatter.class.getName(), FormatGeneratorUtil.getFormatterName(grammar, "")); bindFactory.addTypeToType(INodeModelFormatter.class.getName(), RegionNodeModelFormatter.class.getName()); bindFactory.addTypeToType(INodeModelStreamer.class.getName(), DirectNodeModelStreamer.class.getName()); return bindFactory.getBindings(); }
Example #3
Source File: FormatterFragment.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public Set<Binding> getGuiceBindingsRt(final Grammar grammar) { final Set<Binding> bindings = super.getGuiceBindingsRt(grammar); BindFactory bindFactory = new BindFactory(); bindings.addAll(bindFactory.addTypeToType(INodeModelFormatter.class.getName(), RegionNodeModelFormatter.class.getName()).getBindings()); bindings.addAll(bindFactory.addTypeToType(INodeModelStreamer.class.getName(), DirectNodeModelStreamer.class.getName()).getBindings()); return bindings; }
Example #4
Source File: AbstractXtextTests.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected INodeModelFormatter getNodeModelFormatter() { return getInjector().getInstance(INodeModelFormatter.class); }
Example #5
Source File: AbstractXtextTests.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected INodeModelFormatter getNodeModelFormatter() { return getInjector().getInstance(INodeModelFormatter.class); }
Example #6
Source File: DefaultRuntimeModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public Class<? extends INodeModelFormatter> bindINodeModelFormatter() { return DefaultNodeModelFormatter.class; }
Example #7
Source File: AbstractXtextTests.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected INodeModelFormatter getNodeModelFormatter() { return getInjector().getInstance(INodeModelFormatter.class); }
Example #8
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 #9
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)); }