Franz Kafka
Franz Kafka

Reputation: 10831

xtext/xtend use join to create list with multiple fields

I want to print an enum enum State{A(0),B(1)} as a comma seperated list, in the form A=0, B=1. For this xtext/xtend provides a join operation. However, I can't find any information on how to access multiple fields of the enum. The enum has a toString and numVal method.

E.g. {«State::values.join(', ') [toString»=«numVal]»} does not work. What is the correct syntax for such an operation?

Upvotes: 0

Views: 261

Answers (1)

Stocker
Stocker

Reputation: 141

I think your double colon "::" is a problem.

println( State.values.join(', ')['''«toString»=«numVal»'''] ) works fine.

Or you can do it like this: println( State.values.map['''«toString»=«numVal»'''].join(', ') )

Both produce: A=0, B=1

Upvotes: 3

Related Questions