Search in sources :

Example 1 with TermOrigin

use of mb.nabl2.stratego.TermOrigin in project spoofax by metaborg.

the class AbstractConstraintAnalyzer method message.

private IMessage message(ITerm originatingTerm, IMessageInfo messageInfo, MessageSeverity severity, IUnifier unifier, C context, FileObject defaultLocation) {
    Optional<TermOrigin> maybeOrigin = TermOrigin.get(originatingTerm);
    if (maybeOrigin.isPresent()) {
        TermOrigin origin = maybeOrigin.get();
        ISourceRegion region = JSGLRSourceRegionFactory.fromTokens(origin.getLeftToken(), origin.getRightToken());
        FileObject resource = resourceService.resolve(context.location(), origin.getResource());
        String message = messageInfo.getContent().apply(unifier::findRecursive).toString(prettyprint(context, resource(resource, context)));
        return MessageFactory.newAnalysisMessage(resource, region, message, severity, null);
    } else {
        String message = messageInfo.getContent().apply(unifier::findRecursive).toString(prettyprint(context, null));
        return MessageFactory.newAnalysisMessageAtTop(defaultLocation, message, severity, null);
    }
}
Also used : ISourceRegion(org.metaborg.core.source.ISourceRegion) FileObject(org.apache.commons.vfs2.FileObject) TermOrigin(mb.nabl2.stratego.TermOrigin)

Example 2 with TermOrigin

use of mb.nabl2.stratego.TermOrigin in project nabl by metaborg.

the class Actions method sourceTerm.

public static ITerm sourceTerm(String resource, ITerm term) {
    TermIndex index = ImmutableTermIndex.of(resource, 0);
    TermOrigin origin = ImmutableTermOrigin.of(resource);
    ImmutableClassToInstanceMap<Object> attachments = ImmutableClassToInstanceMap.builder().put(TermIndex.class, index).put(TermOrigin.class, origin).build();
    return term.withAttachments(attachments);
}
Also used : TermOrigin(mb.nabl2.stratego.TermOrigin) ImmutableTermOrigin(mb.nabl2.stratego.ImmutableTermOrigin) ImmutableTermIndex(mb.nabl2.stratego.ImmutableTermIndex) TermIndex(mb.nabl2.stratego.TermIndex)

Aggregations

TermOrigin (mb.nabl2.stratego.TermOrigin)2 ImmutableTermIndex (mb.nabl2.stratego.ImmutableTermIndex)1 ImmutableTermOrigin (mb.nabl2.stratego.ImmutableTermOrigin)1 TermIndex (mb.nabl2.stratego.TermIndex)1 FileObject (org.apache.commons.vfs2.FileObject)1 ISourceRegion (org.metaborg.core.source.ISourceRegion)1