protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) { final FormatterRequest request = this.formatterRequestProvider.get(); request.setAllowIdentityEdits(false); request.setFormatUndefinedHiddenRegionsOnly(false); if ((selection != null)) { request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection))); } if ((preferences != null)) { request.setPreferences(preferences); } final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create(); request.setTextRegionAccess(regionAccess); final IFormatter2 formatter2 = this.formatter2Provider.get(); final List<ITextReplacement> replacements = formatter2.format(request); return replacements; }
public void assertFormatted(FormatterTestRequest req) { checkNotNull(req); checkNotNull(req.getToBeFormatted()); FormatterRequest request = req.getRequest(); checkArgument(request.getTextRegionAccess() == null); String document = req.getToBeFormatted().toString(); XtextResource parsed = parse(document); if (req.isAllowSyntaxErrors()) { request.setExceptionHandler(ExceptionAcceptor.IGNORING); } else { assertNoSyntaxErrors(parsed); request.setExceptionHandler(ExceptionAcceptor.THROWING); } request.setTextRegionAccess(createRegionAccess(parsed, req)); if (request.getPreferences() == null) request.setPreferences(new MapBasedPreferenceValues(Maps.<String, String> newLinkedHashMap())); List<ITextReplacement> replacements = createFormatter(req).format(request); assertReplacementsAreInRegion(replacements, request.getRegions(), document); if (!req.isAllowUnformattedWhitespace()) assertAllWhitespaceIsFormatted(request.getTextRegionAccess(), replacements); String formatted = request.getTextRegionAccess().getRewriter().renderToString(replacements); Assert.assertEquals(req.getExpectationOrToBeFormatted().toString(), formatted); // TODO: assert formatting a second time only produces identity replacements // TODO: assert formatting with undefined whitespace only }
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException { ITextRegionAccess regionAccess = serializeToRegions(obj); FormatterRequest request = formatterRequestProvider.get(); request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting()); request.setTextRegionAccess(regionAccess); IFormatter2 formatter2 = formatter2Provider.get(); List<ITextReplacement> replacements = formatter2.format(request); regionAccess.getRewriter().renderToAppendable(replacements, appendable); }
@Override public void addReplacement(ITextReplacement replacement) { Preconditions.checkNotNull(replacer); ITextSegment replacerRegion = replacer.getRegion(); FormatterRequest request = document.getRequest(); if (!replacerRegion.contains(replacement)) { String frameTitle = replacer.getClass().getSimpleName(); ITextSegment frameRegion = replacer.getRegion(); String replacerTitle = replacement.getReplacementText(); RegionsOutsideFrameException exception = new RegionsOutsideFrameException(frameTitle, frameRegion, Tuples.create(replacerTitle, (ITextSegment) replacement)); request.getExceptionHandler().accept(exception); return; } if (!isInRequestedRange(replacement)) { return; } if (!isInUndefinedRegion(replacement)) { if (request.isFormatUndefinedHiddenRegionsOnly()) { return; } if (!request.allowIdentityEdits() && isIdentityEdit(replacement)) { return; } } try { replacements.add(replacement); } catch (ConflictingRegionsException e) { request.getExceptionHandler().accept(e); } }
public void assertFormatted(FormatterTestRequest req) { checkNotNull(req); checkNotNull(req.getToBeFormatted()); FormatterRequest request = req.getRequest(); checkArgument(request.getTextRegionAccess() == null); String document = req.getToBeFormatted().toString(); XtextResource parsed = parse(document); if (req.isAllowSyntaxErrors()) { if (request.getExplicitExceptionHandler() == null) { request.setExceptionHandler(ExceptionAcceptor.IGNORING); } } else { assertNoSyntaxErrors(parsed); if (request.getExplicitExceptionHandler() == null) { request.setExceptionHandler(ExceptionAcceptor.THROWING); } } request.setTextRegionAccess(createRegionAccess(parsed, req)); if (request.getPreferences() == null) request.setPreferences(new MapBasedPreferenceValues(Maps.<String, String> newLinkedHashMap())); List<ITextReplacement> replacements = createFormatter(req).format(request); assertReplacementsAreInRegion(replacements, request.getRegions(), document); if (!req.isAllowUnformattedWhitespace()) assertAllWhitespaceIsFormatted(request.getTextRegionAccess(), replacements); String formatted = request.getTextRegionAccess().getRewriter().renderToString(replacements); Assert.assertEquals(req.getExpectationOrToBeFormatted().toString(), formatted); // TODO: assert formatting a second time only produces identity replacements // TODO: assert formatting with undefined whitespace only }
@Override public FormatterRequest getRequest() { return first.getRequest(); }
@Override public FormatterRequest getRequest() { return parent.getRequest(); }
@Override public FormatterRequest getRequest() { return formatting.getRequest(); }
@Override public FormatterRequest getRequest() { return formatter.getRequest(); }
public FormatterRequest getRequest() { return request; }
@Inject public FormatterTestRequest setRequest(FormatterRequest request) { this.request = request; return this; }
protected FormatterRequest createFormatterRequest(ITextRegionAccess rewritten) { FormatterRequest request = formatterRequest.get(); request.setTextRegionAccess(rewritten); return request; }
protected FormatterRequest createFormatterRequest(ITextRegionAccessDiff rewritten) { FormatterRequest request = formatterRequest.get(); request.setTextRegionAccess(rewritten); request.setRegions(collectRegionsToFormat(rewritten)); return request; }