Search in sources :

Example 16 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class LanguageComponent method facet.

@Override
public <T extends IFacet> T facet(Class<T> type) {
    // GTODO: code duplication with LanguageComponent, use default interface implementation in Java 8.
    final Iterable<T> facets = facets(type);
    final int size = Iterables.size(facets);
    if (size == 0) {
        return null;
    } else if (size > 1) {
        throw new MetaborgRuntimeException("Multiple facets of type " + type + " found, while only a single facet is supported");
    }
    return Iterables.get(facets, 0);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException)

Example 17 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class LanguageComponent method facetContribution.

@Override
public <T extends IFacet> FacetContribution<T> facetContribution(Class<T> type) {
    // GTODO: code duplication with LanguageComponent, use default interface implementation in Java 8.
    final Iterable<FacetContribution<T>> facetContributions = facetContributions(type);
    final int size = Iterables.size(facetContributions);
    if (size == 0) {
        return null;
    } else if (size > 1) {
        throw new MetaborgRuntimeException("Multiple facets of type " + type + " found, while only a single facet is supported");
    }
    return Iterables.get(facetContributions, 0);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException)

Example 18 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class LanguageImplementation method facetContribution.

@Override
public <T extends IFacet> FacetContribution<T> facetContribution(Class<T> type) {
    // GTODO: code duplication with LanguageComponent, use default interface implementation in Java 8.
    final Iterable<FacetContribution<T>> facetContributions = facetContributions(type);
    final int size = Iterables.size(facetContributions);
    if (size == 0) {
        return null;
    } else if (size > 1) {
        throw new MetaborgRuntimeException("Multiple facets of type " + type + " found, while only a single facet is supported");
    }
    return Iterables.get(facetContributions, 0);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException)

Example 19 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class LanguageImplementation method facet.

@Override
public <T extends IFacet> T facet(Class<T> type) {
    // GTODO: code duplication with LanguageComponent, use default interface implementation in Java 8.
    final Iterable<T> facets = facets(type);
    final int size = Iterables.size(facets);
    if (size == 0) {
        return null;
    } else if (size > 1) {
        throw new MetaborgRuntimeException("Multiple facets of type " + type + " found, while only a single facet is supported");
    }
    return Iterables.get(facets, 0);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException)

Example 20 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException 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

MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)26 FileObject (org.apache.commons.vfs2.FileObject)16 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)9 MetaborgException (org.metaborg.core.MetaborgException)7 Nullable (javax.annotation.Nullable)6 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 IContext (org.metaborg.core.context.IContext)4 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)4 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)4 File (java.io.File)3 IOException (java.io.IOException)3 ContextException (org.metaborg.core.context.ContextException)3 ILanguage (org.metaborg.core.language.ILanguage)3 IdentifiedDialect (org.metaborg.core.language.dialect.IdentifiedDialect)3 IMessage (org.metaborg.core.messages.IMessage)3 IProject (org.metaborg.core.project.IProject)3 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)3 FileName (org.apache.commons.vfs2.FileName)2 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)2