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);
}
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);
}
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);
}
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);
}
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;
}
}
}
});
}
Aggregations