Search in sources :

Example 1 with ConflictingRegionsException

use of org.eclipse.xtext.formatting2.internal.ConflictingRegionsException in project xtext-core by eclipse.

the class FormattableDocument method addReplacer.

@Override
public void addReplacer(ITextReplacer replacer) {
    if (!this.getRegion().contains(replacer.getRegion())) {
        String frameTitle = getClass().getSimpleName();
        ITextSegment frameRegion = getRegion();
        String replacerTitle = replacer.getClass().getSimpleName();
        ITextSegment replacerRegion = replacer.getRegion();
        RegionsOutsideFrameException exception = new RegionsOutsideFrameException(frameTitle, frameRegion, Tuples.create(replacerTitle, replacerRegion));
        getRequest().getExceptionHandler().accept(exception);
        return;
    }
    try {
        getReplacers().add(replacer, getFormatter().createTextReplacerMerger());
    } catch (ConflictingRegionsException e) {
        getRequest().getExceptionHandler().accept(e);
    }
}
Also used : HiddenRegionFormattingToString(org.eclipse.xtext.formatting2.debug.HiddenRegionFormattingToString) TextRegionsToString(org.eclipse.xtext.formatting2.debug.TextRegionsToString) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment)

Example 2 with ConflictingRegionsException

use of org.eclipse.xtext.formatting2.internal.ConflictingRegionsException in project xtext-core by eclipse.

the class FormattingConflictTest method enableDebugTracingFalse.

@Test
public void enableDebugTracingFalse() {
    final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
    final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                Integer _get = execution.get();
                int _plus = ((_get).intValue() + 1);
                execution.set(Integer.valueOf(_plus));
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace(" ");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace("\t");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function_1);
            }
        };
        it.setFormatter(_function_1);
        FormatterRequest _request = it.getRequest();
        _request.setEnableDebugTracing(false);
        FormatterRequest _request_1 = it.getRequest();
        final IAcceptor<Exception> _function_2 = (Exception e) -> {
            wrapper.set(e);
        };
        _request_1.setExceptionHandler(_function_2);
    };
    this._genericFormatterTester.assertFormatted(_function);
    Throwable _get = wrapper.get();
    final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
    Assert.assertEquals(2, (execution.get()).intValue());
    Assert.assertEquals(2, exception.getTraces().size());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 3 with ConflictingRegionsException

use of org.eclipse.xtext.formatting2.internal.ConflictingRegionsException in project xtext-core by eclipse.

the class FormattingConflictTest method enableDebugTracingTrue.

@Test
public void enableDebugTracingTrue() {
    final Wrapper<Throwable> wrapper = new Wrapper<Throwable>();
    final Wrapper<Integer> execution = new Wrapper<Integer>(Integer.valueOf(0));
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("idlist a");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<IDList> _function_1 = new GenericFormatter<IDList>() {

            @Override
            protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                Integer _get = execution.get();
                int _plus = ((_get).intValue() + 1);
                execution.set(Integer.valueOf(_plus));
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace(" ");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.setSpace("\t");
                };
                document.append(regions.regionFor(model).keyword("idlist"), _function_1);
            }
        };
        it.setFormatter(_function_1);
        FormatterRequest _request = it.getRequest();
        _request.setEnableDebugTracing(true);
        FormatterRequest _request_1 = it.getRequest();
        final IAcceptor<Exception> _function_2 = (Exception e) -> {
            wrapper.set(e);
        };
        _request_1.setExceptionHandler(_function_2);
    };
    this._genericFormatterTester.assertFormatted(_function);
    Throwable _get = wrapper.get();
    final ConflictingRegionsException exception = ((ConflictingRegionsException) _get);
    Assert.assertEquals(1, (execution.get()).intValue());
    Assert.assertEquals(2, exception.getTraces().size());
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) ConflictingRegionsException(org.eclipse.xtext.formatting2.internal.ConflictingRegionsException) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IAcceptor(org.eclipse.xtext.util.IAcceptor) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 4 with ConflictingRegionsException

use of org.eclipse.xtext.formatting2.internal.ConflictingRegionsException in project xtext-core by eclipse.

the class TextReplacerContext method addReplacement.

@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);
    }
}
Also used : ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) String(java.lang.String) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Aggregations

FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)2 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)2 ConflictingRegionsException (org.eclipse.xtext.formatting2.internal.ConflictingRegionsException)2 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)2 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)2 IDList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList)2 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)2 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)2 IAcceptor (org.eclipse.xtext.util.IAcceptor)2 Wrapper (org.eclipse.xtext.util.Wrapper)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Test (org.junit.Test)2 String (java.lang.String)1 HiddenRegionFormattingToString (org.eclipse.xtext.formatting2.debug.HiddenRegionFormattingToString)1 TextRegionsToString (org.eclipse.xtext.formatting2.debug.TextRegionsToString)1