5353import org .cadixdev .lorenz .MappingSet ;
5454import org .cadixdev .lorenz .model .ClassMapping ;
5555import org .cadixdev .lorenz .model .MethodMapping ;
56+ import org .checkerframework .checker .nullness .qual .Nullable ;
5657import org .parchmentmc .feather .io .gson .MDCGsonAdapterFactory ;
5758import org .parchmentmc .feather .io .gson .SimpleVersionAdapter ;
5859import org .parchmentmc .feather .mapping .MappingDataContainer ;
@@ -63,36 +64,21 @@ public final class InspectJarPage extends CodeBookPage {
6364
6465 private final Path inputJar ;
6566 private final List <Path > classpathJars ;
66- private final Path paramMappings ;
67+ private final @ Nullable Path paramMappings ;
6768
6869 @ Inject
6970 public InspectJarPage (
7071 @ InputJar final Path inputJar ,
7172 @ ClasspathJars final List <Path > classpathJars ,
72- @ ParamMappings final Path paramMappings ) {
73+ @ ParamMappings @ Nullable final Path paramMappings ) {
7374 this .inputJar = inputJar ;
7475 this .classpathJars = classpathJars ;
7576 this .paramMappings = paramMappings ;
7677 }
7778
7879 @ Override
7980 public void exec () {
80- final Gson gson = new GsonBuilder ()
81- .registerTypeAdapterFactory (new MDCGsonAdapterFactory ())
82- .registerTypeAdapter (SimpleVersion .class , new SimpleVersionAdapter ())
83- .create ();
84-
85- final MappingDataContainer mappings ;
86- try (final FileSystem fs = FileSystems .newFileSystem (this .paramMappings )) {
87- final Path jsonFile = fs .getPath ("/parchment.json" );
88- try (final BufferedReader reader = Files .newBufferedReader (jsonFile )) {
89- mappings = gson .fromJson (reader , VersionedMappingDataContainer .class );
90- }
91- } catch (final IOException e ) {
92- throw new UnexpectedException ("Failed to read param mappings file" , e );
93- }
94-
95- final MappingSet lorenzMappings = this .toLorenz (mappings );
81+ final MappingSet lorenzMappings = this .loadMappings ();
9682
9783 final HypoContext ctx ;
9884
@@ -119,15 +105,39 @@ public void exec() {
119105 throw new UnexpectedException ("Failed to hydrate data model" , e );
120106 }
121107
122- // Fill in any missing mapping information
123- final MappingSet completedMappings = ChangeChain .create ()
124- .addLink (
125- CopyMappingsDown .createWithoutOverwrite (),
126- CopyLambdaParametersDown .createWithoutOverwrite (),
127- CopyRecordParameters .create ())
128- .applyChain (lorenzMappings , MappingsCompletionManager .create (ctx ));
108+ if (this .paramMappings != null ) {
109+ // Fill in any missing mapping information
110+ final MappingSet completedMappings = ChangeChain .create ()
111+ .addLink (
112+ CopyMappingsDown .createWithoutOverwrite (),
113+ CopyLambdaParametersDown .createWithoutOverwrite (),
114+ CopyRecordParameters .create ())
115+ .applyChain (lorenzMappings , MappingsCompletionManager .create (ctx ));
116+
117+ this .bind (ParamMappings .KEY ).to (completedMappings );
118+ } else {
119+ this .bind (ParamMappings .KEY ).to (null );
120+ }
121+ }
129122
130- this .bind (ParamMappings .KEY ).to (completedMappings );
123+ private MappingSet loadMappings () {
124+ if (this .paramMappings == null ) {
125+ return MappingSet .create ();
126+ }
127+
128+ final Gson gson = new GsonBuilder ()
129+ .registerTypeAdapterFactory (new MDCGsonAdapterFactory ())
130+ .registerTypeAdapter (SimpleVersion .class , new SimpleVersionAdapter ())
131+ .create ();
132+
133+ try (final FileSystem fs = FileSystems .newFileSystem (this .paramMappings )) {
134+ final Path jsonFile = fs .getPath ("/parchment.json" );
135+ try (final BufferedReader reader = Files .newBufferedReader (jsonFile )) {
136+ return this .toLorenz (gson .fromJson (reader , VersionedMappingDataContainer .class ));
137+ }
138+ } catch (final IOException e ) {
139+ throw new UnexpectedException ("Failed to read param mappings file" , e );
140+ }
131141 }
132142
133143 private MappingSet toLorenz (final MappingDataContainer container ) {
0 commit comments