All files / views/trees/definition-tree/nodes/classes classes-node.ts

100% Statements 20/20
100% Branches 4/4
100% Functions 7/7
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                    1x       1x       1x       2x 2x     2x   2x       16x 16x   16x       1x       6x   6x 2x     4x   4x     3x     4x 4x   4x    
import * as vscode from "vscode";
import { RDFS } from "@faubulous/mentor-rdf";
import { DefinitionTreeNode } from "../../definition-tree-node";
import { ClassNode } from "./class-node";
 
/**
 * The group node representing all classes defined in the document.
 */
export class ClassesNode extends ClassNode {
	override getContextValue(): string {
		return 'classes';
	}
 
	override getIcon(): vscode.ThemeIcon | undefined {
		return undefined;
	}
 
	override getLabel(): vscode.TreeItemLabel {
		return { label: 'Classes' };
	}
 
	override getDescription(): string {
		const graphs = this.getOntologyGraphs();
		const options = this.getQueryOptions();
 
		// Note: We only want to display the number of classes defined in the document, hence {@link getDocumentGraphs}.
		const classes = [...this.vocabulary.getClasses(graphs, options)];
 
		return classes.length.toString();
	}
 
	override getSubClassIris(): IterableIterator<string> {
		const graphs = this.getOntologyGraphs();
		const options = this.getQueryOptions();
 
		return this.vocabulary.getSubClasses(graphs, undefined, options);
	}
 
	override getTooltip(): vscode.MarkdownString | undefined {
		return undefined;
	}
 
	override resolveNodeForUri(iri: string): DefinitionTreeNode | undefined {
		const graphs = this.getOntologyGraphs();
 
		if (!this.vocabulary.hasType(graphs, iri, RDFS.Class)) {
			return undefined;
		}
 
		const options = this.getQueryOptions();
 
		if (options.includeReferenced) {
			// If referenced classes are included, we want to include classes 
			// that are defined in other ontologies.
			options.definedBy = null;
		}
 
		const rootToNode = [...this.vocabulary.getRootClassPath(graphs, iri, options)].reverse();
		rootToNode.push(iri);
 
		return this.walkHierarchyPath(rootToNode);
	}
}