diff --git a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java index 33d253c8..20c2c249 100644 --- a/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java +++ b/src/main/java/org/spongepowered/asm/mixin/MixinEnvironment.java @@ -41,6 +41,7 @@ import org.apache.logging.log4j.core.helpers.Booleans; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.extensibility.IEnvironmentTokenProvider; import org.spongepowered.asm.mixin.transformer.MixinTransformer; +import org.spongepowered.asm.util.ITokenProvider; import org.spongepowered.asm.util.PrettyPrinter; import com.google.common.collect.ImmutableList; @@ -57,7 +58,7 @@ import net.minecraft.launchwrapper.LaunchClassLoader; * The mixin environment manages global state information for the mixin * subsystem. */ -public class MixinEnvironment { +public class MixinEnvironment implements ITokenProvider { /** * Environment phase, deliberately not implemented as an enum @@ -588,6 +589,7 @@ public class MixinEnvironment { * @return token value or null if the token is not present in the * environment */ + @Override public Integer getToken(String token) { token = token.toUpperCase(); diff --git a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java index e4238e3b..fdabbc76 100644 --- a/src/main/java/org/spongepowered/asm/util/ConstraintParser.java +++ b/src/main/java/org/spongepowered/asm/util/ConstraintParser.java @@ -28,7 +28,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.spongepowered.asm.lib.tree.AnnotationNode; -import org.spongepowered.asm.mixin.MixinEnvironment; /** @@ -220,7 +219,7 @@ public final class ConstraintParser { return this.max; } - public void check(MixinEnvironment environment) throws ConstraintViolationException { + public void check(ITokenProvider environment) throws ConstraintViolationException { if (this != Constraint.NONE) { Integer value = environment.getToken(this.token); if (value == null) { diff --git a/src/main/java/org/spongepowered/asm/util/ITokenProvider.java b/src/main/java/org/spongepowered/asm/util/ITokenProvider.java new file mode 100644 index 00000000..c86decc9 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/util/ITokenProvider.java @@ -0,0 +1,42 @@ +/* + * 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.util; + + +/** + * Agent which can supply token values to a + * {@link org.spongepowered.asm.util.ConstraintParser.Constraint}. + */ +public interface ITokenProvider { + + /** + * Get a token value from this provider + * + * @param token Token to fetch + * @return token value or null if the token is not provided by this provider + */ + public abstract Integer getToken(String token); + +}