Skip to content

Commit

Permalink
Fix context not being marked dirty properly
Browse files Browse the repository at this point in the history
  • Loading branch information
caseif committed Mar 2, 2016
1 parent 7fb17fc commit 6323460
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/blue/lapis/nocturne/mapping/MappingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,26 @@ public ImmutableMap<String, TopLevelClassMapping> 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.
*
* <p>Note that mappings from the provided set will take precedence over
* existing ones if they are already present.</p>
*
* @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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public ImmutableMap<String, InnerClassMapping> getInnerClassMappings() {
void addFieldMapping(FieldMapping mapping) {
mapping.initialize();
fieldMappings.put(mapping.getObfuscatedName(), mapping);
getContext().setDirty(true);
}

/**
Expand Down Expand Up @@ -142,8 +141,6 @@ public void removeMethodMapping(String methodName) {
void addInnerClassMapping(InnerClassMapping mapping) {
mapping.initialize();
innerClassMappings.put(mapping.getObfuscatedName(), mapping);

getContext().setDirty(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -62,6 +62,10 @@ public MappingContext getContext() {
return parent;
}

public void setContext(MappingContext context) {
this.parent = context;
}

@Override
public String getFullObfuscatedName() {
return getObfuscatedName();
Expand Down

0 comments on commit 6323460

Please sign in to comment.