Skip to content

Commit

Permalink
Make locations map immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin committed Aug 26, 2024
1 parent 402c8c2 commit 8bc5d20
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/mdo/model.vm
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public class ${class.name}
final ${type} $field.name;
#end
#if ( $locationTracking )
#if ( ! $class.superClass )
/** Locations */
final Map<Object, InputLocation> locations;
#if ( ! $class.superClass )
/** Location tracking */
final InputLocation importedFrom;
#end
Expand Down Expand Up @@ -170,14 +170,16 @@ public class ${class.name}
#if ( $locationTracking )
Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
Map<Object, InputLocation> 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
}

Expand Down

0 comments on commit 8bc5d20

Please sign in to comment.