Search in sources :

Example 1 with UpdateKind

use of org.metaborg.core.build.UpdateKind in project spoofax by metaborg.

the class ParseResultProcessor method request.

@Override
public Observable<P> request(final I input) {
    final FileObject resource = input.source();
    return Observable.create(new OnSubscribe<P>() {

        @Override
        public void call(Subscriber<? super P> observer) {
            if (observer.isUnsubscribed()) {
                logger.trace("Unsubscribed from parse result request for {}", input);
                return;
            }
            final BehaviorSubject<ParseChange<P>> updates = getUpdates(input);
            final ParseChange<P> update = updates.toBlocking().first(new Func1<ParseChange<P>, Boolean>() {

                @Override
                public Boolean call(ParseChange<P> updateToFilter) {
                    final UpdateKind kind = updateToFilter.kind;
                    return kind != UpdateKind.Invalidate;
                }
            });
            if (observer.isUnsubscribed()) {
                logger.trace("Unsubscribed from parse result request for {}", resource);
                return;
            }
            switch(update.kind) {
                case Update:
                    logger.trace("Returning cached parse result for {}", resource);
                    observer.onNext(update.unit);
                    observer.onCompleted();
                    break;
                case Error:
                    logger.trace("Returning parse error for {}", resource);
                    observer.onError(update.exception);
                    break;
                case Remove:
                    {
                        final String message = logger.format("Parse result for {} was removed unexpectedly", resource);
                        logger.error(message);
                        observer.onError(new ParseException(input, message));
                        break;
                    }
                default:
                    {
                        final String message = logger.format("Unexpected parse update kind {} for {}", update.kind, resource);
                        logger.error(message);
                        observer.onError(new ParseException(input, message));
                        break;
                    }
            }
        }
    });
}
Also used : BehaviorSubject(rx.subjects.BehaviorSubject) UpdateKind(org.metaborg.core.build.UpdateKind) FileObject(org.apache.commons.vfs2.FileObject) ParseException(org.metaborg.core.syntax.ParseException) Func1(rx.functions.Func1)

Example 2 with UpdateKind

use of org.metaborg.core.build.UpdateKind in project spoofax by metaborg.

the class AnalysisResultProcessor method request.

@Override
public Observable<A> request(final I input, final IContext context) {
    if (input.detached()) {
        throw new MetaborgRuntimeException("Cannot request updates for detached (no source) units");
    }
    final FileObject resource = input.source();
    return Observable.create(new OnSubscribe<A>() {

        @Override
        public void call(Subscriber<? super A> observer) {
            if (observer.isUnsubscribed()) {
                logger.trace("Unsubscribed from analysis result request for {}", resource);
                return;
            }
            final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(input, context);
            final AnalysisChange<A> update = updates.toBlocking().first(new Func1<AnalysisChange<A>, Boolean>() {

                @Override
                public Boolean call(AnalysisChange<A> updateToFilter) {
                    final UpdateKind kind = updateToFilter.kind;
                    return kind != UpdateKind.Invalidate;
                }
            });
            if (observer.isUnsubscribed()) {
                logger.trace("Unsubscribed from analysis result request for {}", resource);
                return;
            }
            switch(update.kind) {
                case Update:
                    logger.trace("Returning cached analysis result for {}", resource);
                    observer.onNext(update.result);
                    observer.onCompleted();
                    break;
                case Error:
                    logger.trace("Returning analysis error for {}", resource);
                    observer.onError(update.exception);
                    break;
                case Remove:
                    {
                        final String message = String.format("Analysis result for %s was removed unexpectedly", resource);
                        logger.error(message);
                        observer.onError(new AnalysisException(context, message));
                        break;
                    }
                default:
                    {
                        final String message = String.format("Unexpected analysis update kind %s for %s", update.kind, resource);
                        logger.error(message);
                        observer.onError(new MetaborgRuntimeException(message));
                        break;
                    }
            }
        }
    });
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) BehaviorSubject(rx.subjects.BehaviorSubject) UpdateKind(org.metaborg.core.build.UpdateKind) AnalysisException(org.metaborg.core.analysis.AnalysisException) FileObject(org.apache.commons.vfs2.FileObject) Func1(rx.functions.Func1)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)2 UpdateKind (org.metaborg.core.build.UpdateKind)2 Func1 (rx.functions.Func1)2 BehaviorSubject (rx.subjects.BehaviorSubject)2 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)1 AnalysisException (org.metaborg.core.analysis.AnalysisException)1 ParseException (org.metaborg.core.syntax.ParseException)1