2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-07-18 21:28:51 +03:00
|
|
|
import NoteSet = require('../note_set');
|
|
|
|
import SearchContext = require('../search_context');
|
2024-02-18 00:45:21 +02:00
|
|
|
|
|
|
|
import becca = require('../../../becca/becca');
|
|
|
|
import Expression = require('./expression');
|
2020-05-17 10:11:19 +02:00
|
|
|
|
2020-05-22 09:38:30 +02:00
|
|
|
class AttributeExistsExp extends Expression {
|
2024-02-18 00:45:21 +02:00
|
|
|
|
|
|
|
private attributeType: string;
|
|
|
|
private attributeName: string;
|
|
|
|
private isTemplateLabel: boolean;
|
2024-02-18 02:27:04 +02:00
|
|
|
private prefixMatch: boolean;
|
2024-02-18 00:45:21 +02:00
|
|
|
|
2024-02-18 02:27:04 +02:00
|
|
|
constructor(attributeType: string, attributeName: string, prefixMatch: boolean) {
|
2020-05-22 09:38:30 +02:00
|
|
|
super();
|
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
this.attributeType = attributeType;
|
|
|
|
this.attributeName = attributeName;
|
2023-11-16 00:11:14 +01:00
|
|
|
// template attr is used as a marker for templates, but it's not meant to be inherited
|
|
|
|
this.isTemplateLabel = this.attributeType === 'label' && (this.attributeName === 'template' || this.attributeName === 'workspacetemplate');
|
2020-05-21 12:05:12 +02:00
|
|
|
this.prefixMatch = prefixMatch;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-18 00:45:21 +02:00
|
|
|
execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {
|
2020-05-21 12:05:12 +02:00
|
|
|
const attrs = this.prefixMatch
|
2021-04-16 23:00:08 +02:00
|
|
|
? becca.findAttributesWithPrefix(this.attributeType, this.attributeName)
|
|
|
|
: becca.findAttributes(this.attributeType, this.attributeName);
|
2020-05-21 12:05:12 +02:00
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
const resultNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const attr of attrs) {
|
|
|
|
const note = attr.note;
|
|
|
|
|
2023-11-16 00:11:14 +01:00
|
|
|
if (attr.isInheritable && !this.isTemplateLabel) {
|
2021-12-20 21:35:12 +01:00
|
|
|
resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated());
|
|
|
|
}
|
2023-11-16 00:11:14 +01:00
|
|
|
else if (note.isInherited() && !this.isTemplateLabel) {
|
2023-01-06 20:31:55 +01:00
|
|
|
resultNoteSet.addAll(note.getInheritingNotes());
|
2021-12-20 21:35:12 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
resultNoteSet.add(note);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-21 00:39:17 +02:00
|
|
|
|
2021-12-20 21:35:12 +01:00
|
|
|
return resultNoteSet.intersection(inputNoteSet);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
2024-02-18 00:45:21 +02:00
|
|
|
export = AttributeExistsExp;
|