| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-17 10:11:19 +02:00
										 |  |  | const NoteSet = require('../note_set'); | 
					
						
							| 
									
										
										
										
											2021-06-29 22:15:57 +02:00
										 |  |  | const becca = require('../../../becca/becca'); | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  | const Expression = require('./expression'); | 
					
						
							| 
									
										
										
										
											2020-05-17 10:11:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  | class AttributeExistsExp extends Expression { | 
					
						
							| 
									
										
										
										
											2020-05-21 12:05:12 +02:00
										 |  |  |     constructor(attributeType, attributeName, prefixMatch) { | 
					
						
							| 
									
										
										
										
											2020-05-22 09:38:30 +02:00
										 |  |  |         super(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |         this.attributeType = attributeType; | 
					
						
							|  |  |  |         this.attributeName = attributeName; | 
					
						
							| 
									
										
										
										
											2020-05-21 12:05:12 +02:00
										 |  |  |         this.prefixMatch = prefixMatch; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 12:27:44 +02:00
										 |  |  |     execute(inputNoteSet) { | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 12:27:44 +02:00
										 |  |  |             if (inputNoteSet.hasNoteId(note.noteId)) { | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |                 if (attr.isInheritable) { | 
					
						
							| 
									
										
										
										
											2021-05-17 22:35:36 +02:00
										 |  |  |                     resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-05-17 22:35:36 +02:00
										 |  |  |                 else if (note.isTemplate()) { | 
					
						
							|  |  |  |                     resultNoteSet.addAll(note.getTemplatedNotes()); | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							|  |  |  |                     resultNoteSet.add(note); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-05-21 00:39:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return resultNoteSet; | 
					
						
							| 
									
										
										
										
											2020-05-16 23:12:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-17 09:48:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 00:03:33 +02:00
										 |  |  | module.exports = AttributeExistsExp; |