/** {@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(); }
@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; }
public void assertFormattedAs(final CharSequence input, final CharSequence expected) { try { String _string = expected.toString(); Model _parse = this._parseHelper.parse(input); Resource _eResource = _parse.eResource(); IParseResult _parseResult = ((XtextResource) _eResource).getParseResult(); ICompositeNode _rootNode = _parseResult.getRootNode(); int _length = input.length(); INodeModelFormatter.IFormattedRegion _format = this._iNodeModelFormatter.format(_rootNode, 0, _length); String _formattedText = _format.getFormattedText(); Assert.assertEquals(_string, _formattedText); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected INodeModelFormatter getNodeModelFormatter() { return getInjector().getInstance(INodeModelFormatter.class); }
public Class<? extends INodeModelFormatter> bindINodeModelFormatter() { return DefaultNodeModelFormatter.class; }
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); }
/** * 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)); }