Java 类org.eclipse.xtext.formatting2.FormatterRequest 实例源码

项目:xtext-core    文件:FormattingService.java   
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;
}
项目:xtext-extras    文件:FormatterTester.java   
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
}
项目:xtext-core    文件:Serializer.java   
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);
}
项目:xtext-core    文件:TextReplacerContext.java   
@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);
    }
}
项目:xtext-core    文件:FormatterTestHelper.java   
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
}
项目:xtext-core    文件:DoubleHiddenRegionFormatter.java   
@Override
public FormatterRequest getRequest() {
    return first.getRequest();
}
项目:xtext-core    文件:SubDocument.java   
@Override
public FormatterRequest getRequest() {
    return parent.getRequest();
}
项目:xtext-core    文件:SingleHiddenRegionFormatter.java   
@Override
public FormatterRequest getRequest() {
    return formatting.getRequest();
}
项目:xtext-core    文件:HiddenRegionFormatting.java   
@Override
public FormatterRequest getRequest() {
    return formatter.getRequest();
}
项目:xtext-core    文件:RootDocument.java   
@Override
public FormatterRequest getRequest() {
    return formatter.getRequest();
}
项目:xtext-core    文件:FormatterTestRequest.java   
public FormatterRequest getRequest() {
    return request;
}
项目:xtext-core    文件:FormatterTestRequest.java   
@Inject
public FormatterTestRequest setRequest(FormatterRequest request) {
    this.request = request;
    return this;
}
项目:xtext-core    文件:RegionDiffFormatter.java   
protected FormatterRequest createFormatterRequest(ITextRegionAccess rewritten) {
    FormatterRequest request = formatterRequest.get();
    request.setTextRegionAccess(rewritten);
    return request;
}
项目:xtext-core    文件:RegionDiffFormatter.java   
protected FormatterRequest createFormatterRequest(ITextRegionAccessDiff rewritten) {
    FormatterRequest request = formatterRequest.get();
    request.setTextRegionAccess(rewritten);
    request.setRegions(collectRegionsToFormat(rewritten));
    return request;
}