From bf6c2496cc230d8688caae43c36ae240df508801 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 10 Apr 2015 14:01:02 +0200 Subject: Got rid of some unecessary output in ontology serialization. --- src/plugins/xml/XmlOutput.cpp | 42 +++++++++++++++------- .../lots_of_empty_elements.out.osxml | 7 ++-- .../attributes_descriptor.out.osxml | 6 ++-- .../ontology_serialization/simple.out.osxml | 15 +++----- .../ontology_serialization/syntax.out.osxml | 10 +++--- .../ontology_serialization/typesystem.out.osxml | 7 ++-- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index 0d7b0dc..1a7ea2a 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -276,14 +276,17 @@ static Rooted transformFieldDescriptor(Handle parent, std::map attrs; addNameAttribute(fd, attrs); bool isSubtree = fd->getFieldType() == FieldDescriptor::FieldType::SUBTREE; - attrs.emplace("subtree", getStringForBool(isSubtree)); - attrs.emplace("optional", getStringForBool(fd->isOptional())); + if (isSubtree) { + attrs.emplace("subtree", getStringForBool(true)); + } + if (fd->isOptional()) { + attrs.emplace("optional", getStringForBool(true)); + } // TODO: whitespace mode? // create the XML element itself. Rooted fieldDescriptor{new Element(P.mgr, parent, tagName, attrs)}; // translate the syntax. Rooted syntax{new Element(P.mgr, parent, "syntax")}; - fieldDescriptor->addChild(syntax); { Rooted open = transformTokenDescriptor(syntax, fd->getOpenToken(), "open", P); @@ -296,6 +299,9 @@ static Rooted transformFieldDescriptor(Handle parent, syntax->addChild(close); } } + if (!syntax->getChildren().empty()) { + fieldDescriptor->addChild(syntax); + } if (!fd->isPrimitive()) { // translate the child references. for (auto s : fd->getChildren()) { @@ -323,7 +329,9 @@ static void transformDescriptor(Handle elem, Handle syntax, elem, "attributes", "attribute", d->getAttributesDescriptor(), P); // remove the parent entry if it is there. attributes->getAttributes().erase("parent"); - elem->addChild(attributes); + if (!attributes->getChildren().empty()) { + elem->addChild(attributes); + } // transform the syntactic sugar description. { Rooted open = @@ -350,20 +358,25 @@ static Rooted transformStructuredClass(Handle parent, { Rooted structuredClass{new Element(P.mgr, parent, "struct")}; // transform the specific StructuredClass properties. - structuredClass->getAttributes().emplace( - "cardinality", toString(Variant(s->getCardinality()), P)); + if (s->getCardinality() != Cardinality::any()) { + structuredClass->getAttributes().emplace( + "cardinality", toString(Variant(s->getCardinality()), P)); + } if (s->getSuperclass() != nullptr) { structuredClass->getAttributes().emplace( "isa", getStructuredClassRef(s, s->getSuperclass())); } - structuredClass->getAttributes().emplace( - "transparent", getStringForBool(s->isTransparent())); - structuredClass->getAttributes().emplace( - "root", getStringForBool(s->hasRootPermission())); + if (s->isTransparent()) { + structuredClass->getAttributes().emplace("transparent", + getStringForBool(true)); + } + if (s->hasRootPermission()) { + structuredClass->getAttributes().emplace("root", + getStringForBool(true)); + } // transform the syntactic sugar descriptors Rooted syntax{new Element(P.mgr, structuredClass, "syntax")}; - structuredClass->addChild(syntax); { Rooted shortForm = transformTokenDescriptor(syntax, s->getShortToken(), "short", P); @@ -374,6 +387,9 @@ static Rooted transformStructuredClass(Handle parent, // transform the descriptor properties transformDescriptor(structuredClass, syntax, s, P); + if (!syntax->getChildren().empty()) { + structuredClass->addChild(syntax); + } return structuredClass; } @@ -383,8 +399,10 @@ static Rooted transformAnnotationClass(Handle parent, { Rooted annotationClass{new Element(P.mgr, parent, "struct")}; Rooted syntax{new Element(P.mgr, annotationClass, "syntax")}; - annotationClass->addChild(syntax); transformDescriptor(annotationClass, syntax, a, P); + if (!syntax->getChildren().empty()) { + annotationClass->addChild(syntax); + } return annotationClass; } diff --git a/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml index 07caa33..21935f2 100644 --- a/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml +++ b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml @@ -1,11 +1,8 @@ - - - - - + + diff --git a/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml b/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml index 00f21f5..44b7aef 100644 --- a/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml +++ b/testdata/integration/ontology_serialization/attributes_descriptor.out.osxml @@ -1,14 +1,12 @@ - - + - - + diff --git a/testdata/integration/ontology_serialization/simple.out.osxml b/testdata/integration/ontology_serialization/simple.out.osxml index 4aa15a6..2d00fc5 100644 --- a/testdata/integration/ontology_serialization/simple.out.osxml +++ b/testdata/integration/ontology_serialization/simple.out.osxml @@ -1,22 +1,15 @@ - - - - - + + - - + - - - - + diff --git a/testdata/integration/ontology_serialization/syntax.out.osxml b/testdata/integration/ontology_serialization/syntax.out.osxml index 3e8190a..79909fe 100644 --- a/testdata/integration/ontology_serialization/syntax.out.osxml +++ b/testdata/integration/ontology_serialization/syntax.out.osxml @@ -1,17 +1,15 @@ - + + + + ยง << >> - - - - - diff --git a/testdata/integration/ontology_serialization/typesystem.out.osxml b/testdata/integration/ontology_serialization/typesystem.out.osxml index a822191..4811b87 100644 --- a/testdata/integration/ontology_serialization/typesystem.out.osxml +++ b/testdata/integration/ontology_serialization/typesystem.out.osxml @@ -1,14 +1,11 @@ - - + - - - + -- cgit v1.2.3