diff options
Diffstat (limited to 'src/core/model')
| -rw-r--r-- | src/core/model/Domain.cpp | 69 | ||||
| -rw-r--r-- | src/core/model/Domain.hpp | 14 | 
2 files changed, 50 insertions, 33 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index ae20068..ac0699e 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -569,17 +569,22 @@ void Descriptor::addAndSortFieldDescriptor(Handle<FieldDescriptor> fd,  		if (!fds.empty() &&  		    fds.back()->getFieldType() == FieldDescriptor::FieldType::TREE &&  		    fd->getFieldType() != FieldDescriptor::FieldType::TREE) { -			// if so we add the new field before the TREE field and log a -			// warning. - -			logger.warning( -			    std::string("Field \"") + fd->getName() + -			        "\" was declared after main field \"" + -			        fds.back()->getName() + -			        "\". The order of fields was changed to make the " -			        "main field the last field.", -			    *fd); +			// if so we add the new field before the TREE field.  			fieldDescriptors.insert(fieldDescriptors.end() - 1, fd); + +			// if the new field was from the same domain we warn the user +			// because that is bad coding style. +			if (fd->getParent() != nullptr && +			    fd->getParent().cast<Descriptor>()->getParent() == +			        getParent()) { +				logger.warning( +				    std::string("Field \"") + fd->getName() + +				        "\" was declared after main field \"" + +				        fds.back()->getName() + +				        "\". The order of fields was changed to make the " +				        "main field the last field.", +				    *fd); +			}  		} else {  			fieldDescriptors.push_back(fd);  		} @@ -778,36 +783,40 @@ void StructuredClass::removeSubclass(Handle<StructuredClass> sc, Logger &logger)  	sc->setSuperclass(nullptr, logger);  } -void StructuredClass::gatherFieldDescriptors( +Rooted<FieldDescriptor> StructuredClass::gatherFieldDescriptors(      NodeVector<FieldDescriptor> ¤t,      std::set<std::string> &overriddenFields, bool hasTREE) const  { -	// append all FieldDescriptors that are not overridden. -	for (auto &f : Descriptor::getFieldDescriptors()) { +	Rooted<FieldDescriptor> mainField; +	NodeVector<FieldDescriptor> tmp; +	// first gather the non-overridden fields. +	for (auto f : Descriptor::getFieldDescriptors()) {  		if (overriddenFields.insert(f->getName()).second) {  			bool isTREE = f->getFieldType() == FieldDescriptor::FieldType::TREE; -			if (hasTREE) { -				if (!isTREE) { -					/* -					 * If we already have a tree field it has to be at the end -					 * of the current vector. So ensure that all new non-TREE -					 * fields are inserted before the TREE field such that after -					 * this method the TREE field is still at the end. -					 */ -					current.insert(current.end() - 1, f); -				} +			if (!isTREE) { +				tmp.push_back(f);  			} else { -				if (isTREE) { +				if (!hasTREE) {  					hasTREE = true; +					mainField = f;  				} -				current.push_back(f);  			}  		}  	} -	// if we have a superclass, go there. +	// append all non-overridden superclass fields. +  	if (superclass != nullptr) { -		superclass->gatherFieldDescriptors(current, overriddenFields, hasTREE); +		Rooted<FieldDescriptor> super_main_field = +		    superclass->gatherFieldDescriptors(current, overriddenFields, +		                                       hasTREE); +		if (!hasTREE) { +			mainField = super_main_field; +		}  	} +	// then append all subtree fields of this level. +	current.insert(current.end(), tmp.begin(), tmp.end()); +	// and return the main field. +	return mainField;  }  NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const @@ -815,7 +824,11 @@ NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const  	// in this case we return a NodeVector of Rooted entries without owner.  	NodeVector<FieldDescriptor> vec;  	std::set<std::string> overriddenFields; -	gatherFieldDescriptors(vec, overriddenFields, false); +	Rooted<FieldDescriptor> mainField = +	    gatherFieldDescriptors(vec, overriddenFields, false); +	if (mainField != nullptr) { +		vec.push_back(mainField); +	}  	return vec;  } diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 081435a..350c7ba 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -791,9 +791,9 @@ private:  	/**  	 * Helper method for getFieldDescriptors.  	 */ -	void gatherFieldDescriptors(NodeVector<FieldDescriptor> ¤t, -	                            std::set<std::string> &overriddenFields, -	                            bool hasTREE) const; +	Rooted<FieldDescriptor> gatherFieldDescriptors( +	    NodeVector<FieldDescriptor> ¤t, +	    std::set<std::string> &overriddenFields, bool hasTREE) const;  protected:  	bool doValidate(Logger &logger) const override; @@ -915,10 +915,14 @@ public:  	void removeSubclass(Handle<StructuredClass> sc, Logger &logger);  	/** -	 * Returns a const reference to the NodeVector of all FieldDescriptors of +	 * Returns a NodeVector of all FieldDescriptors of  	 * this StructuredClass. This also merges the FieldDescriptors directly  	 * belonging to this StructuredClass with all FieldDescritptors of its -	 * Superclass (and so on recurvively). +	 * Superclass (and so on recurvively). The order of field descriptors is +	 * as follows: +	 * 1.) non-overridden SUBTREE FieldDescriptors of super classes. +	 * 2.) SUBTREE FieldDescriptors of this class. +	 * 3.) TREE FieldDescriptor (either inherited from super class or direct)  	 *  	 * @return a NodeVector of all FieldDescriptors of this StructuredClass.  	 */  | 
