From f3499558ef67958809670e6319977ad5b74e189c Mon Sep 17 00:00:00 2001 From: hghianni Date: Tue, 19 Apr 2022 15:38:02 -0300 Subject: [PATCH] W-10547488: Fixed exceptions thrown in Emitters --- .../vocabularies/VocabularyEmitter.scala | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/amf-aml/shared/src/main/scala/amf/aml/internal/render/emitters/vocabularies/VocabularyEmitter.scala b/amf-aml/shared/src/main/scala/amf/aml/internal/render/emitters/vocabularies/VocabularyEmitter.scala index 66b8b3b6..ae501243 100644 --- a/amf-aml/shared/src/main/scala/amf/aml/internal/render/emitters/vocabularies/VocabularyEmitter.scala +++ b/amf-aml/shared/src/main/scala/amf/aml/internal/render/emitters/vocabularies/VocabularyEmitter.scala @@ -279,27 +279,30 @@ case class VocabularyEmitter(vocabulary: Vocabulary, document: DocumentCreator) private def vocabularyPropertiesEmitter(ordering: SpecOrdering) = { var emitters: Seq[EntryEmitter] = Nil - emitters ++= Seq(new EntryEmitter { - override def emit(b: EntryBuilder): Unit = { - MapEntryEmitter("base", vocabulary.base.value()).emit(b) - } - - override def position(): Position = ZERO + if (vocabulary.base.nonEmpty) { + emitters ++= Seq(new EntryEmitter { + override def emit(b: EntryBuilder): Unit = { + MapEntryEmitter("base", vocabulary.base.value()).emit(b) + } - }) + override def position(): Position = ZERO - emitters ++= Seq(new EntryEmitter { - override def emit(b: EntryBuilder): Unit = MapEntryEmitter("vocabulary", vocabulary.name.value()).emit(b) + }) + } - override def position(): Position = - vocabulary.fields - .get(VocabularyModel.Name) - .annotations - .find(classOf[LexicalInformation]) - .map(_.range.start) - .getOrElse(ZERO) - }) + if (vocabulary.name.nonEmpty) { + emitters ++= Seq(new EntryEmitter { + override def emit(b: EntryBuilder): Unit = MapEntryEmitter("vocabulary", vocabulary.name.value()).emit(b) + override def position(): Position = + vocabulary.fields + .get(VocabularyModel.Name) + .annotations + .find(classOf[LexicalInformation]) + .map(_.range.start) + .getOrElse(ZERO) + }) + } if (vocabulary.usage.nonEmpty) { emitters ++= Seq(new EntryEmitter { override def emit(b: EntryBuilder): Unit = MapEntryEmitter("usage", vocabulary.usage.value()).emit(b)