@@ -136,9 +136,9 @@ public class ${class.name}
136136    final ${type} $field.name;
137137    #end
138138    #if ( $locationTracking )
139-       #if ( ! $class.superClass )
140139    /** Locations */
141140    final Map<Object, InputLocation> locations;
141+       #if ( ! $class.superClass )
142142    /** Location tracking */
143143    final InputLocation importedFrom;
144144      #end
@@ -170,14 +170,16 @@ public class ${class.name}
170170    #if ( $locationTracking )
171171        Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
172172        Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
173+         this.locations = Map.ofEntries(
174+             Map.entry("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get("")),
175+         #foreach ( $field in $allFields )
176+             #set ( $sep = "#if($field!=${allFields[${allFields.size()} - 1]}),#end" )
177+             Map.entry("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}"))${sep}
178+         #end
179+         );
173180      #if ( ! $class.superClass )
174-         this.locations = new HashMap<>();
175181        this.importedFrom = builder.importedFrom;
176-         this.locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
177182      #end
178-         #foreach ( $field in $class.getFields($version) )
179-         this.locations.put("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}"));
180-         #end
181183    #end
182184    }
183185
0 commit comments