diff --git a/gradle.properties b/gradle.properties index e2f84d7f..030b3362 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,5 +4,5 @@ packaging=jar description=Mixin url=https://www.spongepowered.org organization=SpongePowered -buildVersion=0.5.5 +buildVersion=0.5.6 buildType=SNAPSHOT diff --git a/src/agent/java/org/spongepowered/tools/agent/MixinAgent.java b/src/agent/java/org/spongepowered/tools/agent/MixinAgent.java index 4bbb8434..04bc68e6 100644 --- a/src/agent/java/org/spongepowered/tools/agent/MixinAgent.java +++ b/src/agent/java/org/spongepowered/tools/agent/MixinAgent.java @@ -34,9 +34,9 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.transformer.MixinReloadException; import org.spongepowered.asm.mixin.transformer.MixinTransformer; import org.spongepowered.asm.mixin.transformer.debug.IHotSwap; +import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException; import net.minecraft.launchwrapper.Launch; diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java index 35067eb7..41ed260e 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/AnnotatedMixinElementHandler.java @@ -38,8 +38,8 @@ import org.spongepowered.asm.mixin.injection.struct.MemberInfo; import org.spongepowered.asm.obfuscation.SrgMethod; import org.spongepowered.asm.util.ConstraintParser; import org.spongepowered.asm.util.ConstraintParser.Constraint; -import org.spongepowered.asm.util.ConstraintViolationException; -import org.spongepowered.asm.util.InvalidConstraintException; +import org.spongepowered.asm.util.throwables.ConstraintViolationException; +import org.spongepowered.asm.util.throwables.InvalidConstraintException; import org.spongepowered.tools.MirrorUtils; import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor; import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager; diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationManager.java b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationManager.java index c926fdb9..f4a071e4 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationManager.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/ObfuscationManager.java @@ -36,7 +36,7 @@ import javax.tools.FileObject; import javax.tools.StandardLocation; import org.spongepowered.asm.mixin.injection.struct.MemberInfo; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; import org.spongepowered.asm.obfuscation.SrgField; import org.spongepowered.asm.obfuscation.SrgMethod; import org.spongepowered.asm.util.Constants; diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationEnvironment.java b/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationEnvironment.java index 56a17919..1ec418d2 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationEnvironment.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TargetObfuscationEnvironment.java @@ -42,7 +42,7 @@ import javax.tools.FileObject; import javax.tools.StandardLocation; import org.spongepowered.asm.mixin.injection.struct.MemberInfo; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; import org.spongepowered.asm.obfuscation.SrgMethod; import org.spongepowered.asm.obfuscation.SrgContainer; import org.spongepowered.asm.obfuscation.SrgField; diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java index 22441445..846233b2 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/interfaces/IObfuscationManager.java @@ -25,7 +25,7 @@ package org.spongepowered.tools.obfuscation.interfaces; import org.spongepowered.asm.mixin.injection.struct.MemberInfo; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; import org.spongepowered.asm.obfuscation.SrgMethod; import org.spongepowered.tools.obfuscation.ObfuscationData; import org.spongepowered.tools.obfuscation.TypeHandle; diff --git a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java index c7ccddea..67b8c7c7 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinBootstrap.java @@ -60,7 +60,7 @@ public abstract class MixinBootstrap { /** * Subsystem version */ - public static final String VERSION = "0.5.5"; + public static final String VERSION = "0.5.6"; /** * Blackboard key where the subsystem version will be stored to indicate diff --git a/src/main/java/org/spongepowered/asm/launch/MixinLaunchAgentDefault.java b/src/main/java/org/spongepowered/asm/launch/MixinLaunchAgentDefault.java index 6b542fa5..87da8172 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinLaunchAgentDefault.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinLaunchAgentDefault.java @@ -42,10 +42,13 @@ public class MixinLaunchAgentDefault extends MixinLaunchAgentAbstract { super(uri); } + @SuppressWarnings("deprecation") @Override public void prepare() { String compatibilityLevel = this.attributes.get(MixinLaunchAgentDefault.MFATT_COMPATIBILITY); if (compatibilityLevel != null) { + MixinLaunchAgentAbstract.logger.warn("{} Setting mixin compatibility level via manifest is deprecated, " + + "use 'compatibilityLevel' key in config instead", this.container); MixinTweaker.setCompatibilityLevel(compatibilityLevel); } diff --git a/src/main/java/org/spongepowered/asm/launch/MixinTweaker.java b/src/main/java/org/spongepowered/asm/launch/MixinTweaker.java index dce86e5c..1de3731c 100644 --- a/src/main/java/org/spongepowered/asm/launch/MixinTweaker.java +++ b/src/main/java/org/spongepowered/asm/launch/MixinTweaker.java @@ -37,6 +37,7 @@ import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel; import org.spongepowered.asm.mixin.MixinEnvironment.Phase; +import org.spongepowered.asm.mixin.Mixins; import net.minecraft.launchwrapper.ITweaker; import net.minecraft.launchwrapper.Launch; @@ -213,6 +214,7 @@ public class MixinTweaker implements ITweaker { * * @param level compatibility level as a string */ + @Deprecated static void setCompatibilityLevel(String level) { try { CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase()); @@ -234,13 +236,14 @@ public class MixinTweaker implements ITweaker { static void addConfig(String config) { if (config.endsWith(".json")) { MixinTweaker.logger.debug("Registering mixin config: {}", config); - MixinEnvironment.getDefaultEnvironment().addConfiguration(config); + Mixins.addConfiguration(config); } else if (config.contains(".json@")) { int pos = config.indexOf(".json@"); String phaseName = config.substring(pos + 6); config = config.substring(0, pos + 5); Phase phase = Phase.forName(phaseName); if (phase != null) { + MixinTweaker.logger.warn("Setting config phase via manifest is deprecated: {}. Specify target in config instead", config); MixinTweaker.logger.debug("Registering mixin config: {}", config); MixinEnvironment.getEnvironment(phase).addConfiguration(config); } diff --git a/src/main/java/org/spongepowered/asm/mixin/Final.java b/src/main/java/org/spongepowered/asm/mixin/Final.java index 1b78a4de..73834c13 100644 --- a/src/main/java/org/spongepowered/asm/mixin/Final.java +++ b/src/main/java/org/spongepowered/asm/mixin/Final.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.transformer.InvalidMixinException; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; /** * This annotation has two uses: diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index caf310c0..99ea0dcb 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -51,7 +50,9 @@ import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.mixin.extensibility.IEnvironmentTokenProvider; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.throwables.MixinException; import org.spongepowered.asm.mixin.transformer.MixinTransformer; +import org.spongepowered.asm.obfuscation.RemapperChain; import org.spongepowered.asm.util.ITokenProvider; import org.spongepowered.asm.util.JavaVersion; import org.spongepowered.asm.util.PrettyPrinter; @@ -69,7 +70,7 @@ import net.minecraft.launchwrapper.LaunchClassLoader; * The mixin environment manages global state information for the mixin * subsystem. */ -public class MixinEnvironment implements ITokenProvider { +public final class MixinEnvironment implements ITokenProvider { /** * Environment phase, deliberately not implemented as an enum @@ -440,9 +441,9 @@ public class MixinEnvironment implements ITokenProvider { */ public static enum CompatibilityLevel { - JAVA_6(Opcodes.V1_6, false), + JAVA_6(6, Opcodes.V1_6, false), - JAVA_7(Opcodes.V1_7, false) { + JAVA_7(7, Opcodes.V1_7, false) { @Override boolean isSupported() { @@ -451,7 +452,7 @@ public class MixinEnvironment implements ITokenProvider { }, - JAVA_8(Opcodes.V1_8, true) { + JAVA_8(8, Opcodes.V1_8, true) { @Override boolean isSupported() { @@ -460,15 +461,25 @@ public class MixinEnvironment implements ITokenProvider { }; + private final int ver; + private final int classVersion; private final boolean supportsMethodsInInterfaces; - private CompatibilityLevel(int classVersion, boolean resolveMethodsInInterfaces) { + private CompatibilityLevel maxCompatibleLevel; + + private CompatibilityLevel(int ver, int classVersion, boolean resolveMethodsInInterfaces) { + this.ver = ver; this.classVersion = classVersion; this.supportsMethodsInInterfaces = resolveMethodsInInterfaces; } + @SuppressWarnings("unused") + private void setMaxCompatibleLevel(CompatibilityLevel maxCompatibleLevel) { + this.maxCompatibleLevel = maxCompatibleLevel; + } + boolean isSupported() { return true; } @@ -482,7 +493,22 @@ public class MixinEnvironment implements ITokenProvider { } public boolean isAtLeast(CompatibilityLevel level) { - return this.ordinal() >= level.ordinal(); + return this.ver >= level.ver; + } + + public boolean canElevateTo(CompatibilityLevel level) { + if (level == null || this.maxCompatibleLevel == null) { + return true; + } + return level.ver <= this.maxCompatibleLevel.ver; + } + + public boolean canSupport(CompatibilityLevel level) { + if (level == null) { + return true; + } + + return level.canElevateTo(this); } } @@ -640,10 +666,7 @@ public class MixinEnvironment implements ITokenProvider { */ private final boolean[] options; - /** - * Error handlers for environment - */ - private final Set errorHandlers = new LinkedHashSet(); +// private final Map configs; /** * List of token provider classes @@ -758,7 +781,9 @@ public class MixinEnvironment implements ITokenProvider { * Get mixin configurations from the blackboard * * @return list of registered mixin configs + * @deprecated no replacement */ + @Deprecated public List getMixinConfigs() { List mixinConfigs = Blackboard.>get(this.configsKey); if (mixinConfigs == null) { @@ -773,23 +798,31 @@ public class MixinEnvironment implements ITokenProvider { * * @param config Name of configuration resource to add * @return fluent interface + * @deprecated use Mixins::addConfiguration instead */ + @Deprecated public MixinEnvironment addConfiguration(String config) { + Mixins.addConfiguration(config, this); + return this; + } + + void registerConfig(String config) { List configs = this.getMixinConfigs(); if (!configs.contains(config)) { configs.add(config); } - return this; } - + /** * Add a new error handler class to this environment * * @param handlerName Handler class to add * @return fluent interface + * @deprecated use Mixins::registerErrorHandlerClass */ + @Deprecated public MixinEnvironment registerErrorHandlerClass(String handlerName) { - this.errorHandlers.add(handlerName); + Mixins.registerErrorHandlerClass(handlerName); return this; } @@ -858,9 +891,11 @@ public class MixinEnvironment implements ITokenProvider { * Get all registered error handlers for this environment * * @return set of error handler class names + * @deprecated use Mixins::getErrorHandlerClasses */ + @Deprecated public Set getErrorHandlerClasses() { - return Collections.unmodifiableSet(this.errorHandlers); + return Mixins.getErrorHandlerClasses(); } /** @@ -1160,7 +1195,9 @@ public class MixinEnvironment implements ITokenProvider { * * @param level Level to set, ignored if less than the current level * @throws IllegalArgumentException if the specified level is not supported + * @deprecated set compatibility level in configuration */ + @Deprecated public static void setCompatibilityLevel(CompatibilityLevel level) throws IllegalArgumentException { if (level != MixinEnvironment.compatibility && level.isAtLeast(MixinEnvironment.compatibility)) { if (!level.isSupported()) { diff --git a/src/main/java/org/spongepowered/asm/mixin/Mixins.java b/src/main/java/org/spongepowered/asm/mixin/Mixins.java new file mode 100644 index 00000000..ccedec09 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/Mixins.java @@ -0,0 +1,119 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.asm.mixin; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.spongepowered.asm.launch.Blackboard; +import org.spongepowered.asm.mixin.transformer.Config; + +import net.minecraft.launchwrapper.Launch; + +/** + * Entry point for registering global mixin resources. Compatibility with + * pre-0.6 versions is maintained via the methods on {@link MixinEnvironment} + * delegating to the methods here. + */ +public class Mixins { + + /** + * Logger + */ + private static final Logger logger = LogManager.getLogger("mixin"); + + /** + * Blackboard key storing mixin configs which are pending + */ + private static final String CONFIGS_KEY = Blackboard.Keys.CONFIGS + ".queue"; + + /** + * Error handlers for environment + */ + private static final Set errorHandlers = new LinkedHashSet(); + + /** + * Add a mixin configuration resource + * + * @param configFile path to configuration resource + */ + public static void addConfiguration(String configFile) { + Mixins.addConfiguration(configFile, MixinEnvironment.getDefaultEnvironment()); + } + + @Deprecated + static void addConfiguration(String configFile, MixinEnvironment fallback) { + Config config = null; + + try { + config = Config.create(configFile, fallback); + } catch (Exception ex) { + Mixins.logger.error("Error encountered reading mixin config " + configFile + ": " + ex.getClass().getName() + " " + ex.getMessage(), ex); + } + + if (config != null) { + MixinEnvironment env = config.getEnvironment(); + if (env != null) { + env.registerConfig(configFile); + } + Mixins.getConfigs().add(config); + } + } + + /** + * Get current pending configs set, only configs which have yet to be + * consumed are present in this set + */ + public static Set getConfigs() { + Set mixinConfigs = Blackboard.>get(Mixins.CONFIGS_KEY); + if (mixinConfigs == null) { + mixinConfigs = new LinkedHashSet(); + Launch.blackboard.put(Mixins.CONFIGS_KEY, mixinConfigs); + } + return mixinConfigs; + } + + /** + * Register a gloabl error handler class + * + * @param handlerName Fully qualified class name + */ + public static void registerErrorHandlerClass(String handlerName) { + if (handlerName != null) { + Mixins.errorHandlers.add(handlerName); + } + } + + /** + * Get current error handlers + */ + public static Set getErrorHandlerClasses() { + return Collections.unmodifiableSet(Mixins.errorHandlers); + } + +} diff --git a/src/main/java/org/spongepowered/asm/mixin/Shadow.java b/src/main/java/org/spongepowered/asm/mixin/Shadow.java index d43eac06..79aadd1f 100644 --- a/src/main/java/org/spongepowered/asm/mixin/Shadow.java +++ b/src/main/java/org/spongepowered/asm/mixin/Shadow.java @@ -29,7 +29,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.spongepowered.asm.mixin.transformer.InvalidMixinException; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; /** * Used to indicate a Mixin class member which is acting as a placeholder for a diff --git a/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinErrorHandler.java b/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinErrorHandler.java index fff9bc6c..551b7a7b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinErrorHandler.java +++ b/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinErrorHandler.java @@ -51,8 +51,9 @@ public interface IMixinErrorHandler { WARN(Level.WARN), /** - * Throw a {@link org.spongepowered.asm.mixin.MixinApplyError} to halt - * further processing if possible + * Throw a + * {@link org.spongepowered.asm.mixin.throwables.MixinApplyError} to + * halt further processing if possible */ ERROR(Level.FATAL); diff --git a/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinInfo.java index 58005a42..a5612820 100644 --- a/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/extensibility/IMixinInfo.java @@ -106,11 +106,4 @@ public interface IMixinInfo { */ public abstract Phase getPhase(); - /** - * Get whether this is an interface mixin or not - * - * @return true if this is an interface mixin - */ - public abstract boolean isInterfaceMixin(); - } diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java b/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java index fcbfdfeb..89d682fc 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/Inject.java @@ -32,6 +32,8 @@ import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * Specifies that this mixin method should inject a callback (or diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java b/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java index a37dc776..8bec0619 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java @@ -49,6 +49,7 @@ import org.spongepowered.asm.mixin.injection.points.BeforeStringInvoke; import org.spongepowered.asm.mixin.injection.points.JumpInsnPoint; import org.spongepowered.asm.mixin.injection.points.MethodHead; import org.spongepowered.asm.mixin.injection.struct.InjectionPointData; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.mixin.transformer.MixinTargetContext; import org.spongepowered.asm.util.ASMHelper; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InjectorGroupInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/InjectorGroupInfo.java index a9fdf162..e0442e2c 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectorGroupInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/InjectorGroupInfo.java @@ -34,6 +34,7 @@ import org.apache.logging.log4j.LogManager; import org.spongepowered.asm.lib.tree.AnnotationNode; import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; +import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException; import org.spongepowered.asm.util.ASMHelper; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java index d034db09..3f89f27d 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyArg.java @@ -30,6 +30,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * Specifies that this mixin method should inject an argument modifier to itself diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java index bfa1a6d5..abec6df6 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyConstant.java @@ -30,6 +30,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * Specifies that this mixin method should inject a constant modifier callback diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java index 6dfbafa0..1579b03c 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/ModifyVariable.java @@ -30,6 +30,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * Specifies that this mixin method should inject a variable modifier callback diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java b/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java index 5bd3b6c6..0003b286 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/Redirect.java @@ -30,6 +30,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** *

Specifies that this mixin method should redirect the specified diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java index 7dc861c0..84b22bb7 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java @@ -31,15 +31,15 @@ import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.lib.Type; import org.spongepowered.asm.lib.tree.*; import org.spongepowered.asm.mixin.injection.Coerce; -import org.spongepowered.asm.mixin.injection.InjectionError; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.Surrogate; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.points.BeforeReturn; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.Constants; import org.spongepowered.asm.util.Locals; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java b/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java index 1bc1c694..600faa08 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/code/Injector.java @@ -42,9 +42,9 @@ import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.util.ASMHelper; import com.google.common.base.Joiner; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java index 299c3b5a..c53355f7 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/InvokeInjector.java @@ -34,10 +34,10 @@ import org.spongepowered.asm.lib.tree.MethodInsnNode; import org.spongepowered.asm.lib.tree.VarInsnNode; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * Base class for injectors which inject at method invokes diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java index 6bff31d0..cb093bae 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyArgInjector.java @@ -31,11 +31,11 @@ import org.spongepowered.asm.lib.Type; import org.spongepowered.asm.lib.tree.InsnList; import org.spongepowered.asm.lib.tree.MethodInsnNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; /** * A bytecode injector which allows a single argument of a chosen method call to diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java index 84d487df..dca2f087 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/ModifyConstantInjector.java @@ -30,9 +30,9 @@ import org.spongepowered.asm.lib.tree.AbstractInsnNode; import org.spongepowered.asm.lib.tree.InsnList; import org.spongepowered.asm.lib.tree.VarInsnNode; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.util.ASMHelper; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java index 4882d234..49bab166 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/invoke/RedirectInjector.java @@ -36,11 +36,11 @@ import org.spongepowered.asm.lib.tree.MethodInsnNode; import org.spongepowered.asm.lib.tree.VarInsnNode; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.util.ASMHelper; import com.google.common.base.Joiner; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/InvalidImplicitDiscriminatorException.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/InvalidImplicitDiscriminatorException.java index 8a0a7ac4..4848eaaf 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/modify/InvalidImplicitDiscriminatorException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/InvalidImplicitDiscriminatorException.java @@ -24,7 +24,7 @@ */ package org.spongepowered.asm.mixin.injection.modify; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * Thrown when an implicit discriminator (no args) fails to identify diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java index c0f70853..d6a078a5 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/modify/ModifyVariableInjector.java @@ -35,11 +35,11 @@ import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.lib.tree.VarInsnNode; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.mixin.transformer.MixinTargetContext; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.PrettyPrinter; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java index 83d9f3a7..9bb21819 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionInfo.java @@ -41,19 +41,19 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.InjectionError; import org.spongepowered.asm.mixin.injection.InjectionNodes.InjectionNode; import org.spongepowered.asm.mixin.injection.InjectionPoint; import org.spongepowered.asm.mixin.injection.InjectorGroupInfo; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.code.Injector; -import org.spongepowered.asm.mixin.transformer.InvalidMixinException; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.mixin.transformer.MixinTargetContext; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.util.ASMHelper; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java index 9d1e5078..8566b356 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InjectionPointData.java @@ -31,7 +31,7 @@ import java.util.Map; import org.spongepowered.asm.lib.tree.AnnotationNode; import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.InvalidInjectionPointException; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionPointException; import org.spongepowered.asm.mixin.transformer.MixinTargetContext; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InvalidMemberDescriptorException.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InvalidMemberDescriptorException.java index 899eecb0..15be6346 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/InvalidMemberDescriptorException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/InvalidMemberDescriptorException.java @@ -24,7 +24,7 @@ */ package org.spongepowered.asm.mixin.injection.struct; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * Thrown when a {@link MemberInfo} fails basic syntax validation diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java index 4a2ce096..956f47fc 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/MemberInfo.java @@ -28,8 +28,9 @@ import org.spongepowered.asm.lib.Type; import org.spongepowered.asm.lib.tree.AbstractInsnNode; import org.spongepowered.asm.lib.tree.FieldInsnNode; import org.spongepowered.asm.lib.tree.MethodInsnNode; -import org.spongepowered.asm.mixin.MixinException; -import org.spongepowered.asm.mixin.transformer.IReferenceMapperContext; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; +import org.spongepowered.asm.mixin.throwables.MixinException; import org.spongepowered.asm.obfuscation.SrgMethod; import org.spongepowered.asm.util.SignaturePrinter; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyConstantInjectionInfo.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyConstantInjectionInfo.java index 2000c39f..36e52a5d 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyConstantInjectionInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/ModifyConstantInjectionInfo.java @@ -38,9 +38,9 @@ import org.spongepowered.asm.lib.tree.InsnList; import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.InjectionPoint; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.code.Injector; import org.spongepowered.asm.mixin.injection.invoke.ModifyConstantInjector; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.mixin.transformer.MixinTargetContext; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.Constants; diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionError.java b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionError.java similarity index 96% rename from src/main/java/org/spongepowered/asm/mixin/injection/InjectionError.java rename to src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionError.java index 4c1ea1db..518cf649 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionError.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionError.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.injection; +package org.spongepowered.asm.mixin.injection.throwables; /** * Error to throw for critical injection problems diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionValidationException.java b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionValidationException.java similarity index 93% rename from src/main/java/org/spongepowered/asm/mixin/injection/InjectionValidationException.java rename to src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionValidationException.java index 8efcbd2e..e9b9c9dd 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InjectionValidationException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InjectionValidationException.java @@ -22,7 +22,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.injection; +package org.spongepowered.asm.mixin.injection.throwables; + +import org.spongepowered.asm.mixin.injection.InjectorGroupInfo; /** * Thrown when an injector group fails an injection check diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java similarity index 77% rename from src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java rename to src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java index bd0517ca..630a1f4c 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionException.java @@ -22,11 +22,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.injection; +package org.spongepowered.asm.mixin.injection.throwables; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; -import org.spongepowered.asm.mixin.transformer.InvalidMixinException; -import org.spongepowered.asm.mixin.transformer.MixinTargetContext; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; /** * Thrown when an injector fails a state check, for example if an injector @@ -34,12 +34,12 @@ import org.spongepowered.asm.mixin.transformer.MixinTargetContext; */ public class InvalidInjectionException extends InvalidMixinException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; private final InjectionInfo info; - public InvalidInjectionException(MixinTargetContext mixin, String message) { - super(mixin, message); + public InvalidInjectionException(IReferenceMapperContext context, String message) { + super(context, message); this.info = null; } @@ -48,8 +48,8 @@ public class InvalidInjectionException extends InvalidMixinException { this.info = info; } - public InvalidInjectionException(MixinTargetContext mixin, Throwable cause) { - super(mixin, cause); + public InvalidInjectionException(IReferenceMapperContext context, Throwable cause) { + super(context, cause); this.info = null; } @@ -58,8 +58,8 @@ public class InvalidInjectionException extends InvalidMixinException { this.info = info; } - public InvalidInjectionException(MixinTargetContext mixin, String message, Throwable cause) { - super(mixin, message, cause); + public InvalidInjectionException(IReferenceMapperContext context, String message, Throwable cause) { + super(context, message, cause); this.info = null; } diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionPointException.java b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionPointException.java similarity index 77% rename from src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionPointException.java rename to src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionPointException.java index 23a0b59d..e27ce55f 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/InvalidInjectionPointException.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/throwables/InvalidInjectionPointException.java @@ -22,28 +22,28 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.injection; +package org.spongepowered.asm.mixin.injection.throwables; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; -import org.spongepowered.asm.mixin.transformer.MixinTargetContext; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; /** * Thrown when an injection point cannot be parsed due to invalid data */ public class InvalidInjectionPointException extends InvalidInjectionException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; - public InvalidInjectionPointException(MixinTargetContext mixin, String format, Object... args) { - super(mixin, String.format(format, args)); + public InvalidInjectionPointException(IReferenceMapperContext context, String format, Object... args) { + super(context, String.format(format, args)); } public InvalidInjectionPointException(InjectionInfo info, String format, Object... args) { super(info, String.format(format, args)); } - public InvalidInjectionPointException(MixinTargetContext mixin, Throwable cause, String format, Object... args) { - super(mixin, String.format(format, args), cause); + public InvalidInjectionPointException(IReferenceMapperContext context, Throwable cause, String format, Object... args) { + super(context, String.format(format, args), cause); } public InvalidInjectionPointException(InjectionInfo info, Throwable cause, String format, Object... args) { diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/IReferenceMapperContext.java b/src/main/java/org/spongepowered/asm/mixin/refmap/IReferenceMapperContext.java similarity index 89% rename from src/main/java/org/spongepowered/asm/mixin/transformer/IReferenceMapperContext.java rename to src/main/java/org/spongepowered/asm/mixin/refmap/IReferenceMapperContext.java index 0e54d166..c1656897 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/IReferenceMapperContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/refmap/IReferenceMapperContext.java @@ -22,14 +22,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.refmap; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; /** * Context for performing reference mapping */ public interface IReferenceMapperContext { + + /** + * Get the mixin info + */ + public abstract IMixinInfo getMixin(); /** * Get the internal mixin class name diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ReferenceMapper.java b/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java similarity index 99% rename from src/main/java/org/spongepowered/asm/mixin/injection/struct/ReferenceMapper.java rename to src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java index 65b1485b..81199606 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/ReferenceMapper.java +++ b/src/main/java/org/spongepowered/asm/mixin/refmap/ReferenceMapper.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.injection.struct; +package org.spongepowered.asm.mixin.refmap; import java.io.IOException; import java.io.InputStreamReader; diff --git a/src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java b/src/main/java/org/spongepowered/asm/mixin/throwables/ClassAlreadyLoadedException.java similarity index 94% rename from src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java rename to src/main/java/org/spongepowered/asm/mixin/throwables/ClassAlreadyLoadedException.java index bc0c2b58..375c8185 100644 --- a/src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/ClassAlreadyLoadedException.java @@ -25,10 +25,7 @@ /** * */ -package org.spongepowered.asm.mixin.audit; - -import org.spongepowered.asm.mixin.MixinException; - +package org.spongepowered.asm.mixin.throwables; /** * Exception raised when a class was loaded before mixins were able to be diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinApplyError.java similarity index 97% rename from src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java rename to src/main/java/org/spongepowered/asm/mixin/throwables/MixinApplyError.java index 551700a5..a3fa7bfc 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinApplyError.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinApplyError.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin; +package org.spongepowered.asm.mixin.throwables; /** * Error to throw for required mixins when mixing of the mixin fails diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinException.java b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java similarity index 97% rename from src/main/java/org/spongepowered/asm/mixin/MixinException.java rename to src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java index 059723c0..145f5452 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinException.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinException.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin; +package org.spongepowered.asm.mixin.throwables; /** * Base class for all mixin processor exceptions diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinPrepareError.java b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinPrepareError.java similarity index 97% rename from src/main/java/org/spongepowered/asm/mixin/MixinPrepareError.java rename to src/main/java/org/spongepowered/asm/mixin/throwables/MixinPrepareError.java index bcc7e3db..f5e64c05 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinPrepareError.java +++ b/src/main/java/org/spongepowered/asm/mixin/throwables/MixinPrepareError.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin; +package org.spongepowered.asm.mixin.throwables; /** * Error to throw for required configs when initialising of the config fails diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java index 98ce2cd9..500676f1 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/ClassInfo.java @@ -47,6 +47,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.transformer.ClassInfo.Member.Type; +import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinClassNode; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/Config.java b/src/main/java/org/spongepowered/asm/mixin/transformer/Config.java new file mode 100644 index 00000000..0f173282 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/Config.java @@ -0,0 +1,117 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.asm.mixin.transformer; + +import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.asm.mixin.extensibility.IMixinConfig; + +/** + * Handle for marshalling mixin configs outside of the transformer package + */ +public class Config { + + /** + * Config name, used as identity for the purposes of {@link #equals} + */ + private final String name; + + /** + * Config + */ + private final MixinConfig config; + + public Config(MixinConfig config) { + this.name = config.getName(); + this.config = config; + } + + /** + * Access inner config + */ + MixinConfig get() { + return this.config; + } + + /** + * Get API-level config view + */ + public IMixinConfig getConfig() { + return this.config; + } + + /** + * Get environment for the config + */ + public MixinEnvironment getEnvironment() { + return this.config.getEnvironment(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.config.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof Config && this.name.equals(((Config)obj).name); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.name.hashCode(); + } + + /** + * Factory method, create a config from the specified config file and fail + * over to the specified environment if no selector is present in the config + * + * @param configFile config resource + * @param outer failover environment + * @return new config or null if invalid config version + */ + @Deprecated + public static Config create(String configFile, MixinEnvironment outer) { + return MixinConfig.create(configFile, outer); + } + + /** + * Factory method, create a config from the specified config resource + * + * @param configFile config resource + * @return new config or null if invalid config version + */ + public static Config create(String configFile) { + return MixinConfig.create(configFile, MixinEnvironment.getDefaultEnvironment()); + } +} diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java index 0da51a79..ce7360e8 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceInfo.java @@ -33,6 +33,7 @@ import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.util.ASMHelper; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MemberRef.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MemberRef.java index fc0bf2d5..dc438dde 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MemberRef.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MemberRef.java @@ -27,6 +27,7 @@ package org.spongepowered.asm.mixin.transformer; import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.lib.tree.FieldInsnNode; import org.spongepowered.asm.lib.tree.MethodInsnNode; +import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError; import org.spongepowered.asm.util.ASMHelper; /** diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinApplicator.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java similarity index 93% rename from src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinApplicator.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java index 087fbf0c..3f422627 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinApplicator.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorInterface.java @@ -28,22 +28,23 @@ import java.util.Map.Entry; import org.spongepowered.asm.lib.tree.FieldNode; import org.spongepowered.asm.lib.tree.MethodNode; -import org.spongepowered.asm.mixin.injection.InvalidInjectionException; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; +import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidInterfaceMixinException; /** * Applicator for interface mixins, mainly just disables things which aren't * supported for interface mixins */ -public class InterfaceMixinApplicator extends MixinApplicator { +public class MixinApplicatorInterface extends MixinApplicatorStandard { /** * ctor * * @param context applier context */ - InterfaceMixinApplicator(TargetClassContext context) { + MixinApplicatorInterface(TargetClassContext context) { super(context); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicator.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java similarity index 96% rename from src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicator.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java index 0eb44d32..267670c7 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicator.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinApplicatorStandard.java @@ -55,17 +55,18 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.Constants; import org.spongepowered.asm.util.ConstraintParser; import org.spongepowered.asm.util.ConstraintParser.Constraint; -import org.spongepowered.asm.util.ConstraintViolationException; -import org.spongepowered.asm.util.InvalidConstraintException; +import org.spongepowered.asm.util.throwables.ConstraintViolationException; +import org.spongepowered.asm.util.throwables.InvalidConstraintException; /** * Applies mixins to a target class */ -public class MixinApplicator { +public class MixinApplicatorStandard { /** * Passes the mixin applicator applies to each mixin @@ -193,7 +194,7 @@ public class MixinApplicator { */ protected final ClassNode targetClass; - MixinApplicator(TargetClassContext context) { + MixinApplicatorStandard(TargetClassContext context) { this.context = context; this.targetName = context.getClassName(); this.targetClass = context.getClassNode(); @@ -323,7 +324,7 @@ public class MixinApplicator { this.mergeAnnotations(shadow, target); // Strip the FINAL flag from @Mutable non-private fields - if (entry.getValue().isDecoratedMutable() && !MixinApplicator.hasFlag(target, Opcodes.ACC_PRIVATE)) { + if (entry.getValue().isDecoratedMutable() && !MixinApplicatorStandard.hasFlag(target, Opcodes.ACC_PRIVATE)) { target.access &= ~Opcodes.ACC_FINAL; } } @@ -364,9 +365,9 @@ public class MixinApplicator { this.checkConstraints(mixin, overwrite); } - if (MixinApplicator.hasFlag(mixinMethod, Opcodes.ACC_STATIC) - && !MixinApplicator.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE) - && !MixinApplicator.hasFlag(mixinMethod, Opcodes.ACC_SYNTHETIC) + if (MixinApplicatorStandard.hasFlag(mixinMethod, Opcodes.ACC_STATIC) + && !MixinApplicatorStandard.hasFlag(mixinMethod, Opcodes.ACC_PRIVATE) + && !MixinApplicatorStandard.hasFlag(mixinMethod, Opcodes.ACC_SYNTHETIC) && !isOverwrite) { throw new InvalidMixinException(mixin, String.format("Mixin %s contains non-private static method %s%s", mixin, mixinMethod.name, mixinMethod.desc)); @@ -440,8 +441,8 @@ public class MixinApplicator { throw new ClassFormatError("Invalid @MixinMerged annotation found in" + mixin + " at " + method.name + " in " + this.targetClass.name); } - if (MixinApplicator.hasFlag(target, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE) - && MixinApplicator.hasFlag(method, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE)) { + if (MixinApplicatorStandard.hasFlag(target, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE) + && MixinApplicatorStandard.hasFlag(method, Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE)) { if (mixin.getEnvironment().getOption(Option.DEBUG_VERBOSE)) { this.logger.warn("Synthetic bridge method clash for {} in {}", method.name, mixin); } @@ -486,7 +487,7 @@ public class MixinApplicator { } String methodName = method.name + method.desc; - if (MixinApplicator.hasFlag(method, Opcodes.ACC_STATIC)) { + if (MixinApplicatorStandard.hasFlag(method, Opcodes.ACC_STATIC)) { throw new InvalidMixinException(mixin, "@Intrinsic method cannot be static, found " + methodName + " in " + mixin); } @@ -544,7 +545,7 @@ public class MixinApplicator { MethodNode target = this.findTargetMethod(method); if (target != null) { - AbstractInsnNode returnNode = MixinApplicator.findInsn(target, Opcodes.RETURN); + AbstractInsnNode returnNode = MixinApplicatorStandard.findInsn(target, Opcodes.RETURN); if (returnNode != null) { Iterator injectIter = method.instructions.iterator(); @@ -603,7 +604,7 @@ public class MixinApplicator { MethodNode ctor = null; for (MethodNode mixinMethod : mixin.getMethods()) { - if (Constants.CTOR.equals(mixinMethod.name) && MixinApplicator.hasLineNumbers(mixinMethod)) { + if (Constants.CTOR.equals(mixinMethod.name) && MixinApplicatorStandard.hasLineNumbers(mixinMethod)) { if (ctor == null) { ctor = mixinMethod; } else { @@ -710,7 +711,7 @@ public class MixinApplicator { trimAtOpcode = -1; continue; } - for (int ivalidOp : MixinApplicator.INITIALISER_OPCODE_BLACKLIST) { + for (int ivalidOp : MixinApplicatorStandard.INITIALISER_OPCODE_BLACKLIST) { if (opcode == ivalidOp) { // At the moment I don't handle any transient locals because I haven't seen any in the wild, but let's avoid writing // code which will likely break things and fix it if a real test case ever appears diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassNode.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassNode.java deleted file mode 100644 index b54c68c8..00000000 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinClassNode.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of Mixin, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.asm.mixin.transformer; - -import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.lib.tree.ClassNode; - -/** - * ClassNode for a MixinInfo - */ -public class MixinClassNode extends ClassNode { - - private final MixinInfo mixin; - - public MixinClassNode(MixinInfo mixin) { - this(Opcodes.ASM5, mixin); - } - - public MixinClassNode(int api, MixinInfo mixin) { - super(api); - this.mixin = mixin; - } - - public MixinInfo getMixin() { - return this.mixin; - } -} diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java index 2f1e53db..67bc5f98 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinConfig.java @@ -34,6 +34,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -41,12 +43,15 @@ import org.apache.logging.log4j.Logger; import org.spongepowered.asm.launch.MixinInitialisationError; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.mixin.MixinEnvironment; +import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel; import org.spongepowered.asm.mixin.MixinEnvironment.Option; +import org.spongepowered.asm.mixin.MixinEnvironment.Phase; import org.spongepowered.asm.mixin.extensibility.IMixinConfig; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; import org.spongepowered.asm.mixin.transformer.debug.IHotSwap; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; import org.spongepowered.asm.util.VersionNumber; import com.google.gson.Gson; @@ -82,7 +87,7 @@ class MixinConfig implements Comparable, IMixinConfig { * Global list of mixin classes, so we can skip any duplicates */ private static final Set globalMixinList = new HashSet(); - + /** * Log even more things */ @@ -107,13 +112,30 @@ class MixinConfig implements Comparable, IMixinConfig { * Synthetic inner classes for mixins in this set */ private final transient Set syntheticInnerClasses = new HashSet(); + + /** + * Marshal + */ + private transient Config handle; + + /** + * Target selector, eg. @env(DEFAULT) + */ + @SerializedName("target") + private String selector; /** * Minimum version of the mixin subsystem required to correctly apply mixins * in this configuration. */ @SerializedName("minVersion") - private String version; + private String version; + + /** + * Minimum compatibility level required for mixins in this set + */ + @SerializedName("compatibilityLevel") + private String compatibility; /** * Determines whether failures in this mixin config are considered terminal @@ -187,6 +209,11 @@ class MixinConfig implements Comparable, IMixinConfig { * Intrinsic order (for sorting configurations with identical priority) */ private final transient int order = MixinConfig.configOrder++; + +// /** +// * Phase selector +// */ +// private transient List selectors; /** * Parent environment @@ -223,7 +250,7 @@ class MixinConfig implements Comparable, IMixinConfig { /** * Keep track of initialisation state */ - private transient boolean initialised = false; + private transient boolean prepared = false; /** * Spawn via GSON, no public ctor for you @@ -233,18 +260,74 @@ class MixinConfig implements Comparable, IMixinConfig { /** * Called immediately after deserialisation * - * @param env Parent environment * @param name Mixin config name + * @param fallbackEnvironment Fallback environment if not specified in + * config * @return true if the config was successfully initialised and should be * returned, or false if initialisation failed and the config should * be discarded */ - private boolean onLoad(MixinEnvironment env, String name) { - this.env = env; + private boolean onLoad(String name, MixinEnvironment fallbackEnvironment) { this.name = name; + this.env = this.parseSelector(this.selector, fallbackEnvironment); + this.initCompatibilityLevel(); + return this.checkVersion(); + } + + @SuppressWarnings("deprecation") + private void initCompatibilityLevel() { + if (this.compatibility == null) { + return; + } + CompatibilityLevel level = CompatibilityLevel.valueOf(this.compatibility.trim().toUpperCase()); + CompatibilityLevel current = MixinEnvironment.getCompatibilityLevel(); + + if (level == current) { + return; + } + + // Current level is higher than required but too new to support it + if (current.isAtLeast(level)) { + if (!current.canSupport(level)) { + throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is too old"); + } + } + + // Current level is lower than required but current level prohibits elevation + if (!current.canElevateTo(level)) { + throw new MixinInitialisationError("Mixin config " + this.name + " requires compatibility level " + level + " which is prohibited by " + + current); + } + + MixinEnvironment.setCompatibilityLevel(level); + } + + // AMS - temp + private MixinEnvironment parseSelector(String target, MixinEnvironment fallbackEnvironment) { + if (target != null) { + String[] selectors = target.split("[&\\| ]"); + for (String selector : selectors) { + selector = selector.trim(); + Pattern environmentSelector = Pattern.compile("^@env(?:ironment)?\\(([A-Z]+)\\)$"); + Matcher environmentSelectorMatcher = environmentSelector.matcher(selector); + if (environmentSelectorMatcher.matches()) { + // only parse first env selector + return MixinEnvironment.getEnvironment(Phase.forName(environmentSelectorMatcher.group(1))); + } + } + + Phase phase = Phase.forName(target); + if (phase != null) { + return MixinEnvironment.getEnvironment(phase); + } + } + return fallbackEnvironment; + } + + private boolean checkVersion() throws MixinInitialisationError { VersionNumber minVersion = VersionNumber.parse(this.version); - VersionNumber curVersion = VersionNumber.parse(env.getVersion()); + VersionNumber curVersion = VersionNumber.parse(this.env.getVersion()); if (minVersion.compareTo(curVersion) > 0) { this.logger.warn("Mixin config {} requires mixin subsystem version {} but {} was found. The mixin config will not be applied.", this.name, minVersion, curVersion); @@ -256,6 +339,13 @@ class MixinConfig implements Comparable, IMixinConfig { return false; } + return true; + } + + /** + * Initialise the config once it's selected + */ + void onSelect() { if (this.pluginClassName != null) { try { Class pluginClass = Class.forName(this.pluginClassName, true, Launch.classLoader); @@ -285,9 +375,7 @@ class MixinConfig implements Comparable, IMixinConfig { } this.refMapper = ReferenceMapper.read(this.refMapperConfig); - this.verboseLogging |= env.getOption(Option.DEBUG_VERBOSE); - - return true; + this.verboseLogging |= this.env.getOption(Option.DEBUG_VERBOSE); } /** @@ -303,20 +391,20 @@ class MixinConfig implements Comparable, IMixinConfig { * either the hasMixinsFor() or getMixinsFor() methods. *

*/ - void initialise(IHotSwap hotSwapper) { - if (this.initialised) { + void prepare(IHotSwap hotSwapper) { + if (this.prepared) { return; } - this.initialised = true; + this.prepared = true; - this.initialiseMixins(this.mixinClasses, false, hotSwapper); + this.prepareMixins(this.mixinClasses, false, hotSwapper); switch (this.env.getSide()) { case CLIENT: - this.initialiseMixins(this.mixinClassesClient, false, hotSwapper); + this.prepareMixins(this.mixinClassesClient, false, hotSwapper); break; case SERVER: - this.initialiseMixins(this.mixinClassesServer, false, hotSwapper); + this.prepareMixins(this.mixinClassesServer, false, hotSwapper); break; case UNKNOWN: //$FALL-THROUGH$ @@ -329,7 +417,7 @@ class MixinConfig implements Comparable, IMixinConfig { void postInitialise(IHotSwap hotSwapper) { if (this.plugin != null) { List pluginMixins = this.plugin.getMixins(); - this.initialiseMixins(pluginMixins, true, hotSwapper); + this.prepareMixins(pluginMixins, true, hotSwapper); } for (Iterator iter = this.mixins.iterator(); iter.hasNext();) { @@ -361,7 +449,7 @@ class MixinConfig implements Comparable, IMixinConfig { } } - private void initialiseMixins(List mixinClasses, boolean suppressPlugin, IHotSwap hotSwapper) { + private void prepareMixins(List mixinClasses, boolean suppressPlugin, IHotSwap hotSwapper) { if (mixinClasses == null) { return; } @@ -407,6 +495,16 @@ class MixinConfig implements Comparable, IMixinConfig { this.unhandledTargets.remove(transformedName); } + /** + * Get marshalling handle + */ + public Config getHandle() { + if (this.handle == null) { + this.handle = new Config(this); + } + return this.handle; + } + /* (non-Javadoc) * @see org.spongepowered.asm.mixin.transformer.IMixinConfig#isRequired() */ @@ -475,6 +573,11 @@ class MixinConfig implements Comparable, IMixinConfig { String defaultGroup = this.injectorOptions.defaultGroup; return defaultGroup != null && !defaultGroup.isEmpty() ? defaultGroup : "default"; } + + // AMS - temp + public boolean select(MixinEnvironment environment) { + return this.env == environment; + } /** * Get the number of mixins in this config, for debug logging @@ -652,19 +755,19 @@ class MixinConfig implements Comparable, IMixinConfig { * specified configFile, which must be accessible on the classpath * * @param configFile - * @param env parent environment + * @param outer fallback environment * @return */ - static MixinConfig create(String configFile, MixinEnvironment env) { + static Config create(String configFile, MixinEnvironment outer) { try { MixinConfig config = new Gson().fromJson(new InputStreamReader(Launch.classLoader.getResourceAsStream(configFile)), MixinConfig.class); - if (config.onLoad(env, configFile)) { - return config; + if (config.onLoad(configFile, outer)) { + return config.getHandle(); } return null; } catch (Exception ex) { ex.printStackTrace(); - throw new IllegalArgumentException(String.format("The specified configuration file '%s' was invalid or could not be read", configFile)); + throw new IllegalArgumentException(String.format("The specified resource '%s' was invalid or could not be read", configFile), ex); } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java index f052e937..364adbbe 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinInfo.java @@ -27,6 +27,7 @@ package org.spongepowered.asm.mixin.transformer; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -37,7 +38,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.lib.ClassReader; import org.spongepowered.asm.lib.Opcodes; -import org.spongepowered.asm.lib.Type; import org.spongepowered.asm.lib.tree.AnnotationNode; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.lib.tree.FieldNode; @@ -48,12 +48,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel; import org.spongepowered.asm.mixin.MixinEnvironment.Phase; -import org.spongepowered.asm.mixin.MixinException; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.extensibility.IMixinConfig; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; +import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException; import org.spongepowered.asm.util.ASMHelper; import com.google.common.base.Function; @@ -67,60 +68,105 @@ import net.minecraft.launchwrapper.LaunchClassLoader; * Runtime information bundle about a mixin */ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { + + /** + * ClassNode for a MixinInfo + */ + public class MixinClassNode extends ClassNode { + + public MixinClassNode(MixinInfo mixin) { + this(Opcodes.ASM5); + } + + public MixinClassNode(int api) { + super(api); + } + + public MixinInfo getMixin() { + return MixinInfo.this; + } + + } /** - * State that can be reloaded. + * Mixin preparation/parse/validation state */ - private class ValidationState { + class State { /** * Mixin bytes (read once, generate tree on demand) */ - byte[] mixinBytes; - - /** - * All interfaces implemented by this mixin, including soft - * implementations - */ - final Set interfaces = new HashSet(); - - /** - * Interfaces soft-implemented using {@link Implements} - */ - final List softImplements = new ArrayList(); - - /** - * Synthetic inner classes - */ - final Set syntheticInnerClasses = new HashSet(); + private byte[] mixinBytes; /** * Mixin ClassInfo */ - final ClassInfo classInfo; + private final ClassInfo classInfo; /** * True if the superclass of the mixin is not the direct * superclass of one or more targets */ - boolean detachedSuper; + private boolean detachedSuper; + + /** + * All interfaces implemented by this mixin, including soft + * implementations + */ + protected final Set interfaces = new HashSet(); + + /** + * Interfaces soft-implemented using {@link Implements} + */ + protected final List softImplements = new ArrayList(); + + /** + * Synthetic inner classes + */ + protected final Set syntheticInnerClasses = new HashSet(); /** * Initial ClassNode created for mixin validation, not used for actual * application */ - ClassNode classNode; + protected ClassNode classNode; - ValidationState(byte[] mixinBytes, ClassInfo classInfo) { - this.mixinBytes = mixinBytes; - this.classNode = this.getClassNode(0); - this.classInfo = classInfo; + State(byte[] mixinBytes) { + this(mixinBytes, null); } - ValidationState(byte[] mixinBytes) { + State(byte[] mixinBytes, ClassInfo classInfo) { this.mixinBytes = mixinBytes; - this.classNode = this.getClassNode(0); - this.classInfo = ClassInfo.fromClassNode(this.classNode); + this.classNode = this.createClassNode(0); + this.classInfo = classInfo != null ? classInfo : ClassInfo.fromClassNode(this.classNode); + } + + ClassInfo getClassInfo() { + return this.classInfo; + } + + byte[] getClassBytes() { + return this.mixinBytes; + } + + ClassNode getClassNode() { + return this.classNode; + } + + boolean isDetachedSuper() { + return this.detachedSuper; + } + + List getSoftImplements() { + return this.softImplements; + } + + Set getSyntheticInnerClasses() { + return this.syntheticInnerClasses; + } + + Set getInterfaces() { + return this.interfaces; } /** @@ -129,23 +175,147 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * @param flags Flags passed into classReader * @return Tree representing the bytecode */ - ClassNode getClassNode(int flags) { + ClassNode createClassNode(int flags) { MixinClassNode classNode = new MixinClassNode(MixinInfo.this); ClassReader classReader = new ClassReader(this.mixinBytes); classReader.accept(classNode, flags); return classNode; } + + /** + * Performs pre-flight checks on the mixin + * + * @param type Mixin Type + * @param targetClasses Mixin's target classes + */ + void validate(SubType type, List targetClasses) { + type.validate(this, targetClasses); + + this.detachedSuper = type.isDetachedSuper(); + + // Pre-flight checks + this.validateInner(); + this.validateClassVersion(); + this.validateRemappables(targetClasses); + + // Read information from the mixin + this.readImplementations(); + this.readInnerClasses(); + + // Takeoff validation + this.validateChanges(type, targetClasses); + + // Null out the validation classnode + this.classNode = null; + } + + private void validateInner() { + // isInner (shouldn't) return true for static inner classes + if (!this.classInfo.isProbablyStatic()) { + throw new InvalidMixinException(MixinInfo.this, "Inner class mixin must be declared static"); + } + } + + private void validateClassVersion() { + if (this.classNode.version > MixinEnvironment.getCompatibilityLevel().classVersion()) { + String helpText = "."; + for (CompatibilityLevel level : CompatibilityLevel.values()) { + if (level.classVersion() >= this.classNode.version) { + helpText = String.format(". Mixin requires compatibility level %s or above.", level.name()); + } + } + + throw new InvalidMixinException(MixinInfo.this, "Unsupported mixin class version " + this.classNode.version + helpText); + } + } + + private void validateRemappables(List targetClasses) { + // Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names + if (targetClasses.size() > 1) { + for (FieldNode field : this.classNode.fields) { + this.validateRemappable(Shadow.class, field.name, ASMHelper.getVisibleAnnotation(field, Shadow.class)); + } + + for (MethodNode method : this.classNode.methods) { + this.validateRemappable(Shadow.class, method.name, ASMHelper.getVisibleAnnotation(method, Shadow.class)); + AnnotationNode overwrite = ASMHelper.getVisibleAnnotation(method, Overwrite.class); + if (overwrite != null && ((method.access & Opcodes.ACC_STATIC) == 0 || (method.access & Opcodes.ACC_PUBLIC) == 0)) { + throw new InvalidMixinException(MixinInfo.this, "Found @Overwrite annotation on " + method.name + " in " + this); + } + } + } + } + + private void validateRemappable(Class annotationClass, String name, AnnotationNode annotation) { + if (annotation != null && ASMHelper.getAnnotationValue(annotation, "remap", Boolean.TRUE)) { + throw new InvalidMixinException(MixinInfo.this, "Found a remappable @" + annotationClass.getSimpleName() + " annotation on " + name + + " in " + this); + } + } + + /** + * Read and process any {@link Implements} annotations on the mixin + */ + void readImplementations() { + this.interfaces.addAll(this.classNode.interfaces); + + AnnotationNode implementsAnnotation = ASMHelper.getInvisibleAnnotation(this.classNode, Implements.class); + if (implementsAnnotation == null) { + return; + } + + List interfaces = ASMHelper.getAnnotationValue(implementsAnnotation); + if (interfaces == null) { + return; + } + + for (AnnotationNode interfaceNode : interfaces) { + InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(MixinInfo.this, interfaceNode); + this.softImplements.add(interfaceInfo); + this.interfaces.add(interfaceInfo.getInternalName()); + // only add interface if its initial initialisation + if (!(this instanceof Reloaded)) { + this.classInfo.addInterface(interfaceInfo.getInternalName()); + } + } + } + + /** + * Read inner class definitions for the class and locate any synthetic + * inner classes so that we can add them to the passthrough set in our + * parent config. + */ + void readInnerClasses() { + for (InnerClassNode inner : this.classNode.innerClasses) { + ClassInfo innerClass = ClassInfo.forName(inner.name); + if (innerClass.isSynthetic() && innerClass.isProbablyStatic()) { + if ((inner.outerName != null && inner.outerName.equals(this.classInfo.getName())) + || inner.name.startsWith(this.classNode.name + "$")) { + this.syntheticInnerClasses.add(inner.name); + } else { + throw new InvalidMixinException(MixinInfo.this, "Unhandled synthetic inner class found: " + inner.name); + } + } + } + } + + protected void validateChanges(SubType type, List targetClasses) { + type.createPreProcessor(this.classNode).prepare(); + } } - private class ReloadedState extends ValidationState { + /** + * State use when hotswap reloading a mixin + */ + class Reloaded extends State { /** * The previous validation state to compare the changes to */ - private final ValidationState previous; + private final State previous; - ReloadedState(ValidationState previous, byte[] mixinBytes) { - super(mixinBytes, previous.classInfo); + Reloaded(State previous, byte[] mixinBytes) { + super(mixinBytes, previous.getClassInfo()); this.previous = previous; } @@ -153,7 +323,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * Validates that the changes are allowed to be made, these restrictions * only exits while reloading mixins. */ - void validateChanges() { + @Override + protected void validateChanges(SubType type, List targetClasses) { if (!this.syntheticInnerClasses.equals(this.previous.syntheticInnerClasses)) { throw new MixinReloadException(MixinInfo.this, "Cannot change inner classes"); } @@ -164,7 +335,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { throw new MixinReloadException(MixinInfo.this, "Cannot change soft interfaces"); } List targets = MixinInfo.this.readTargetClasses(this.classNode, true); - if (!new HashSet(targets).equals(new HashSet(MixinInfo.this.getTargets0()))) { + if (!new HashSet(targets).equals(new HashSet(targetClasses))) { throw new MixinReloadException(MixinInfo.this, "Cannot change target classes"); } int priority = MixinInfo.this.readPriority(this.classNode); @@ -173,7 +344,142 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { } } } + + /** + * Mixin sub-type, eg. standard mixin, interface mixin, accessor + */ + abstract static class SubType { + + /** + * Outer + */ + protected final MixinInfo mixin; + + /** + * String representation of annotation type, for use in messages + */ + protected final String annotationType; + + /** + * Target of this mixin subtype must be an interface, false for a class + */ + protected final boolean targetMustBeInterface; + + /** + * Detached super, parsed out during validation + */ + protected boolean detached; + + SubType(MixinInfo info, String annotationType, boolean targetMustBeInterface) { + this.mixin = info; + this.annotationType = annotationType; + this.targetMustBeInterface = targetMustBeInterface; + } + + /** + * Get whether this mixin is detached super, must call {@link #validate} + * first + * + * @return + */ + boolean isDetachedSuper() { + return this.detached; + } + + /** + * Validate a single target before adding + * + * @param targetName + * @param targetInfo + */ + void validateTarget(String targetName, ClassInfo targetInfo) { + boolean targetIsInterface = targetInfo.isInterface(); + if (targetIsInterface != this.targetMustBeInterface) { + String not = targetIsInterface ? "" : "not "; + throw new InvalidMixinException(this.mixin, this.annotationType + " target type mismatch: " + targetName + + " is " + not + "an interface in " + this); + } + } + + abstract void validate(State state, List targetClasses); + abstract MixinPreProcessorStandard createPreProcessor(ClassNode classNode); + + /** + * A standard mixin + */ + static class Standard extends SubType { + + Standard(MixinInfo info) { + super(info, "@Mixin", false); + } + + @Override + void validate(State state, List targetClasses) { + ClassNode classNode = state.getClassNode(); + + for (ClassInfo targetClass : targetClasses) { + if (classNode.superName.equals(targetClass.getSuperName())) { + continue; + } + + if (!targetClass.hasSuperClass(classNode.superName, ClassInfo.Traversal.SUPER)) { + ClassInfo superClass = ClassInfo.forName(classNode.superName); + if (superClass.isMixin()) { + // If superclass is a mixin, check for hierarchy derp + for (ClassInfo superTarget : superClass.getTargets()) { + if (targetClasses.contains(superTarget)) { + throw new InvalidMixinException(this.mixin, "Illegal hierarchy detected. Derived mixin " + this + + " targets the same class " + superTarget.getClassName() + " as its superclass " + + superClass.getClassName()); + } + } + } + + throw new InvalidMixinException(this.mixin, "Super class '" + classNode.superName.replace('/', '.') + "' of " + + this.mixin.getName() + " was not found in the hierarchy of target class '" + targetClass + "'"); + } + + this.detached = true; + } + } + + @Override + MixinPreProcessorStandard createPreProcessor(ClassNode classNode) { + return new MixinPreProcessorStandard(this.mixin, classNode); + } + } + + /** + * An interface mixin + */ + static class Interface extends SubType { + + Interface(MixinInfo info) { + super(info, "@Mixin", true); + } + + @Override + void validate(State state, List targetClasses) { + if (!MixinEnvironment.getCompatibilityLevel().supportsMethodsInInterfaces()) { + throw new InvalidMixinException(this.mixin, "Interface mixin not supported in current enviromnment"); + } + + ClassNode classNode = state.getClassNode(); + + if (!"java/lang/Object".equals(classNode.superName)) { + throw new InvalidMixinException(this.mixin, "Super class of " + this + " is invalid, found " + + classNode.superName.replace('/', '.')); + } + } + + @Override + MixinPreProcessorStandard createPreProcessor(ClassNode classNode) { + return new MixinPreProcessorInterface(this.mixin, classNode); + } + } + } + /** * Global order of mixin infos, used to determine ordering between mixins * with equivalent priority @@ -238,19 +544,19 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { private final transient ClassInfo info; /** - * True if this is an interface mixin rather than a regular mixin + * Mixin type */ - private final transient boolean isInterfaceMixin; + private final transient SubType type; /** * Holds state that currently is not fully initialised or validated */ - private transient ValidationState uninitialisedState; + private transient State pendingState; /** * Holds the current validated state */ - private transient ValidationState validationState; + private transient State state; /** * Internal ctor, called by {@link MixinConfig} @@ -269,41 +575,50 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { this.plugin = plugin; this.phase = MixinEnvironment.getCurrentEnvironment().getPhase(); - ClassNode classNode = null; - // Read the class bytes and transform try { - byte[] mixinBytes = this.loadMixinClass(this.className, runTransformers); - this.uninitialisedState = new ValidationState(mixinBytes); - this.info = this.uninitialisedState.classInfo; - classNode = this.uninitialisedState.getClassNode(0); - this.isInterfaceMixin = this.info.isInterface(); + this.pendingState = new State(this.loadMixinClass(this.className, runTransformers)); + this.info = this.pendingState.getClassInfo(); + this.type = this.initType(); + } catch (Exception ex) { + throw new InvalidMixinException(this, ex); + } + + // Read the class bytes and transform + try { + this.priority = this.readPriority(this.pendingState.getClassNode()); + this.targetClasses = this.readTargetClasses(this.pendingState.getClassNode(), suppressPlugin); + this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction())); } catch (Exception ex) { throw new InvalidMixinException(this, ex); } - - this.priority = this.readPriority(classNode); - this.targetClasses = this.readTargetClasses(classNode, suppressPlugin); - this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction())); } + /** + * Initialise the mixin subtype handler + * + * @return subtype + */ + private SubType initType() { + if (this.info.isInterface()) { + return new SubType.Interface(this); + } + return new SubType.Standard(this); + } + + /** + * Run validation pass + */ void validate() { + if (this.pendingState == null) { + throw new IllegalStateException("No pending validation state for " + this); + } + try { - ClassNode classNode = this.uninitialisedState.classNode; - this.uninitialisedState.detachedSuper = this.validateTargetClasses(classNode); - this.validateMixin(this.uninitialisedState); - this.readImplementations(this.uninitialisedState); - this.readInnerClasses(this.uninitialisedState); - if (this.uninitialisedState instanceof ReloadedState) { - ((ReloadedState) this.uninitialisedState).validateChanges(); - } else { - this.createPreProcessor(classNode).prepare(); - } - this.uninitialisedState.classNode = null; - // the state is now fully initialised and validated - this.validationState = this.uninitialisedState; + this.pendingState.validate(this.type, this.targetClasses); + this.state = this.pendingState; } finally { - this.uninitialisedState = null; + this.pendingState = null; } } @@ -325,13 +640,13 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { } List targets = new ArrayList(); - List publicTargets = ASMHelper.getAnnotationValue(mixin, "value"); + List publicTargets = ASMHelper.getAnnotationValue(mixin, "value"); List privateTargets = ASMHelper.getAnnotationValue(mixin, "targets"); if (publicTargets != null) { - this.readTargets(targets, Lists.transform(publicTargets, new Function() { + this.readTargets(targets, Lists.transform(publicTargets, new Function() { @Override - public String apply(Type input) { + public String apply(org.spongepowered.asm.lib.Type input) { return input.getClassName(); } }), suppressPlugin, false); @@ -352,12 +667,11 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { /** * Reads a target list into the outTargets list */ - private void readTargets(List outTargets, List inTargets, boolean suppressPlugin, boolean checkPublic) { - for (String targetClassName : inTargets) { - targetClassName = targetClassName.replace('/', '.'); - if (this.plugin == null || suppressPlugin || this.plugin.shouldApplyMixin(targetClassName, this.className)) { - ClassInfo targetInfo = ClassInfo.forName(targetClassName); - this.checkTarget(targetClassName, targetInfo, checkPublic); + private void readTargets(Collection outTargets, Collection inTargets, boolean suppressPlugin, boolean checkPublic) { + for (String targetName : inTargets) { + targetName = targetName.replace('/', '.'); + if (this.plugin == null || suppressPlugin || this.plugin.shouldApplyMixin(targetName, this.className)) { + ClassInfo targetInfo = this.getTarget(targetName, checkPublic); if (!outTargets.contains(targetInfo)) { outTargets.add(targetInfo); targetInfo.addMixin(this); @@ -366,19 +680,17 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { } } - private void checkTarget(String targetClassName, ClassInfo targetInfo, boolean checkPublic) throws InvalidMixinException { + private ClassInfo getTarget(String targetName, boolean checkPublic) throws InvalidMixinException { + ClassInfo targetInfo = ClassInfo.forName(targetName); if (targetInfo == null) { - throw new MixinException("@Mixin target " + targetClassName + " was not found " + this); - } - boolean targetIsInterface = targetInfo.isInterface(); - if (targetIsInterface != this.isInterfaceMixin) { - String not = targetIsInterface ? "" : "not "; - throw new InvalidMixinException(this, "@Mixin target type mismatch: " + targetClassName + " is " + not + "an interface in " + this); + throw new InvalidMixinException(this, "@Mixin target " + targetName + " was not found " + this); } + this.type.validateTarget(targetName, targetInfo); if (checkPublic && targetInfo.isPublic()) { - throw new InvalidMixinException(this, "@Mixin target " + targetClassName + " is public in " + this + throw new InvalidMixinException(this, "@Mixin target " + targetName + " is public in " + this + " and must be specified in value"); } + return targetInfo; } /** @@ -401,170 +713,17 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { return priority == null ? this.parent.getDefaultMixinPriority() : priority.intValue(); } - private boolean validateTargetClasses(ClassNode classNode) { - if (this.isInterfaceMixin) { - return this.validateInterfaceMixinTargets(classNode); - } - return this.validateClassMixinTargets(classNode); - } - - private boolean validateInterfaceMixinTargets(ClassNode classNode) { - if (!"java/lang/Object".equals(classNode.superName)) { - throw new InvalidMixinException(this, "Super class of " + this + " is invalid, found " + classNode.superName.replace('/', '.')); - } - - return false; - } - - private boolean validateClassMixinTargets(ClassNode classNode) { - boolean detached = false; - - for (ClassInfo targetClass : this.targetClasses) { - if (classNode.superName.equals(targetClass.getSuperName())) { - continue; - } - - if (!targetClass.hasSuperClass(classNode.superName, ClassInfo.Traversal.SUPER)) { - ClassInfo superClass = ClassInfo.forName(classNode.superName); - if (superClass.isMixin()) { - // If superclass is a mixin, check for hierarchy derp - for (ClassInfo superTarget : superClass.getTargets()) { - if (this.targetClasses.contains(superTarget)) { - throw new InvalidMixinException(this, "Illegal hierarchy detected. Derived mixin " + this + " targets the same class " - + superTarget.getClassName() + " as its superclass " + superClass.getClassName()); - } - } - } - - throw new InvalidMixinException(this, "Super class '" + classNode.superName.replace('/', '.') + "' of " + this.name - + " was not found in the hierarchy of target class '" + targetClass + "'"); - } - - detached = true; - } - - return detached; - } - - /** - * Performs pre-flight checks on the mixin - * - * @param state State to validate - */ - private void validateMixin(ValidationState state) { - this.validateType(); - this.validateInner(state); - this.validateClassVersion(state); - this.validateRemappables(state); - } - - private void validateType() { - if (this.isInterfaceMixin && !MixinEnvironment.getCompatibilityLevel().supportsMethodsInInterfaces()) { - throw new InvalidMixinException(this, "Interface mixin not supported in current enviromnment"); - } - } - - private void validateInner(ValidationState state) { - // isInner (shouldn't) return true for static inner classes - if (!state.classInfo.isProbablyStatic()) { - throw new InvalidMixinException(this, "Inner class mixin must be declared static"); - } - } - - private void validateClassVersion(ValidationState state) { - if (state.classNode.version > MixinEnvironment.getCompatibilityLevel().classVersion()) { - String helpText = "."; - for (CompatibilityLevel level : CompatibilityLevel.values()) { - if (level.classVersion() >= state.classNode.version) { - helpText = String.format(". Mixin requires compatibility level %s or above.", level.name()); - } - } - - throw new InvalidMixinException(this, "Unsupported mixin class version " + state.classNode.version + helpText); - } - } - - private void validateRemappables(ValidationState state) { - // Can't have remappable fields or methods on a multi-target mixin, because after obfuscation the fields will remap to conflicting names - if (this.targetClasses.size() > 1) { - for (FieldNode field : state.classNode.fields) { - this.checkRemappable(Shadow.class, field.name, ASMHelper.getVisibleAnnotation(field, Shadow.class)); - } - - for (MethodNode method : state.classNode.methods) { - this.checkRemappable(Shadow.class, method.name, ASMHelper.getVisibleAnnotation(method, Shadow.class)); - AnnotationNode overwrite = ASMHelper.getVisibleAnnotation(method, Overwrite.class); - if (overwrite != null && ((method.access & Opcodes.ACC_STATIC) == 0 || (method.access & Opcodes.ACC_PUBLIC) == 0)) { - throw new InvalidMixinException(this, "Found @Overwrite annotation on " + method.name + " in " + this); - } - } - } - } - - private void checkRemappable(Class annotationClass, String name, AnnotationNode annotation) { - if (annotation != null && ASMHelper.getAnnotationValue(annotation, "remap", Boolean.TRUE)) { - throw new InvalidMixinException(this, "Found a remappable @" + annotationClass.getSimpleName() + " annotation on " + name - + " in " + this); - } - } - - /** - * Read and process any {@link Implements} annotations on the mixin - */ - private void readImplementations(ValidationState state) { - state.interfaces.addAll(state.classNode.interfaces); - - AnnotationNode implementsAnnotation = ASMHelper.getInvisibleAnnotation(state.classNode, Implements.class); - if (implementsAnnotation == null) { - return; - } - - List interfaces = ASMHelper.getAnnotationValue(implementsAnnotation); - if (interfaces == null) { - return; - } - - for (AnnotationNode interfaceNode : interfaces) { - InterfaceInfo interfaceInfo = InterfaceInfo.fromAnnotation(this, interfaceNode); - state.softImplements.add(interfaceInfo); - state.interfaces.add(interfaceInfo.getInternalName()); - // only add interface if its initial initialisation - if (!(state instanceof ReloadedState)) { - state.classInfo.addInterface(interfaceInfo.getInternalName()); - } - } - } - - /** - * Read inner class definitions for the class and locate any synthetic inner - * classes so that we can add them to the passthrough set in our parent - * config. - */ - private void readInnerClasses(ValidationState state) { - for (InnerClassNode inner : state.classNode.innerClasses) { - ClassInfo innerClass = ClassInfo.forName(inner.name); - if (innerClass.isSynthetic() && innerClass.isProbablyStatic()) { - if ((inner.outerName != null && inner.outerName.equals(state.classInfo.getName())) - || inner.name.startsWith(state.classNode.name + "$")) { - state.syntheticInnerClasses.add(inner.name); - } else { - throw new InvalidMixinException(this, "Unhandled synthetic inner class found: " + inner.name); - } - } - } - } - /** * Current state, either the validated state or the uninitialised state if * the mixin is initialising for the first time. Should never return null. */ - private ValidationState getCurrentState() { - if (this.validationState == null) { - return this.uninitialisedState; - } - return this.validationState; + private State getState() { + return this.state != null ? this.state : this.pendingState; } + /** + * Get the ClassInfo for the mixin class + */ ClassInfo getClassInfo() { return this.info; } @@ -580,10 +739,18 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { /** * Get the parent config which declares this mixin */ - public MixinConfig getParent() { + MixinConfig getParent() { return this.parent; } + /** + * Get the mixin priority + */ + @Override + public int getPriority() { + return this.priority; + } + /** * Get the simple name of the mixin */ @@ -613,7 +780,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { */ @Override public byte[] getClassBytes() { - return this.getCurrentState().mixinBytes; + return this.getState().getClassBytes(); } /** @@ -622,7 +789,7 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { */ @Override public boolean isDetachedSuper() { - return this.getCurrentState().detachedSuper; + return this.getState().isDetachedSuper(); } /** @@ -639,21 +806,13 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { public Phase getPhase() { return this.phase; } - - /** - * Get whether this is an interface mixin or not - */ - @Override - public boolean isInterfaceMixin() { - return this.isInterfaceMixin; - } /** * Get a new tree for the class bytecode */ @Override public ClassNode getClassNode(int flags) { - return this.getCurrentState().getClassNode(flags); + return this.getState().createClassNode(flags); } /** @@ -668,36 +827,21 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * Get the soft implementations for this mixin */ List getSoftImplements() { - return Collections.unmodifiableList(this.getCurrentState().softImplements); + return Collections.unmodifiableList(this.getState().getSoftImplements()); } /** * Get the synthetic inner classes for this mixin */ - public Set getSyntheticInnerClasses() { - return Collections.unmodifiableSet(this.getCurrentState().syntheticInnerClasses); + Set getSyntheticInnerClasses() { + return Collections.unmodifiableSet(this.getState().getSyntheticInnerClasses()); } /** * Get the target class list for this mixin */ - public List getTargets() { - return Collections.unmodifiableList(this.getTargets0()); - } - - /** - * Internal method to avoid synthetic bridge generation - */ - protected List getTargets0() { - return this.targetClasses; - } - - /** - * Get the mixin priority - */ - @Override - public int getPriority() { - return this.priority; + List getTargets() { + return Collections.unmodifiableList(this.targetClasses); } /** @@ -705,8 +849,8 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * * @return mixin interfaces */ - public Set getInterfaces() { - return this.getCurrentState().interfaces; + Set getInterfaces() { + return this.getState().getInterfaces(); } /** @@ -715,21 +859,9 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * @param target * @return new context */ - public MixinTargetContext createContextFor(TargetClassContext target) { + MixinTargetContext createContextFor(TargetClassContext target) { ClassNode classNode = this.getClassNode(ClassReader.EXPAND_FRAMES); - return this.createPreProcessor(classNode).prepare().createContextFor(target); - } - - /** - * Create a preprocessor based on this mixin's type - * - * @return new preprocessor - */ - private MixinPreProcessor createPreProcessor(ClassNode classNode) { - if (this.isInterfaceMixin) { - return new InterfaceMixinPreProcessor(this, classNode); - } - return new MixinPreProcessor(this, classNode); + return this.type.createPreProcessor(classNode).prepare().createContextFor(target); } /** @@ -766,10 +898,10 @@ class MixinInfo extends TreeInfo implements Comparable, IMixinInfo { * @param mixinBytes New bytecode */ void reloadMixin(byte[] mixinBytes) { - if (this.uninitialisedState != null) { + if (this.pendingState != null) { throw new IllegalStateException("Cannot reload mixin while it is initialising"); } - this.uninitialisedState = new ReloadedState(this.validationState, mixinBytes); + this.pendingState = new Reloaded(this.state, mixinBytes); this.validate(); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinPreProcessor.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorInterface.java similarity index 89% rename from src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinPreProcessor.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorInterface.java index 84fcca3b..4fe187f9 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InterfaceMixinPreProcessor.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorInterface.java @@ -30,12 +30,13 @@ import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.lib.tree.FieldNode; import org.spongepowered.asm.lib.tree.MethodNode; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidInterfaceMixinException; /** * Bytecode preprocessor for interface mixins, simply performs some additional * verification for things which are unsupported in interfaces */ -class InterfaceMixinPreProcessor extends MixinPreProcessor { +class MixinPreProcessorInterface extends MixinPreProcessorStandard { /** * Ctor @@ -43,7 +44,7 @@ class InterfaceMixinPreProcessor extends MixinPreProcessor { * @param mixin Mixin info * @param classNode Mixin classnode */ - InterfaceMixinPreProcessor(MixinInfo mixin, ClassNode classNode) { + MixinPreProcessorInterface(MixinInfo mixin, ClassNode classNode) { super(mixin, classNode); } @@ -55,7 +56,7 @@ class InterfaceMixinPreProcessor extends MixinPreProcessor { @Override protected void prepareMethod(MethodNode mixinMethod, Method method) { // I have no idea how the hell you'd compile this, but we make sure anyway! - if (!MixinApplicator.hasFlag(mixinMethod, Opcodes.ACC_PUBLIC)) { + if (!MixinApplicatorStandard.hasFlag(mixinMethod, Opcodes.ACC_PUBLIC)) { throw new InvalidInterfaceMixinException(this.mixin, "Interface mixin contains a non-public method! Found " + method + " in " + this.mixin); } @@ -72,7 +73,7 @@ class InterfaceMixinPreProcessor extends MixinPreProcessor { */ @Override protected boolean validateField(MixinTargetContext context, FieldNode field, AnnotationNode shadow) { - if (!MixinApplicator.hasFlag(field, Opcodes.ACC_STATIC)) { + if (!MixinApplicatorStandard.hasFlag(field, Opcodes.ACC_STATIC)) { throw new InvalidInterfaceMixinException(this.mixin, "Interface mixin contains an instance field! Found " + field.name + " in " + this.mixin); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessor.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java similarity index 91% rename from src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessor.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java index 25f2bc10..19e500be 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessor.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinPreProcessorStandard.java @@ -45,13 +45,14 @@ import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.RemapperChain; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.Surrogate; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; import org.spongepowered.asm.mixin.transformer.meta.MixinRenamed; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; +import org.spongepowered.asm.obfuscation.RemapperChain; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.Constants; @@ -74,7 +75,7 @@ import org.spongepowered.asm.util.Constants; * target-context-sensitive pass on the other hand can only operate on private * class members for obvious reasons.

*/ -class MixinPreProcessor { +class MixinPreProcessorStandard { /** * Logger @@ -95,7 +96,7 @@ class MixinPreProcessor { private boolean prepared, attached; - MixinPreProcessor(MixinInfo mixin, ClassNode classNode) { + MixinPreProcessorStandard(MixinInfo mixin, ClassNode classNode) { this.mixin = mixin; this.classNode = classNode; this.verboseLogging = mixin.getParent().getEnvironment().getOption(Option.DEBUG_VERBOSE); @@ -106,7 +107,7 @@ class MixinPreProcessor { * * @return Prepared classnode */ - MixinPreProcessor prepare() { + MixinPreProcessorStandard prepare() { if (!this.prepared) { this.prepared = true; @@ -234,13 +235,13 @@ class MixinPreProcessor { } Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL); - MethodNode target = MixinPreProcessor.findMethod(context.getTargetClass(), mixinMethod, annotation); + MethodNode target = MixinPreProcessorStandard.findMethod(context.getTargetClass(), mixinMethod, annotation); if (target == null) { if (!mustExist) { return false; } - target = MixinPreProcessor.findRemappedMethod(context.getTargetClass(), mixinMethod); + target = MixinPreProcessorStandard.findRemappedMethod(context.getTargetClass(), mixinMethod); if (target == null) { throw new InvalidMixinException(this.mixin, annotationType.getSimpleName() + " method " + mixinMethod.name + " was not located in the target class"); @@ -292,12 +293,12 @@ class MixinPreProcessor { context.transformDescriptor(mixinField); Field field = this.mixin.getClassInfo().findField(mixinField); - FieldNode target = MixinPreProcessor.findField(context.getTargetClass(), mixinField, shadow); + FieldNode target = MixinPreProcessorStandard.findField(context.getTargetClass(), mixinField, shadow); if (target == null) { if (shadow == null) { continue; } - target = MixinPreProcessor.findRemappedField(context.getTargetClass(), mixinField); + target = MixinPreProcessorStandard.findRemappedField(context.getTargetClass(), mixinField); if (target == null) { // If this field is a shadow field but is NOT found in the target class, that's bad, mmkay throw new InvalidMixinException(this.mixin, "Shadow field " + mixinField.name + " was not located in the target class"); @@ -329,11 +330,11 @@ class MixinPreProcessor { } field.setDecoratedFinal(isFinal, isMutable); - if (this.verboseLogging && MixinApplicator.hasFlag(target, Opcodes.ACC_FINAL) != isFinal) { + if (this.verboseLogging && MixinApplicatorStandard.hasFlag(target, Opcodes.ACC_FINAL) != isFinal) { String message = isFinal ? "@Shadow field {}::{} is decorated with @Final but target is not final" : "@Shadow target {}::{} is final but shadow is not decorated with @Final"; - MixinPreProcessor.logger.warn(message, this.mixin, mixinField.name); + MixinPreProcessorStandard.logger.warn(message, this.mixin, mixinField.name); } context.addShadowField(mixinField, field); @@ -343,9 +344,9 @@ class MixinPreProcessor { protected boolean validateField(MixinTargetContext context, FieldNode field, AnnotationNode shadow) { // Public static fields will fall foul of early static binding in java, including them in a mixin is an error condition - if (MixinApplicator.hasFlag(field, Opcodes.ACC_STATIC) - && !MixinApplicator.hasFlag(field, Opcodes.ACC_PRIVATE) - && !MixinApplicator.hasFlag(field, Opcodes.ACC_SYNTHETIC) + if (MixinApplicatorStandard.hasFlag(field, Opcodes.ACC_STATIC) + && !MixinApplicatorStandard.hasFlag(field, Opcodes.ACC_PRIVATE) + && !MixinApplicatorStandard.hasFlag(field, Opcodes.ACC_SYNTHETIC) && shadow == null) { throw new InvalidMixinException(context, String.format("Mixin %s contains non-private static field %s:%s", context, field.name, field.desc)); @@ -409,7 +410,7 @@ class MixinPreProcessor { } } - return MixinPreProcessor.findMethodRecursive(classNode, aliases, method.desc); + return MixinPreProcessorStandard.findMethodRecursive(classNode, aliases, method.desc); } protected static MethodNode findRemappedMethod(ClassNode classNode, MethodNode method) { @@ -422,7 +423,7 @@ class MixinPreProcessor { Deque aliases = new LinkedList(); aliases.add(remappedName); - return MixinPreProcessor.findMethodRecursive(classNode, aliases, method.desc); + return MixinPreProcessorStandard.findMethodRecursive(classNode, aliases, method.desc); } private static MethodNode findMethodRecursive(ClassNode classNode, Deque aliases, String desc) { @@ -437,7 +438,7 @@ class MixinPreProcessor { } } - return MixinPreProcessor.findMethodRecursive(classNode, aliases, desc); + return MixinPreProcessorStandard.findMethodRecursive(classNode, aliases, desc); } protected static FieldNode findField(ClassNode classNode, FieldNode field, AnnotationNode shadow) { @@ -450,7 +451,7 @@ class MixinPreProcessor { } } - return MixinPreProcessor.findFieldRecursive(classNode, aliases, field.desc); + return MixinPreProcessorStandard.findFieldRecursive(classNode, aliases, field.desc); } protected static FieldNode findRemappedField(ClassNode classNode, FieldNode field) { @@ -462,7 +463,7 @@ class MixinPreProcessor { Deque aliases = new LinkedList(); aliases.add(remappedName); - return MixinPreProcessor.findFieldRecursive(classNode, aliases, field.desc); + return MixinPreProcessorStandard.findFieldRecursive(classNode, aliases, field.desc); } /** @@ -484,6 +485,6 @@ class MixinPreProcessor { } } - return MixinPreProcessor.findFieldRecursive(classNode, aliases, desc); + return MixinPreProcessorStandard.findFieldRecursive(classNode, aliases, desc); } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java index 64586be2..76b8bdac 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTargetContext.java @@ -44,16 +44,20 @@ import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.SoftOverride; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.InjectionError; -import org.spongepowered.asm.mixin.injection.InjectionValidationException; import org.spongepowered.asm.mixin.injection.InjectorGroupInfo; import org.spongepowered.asm.mixin.injection.struct.InjectionInfo; -import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper; import org.spongepowered.asm.mixin.injection.struct.Target; +import org.spongepowered.asm.mixin.injection.throwables.InjectionError; +import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; +import org.spongepowered.asm.mixin.refmap.ReferenceMapper; import org.spongepowered.asm.mixin.transformer.ClassInfo.Field; import org.spongepowered.asm.mixin.transformer.ClassInfo.Traversal; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; +import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError; import org.spongepowered.asm.util.ASMHelper; import org.spongepowered.asm.util.Constants; @@ -767,6 +771,15 @@ public class MixinTargetContext implements IReferenceMapperContext { throw new InvalidMixinException(this, "Unsupported mixin class version " + version); } } + + /* (non-Javadoc) + * @see org.spongepowered.asm.mixin.refmap.IReferenceMapperContext + * #getMixin() + */ + @Override + public IMixinInfo getMixin() { + return this.mixin; + } /** * Get the mixin info for this mixin diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java index 2f5c63f8..c2849c4f 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java @@ -31,6 +31,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.SortedSet; @@ -46,20 +47,25 @@ import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.lib.tree.ClassNode; import org.spongepowered.asm.lib.tree.FieldNode; import org.spongepowered.asm.lib.tree.MethodNode; -import org.spongepowered.asm.mixin.MixinApplyError; import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.MixinEnvironment.Phase; -import org.spongepowered.asm.mixin.MixinException; -import org.spongepowered.asm.mixin.MixinPrepareError; -import org.spongepowered.asm.mixin.audit.ClassAlreadyLoadedException; +import org.spongepowered.asm.mixin.Mixins; +import org.spongepowered.asm.mixin.extensibility.IMixinConfig; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler; import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler.ErrorAction; +import org.spongepowered.asm.mixin.throwables.ClassAlreadyLoadedException; +import org.spongepowered.asm.mixin.throwables.MixinApplyError; +import org.spongepowered.asm.mixin.throwables.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinPrepareError; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.mixin.transformer.MixinTransformerModuleCheckClass.ValidationFailedException; import org.spongepowered.asm.mixin.transformer.debug.IDecompiler; import org.spongepowered.asm.mixin.transformer.debug.IHotSwap; import org.spongepowered.asm.mixin.transformer.meta.MixinMerged; +import org.spongepowered.asm.mixin.transformer.throwables.InvalidMixinException; +import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError; import org.spongepowered.asm.transformers.TreeTransformer; import org.spongepowered.asm.util.Constants; import org.spongepowered.asm.util.PrettyPrinter; @@ -82,9 +88,9 @@ public class MixinTransformer extends TreeTransformer { */ PREPARE { @Override - ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, MixinInfo mixin, ErrorAction action) { + ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, IMixinInfo mixin, ErrorAction action) { try { - return handler.onPrepareError(mixin.getParent(), ex, mixin, action); + return handler.onPrepareError(mixin.getConfig(), ex, mixin, action); } catch (AbstractMethodError ame) { // Catch if error handler is pre-0.5.4 return action; @@ -92,7 +98,7 @@ public class MixinTransformer extends TreeTransformer { } @Override - protected String getContext(MixinInfo mixin, String context) { + protected String getContext(IMixinInfo mixin, String context) { return String.format("preparing %s in %s", mixin.getName(), context); } }, @@ -101,7 +107,7 @@ public class MixinTransformer extends TreeTransformer { */ APPLY { @Override - ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, MixinInfo mixin, ErrorAction action) { + ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, IMixinInfo mixin, ErrorAction action) { try { return handler.onApplyError(context, ex, mixin, action); } catch (AbstractMethodError ame) { @@ -111,7 +117,7 @@ public class MixinTransformer extends TreeTransformer { } @Override - protected String getContext(MixinInfo mixin, String context) { + protected String getContext(IMixinInfo mixin, String context) { return String.format("%s -> %s", mixin, context); } }; @@ -125,15 +131,15 @@ public class MixinTransformer extends TreeTransformer { this.text = this.name().toLowerCase(); } - abstract ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, MixinInfo mixin, ErrorAction action); + abstract ErrorAction onError(IMixinErrorHandler handler, String context, InvalidMixinException ex, IMixinInfo mixin, ErrorAction action); - protected abstract String getContext(MixinInfo mixin, String context); + protected abstract String getContext(IMixinInfo mixin, String context); - public String getLogMessage(String context, InvalidMixinException ex, MixinInfo mixin) { + public String getLogMessage(String context, InvalidMixinException ex, IMixinInfo mixin) { return String.format("Mixin %s failed %s: %s %s", this.text, this.getContext(mixin, context), ex.getClass().getName(), ex.getMessage()); } - public String getErrorMessage(MixinInfo mixin, MixinConfig config, Phase phase) { + public String getErrorMessage(IMixinInfo mixin, IMixinConfig config, Phase phase) { return String.format("Mixin [%s] from phase [%s] in config [%s] FAILED during %s", mixin, phase, config, this.name()); } @@ -469,7 +475,7 @@ public class MixinTransformer extends TreeTransformer { if (this.currentEnvironment != environment && !locked) { try { - this.init(environment); + this.select(environment); } catch (Exception ex) { this.lock.pop(); throw new MixinException(ex); @@ -553,14 +559,14 @@ public class MixinTransformer extends TreeTransformer { return targets; } - private void init(MixinEnvironment environment) { + private void select(MixinEnvironment environment) { this.verboseLoggingLevel = (environment.getOption(Option.DEBUG_VERBOSE)) ? Level.INFO : Level.DEBUG; this.logger.log(this.verboseLoggingLevel, "Preparing mixins for {}", environment); long startTime = System.currentTimeMillis(); - this.addConfigs(environment); - this.addModules(environment); - int totalMixins = this.initConfigs(environment); + this.selectConfigs(environment); + this.selectModules(environment); + int totalMixins = this.prepareConfigs(environment); this.currentEnvironment = environment; double elapsedTime = (System.currentTimeMillis() - startTime) * 0.001D; @@ -576,20 +582,19 @@ public class MixinTransformer extends TreeTransformer { * * @param environment Environment to query */ - private void addConfigs(MixinEnvironment environment) { - List configs = environment.getMixinConfigs(); - - if (configs != null) { - for (String configFile : configs) { - try { - MixinConfig config = MixinConfig.create(configFile, environment); - if (config != null) { - this.logger.log(this.verboseLoggingLevel, "Adding config {}", config); - this.pendingConfigs.add(config); - } - } catch (Exception ex) { - this.logger.warn(String.format("Failed to load mixin config: %s", configFile), ex); + private void selectConfigs(MixinEnvironment environment) { + for (Iterator iter = Mixins.getConfigs().iterator(); iter.hasNext();) { + Config handle = iter.next(); + try { + MixinConfig config = handle.get(); + if (config.select(environment)) { + iter.remove(); + this.logger.log(this.verboseLoggingLevel, "Selecting config {}", config); + config.onSelect(); + this.pendingConfigs.add(config); } + } catch (Exception ex) { + this.logger.warn(String.format("Failed to select mixin config: %s", handle), ex); } } @@ -601,7 +606,7 @@ public class MixinTransformer extends TreeTransformer { * * @param environment Environment to query */ - private void addModules(MixinEnvironment environment) { + private void selectModules(MixinEnvironment environment) { this.modules.clear(); // Run CheckClassAdapter on the mixin bytecode if debug option is enabled @@ -616,18 +621,18 @@ public class MixinTransformer extends TreeTransformer { } /** - * Initialise mixin configs + * Prepare mixin configs * * @param environment Environment * @return total number of mixins initialised */ - private int initConfigs(MixinEnvironment environment) { + private int prepareConfigs(MixinEnvironment environment) { int totalMixins = 0; for (MixinConfig config : this.pendingConfigs) { try { this.logger.log(this.verboseLoggingLevel, "Preparing {} ({})", config, config.getDeclaredMixinCount()); - config.initialise(this.hotSwapper); + config.prepare(this.hotSwapper); totalMixins += config.getMixinCount(); } catch (InvalidMixinException ex) { this.handleMixinPrepareError(config, ex, environment); @@ -766,14 +771,14 @@ public class MixinTransformer extends TreeTransformer { private void handleMixinError(String context, InvalidMixinException ex, MixinEnvironment environment, ErrorPhase errorPhase) throws Error { this.errorState = true; - MixinInfo mixin = ex.getMixin(); + IMixinInfo mixin = ex.getMixin(); if (mixin == null) { this.logger.error("InvalidMixinException has no mixin!", ex); throw ex; } - MixinConfig config = mixin.getParent(); + IMixinConfig config = mixin.getConfig(); Phase phase = mixin.getPhase(); ErrorAction action = config.isRequired() ? ErrorAction.ERROR : ErrorAction.WARN; @@ -814,7 +819,7 @@ public class MixinTransformer extends TreeTransformer { private List getErrorHandlers(Phase phase) { List handlers = new ArrayList(); - for (String handlerClassName : MixinEnvironment.getEnvironment(phase).getErrorHandlerClasses()) { + for (String handlerClassName : Mixins.getErrorHandlerClasses()) { try { this.logger.info("Instancing error handler class {}", handlerClassName); Class handlerClass = Class.forName(handlerClassName, true, Launch.classLoader); diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerModuleCheckClass.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerModuleCheckClass.java index 4240a8e8..73cb870b 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerModuleCheckClass.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerModuleCheckClass.java @@ -26,7 +26,7 @@ package org.spongepowered.asm.mixin.transformer; import org.spongepowered.asm.lib.ClassWriter; import org.spongepowered.asm.lib.util.CheckClassAdapter; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * Mixin transformer module which runs CheckClassAdapter on the post-mixin diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java b/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java index 57e36828..32ec4cfc 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/TargetClassContext.java @@ -213,15 +213,15 @@ class TargetClassContext { throw new IllegalStateException("Mixins already applied to target class " + this.className); } this.applied = true; - MixinApplicator applicator = this.createApplicator(); + MixinApplicatorStandard applicator = this.createApplicator(); applicator.apply(this.mixins); } - private MixinApplicator createApplicator() { + private MixinApplicatorStandard createApplicator() { if (this.classInfo.isInterface()) { - return new InterfaceMixinApplicator(this); + return new MixinApplicatorInterface(this); } - return new MixinApplicator(this); + return new MixinApplicatorStandard(this); } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/meta/MixinMerged.java b/src/main/java/org/spongepowered/asm/mixin/transformer/meta/MixinMerged.java index 28e9922f..9af19373 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/meta/MixinMerged.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/meta/MixinMerged.java @@ -29,14 +29,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.spongepowered.asm.mixin.transformer.MixinApplicator; +import org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard; /** *

For internal use only! Contains small parts. Keep out of reach of * children.

* - *

Decoration annotation used by the {@link MixinApplicator} to mark methods - * in a class which have been added or overwritten by a mixin.

+ *

Decoration annotation used by the {@link MixinApplicatorStandard} to mark + * methods in a class which have been added or overwritten by a mixin.

*/ @Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidInterfaceMixinException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidInterfaceMixinException.java similarity index 62% rename from src/main/java/org/spongepowered/asm/mixin/transformer/InvalidInterfaceMixinException.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidInterfaceMixinException.java index c1fdbaf7..e7467064 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidInterfaceMixinException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidInterfaceMixinException.java @@ -22,37 +22,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.transformer.throwables; + +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; /** * Exception thrown for bad states when parsing/loading interface mixins */ public class InvalidInterfaceMixinException extends InvalidMixinException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; - public InvalidInterfaceMixinException(MixinInfo mixin, String message) { + public InvalidInterfaceMixinException(IMixinInfo mixin, String message) { super(mixin, message); } - public InvalidInterfaceMixinException(MixinTargetContext mixin, String message) { - super(mixin, message); + public InvalidInterfaceMixinException(IReferenceMapperContext context, String message) { + super(context, message); } - public InvalidInterfaceMixinException(MixinInfo mixin, Throwable message) { - super(mixin, message); + public InvalidInterfaceMixinException(IMixinInfo mixin, Throwable cause) { + super(mixin, cause); } - public InvalidInterfaceMixinException(MixinTargetContext mixin, Throwable message) { - super(mixin, message); + public InvalidInterfaceMixinException(IReferenceMapperContext context, Throwable cause) { + super(context, cause); } - public InvalidInterfaceMixinException(MixinInfo mixin, String message, Throwable cause) { + public InvalidInterfaceMixinException(IMixinInfo mixin, String message, Throwable cause) { super(mixin, message, cause); } - public InvalidInterfaceMixinException(MixinTargetContext mixin, String message, Throwable cause) { - super(mixin, message, cause); + public InvalidInterfaceMixinException(IReferenceMapperContext context, String message, Throwable cause) { + super(context, message, cause); } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java similarity index 62% rename from src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java index 447285be..2d87c77a 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/InvalidMixinException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/InvalidMixinException.java @@ -22,50 +22,50 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.transformer.throwables; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * Thrown by the mixin validator when a mixin fails a pre-flight check */ public class InvalidMixinException extends MixinException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; - private final MixinInfo mixin; + private final IMixinInfo mixin; - public InvalidMixinException(MixinInfo mixin, String message) { + public InvalidMixinException(IMixinInfo mixin, String message) { super(message); this.mixin = mixin; } - public InvalidMixinException(MixinTargetContext mixin, String message) { - super(message); - this.mixin = mixin.getInfo(); + public InvalidMixinException(IReferenceMapperContext context, String message) { + this(context.getMixin(), message); } - public InvalidMixinException(MixinInfo mixin, Throwable message) { - super(message); + public InvalidMixinException(IMixinInfo mixin, Throwable cause) { + super(cause); this.mixin = mixin; } - public InvalidMixinException(MixinTargetContext mixin, Throwable message) { - super(message); - this.mixin = mixin.getInfo(); + public InvalidMixinException(IReferenceMapperContext context, Throwable cause) { + this(context.getMixin(), cause); } - public InvalidMixinException(MixinInfo mixin, String message, Throwable cause) { + public InvalidMixinException(IMixinInfo mixin, String message, Throwable cause) { super(message, cause); this.mixin = mixin; } - public InvalidMixinException(MixinTargetContext mixin, String message, Throwable cause) { + public InvalidMixinException(IReferenceMapperContext context, String message, Throwable cause) { super(message, cause); - this.mixin = mixin.getInfo(); + this.mixin = context.getMixin(); } - public MixinInfo getMixin() { + public IMixinInfo getMixin() { return this.mixin; } } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinReloadException.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinReloadException.java similarity index 79% rename from src/main/java/org/spongepowered/asm/mixin/transformer/MixinReloadException.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinReloadException.java index b9f45b33..f35e3118 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinReloadException.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinReloadException.java @@ -22,25 +22,28 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.transformer.throwables; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * An exception that occurs when a mixin reloads and does something it is * normally allowed to do but isn't due to reloading restrictions. */ public class MixinReloadException extends MixinException { - private static final long serialVersionUID = 1L; + + private static final long serialVersionUID = 2L; - private final MixinInfo mixinInfo; + private final IMixinInfo mixinInfo; - public MixinReloadException(MixinInfo mixinInfo, String message) { + public MixinReloadException(IMixinInfo mixinInfo, String message) { super(message); this.mixinInfo = mixinInfo; } - public MixinInfo getMixinInfo() { + public IMixinInfo getMixinInfo() { return this.mixinInfo; } + } diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinTransformerError.java similarity index 96% rename from src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinTransformerError.java index a0f81384..103e6660 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformerError.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/throwables/MixinTransformerError.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.transformer.throwables; /** * Error to throw for things which really shouldn't happen diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinVerifier.java b/src/main/java/org/spongepowered/asm/mixin/transformer/verify/MixinVerifier.java similarity index 97% rename from src/main/java/org/spongepowered/asm/mixin/transformer/MixinVerifier.java rename to src/main/java/org/spongepowered/asm/mixin/transformer/verify/MixinVerifier.java index c1af764f..3e0a93e8 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinVerifier.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/verify/MixinVerifier.java @@ -22,12 +22,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin.transformer; +package org.spongepowered.asm.mixin.transformer.verify; import java.util.List; import org.spongepowered.asm.lib.Type; import org.spongepowered.asm.lib.tree.analysis.SimpleVerifier; +import org.spongepowered.asm.mixin.transformer.ClassInfo; /** * Verifier which handles class info lookups via {@link ClassInfo} diff --git a/src/main/java/org/spongepowered/asm/mixin/RemapperChain.java b/src/main/java/org/spongepowered/asm/obfuscation/RemapperChain.java similarity index 98% rename from src/main/java/org/spongepowered/asm/mixin/RemapperChain.java rename to src/main/java/org/spongepowered/asm/obfuscation/RemapperChain.java index b0aed8c0..411adcdb 100644 --- a/src/main/java/org/spongepowered/asm/mixin/RemapperChain.java +++ b/src/main/java/org/spongepowered/asm/obfuscation/RemapperChain.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.mixin; +package org.spongepowered.asm.obfuscation; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/spongepowered/asm/obfuscation/SrgContainer.java b/src/main/java/org/spongepowered/asm/obfuscation/SrgContainer.java index a8ba90b8..86891539 100644 --- a/src/main/java/org/spongepowered/asm/obfuscation/SrgContainer.java +++ b/src/main/java/org/spongepowered/asm/obfuscation/SrgContainer.java @@ -28,7 +28,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.Charset; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinException; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; diff --git a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java index 23a27b8f..4ef7af17 100644 --- a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java +++ b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java @@ -28,6 +28,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.spongepowered.asm.lib.tree.AnnotationNode; +import org.spongepowered.asm.util.throwables.ConstraintViolationException; +import org.spongepowered.asm.util.throwables.InvalidConstraintException; /** * Parser for constraints diff --git a/src/main/java/org/spongepowered/asm/util/Locals.java b/src/main/java/org/spongepowered/asm/util/Locals.java index 1bb3aa92..81603529 100644 --- a/src/main/java/org/spongepowered/asm/util/Locals.java +++ b/src/main/java/org/spongepowered/asm/util/Locals.java @@ -48,7 +48,8 @@ import org.spongepowered.asm.lib.tree.analysis.Frame; import org.spongepowered.asm.mixin.transformer.ClassInfo; import org.spongepowered.asm.mixin.transformer.ClassInfo.FrameData; import org.spongepowered.asm.mixin.transformer.ClassInfo.Method; -import org.spongepowered.asm.mixin.transformer.MixinVerifier; +import org.spongepowered.asm.mixin.transformer.verify.MixinVerifier; +import org.spongepowered.asm.util.throwables.LVTGeneratorException; /** * Utility methods for working with local variables using ASM diff --git a/src/main/java/org/spongepowered/asm/util/ConstraintViolationException.java b/src/main/java/org/spongepowered/asm/util/throwables/ConstraintViolationException.java similarity index 98% rename from src/main/java/org/spongepowered/asm/util/ConstraintViolationException.java rename to src/main/java/org/spongepowered/asm/util/throwables/ConstraintViolationException.java index 3c3a8e8d..581b9a0b 100644 --- a/src/main/java/org/spongepowered/asm/util/ConstraintViolationException.java +++ b/src/main/java/org/spongepowered/asm/util/throwables/ConstraintViolationException.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.util; +package org.spongepowered.asm.util.throwables; import org.spongepowered.asm.util.ConstraintParser.Constraint; diff --git a/src/main/java/org/spongepowered/asm/util/InvalidConstraintException.java b/src/main/java/org/spongepowered/asm/util/throwables/InvalidConstraintException.java similarity index 97% rename from src/main/java/org/spongepowered/asm/util/InvalidConstraintException.java rename to src/main/java/org/spongepowered/asm/util/throwables/InvalidConstraintException.java index 2e6c1ce9..9e821648 100644 --- a/src/main/java/org/spongepowered/asm/util/InvalidConstraintException.java +++ b/src/main/java/org/spongepowered/asm/util/throwables/InvalidConstraintException.java @@ -22,7 +22,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.util; +package org.spongepowered.asm.util.throwables; /** * Exception thrown when a constraint declaration is invalid diff --git a/src/main/java/org/spongepowered/asm/util/LVTGeneratorException.java b/src/main/java/org/spongepowered/asm/util/throwables/LVTGeneratorException.java similarity index 93% rename from src/main/java/org/spongepowered/asm/util/LVTGeneratorException.java rename to src/main/java/org/spongepowered/asm/util/throwables/LVTGeneratorException.java index a9bc5348..012bac11 100644 --- a/src/main/java/org/spongepowered/asm/util/LVTGeneratorException.java +++ b/src/main/java/org/spongepowered/asm/util/throwables/LVTGeneratorException.java @@ -22,9 +22,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.asm.util; +package org.spongepowered.asm.util.throwables; -import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.throwables.MixinException; /** * Exception thrown when something goes horribly wrong whilst summoning the