Remove order-sensitivity in MixinConfig

This commit is contained in:
Mumfrey committed 2015-02-22 21:35:22 +00:00
1 parent 67e33532c2
commit 9afaa6ba0f
2 files changed
+49 -10

No files matched your search

@@ -28,6 +28,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -71,6 +72,11 @@ class MixinConfig implements Comparable<MixinConfig> {
*/
private final transient Map<String, List<MixinInfo>> mixinMapping = new HashMap<String, List<MixinInfo>>();
/**
* All mixins loaded by this config
*/
private final transient List<MixinInfo> mixins = new ArrayList<MixinInfo>();
/**
* Configuration priority
*/
@@ -237,6 +243,27 @@ class MixinConfig implements Comparable<MixinConfig> {
List<String> pluginMixins = this.plugin.getMixins();
this.initialiseMixins(pluginMixins, true);
}
for (Iterator<MixinInfo> iter = this.mixins.iterator(); iter.hasNext();) {
MixinInfo mixin = iter.next();
try {
mixin.validate();
} catch (Exception ex) {
this.logger.error(ex.getMessage(), ex);
this.removeMixin(mixin);
iter.remove();
}
}
}
private void removeMixin(MixinInfo remove) {
for (List<MixinInfo> mixinsFor : this.mixinMapping.values()) {
for (Iterator<MixinInfo> iter = mixinsFor.iterator(); iter.hasNext();) {
if (remove == iter.next()) {
iter.remove();
}
}
}
}
private void initialiseMixins(List<String> mixinClasses, boolean suppressPlugin) {
@@ -256,6 +283,7 @@ class MixinConfig implements Comparable<MixinConfig> {
for (String targetClass : mixin.getTargetClasses()) {
this.mixinsFor(targetClass.replace('/', '.')).add(mixin);
}
this.mixins.add(mixin);
}
} catch (Exception ex) {
this.logger.error(ex.getMessage(), ex);
@@ -115,12 +115,6 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
*/
private final List<String> targetClassNames;
/**
* True if the superclass of the mixin is <b>not</b> the direct superclass
* of one or more targets
*/
private final boolean detachedSuper;
/**
* Intrinsic order (for sorting mixins with identical priority)
*/
@@ -145,6 +139,18 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
* Interfaces soft-implemented using {@link Implements}
*/
private final transient List<InterfaceInfo> softImplements = new ArrayList<InterfaceInfo>();
/**
* Initial ClassNode created for mixin validation, not used for actual
* application
*/
private ClassNode validationClassNode;
/**
* True if the superclass of the mixin is <b>not</b> the direct superclass
* of one or more targets
*/
private boolean detachedSuper;
/**
* Internal ctor, called by {@link MixinConfig}
@@ -171,10 +177,15 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
this.priority = this.readPriority(classNode);
this.targetClasses = this.readTargetClasses(classNode, suppressPlugin);
this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
this.detachedSuper = this.validateTargetClasses(classNode);
this.validateMixin(classNode);
this.readImplementations(classNode);
this.prepare(classNode);
this.validationClassNode = classNode;
}
void validate() {
this.detachedSuper = this.validateTargetClasses(this.validationClassNode);
this.validateMixin(this.validationClassNode);
this.readImplementations(this.validationClassNode);
this.prepare(this.validationClassNode);
this.validationClassNode = null;
}
/**