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);
}
}
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());
}
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());
}
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);
}
}
Aggregations