use of org.eclipse.xtext.util.Wrapper in project xtext-eclipse by eclipse.
the class DisplayRunnable method syncExec.
public void syncExec() {
if (Display.getCurrent() == null) {
final Wrapper<Exception> exceptionWrapper = new Wrapper<Exception>();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
DisplayRunnable.this.run();
} catch (Exception e) {
exceptionWrapper.set(e);
}
}
});
if (exceptionWrapper.get() != null)
throw new WrappedException(exceptionWrapper.get());
} else {
try {
run();
} catch (Exception e) {
throw new WrappedException(e);
}
}
}
use of org.eclipse.xtext.util.Wrapper in project xtext-eclipse by eclipse.
the class DisplayRunnableWithResult method syncExec.
public T syncExec() {
if (Display.getCurrent() == null) {
final Wrapper<T> resultWrapper = new Wrapper<T>();
final Wrapper<Exception> exceptionWrapper = new Wrapper<Exception>();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
resultWrapper.set(DisplayRunnableWithResult.this.run());
} catch (Exception e) {
exceptionWrapper.set(e);
}
}
});
Exception exception = exceptionWrapper.get();
if (exception != null)
throw (exception instanceof RuntimeException) ? (RuntimeException) exception : new WrappedException(exception);
return resultWrapper.get();
} else {
try {
return run();
} catch (Exception e) {
throw new WrappedException(e);
}
}
}
use of org.eclipse.xtext.util.Wrapper 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.util.Wrapper 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.util.Wrapper in project xtext-xtend by eclipse.
the class CodeBuilderQuickfix method getXtendModification.
protected IModification getXtendModification(final ICodeBuilder.Xtend builder) {
final IModification _function = (IModificationContext it) -> {
final XtendTypeDeclaration xtendClass = builder.getXtendType();
final IEditorPart editor = this.editorOpener.open(EcoreUtil.getURI(xtendClass), false);
if ((!(editor instanceof XtextEditor))) {
return;
}
final XtextEditor xtextEditor = ((XtextEditor) editor);
final IXtextDocument document = xtextEditor.getDocument();
final Wrapper<Integer> wrapper = Wrapper.<Integer>forType(Integer.class);
final IUnitOfWork<ReplacingAppendable, XtextResource> _function_1 = (XtextResource resource) -> {
ReplacingAppendable _xblockexpression = null;
{
int offset = builder.getInsertOffset(resource);
wrapper.set(Integer.valueOf(offset));
final int typeIndentation = this.getTypeIndentation(resource, document, xtendClass);
DocumentSourceAppender.Factory.OptionalParameters _optionalParameters = new DocumentSourceAppender.Factory.OptionalParameters();
final Procedure1<DocumentSourceAppender.Factory.OptionalParameters> _function_2 = (DocumentSourceAppender.Factory.OptionalParameters it_1) -> {
int _indentationLevel = builder.getIndentationLevel();
int _plus = (_indentationLevel + typeIndentation);
it_1.baseIndentationLevel = _plus;
it_1.ensureEmptyLinesAround = true;
};
DocumentSourceAppender.Factory.OptionalParameters _doubleArrow = ObjectExtensions.<DocumentSourceAppender.Factory.OptionalParameters>operator_doubleArrow(_optionalParameters, _function_2);
_xblockexpression = this.appendableFactory.create(document, resource, offset, 0, _doubleArrow);
}
return _xblockexpression;
};
final ReplacingAppendable appendable = document.<ReplacingAppendable>readOnly(_function_1);
Integer offset = wrapper.get();
builder.build(appendable);
appendable.commitChanges();
xtextEditor.setHighlightRange(((offset).intValue() + 1), appendable.length(), true);
};
return _function;
}
Aggregations