Search in sources :

Example 1 with OutlineNode

use of org.metaborg.core.outline.OutlineNode in project spoofax by metaborg.

the class OutlineService method toOutlineNode.

@Nullable
private IOutlineNode toOutlineNode(IStrategoTerm term, @Nullable IOutlineNode parent, FileObject location) {
    if (!(term instanceof IStrategoAppl)) {
        return null;
    }
    final IStrategoAppl appl = (IStrategoAppl) term;
    if (!Tools.hasConstructor(appl, "Node", 2)) {
        return null;
    }
    final IStrategoTerm labelTerm = appl.getSubterm(0);
    final String label = label(labelTerm);
    final FileObject icon = icon(labelTerm, location);
    final ISourceRegion region = region(labelTerm);
    final OutlineNode node = new OutlineNode(label, icon, region, parent);
    final IStrategoTerm nodesTerm = appl.getSubterm(1);
    for (IStrategoTerm nodeTerm : nodesTerm) {
        final IOutlineNode childNode = toOutlineNode(nodeTerm, node, location);
        if (childNode != null) {
            node.addChild(childNode);
        }
    }
    return node;
}
Also used : IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ISourceRegion(org.metaborg.core.source.ISourceRegion) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) OutlineNode(org.metaborg.core.outline.OutlineNode) IOutlineNode(org.metaborg.core.outline.IOutlineNode) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) FileObject(org.apache.commons.vfs2.FileObject) IOutlineNode(org.metaborg.core.outline.IOutlineNode) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 FileObject (org.apache.commons.vfs2.FileObject)1 IOutlineNode (org.metaborg.core.outline.IOutlineNode)1 OutlineNode (org.metaborg.core.outline.OutlineNode)1 ISourceRegion (org.metaborg.core.source.ISourceRegion)1 IStrategoAppl (org.spoofax.interpreter.terms.IStrategoAppl)1 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1