User32516325
User32516325

Reputation: 13

How to filter identical named attributes of classes

With a Xtend file, I am generating a hpp file including attributes of inputed object classes. The following code snippet writes all attributes related to the classes.

«FOR o : myClass.objectClasses»
    Test::ObjectClassHandle _class_«o.fullyQualifiedName.toString("_")»;
    «FOR a : o.attributes»
        Test::AttributeHandle «_attr_«a.fullyQualifiedName.toString("_")»;
    «ENDFOR»
«ENDFOR»

The problem is that some classes include the same attributes. How can I filter identical named attributes so each attribute is written once?

Upvotes: 1

Views: 51

Answers (1)

kapex
kapex

Reputation: 29999

You can convert attributes to a map, using the attribute name as a key. Only one attribute is stored for each key, so all of the map's values will be attributes with unique names:

o.attributes.toMap[fullyQualifiedName.toString("_")].values

Upvotes: 1

Related Questions