File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
src/main/java/com/regnosys/rosetta/generator Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -100,10 +100,14 @@ class Choice extends Data {
100
100
}
101
101
102
102
class ChoiceOption extends Attribute {
103
+ String _hardcodedName
103
104
contains RosettaCardinality _hardcodedCardinality
104
105
105
106
op String getName() {
106
- NodeModelUtils.findNodesForFeature(typeCall, Literals.TYPE_CALL__TYPE).head.text.strip
107
+ if (_hardcodedName === null) {
108
+ _hardcodedName = NodeModelUtils.getTokenText(NodeModelUtils.findNodesForFeature(typeCall, Literals.TYPE_CALL__TYPE).head)
109
+ }
110
+ return _hardcodedName
107
111
}
108
112
109
113
op RosettaCardinality getCard() {
Original file line number Diff line number Diff line change @@ -269,12 +269,24 @@ private void computeActualNames() {
269
269
List <GeneratedIdentifier > ids = idsByDesiredName .get (desiredName );
270
270
for (int i = 0 ; i < ids .size (); i ++) {
271
271
GeneratedIdentifier id = ids .get (i );
272
- String name = id . getDesiredName () ;
272
+ String name = desiredName ;
273
273
if (ids .size () > 1 ) {
274
274
name += i ;
275
275
}
276
- while (takenNames .contains (name ) || !isValidIdentifier (name )) {
277
- name = escapeName (name );
276
+ boolean lastWasValid = true ;
277
+ while (true ) {
278
+ boolean isValid = isValidIdentifier (name );
279
+ if (!lastWasValid && !isValid ) {
280
+ // Escaping the invalid identifier did not work - throw an exception. Otherwise we could end up in an infinite loop.
281
+ // If this is thrown, this usually indicates there is an implementation error in `escapeName` or `isValidIdentifier`.
282
+ throw new RuntimeException ("Tried escaping the identifier `" + name + "`, but it is still not a valid identifier." );
283
+ }
284
+ if (takenNames .contains (name ) || !isValid ) {
285
+ name = escapeName (name );
286
+ } else {
287
+ break ;
288
+ }
289
+ lastWasValid = isValid ;
278
290
}
279
291
takenNames .add (name );
280
292
this .actualNames .put (id , name );
You can’t perform that action at this time.
0 commit comments