From 6323460f9fcaff9a8b42360f07a8fb9e271d3039 Mon Sep 17 00:00:00 2001 From: Max Roncace Date: Tue, 1 Mar 2016 22:52:59 -0500 Subject: [PATCH] Fix context not being marked dirty properly --- .../gui/io/mappings/MappingsOpenDialogHelper.java | 2 +- .../java/blue/lapis/nocturne/mapping/MappingContext.java | 9 +++++---- .../blue/lapis/nocturne/mapping/model/ClassMapping.java | 3 --- .../nocturne/mapping/model/TopLevelClassMapping.java | 6 +++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/blue/lapis/nocturne/gui/io/mappings/MappingsOpenDialogHelper.java b/src/main/java/blue/lapis/nocturne/gui/io/mappings/MappingsOpenDialogHelper.java index 4e34c90..24c5f1f 100644 --- a/src/main/java/blue/lapis/nocturne/gui/io/mappings/MappingsOpenDialogHelper.java +++ b/src/main/java/blue/lapis/nocturne/gui/io/mappings/MappingsOpenDialogHelper.java @@ -76,7 +76,7 @@ public static void openMappings() throws IOException { try (MappingsReader reader = MappingReaderType.fromExtensionFilter(fileChooser.getSelectedExtensionFilter()) .constructReader(new BufferedReader(new FileReader(selectedFile)))) { MappingContext context = reader.read(); - Main.getMappingContext().merge(context); + Main.getMappingContext().assimilate(context); MainController.INSTANCE.updateClassViews(); Main.getMappingContext().setDirty(false); } diff --git a/src/main/java/blue/lapis/nocturne/mapping/MappingContext.java b/src/main/java/blue/lapis/nocturne/mapping/MappingContext.java index 877dc1b..a5c294c 100644 --- a/src/main/java/blue/lapis/nocturne/mapping/MappingContext.java +++ b/src/main/java/blue/lapis/nocturne/mapping/MappingContext.java @@ -64,25 +64,26 @@ public ImmutableMap getMappings() { public void addMapping(TopLevelClassMapping mapping, boolean updateClassViews) { mappings.put(mapping.getObfuscatedName(), mapping); mapping.initialize(updateClassViews); - - setDirty(true); } //TODO: probably add a removeMapping method at some point /** - * Merges the given {@link MappingContext} into the current one. + * Merges the given {@link MappingContext} into the current one. All + * mappings contained by the passed context will be mutated to indicate that + * the current {@link MappingContext} is now their parent. * *

Note that mappings from the provided set will take precedence over * existing ones if they are already present.

* * @param context The {@link MappingContext} to merge */ - public void merge(MappingContext context) { + public void assimilate(MappingContext context) { this.mappings.putAll(context.getMappings()); if (!context.getMappings().isEmpty()) { setDirty(true); } + context.getMappings().values().forEach(m -> m.setContext(this)); } /** diff --git a/src/main/java/blue/lapis/nocturne/mapping/model/ClassMapping.java b/src/main/java/blue/lapis/nocturne/mapping/model/ClassMapping.java index b105a53..cd8aeed 100644 --- a/src/main/java/blue/lapis/nocturne/mapping/model/ClassMapping.java +++ b/src/main/java/blue/lapis/nocturne/mapping/model/ClassMapping.java @@ -99,7 +99,6 @@ public ImmutableMap getInnerClassMappings() { void addFieldMapping(FieldMapping mapping) { mapping.initialize(); fieldMappings.put(mapping.getObfuscatedName(), mapping); - getContext().setDirty(true); } /** @@ -142,8 +141,6 @@ public void removeMethodMapping(String methodName) { void addInnerClassMapping(InnerClassMapping mapping) { mapping.initialize(); innerClassMappings.put(mapping.getObfuscatedName(), mapping); - - getContext().setDirty(true); } /** diff --git a/src/main/java/blue/lapis/nocturne/mapping/model/TopLevelClassMapping.java b/src/main/java/blue/lapis/nocturne/mapping/model/TopLevelClassMapping.java index d4f5e32..f0c703a 100644 --- a/src/main/java/blue/lapis/nocturne/mapping/model/TopLevelClassMapping.java +++ b/src/main/java/blue/lapis/nocturne/mapping/model/TopLevelClassMapping.java @@ -38,7 +38,7 @@ */ public class TopLevelClassMapping extends ClassMapping { - private final MappingContext parent; + private MappingContext parent; /** * Constructs a new {@link TopLevelClassMapping} with the given parameters. @@ -62,6 +62,10 @@ public MappingContext getContext() { return parent; } + public void setContext(MappingContext context) { + this.parent = context; + } + @Override public String getFullObfuscatedName() { return getObfuscatedName();