Search in sources :

Example 1 with Wrapper

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);
        }
    }
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) WrappedException(org.eclipse.emf.common.util.WrappedException) WrappedException(org.eclipse.emf.common.util.WrappedException)

Example 2 with Wrapper

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);
        }
    }
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) WrappedException(org.eclipse.emf.common.util.WrappedException) WrappedException(org.eclipse.emf.common.util.WrappedException)

Example 3 with Wrapper

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

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());
}
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 5 with Wrapper

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;
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) IEditorPart(org.eclipse.ui.IEditorPart) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) DocumentSourceAppender(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

Wrapper (org.eclipse.xtext.util.Wrapper)5 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)3 WrappedException (org.eclipse.emf.common.util.WrappedException)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)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 IAcceptor (org.eclipse.xtext.util.IAcceptor)2 Test (org.junit.Test)2 IEditorPart (org.eclipse.ui.IEditorPart)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)1