Search in sources :

Example 1 with Resolution

use of org.metaborg.core.tracing.Resolution in project spoofax by metaborg.

the class ResolverService method resolve.

private Resolution resolve(@Nullable TermWithRegion tuple) {
    if (tuple == null) {
        return null;
    }
    final IStrategoTerm output = tuple.term;
    final ISourceRegion offsetRegion = tuple.region;
    final Collection<ISourceLocation> targets = Lists.newLinkedList();
    if (output.getTermType() == IStrategoTerm.LIST) {
        for (IStrategoTerm subterm : output) {
            final ISourceLocation targetLocation = common.getTargetLocation(subterm);
            if (targetLocation == null) {
                logger.debug("Cannot get target location for {}", subterm);
                continue;
            }
            targets.add(targetLocation);
        }
    } else {
        final ISourceLocation targetLocation = common.getTargetLocation(output);
        if (targetLocation == null) {
            logger.debug("Reference resolution failed, cannot get target location for {}", output);
            return null;
        }
        targets.add(targetLocation);
    }
    if (targets.isEmpty()) {
        logger.debug("Reference resolution failed, cannot get target locations for {}", output);
        return null;
    }
    return new Resolution(offsetRegion, targets);
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ISourceRegion(org.metaborg.core.source.ISourceRegion) ISourceLocation(org.metaborg.core.source.ISourceLocation) Resolution(org.metaborg.core.tracing.Resolution)

Aggregations

ISourceLocation (org.metaborg.core.source.ISourceLocation)1 ISourceRegion (org.metaborg.core.source.ISourceRegion)1 Resolution (org.metaborg.core.tracing.Resolution)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1