From 8bc5d202d1bc745ff113d844c69138e814c5c28f Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 26 Aug 2024 09:24:42 +0200 Subject: [PATCH] Make locations map immutable --- src/mdo/model.vm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mdo/model.vm b/src/mdo/model.vm index 2dbf95b2a1c9..0a89f269e83d 100644 --- a/src/mdo/model.vm +++ b/src/mdo/model.vm @@ -136,9 +136,9 @@ public class ${class.name} final ${type} $field.name; #end #if ( $locationTracking ) - #if ( ! $class.superClass ) /** Locations */ final Map locations; + #if ( ! $class.superClass ) /** Location tracking */ final InputLocation importedFrom; #end @@ -170,14 +170,16 @@ public class ${class.name} #if ( $locationTracking ) Map newlocs = builder.locations != null ? builder.locations : Collections.emptyMap(); Map oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap(); + this.locations = Map.ofEntries( + Map.entry("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get("")), + #foreach ( $field in $allFields ) + #set ( $sep = "#if($field!=${allFields[${allFields.size()} - 1]}),#end" ) + Map.entry("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}"))${sep} + #end + ); #if ( ! $class.superClass ) - this.locations = new HashMap<>(); this.importedFrom = builder.importedFrom; - this.locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get("")); #end - #foreach ( $field in $class.getFields($version) ) - this.locations.put("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}")); - #end #end }