Search in sources :

Example 1 with Function0

use of org.eclipse.xtext.xbase.lib.Functions.Function0 in project xtext-core by eclipse.

the class AbstractLanguageServerTest method getServerModule.

protected com.google.inject.Module getServerModule() {
    ServerModule _serverModule = new ServerModule();
    final com.google.inject.Module _function = (Binder it) -> {
        AnnotatedBindingBuilder<RequestManager> _bind = it.<RequestManager>bind(RequestManager.class);
        _bind.toInstance(new RequestManager() {

            @Override
            public <V extends Object> CompletableFuture<V> runRead(final Function1<? super CancelIndicator, ? extends V> request) {
                final CompletableFuture<V> result = new CompletableFuture<V>();
                try {
                    final CancelIndicator _function = () -> {
                        return false;
                    };
                    result.complete(request.apply(_function));
                } catch (final Throwable _t) {
                    if (_t instanceof Throwable) {
                        final Throwable e = (Throwable) _t;
                        result.completeExceptionally(e);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                return result;
            }

            @Override
            public <U extends Object, V extends Object> CompletableFuture<V> runWrite(final Function0<? extends U> nonCancellable, final Function2<? super CancelIndicator, ? super U, ? extends V> request) {
                final CompletableFuture<V> result = new CompletableFuture<V>();
                try {
                    final CancelIndicator _function = () -> {
                        return false;
                    };
                    result.complete(request.apply(_function, nonCancellable.apply()));
                } catch (final Throwable _t) {
                    if (_t instanceof Throwable) {
                        final Throwable e = (Throwable) _t;
                        result.completeExceptionally(e);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                return result;
            }
        });
    };
    return Modules2.mixin(_serverModule, _function);
}
Also used : Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Function0(org.eclipse.xtext.xbase.lib.Functions.Function0) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) ServerModule(org.eclipse.xtext.ide.server.ServerModule) Binder(com.google.inject.Binder) AnnotatedBindingBuilder(com.google.inject.binder.AnnotatedBindingBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 2 with Function0

use of org.eclipse.xtext.xbase.lib.Functions.Function0 in project xtext-eclipse by eclipse.

the class ReplaceFileContentChange method getOldContents.

protected byte[] getOldContents() {
    byte[] _xblockexpression = null;
    {
        final ByteArrayOutputStream oldContentsBAOS = new ByteArrayOutputStream();
        final Function0<byte[]> _function = () -> {
            try {
                byte[] _xblockexpression_1 = null;
                {
                    final InputStream oldContentsIS = this.file.getContents();
                    final Function0<byte[]> _function_1 = () -> {
                        try {
                            int readBytes = 0;
                            final byte[] buffer = new byte[4096];
                            while (((readBytes = oldContentsIS.read(buffer)) != (-1))) {
                                oldContentsBAOS.write(buffer, 0, readBytes);
                            }
                            return oldContentsBAOS.toByteArray();
                        } catch (Throwable _e) {
                            throw Exceptions.sneakyThrow(_e);
                        }
                    };
                    _xblockexpression_1 = TryWithResource.<byte[]>tryWith(oldContentsIS, _function_1);
                }
                return _xblockexpression_1;
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        _xblockexpression = TryWithResource.<byte[]>tryWith(oldContentsBAOS, _function);
    }
    return _xblockexpression;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Function0(org.eclipse.xtext.xbase.lib.Functions.Function0) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Function0 (org.eclipse.xtext.xbase.lib.Functions.Function0)2 Binder (com.google.inject.Binder)1 AnnotatedBindingBuilder (com.google.inject.binder.AnnotatedBindingBuilder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ServerModule (org.eclipse.xtext.ide.server.ServerModule)1 RequestManager (org.eclipse.xtext.ide.server.concurrent.RequestManager)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)1