mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Version 0.8-preview
Add initial modlauncher support Bump ASM version and remove renamed ASM for modlauncher interop Conform static accessor target when transforming accessor, Fixes #342 Detect staticness mismatch on accessors, Fixes #341 Allow Invoker to invoke constructors, Closes #339 Remove commons-io and replace with guava, Fixes #327 Fix refmap generation for non-obfuscated derived classes, Fixes #326 Specify locale for case conversions, Fixes #315 Handle accessor overlap more intelligently, Fixes #307 Add SuppressWarnings support to Annotation Processor, Closes #306 Allow mixins applied to a class to be retrieved easily, Closes #302 Conform refmap entries as they are added to the mapper, fixes #296 Fold in misc lvt generation fixes from fabricmc, closes #295 Fail fast when final method is accidentally hidden by mixin, fixes #293 Fix bug handling 2-slot args in cb injector and args gen, fixes #287 Handle accessor mixin types correctly in mixins, Fixes #305, Fixes #288
This commit is contained in:
1 parent
ab935e061f
commit
fd2f2c79c5
246 files changed
+10899
-3125
No files matched your search
@@ -24,9 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.service.IGlobalPropertyService;
|
||||
import org.spongepowered.asm.service.IPropertyKey;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
/**
|
||||
* Access to underlying global property service provided by the current
|
||||
@@ -39,19 +42,56 @@ public final class GlobalProperties {
|
||||
*/
|
||||
public static final class Keys {
|
||||
|
||||
public static final String INIT = "mixin.initialised";
|
||||
public static final String AGENTS = "mixin.agents";
|
||||
public static final String CONFIGS = "mixin.configs";
|
||||
public static final String TRANSFORMER = "mixin.transformer";
|
||||
public static final String PLATFORM_MANAGER = "mixin.platform";
|
||||
public static final Keys INIT = Keys.of("mixin.initialised");
|
||||
public static final Keys AGENTS = Keys.of("mixin.agents");
|
||||
public static final Keys CONFIGS = Keys.of("mixin.configs");
|
||||
public static final Keys PLATFORM_MANAGER = Keys.of("mixin.platform");
|
||||
|
||||
public static final String FML_LOAD_CORE_MOD = "mixin.launch.fml.loadcoremodmethod";
|
||||
public static final String FML_GET_REPARSEABLE_COREMODS = "mixin.launch.fml.reparseablecoremodsmethod";
|
||||
public static final String FML_CORE_MOD_MANAGER = "mixin.launch.fml.coremodmanagerclass";
|
||||
public static final String FML_GET_IGNORED_MODS = "mixin.launch.fml.ignoredmodsmethod";
|
||||
public static final Keys FML_LOAD_CORE_MOD = Keys.of("mixin.launch.fml.loadcoremodmethod");
|
||||
public static final Keys FML_GET_REPARSEABLE_COREMODS = Keys.of("mixin.launch.fml.reparseablecoremodsmethod");
|
||||
public static final Keys FML_CORE_MOD_MANAGER = Keys.of("mixin.launch.fml.coremodmanagerclass");
|
||||
public static final Keys FML_GET_IGNORED_MODS = Keys.of("mixin.launch.fml.ignoredmodsmethod");
|
||||
|
||||
private static Map<String, Keys> keys;
|
||||
|
||||
private final String name;
|
||||
|
||||
private IPropertyKey key;
|
||||
|
||||
private Keys() {}
|
||||
private Keys(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
IPropertyKey resolve(IGlobalPropertyService service) {
|
||||
if (this.key != null) {
|
||||
return this.key;
|
||||
}
|
||||
if (service == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.key = service.resolveKey(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a new global property key
|
||||
*
|
||||
* @param name name of key to get or create
|
||||
* @return new or existing key
|
||||
*/
|
||||
public static Keys of(String name) {
|
||||
if (Keys.keys == null) {
|
||||
Keys.keys = new HashMap<String, Keys>();
|
||||
}
|
||||
|
||||
Keys key = Keys.keys.get(name);
|
||||
if (key == null) {
|
||||
key = new Keys(name);
|
||||
Keys.keys.put(name, key);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static IGlobalPropertyService service;
|
||||
@@ -60,9 +100,7 @@ public final class GlobalProperties {
|
||||
|
||||
private static IGlobalPropertyService getService() {
|
||||
if (GlobalProperties.service == null) {
|
||||
ServiceLoader<IGlobalPropertyService> serviceLoader =
|
||||
ServiceLoader.<IGlobalPropertyService>load(IGlobalPropertyService.class, GlobalProperties.class.getClassLoader());
|
||||
GlobalProperties.service = serviceLoader.iterator().next();
|
||||
GlobalProperties.service = MixinService.getGlobalPropertyService();
|
||||
}
|
||||
return GlobalProperties.service;
|
||||
}
|
||||
@@ -74,8 +112,9 @@ public final class GlobalProperties {
|
||||
* @param <T> duck type
|
||||
* @return value
|
||||
*/
|
||||
public static <T> T get(String key) {
|
||||
return GlobalProperties.getService().<T>getProperty(key);
|
||||
public static <T> T get(Keys key) {
|
||||
IGlobalPropertyService service = GlobalProperties.getService();
|
||||
return service.<T>getProperty(key.resolve(service));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,8 +123,9 @@ public final class GlobalProperties {
|
||||
* @param key blackboard key
|
||||
* @param value new value
|
||||
*/
|
||||
public static void put(String key, Object value) {
|
||||
GlobalProperties.getService().setProperty(key, value);
|
||||
public static void put(Keys key, Object value) {
|
||||
IGlobalPropertyService service = GlobalProperties.getService();
|
||||
service.setProperty(key.resolve(service), value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +137,9 @@ public final class GlobalProperties {
|
||||
* @param <T> duck type
|
||||
* @return value from blackboard or default value
|
||||
*/
|
||||
public static <T> T get(String key, T defaultValue) {
|
||||
return GlobalProperties.getService().getProperty(key, defaultValue);
|
||||
public static <T> T get(Keys key, T defaultValue) {
|
||||
IGlobalPropertyService service = GlobalProperties.getService();
|
||||
return service.getProperty(key.resolve(service), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,8 +151,9 @@ public final class GlobalProperties {
|
||||
* set or is null
|
||||
* @return value from blackboard or default
|
||||
*/
|
||||
public static String getString(String key, String defaultValue) {
|
||||
return GlobalProperties.getService().getPropertyString(key, defaultValue);
|
||||
public static String getString(Keys key, String defaultValue) {
|
||||
IGlobalPropertyService service = GlobalProperties.getService();
|
||||
return service.getPropertyString(key.resolve(service), defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.platform.CommandLineOptions;
|
||||
import org.spongepowered.asm.launch.platform.MixinPlatformManager;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
@@ -60,7 +61,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.7.12";
|
||||
public static final String VERSION = "0.8-preview";
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
@@ -81,6 +82,11 @@ public abstract class MixinBootstrap {
|
||||
* Platform manager instance
|
||||
*/
|
||||
private static MixinPlatformManager platform;
|
||||
|
||||
/**
|
||||
* Connectors
|
||||
*/
|
||||
private static MixinConnectorManager connectors = new MixinConnectorManager();
|
||||
|
||||
private MixinBootstrap() {}
|
||||
|
||||
@@ -117,7 +123,7 @@ public abstract class MixinBootstrap {
|
||||
return;
|
||||
}
|
||||
|
||||
MixinBootstrap.doInit(null);
|
||||
MixinBootstrap.doInit(CommandLineOptions.defaultArgs());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,16 +143,11 @@ public abstract class MixinBootstrap {
|
||||
if (!MixinBootstrap.initialised) {
|
||||
MixinBootstrap.initialised = true;
|
||||
|
||||
String command = System.getProperty("sun.java.command");
|
||||
if (command != null && command.contains("GradleStart")) {
|
||||
System.setProperty("mixin.env.remapRefMap", "true");
|
||||
}
|
||||
|
||||
Phase initialPhase = MixinService.getService().getInitialPhase();
|
||||
if (initialPhase == Phase.DEFAULT) {
|
||||
MixinBootstrap.logger.error("Initialising mixin subsystem after game pre-init phase! Some mixins may be skipped.");
|
||||
MixinEnvironment.init(initialPhase);
|
||||
MixinBootstrap.getPlatform().prepare(null);
|
||||
MixinBootstrap.getPlatform().prepare(CommandLineOptions.defaultArgs());
|
||||
MixinBootstrap.initState = false;
|
||||
} else {
|
||||
MixinEnvironment.init(initialPhase);
|
||||
@@ -160,10 +161,15 @@ public abstract class MixinBootstrap {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static void doInit(List<String> args) {
|
||||
MixinBootstrap.doInit(CommandLineOptions.ofArgs(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2 of mixin initialisation, initialise the phases
|
||||
*/
|
||||
static void doInit(List<String> args) {
|
||||
static void doInit(CommandLineOptions args) {
|
||||
if (!MixinBootstrap.initialised) {
|
||||
if (MixinBootstrap.isSubsystemRegistered()) {
|
||||
MixinBootstrap.logger.warn("Multiple Mixin containers present, init suppressed for " + MixinBootstrap.VERSION);
|
||||
@@ -187,6 +193,7 @@ public abstract class MixinBootstrap {
|
||||
|
||||
static void inject() {
|
||||
MixinBootstrap.getPlatform().inject();
|
||||
MixinBootstrap.connectors.inject();
|
||||
}
|
||||
|
||||
private static boolean isSubsystemRegistered() {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.connect.IMixinConnector;
|
||||
|
||||
/**
|
||||
* Manager for Mixin containers bootstrapping via {@link IMixinConnector}
|
||||
*/
|
||||
public class MixinConnectorManager {
|
||||
|
||||
/**
|
||||
* Logging to the max
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
private List<IMixinConnector> connectors = new ArrayList<IMixinConnector>();
|
||||
|
||||
MixinConnectorManager() {
|
||||
}
|
||||
|
||||
void inject() {
|
||||
this.loadConnectors();
|
||||
this.initConnectors();
|
||||
}
|
||||
|
||||
void loadConnectors() {
|
||||
ServiceLoader<IMixinConnector> serviceLoader = ServiceLoader.load(IMixinConnector.class);
|
||||
for (Iterator<IMixinConnector> iterator = serviceLoader.iterator(); iterator.hasNext(); ) {
|
||||
try {
|
||||
IMixinConnector connector = iterator.next();
|
||||
this.connectors.add(connector);
|
||||
} catch (ServiceConfigurationError e) {
|
||||
MixinConnectorManager.logger.catching(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initConnectors() {
|
||||
for (IMixinConnector connector : this.connectors) {
|
||||
try {
|
||||
connector.connect();
|
||||
} catch (Exception ex) {
|
||||
MixinConnectorManager.logger.warn("Error initialising Mixin Connector [" + connector.getClass().getName() + "]", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,10 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinError;
|
||||
|
||||
/**
|
||||
* Error raised when mixin subsystem initialisation fails
|
||||
*/
|
||||
public class MixinInitialisationError extends Error {
|
||||
public class MixinInitialisationError extends MixinError {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch.platform;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Options passed in to Mixin via the command line
|
||||
*/
|
||||
public final class CommandLineOptions {
|
||||
|
||||
private List<String> configs = new ArrayList<String>();
|
||||
|
||||
private CommandLineOptions() {
|
||||
}
|
||||
|
||||
public List<String> getConfigs() {
|
||||
return Collections.<String>unmodifiableList(this.configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse command-line arguments
|
||||
*
|
||||
* @param args command-line arguments
|
||||
*/
|
||||
private void parseArgs(List<String> args) {
|
||||
boolean captureNext = false;
|
||||
for (String arg : args) {
|
||||
if (captureNext) {
|
||||
this.configs.add(arg);
|
||||
}
|
||||
captureNext = "--mixin".equals(arg) || "--mixin.config".equals(arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CommandLineOptions with default args (read from system property)
|
||||
*
|
||||
* @return CommandLineOptions instance
|
||||
*/
|
||||
public static CommandLineOptions defaultArgs() {
|
||||
return CommandLineOptions.ofArgs(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CommandLineOptions using the supplied unparsed argument list.
|
||||
* Uses args from system property if
|
||||
*
|
||||
* @param args Argument list to parse, can be null
|
||||
* @return CommandLineOptions instance
|
||||
*/
|
||||
public static CommandLineOptions ofArgs(List<String> args) {
|
||||
CommandLineOptions options = new CommandLineOptions();
|
||||
if (args == null) {
|
||||
String argv = System.getProperty("sun.java.command");
|
||||
if (argv != null) {
|
||||
args = Arrays.asList(argv.split(" "));
|
||||
}
|
||||
}
|
||||
if (args != null) {
|
||||
options.parseArgs(args);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CommandLineOptions using the supplied list of pre-parsed configs
|
||||
*
|
||||
* @param configs List of configs
|
||||
* @return CommandLineOptions instance
|
||||
*/
|
||||
public static CommandLineOptions of(List<String> configs) {
|
||||
CommandLineOptions options = new CommandLineOptions();
|
||||
options.configs.addAll(configs);
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,17 +24,34 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
|
||||
/**
|
||||
* Base interface for platform agents. Platform agents are environment-specific
|
||||
* handlers which are used by the Mixin subsystem to perform platform-specific
|
||||
* tasks required by different environments without having to litter the Mixin
|
||||
* codebase with a bunch of environment-specific cruft.
|
||||
* tasks required by different environments without having to litter other parts
|
||||
* of the Mixin codebase with a bunch of environment-specific cruft.
|
||||
*
|
||||
* <p>Platform Agents handle mixin environment tasks on a per-container basis,
|
||||
* with each container in the environment being assigned one of each available
|
||||
* type of agent to handle those tasks on behalf of the container.</p>
|
||||
*/
|
||||
public interface IMixinPlatformAgent {
|
||||
|
||||
/**
|
||||
* Accept and bind to a container handle. This method is called for agents
|
||||
* hosted by {@link MixinContainer} and the agent should react accordingly.
|
||||
* If the agent is <em>not</em> able to delegate for container handles of
|
||||
* the supplied type, this method should return <tt>false</tt> to indicate
|
||||
* that the agent should not be added for this container.
|
||||
*
|
||||
* @param manager platform manager instance
|
||||
* @param handle handle to container
|
||||
* @return true if this agent can accept a container of the supplied type,
|
||||
* false if the agent cannot handle the container (in which case it
|
||||
* will be discarded)
|
||||
*/
|
||||
public abstract boolean accept(MixinPlatformManager manager, IContainerHandle handle);
|
||||
|
||||
/**
|
||||
* Get the phase provider for this agent
|
||||
@@ -58,11 +75,5 @@ public interface IMixinPlatformAgent {
|
||||
* Called from <tt>inject</tt> in the parent tweaker
|
||||
*/
|
||||
public abstract void inject();
|
||||
|
||||
/**
|
||||
* Get the launch target from this container, should return null if no
|
||||
* custom target is available.
|
||||
*/
|
||||
public abstract String getLaunchTarget();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch.platform;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.IConsumer;
|
||||
|
||||
/**
|
||||
* Service agents provide additional platform-specific extensions leveraged by
|
||||
* mixin services. Implementing this interface on an agent class will cause an
|
||||
* additional instance to be spun up by the service.
|
||||
*/
|
||||
public interface IMixinPlatformServiceAgent extends IMixinPlatformAgent {
|
||||
|
||||
/**
|
||||
* Perform initialisation-stage logic for this agent
|
||||
*/
|
||||
public abstract void init();
|
||||
|
||||
/**
|
||||
* Attempt to determine the side name from the current environment
|
||||
*/
|
||||
public abstract String getSideName();
|
||||
|
||||
/**
|
||||
* Get environment-specific mixin containers
|
||||
*/
|
||||
public abstract Collection<IContainerHandle> getMixinContainers();
|
||||
|
||||
/**
|
||||
* Temp wiring
|
||||
*
|
||||
* @param phase Initial phase
|
||||
* @param phaseConsumer Phase setter callback
|
||||
* @deprecated temporary
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void wire(Phase phase, IConsumer<Phase> phaseConsumer);
|
||||
|
||||
/**
|
||||
* Temp wiring - Called when the DEFAULT phase is started
|
||||
* @deprecated temporary
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void unwire();
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -33,11 +34,14 @@ import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* "Main" attribute cache for a URI container, mainly to avoid constantly
|
||||
* opening jar files just to read odd values out of the manifest.
|
||||
*/
|
||||
final class MainAttributes {
|
||||
public final class MainAttributes {
|
||||
|
||||
private static final Map<URI, MainAttributes> instances = new HashMap<URI, MainAttributes>();
|
||||
|
||||
@@ -54,6 +58,13 @@ final class MainAttributes {
|
||||
this.attributes = MainAttributes.getAttributes(jar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value of attribute with the specified name, or null if not
|
||||
* present
|
||||
*
|
||||
* @param name attribute name
|
||||
* @return attribute value or null if not present
|
||||
*/
|
||||
public final String get(String name) {
|
||||
if (this.attributes != null) {
|
||||
return this.attributes.getValue(name);
|
||||
@@ -61,11 +72,29 @@ final class MainAttributes {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Attributes getAttributes(File jar) {
|
||||
if (jar == null) {
|
||||
private static Attributes getAttributes(File codeSource) {
|
||||
if (codeSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (codeSource.isFile()) {
|
||||
Attributes attributes = MainAttributes.getJarAttributes(codeSource);
|
||||
if (attributes != null) {
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
if (codeSource.isDirectory()) {
|
||||
Attributes attributes = MainAttributes.getDirAttributes(codeSource);
|
||||
if (attributes != null) {
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
return new Attributes();
|
||||
}
|
||||
|
||||
private static Attributes getJarAttributes(File jar) {
|
||||
JarFile jarFile = null;
|
||||
try {
|
||||
jarFile = new JarFile(jar);
|
||||
@@ -84,13 +113,51 @@ final class MainAttributes {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return new Attributes();
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Attributes getDirAttributes(File dir) {
|
||||
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
|
||||
if (manifestFile.isFile()) {
|
||||
ByteSource source = Files.asByteSource(manifestFile);
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = source.openBufferedStream();
|
||||
Manifest manifest = new Manifest(inputStream);
|
||||
return manifest.getMainAttributes();
|
||||
} catch (IOException ex) {
|
||||
// be quiet checkstyle
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a MainAttributes instance for the supplied jar file
|
||||
*
|
||||
* @param jar jar file
|
||||
* @return MainAttributes instance
|
||||
*/
|
||||
public static MainAttributes of(File jar) {
|
||||
return MainAttributes.of(jar.toURI());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a MainAttributes instance for the supplied jar file
|
||||
*
|
||||
* @param uri jar file location
|
||||
* @return MainAttributes instance
|
||||
*/
|
||||
public static MainAttributes of(URI uri) {
|
||||
MainAttributes attributes = MainAttributes.instances.get(uri);
|
||||
if (attributes == null) {
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -33,10 +31,12 @@ import java.util.List;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
/**
|
||||
* A collection of {@link IMixinPlatformAgent} platform agents)
|
||||
* A collection of {@link IMixinPlatformAgent} platform agents) for a particular
|
||||
* container
|
||||
*/
|
||||
public class MixinContainer {
|
||||
|
||||
@@ -50,25 +50,39 @@ public class MixinContainer {
|
||||
MixinContainer.agentClasses.add("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
|
||||
}
|
||||
|
||||
private final Logger logger = LogManager.getLogger("mixin");
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
private final URI uri;
|
||||
private final IContainerHandle handle;
|
||||
|
||||
private final List<IMixinPlatformAgent> agents = new ArrayList<IMixinPlatformAgent>();
|
||||
|
||||
public MixinContainer(MixinPlatformManager manager, URI uri) {
|
||||
this.uri = uri;
|
||||
public MixinContainer(MixinPlatformManager manager, IContainerHandle handle) {
|
||||
this.handle = handle;
|
||||
|
||||
for (String agentClass : MixinContainer.agentClasses) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<IMixinPlatformAgent> clazz = (Class<IMixinPlatformAgent>)Class.forName(agentClass);
|
||||
Constructor<IMixinPlatformAgent> ctor = clazz.getDeclaredConstructor(MixinPlatformManager.class, URI.class);
|
||||
this.logger.debug("Instancing new {} for {}", clazz.getSimpleName(), this.uri);
|
||||
IMixinPlatformAgent agent = ctor.newInstance(manager, uri);
|
||||
this.agents.add(agent);
|
||||
} catch (Exception ex) {
|
||||
this.logger.catching(ex);
|
||||
String simpleName = clazz.getSimpleName();
|
||||
String acceptAction = "rejected";
|
||||
|
||||
MixinContainer.logger.debug("Instancing new {} for {}", simpleName, this.handle);
|
||||
IMixinPlatformAgent agent = clazz.newInstance();
|
||||
|
||||
if (agent.accept(manager, this.handle)) {
|
||||
this.agents.add(agent);
|
||||
acceptAction = "accepted";
|
||||
}
|
||||
|
||||
MixinContainer.logger.debug("{} {} container {}", simpleName, acceptAction, this.handle);
|
||||
} catch (InstantiationException ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException)cause;
|
||||
}
|
||||
throw new RuntimeException(cause);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
MixinContainer.logger.catching(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,8 +90,8 @@ public class MixinContainer {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
public IContainerHandle getDescriptor() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +113,7 @@ public class MixinContainer {
|
||||
*/
|
||||
public void prepare() {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
this.logger.debug("Processing prepare() for {}", agent);
|
||||
MixinContainer.logger.debug("Processing prepare() for {}", agent);
|
||||
agent.prepare();
|
||||
}
|
||||
}
|
||||
@@ -110,7 +124,7 @@ public class MixinContainer {
|
||||
*/
|
||||
public void initPrimaryContainer() {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
this.logger.debug("Processing launch tasks for {}", agent);
|
||||
MixinContainer.logger.debug("Processing launch tasks for {}", agent);
|
||||
agent.initPrimaryContainer();
|
||||
}
|
||||
}
|
||||
@@ -120,26 +134,9 @@ public class MixinContainer {
|
||||
*/
|
||||
public void inject() {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
this.logger.debug("Processing inject() for {}", agent);
|
||||
MixinContainer.logger.debug("Processing inject() for {}", agent);
|
||||
agent.inject();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analogue of <tt>ITweaker::getLaunchTarget</tt>, queries all agents and
|
||||
* returns first valid launch target. Returns null if no agents have launch
|
||||
* target.
|
||||
*
|
||||
* @return launch target from agent or null
|
||||
*/
|
||||
public String getLaunchTarget() {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
String launchTarget = agent.getLaunchTarget();
|
||||
if (launchTarget != null) {
|
||||
return launchTarget;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+61
-25
@@ -24,11 +24,13 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.IConsumer;
|
||||
|
||||
/**
|
||||
* Platform agent base class
|
||||
@@ -40,39 +42,24 @@ public abstract class MixinPlatformAgentAbstract implements IMixinPlatformAgent
|
||||
*/
|
||||
protected static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
protected final MixinPlatformManager manager;
|
||||
protected MixinPlatformManager manager;
|
||||
|
||||
/**
|
||||
* URI to the container
|
||||
*/
|
||||
protected final URI uri;
|
||||
|
||||
/**
|
||||
* File containing this tweaker
|
||||
*/
|
||||
protected final File container;
|
||||
protected IContainerHandle handle;
|
||||
|
||||
/**
|
||||
* "Main" manifest attributes from the container
|
||||
* Ctor
|
||||
*/
|
||||
protected final MainAttributes attributes;
|
||||
|
||||
/**
|
||||
* Create a new platform agent for the specified URI
|
||||
*
|
||||
* @param manager platform manager
|
||||
* @param uri URI of the resource for this agent
|
||||
*/
|
||||
public MixinPlatformAgentAbstract(MixinPlatformManager manager, URI uri) {
|
||||
this.manager = manager;
|
||||
this.uri = uri;
|
||||
this.container = this.uri != null ? new File(this.uri) : null;
|
||||
this.attributes = MainAttributes.of(uri);
|
||||
protected MixinPlatformAgentAbstract() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PlatformAgent[%s:%s]", this.getClass().getSimpleName(), this.uri);
|
||||
public boolean accept(MixinPlatformManager manager, IContainerHandle handle) {
|
||||
this.manager = manager;
|
||||
this.handle = handle;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,4 +67,53 @@ public abstract class MixinPlatformAgentAbstract implements IMixinPlatformAgent
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPrimaryContainer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PlatformAgent[%s:%s]", this.getClass().getSimpleName(), this.handle);
|
||||
}
|
||||
|
||||
protected static String invokeStringMethod(ClassLoader classLoader, String className, String methodName) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className, false, classLoader);
|
||||
Method method = clazz.getDeclaredMethod(methodName);
|
||||
return ((Enum<?>)method.invoke(null)).name();
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// AMS - Temp
|
||||
|
||||
/**
|
||||
* Temp wiring. Called when the initial phase is spun up in the environment.
|
||||
*
|
||||
* @param phase Initial phase
|
||||
* @param phaseConsumer Delegate for the service (or agents) to trigger
|
||||
* later phases
|
||||
* @deprecated temporary
|
||||
*/
|
||||
@Deprecated
|
||||
public void wire(Phase phase, IConsumer<Phase> phaseConsumer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the DEFAULT phase is started
|
||||
* @deprecated temporary
|
||||
*/
|
||||
@Deprecated
|
||||
public void unwire() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,8 +24,6 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.spongepowered.asm.util.Constants.ManifestAttributes;
|
||||
|
||||
/**
|
||||
@@ -34,48 +32,27 @@ import org.spongepowered.asm.util.Constants.ManifestAttributes;
|
||||
*/
|
||||
public class MixinPlatformAgentDefault extends MixinPlatformAgentAbstract {
|
||||
|
||||
/**
|
||||
* @param manager platform manager
|
||||
* @param uri URI of the resource for this agent
|
||||
*/
|
||||
public MixinPlatformAgentDefault(MixinPlatformManager manager, URI uri) {
|
||||
super(manager, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
@SuppressWarnings("deprecation")
|
||||
String compatibilityLevel = this.attributes.get(ManifestAttributes.COMPATIBILITY);
|
||||
String compatibilityLevel = this.handle.getAttribute(ManifestAttributes.COMPATIBILITY);
|
||||
if (compatibilityLevel != null) {
|
||||
this.manager.setCompatibilityLevel(compatibilityLevel);
|
||||
}
|
||||
|
||||
String mixinConfigs = this.attributes.get(ManifestAttributes.MIXINCONFIGS);
|
||||
String mixinConfigs = this.handle.getAttribute(ManifestAttributes.MIXINCONFIGS);
|
||||
if (mixinConfigs != null) {
|
||||
for (String config : mixinConfigs.split(",")) {
|
||||
this.manager.addConfig(config.trim());
|
||||
}
|
||||
}
|
||||
|
||||
String tokenProviders = this.attributes.get(ManifestAttributes.TOKENPROVIDERS);
|
||||
String tokenProviders = this.handle.getAttribute(ManifestAttributes.TOKENPROVIDERS);
|
||||
if (tokenProviders != null) {
|
||||
for (String provider : tokenProviders.split(",")) {
|
||||
this.manager.addTokenProvider(provider.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPrimaryContainer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
return this.attributes.get(ManifestAttributes.MAINCLASS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,26 +24,24 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
//import org.spongepowered.asm.launch.MixinBootstrap.Delegate;
|
||||
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.service.ServiceVersionError;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinError;
|
||||
|
||||
//import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -54,7 +52,6 @@ import org.spongepowered.asm.mixin.Mixins;
|
||||
public class MixinPlatformManager {
|
||||
|
||||
private static final String DEFAULT_MAIN_CLASS = "net.minecraft.client.main.Main";
|
||||
private static final String MIXIN_TWEAKER_CLASS = "org.spongepowered.asm.launch.MixinTweaker";
|
||||
|
||||
/**
|
||||
* Make with the logging already
|
||||
@@ -69,7 +66,7 @@ public class MixinPlatformManager {
|
||||
/**
|
||||
* Tweak containers
|
||||
*/
|
||||
private final Map<URI, MixinContainer> containers = new LinkedHashMap<URI, MixinContainer>();
|
||||
private final Map<IContainerHandle, MixinContainer> containers = new LinkedHashMap<IContainerHandle, MixinContainer>();
|
||||
|
||||
/**
|
||||
* Container for this tweaker
|
||||
@@ -92,25 +89,16 @@ public class MixinPlatformManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this platform manager by scanning the classpath
|
||||
* Initialise the platform manager
|
||||
*/
|
||||
public void init() {
|
||||
MixinPlatformManager.logger.debug("Initialising Mixin Platform Manager");
|
||||
|
||||
// Add agents for the tweak container
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||
if (uri != null) {
|
||||
MixinPlatformManager.logger.debug("Mixin platform: primary container is {}", uri);
|
||||
this.primaryContainer = this.addContainer(uri);
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
IContainerHandle primaryContainerHandle = MixinService.getService().getPrimaryContainer();
|
||||
this.primaryContainer = this.addContainer(primaryContainerHandle);
|
||||
|
||||
// Do an early scan to ensure preinit mixins are discovered
|
||||
this.scanClasspath();
|
||||
this.scanForContainers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,60 +114,54 @@ public class MixinPlatformManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new URI to this platform and return the new container (or an
|
||||
* existing container if the URI was previously registered)
|
||||
* Add a new container to this platform and return the new container (or an
|
||||
* existing container if the handle was previously registered)
|
||||
*
|
||||
* @param uri URI to add
|
||||
* @return container for specified URI
|
||||
* @param handle Container handle to add
|
||||
* @return container for specified resource handle
|
||||
*/
|
||||
public final MixinContainer addContainer(URI uri) {
|
||||
MixinContainer existingContainer = this.containers.get(uri);
|
||||
public final MixinContainer addContainer(IContainerHandle handle) {
|
||||
MixinContainer existingContainer = this.containers.get(handle);
|
||||
if (existingContainer != null) {
|
||||
return existingContainer;
|
||||
}
|
||||
|
||||
MixinPlatformManager.logger.debug("Adding mixin platform agents for container {}", uri);
|
||||
MixinContainer container = new MixinContainer(this, uri);
|
||||
this.containers.put(uri, container);
|
||||
|
||||
MixinContainer container = this.createContainerFor(handle);
|
||||
this.containers.put(handle, container);
|
||||
this.addNestedContainers(handle);
|
||||
return container;
|
||||
}
|
||||
|
||||
private MixinContainer createContainerFor(IContainerHandle handle) {
|
||||
MixinPlatformManager.logger.debug("Adding mixin platform agents for container {}", handle);
|
||||
MixinContainer container = new MixinContainer(this, handle);
|
||||
if (this.prepared) {
|
||||
container.prepare();
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
private void addNestedContainers(IContainerHandle handle) {
|
||||
for (IContainerHandle nested : handle.getNestedContainers()) {
|
||||
if (!this.containers.containsKey(nested)) {
|
||||
this.addContainer(nested);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare all containers in this platform
|
||||
*
|
||||
* @param args command-line arguments from tweaker
|
||||
*/
|
||||
public final void prepare(List<String> args) {
|
||||
public final void prepare(CommandLineOptions args) {
|
||||
this.prepared = true;
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
container.prepare();
|
||||
}
|
||||
if (args != null) {
|
||||
this.parseArgs(args);
|
||||
} else {
|
||||
String argv = System.getProperty("sun.java.command");
|
||||
if (argv != null) {
|
||||
this.parseArgs(Arrays.asList(argv.split(" ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse command-line arguments
|
||||
*
|
||||
* @param args command-line arguments
|
||||
*/
|
||||
private void parseArgs(List<String> args) {
|
||||
boolean captureNext = false;
|
||||
for (String arg : args) {
|
||||
if (captureNext) {
|
||||
this.addConfig(arg);
|
||||
}
|
||||
captureNext = "--mixin".equals(arg);
|
||||
|
||||
for (String config : args.getConfigs()) {
|
||||
this.addConfig(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +178,7 @@ public class MixinPlatformManager {
|
||||
this.primaryContainer.initPrimaryContainer();
|
||||
}
|
||||
|
||||
this.scanClasspath();
|
||||
this.scanForContainers();
|
||||
MixinPlatformManager.logger.debug("inject() running with {} agents", this.containers.size());
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
try {
|
||||
@@ -208,27 +190,26 @@ public class MixinPlatformManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the classpath for mixin containers (containers which declare the
|
||||
* mixin tweaker in their manifest) and add agents for them
|
||||
* Scan the current environment for mixin containers and add agents for them
|
||||
*/
|
||||
private void scanClasspath() {
|
||||
URL[] sources = MixinService.getService().getClassProvider().getClassPath();
|
||||
for (URL url : sources) {
|
||||
private void scanForContainers() {
|
||||
Collection<IContainerHandle> mixinContainers = null;
|
||||
|
||||
try {
|
||||
mixinContainers = MixinService.getService().getMixinContainers();
|
||||
} catch (AbstractMethodError ame) {
|
||||
throw new ServiceVersionError("Mixin service is out of date");
|
||||
}
|
||||
|
||||
List<IContainerHandle> existingContainers = new ArrayList<IContainerHandle>(this.containers.keySet());
|
||||
for (IContainerHandle existingContainer : existingContainers) {
|
||||
this.addNestedContainers(existingContainer);
|
||||
}
|
||||
|
||||
for (IContainerHandle handle : mixinContainers) {
|
||||
try {
|
||||
URI uri = url.toURI();
|
||||
if (this.containers.containsKey(uri)) {
|
||||
continue;
|
||||
}
|
||||
MixinPlatformManager.logger.debug("Scanning {} for mixin tweaker", uri);
|
||||
if (!"file".equals(uri.getScheme()) || !new File(uri).exists()) {
|
||||
continue;
|
||||
}
|
||||
MainAttributes attributes = MainAttributes.of(uri);
|
||||
String tweaker = attributes.get(Constants.ManifestAttributes.TWEAKER);
|
||||
if (MixinPlatformManager.MIXIN_TWEAKER_CLASS.equals(tweaker)) {
|
||||
MixinPlatformManager.logger.debug("{} contains a mixin tweaker, adding agents", uri);
|
||||
this.addContainer(uri);
|
||||
}
|
||||
MixinPlatformManager.logger.debug("Adding agents for Mixin Container {}", handle);
|
||||
this.addContainer(handle);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -240,13 +221,6 @@ public class MixinPlatformManager {
|
||||
* specify a launch target
|
||||
*/
|
||||
public String getLaunchTarget() {
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
String mainClass = container.getLaunchTarget();
|
||||
if (mainClass != null) {
|
||||
return mainClass;
|
||||
}
|
||||
}
|
||||
|
||||
return MixinPlatformManager.DEFAULT_MAIN_CLASS;
|
||||
}
|
||||
|
||||
@@ -259,7 +233,7 @@ public class MixinPlatformManager {
|
||||
@SuppressWarnings("deprecation")
|
||||
final void setCompatibilityLevel(String level) {
|
||||
try {
|
||||
CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase());
|
||||
CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase(Locale.ROOT));
|
||||
MixinPlatformManager.logger.debug("Setting mixin compatibility level: {}", value);
|
||||
MixinEnvironment.setCompatibilityLevel(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
@@ -275,21 +249,12 @@ public class MixinPlatformManager {
|
||||
*
|
||||
* @param config config resource name, does not require a leading /
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
final void addConfig(String config) {
|
||||
if (config.endsWith(".json")) {
|
||||
MixinPlatformManager.logger.debug("Registering mixin config: {}", 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) {
|
||||
MixinPlatformManager.logger.warn("Setting config phase via manifest is deprecated: {}. Specify target in config instead", config);
|
||||
MixinPlatformManager.logger.debug("Registering mixin config: {}", config);
|
||||
MixinEnvironment.getEnvironment(phase).addConfiguration(config);
|
||||
}
|
||||
throw new MixinError("Setting config phase via manifest is no longer supported: " + config + ". Specify target in config instead");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch.platform.container;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.spongepowered.asm.launch.platform.MainAttributes;
|
||||
|
||||
/**
|
||||
* Container handle which directly replaces the use of classpath location URIs
|
||||
* from previous mixin versions
|
||||
*/
|
||||
public class ContainerHandleURI implements IContainerHandle {
|
||||
|
||||
/**
|
||||
* Target URI
|
||||
*/
|
||||
private final URI uri;
|
||||
|
||||
/**
|
||||
* File containing this tweaker
|
||||
*/
|
||||
private final File file;
|
||||
|
||||
/**
|
||||
* "Main" manifest attributes from the container
|
||||
*/
|
||||
private final MainAttributes attributes;
|
||||
|
||||
public ContainerHandleURI(URI uri) {
|
||||
this.uri = uri;
|
||||
this.file = this.uri != null ? new File(this.uri) : null;
|
||||
this.attributes = MainAttributes.of(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URI for this handle
|
||||
*/
|
||||
public URI getURI() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container file
|
||||
*/
|
||||
public File getFile() {
|
||||
return this.file;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.platform.container.IContainerHandle
|
||||
* #getAttribute(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getAttribute(String name) {
|
||||
return this.attributes.get(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.platform.container.IContainerHandle
|
||||
* #getNestedContainers()
|
||||
*/
|
||||
@Override
|
||||
public Collection<IContainerHandle> getNestedContainers() {
|
||||
return Collections.<IContainerHandle>emptyList();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ContainerHandleURI)) {
|
||||
return false;
|
||||
}
|
||||
return this.uri.equals(((ContainerHandleURI)other).uri);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.uri.hashCode();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ContainerHandleURI(%s)", this.uri);
|
||||
}
|
||||
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch.platform.container;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A virtual container, used to marshal other containers around
|
||||
*/
|
||||
public class ContainerHandleVirtual implements IContainerHandle {
|
||||
|
||||
/**
|
||||
* Name, used mainly for differentiation since containers are used as map
|
||||
* keys
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Virtual attributes
|
||||
*/
|
||||
private final Map<String, String> attributes = new HashMap<String, String>();
|
||||
|
||||
/**
|
||||
* Virtual nested containers (might be real containers, depending on the
|
||||
* purpose of this container
|
||||
*/
|
||||
private final Set<IContainerHandle> nestedContainers = new LinkedHashSet<IContainerHandle>();
|
||||
|
||||
/**
|
||||
* .ctor
|
||||
*
|
||||
* @param name Unique container name
|
||||
*/
|
||||
public ContainerHandleVirtual(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a virtual attribute on this virtual container
|
||||
*
|
||||
* @param key attribute key
|
||||
* @param value attribute value
|
||||
* @return fluent interface
|
||||
*/
|
||||
public ContainerHandleVirtual setAttribute(String key, String value) {
|
||||
this.attributes.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a nested container to this virtual container
|
||||
*
|
||||
* @param nested Nested container to add
|
||||
* @return fluent
|
||||
*/
|
||||
public ContainerHandleVirtual add(IContainerHandle nested) {
|
||||
this.nestedContainers.add(nested);
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.platform.container.IContainerHandle
|
||||
* #getAttribute(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getAttribute(String name) {
|
||||
return this.attributes.get(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.platform.container.IContainerHandle
|
||||
* #getNestedContainers()
|
||||
*/
|
||||
@Override
|
||||
public Collection<IContainerHandle> getNestedContainers() {
|
||||
return Collections.<IContainerHandle>unmodifiableSet(this.nestedContainers);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof String && obj.toString().equals(this.name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("ContainerHandleVirtual(%s:%x)", this.name, this.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.launch.platform.container;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Interface for container handles. Previously resources considered by Mixin
|
||||
* were indexed by URI but in order to provide more flexibility the container
|
||||
* handle system now wraps URIs in a more expressive object, and provides
|
||||
* support for both virtual containers and nested container resolution.
|
||||
*/
|
||||
public interface IContainerHandle {
|
||||
|
||||
/**
|
||||
* Retrieve the value of attribute with the specified name, or null if not
|
||||
* present
|
||||
*
|
||||
* @param name attribute name
|
||||
* @return attribute value or null if not present
|
||||
*/
|
||||
public abstract String getAttribute(String name);
|
||||
|
||||
/**
|
||||
* Get nested containers from this container, allows a container to detect
|
||||
* and return containers within itself. For example a folder container
|
||||
* detecting and returning file containers, or a virtual container returning
|
||||
* real containers after a scan.
|
||||
*/
|
||||
public abstract Collection<IContainerHandle> getNestedContainers();
|
||||
|
||||
}
|
||||
@@ -29,34 +29,34 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.launch.GlobalProperties.Keys;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.extensibility.IEnvironmentTokenProvider;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
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.mixin.transformer.IMixinTransformer;
|
||||
import org.spongepowered.asm.obfuscation.RemapperChain;
|
||||
import org.spongepowered.asm.service.ILegacyClassTransformer;
|
||||
import org.spongepowered.asm.service.IMixinService;
|
||||
import org.spongepowered.asm.service.ITransformer;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
import org.spongepowered.asm.service.MixinServiceAbstract;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.IConsumer;
|
||||
import org.spongepowered.asm.util.ITokenProvider;
|
||||
import org.spongepowered.asm.util.JavaVersion;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
import org.spongepowered.asm.util.perf.Profiler;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* The mixin environment manages global state information for the mixin
|
||||
@@ -175,7 +175,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
@Override
|
||||
protected boolean detect() {
|
||||
String sideName = MixinService.getService().getSideName();
|
||||
return "CLIENT".equals(sideName);
|
||||
return Constants.SIDE_CLIENT.equals(sideName);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -186,7 +186,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
@Override
|
||||
protected boolean detect() {
|
||||
String sideName = MixinService.getService().getSideName();
|
||||
return "SERVER".equals(sideName) || "DEDICATEDSERVER".equals(sideName);
|
||||
return Constants.SIDE_SERVER.equals(sideName) || Constants.SIDE_DEDICATEDSERVER.equals(sideName);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -574,7 +574,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
<E extends Enum<E>> E getEnumValue(E defaultValue) {
|
||||
String value = System.getProperty(this.property, defaultValue.name());
|
||||
try {
|
||||
return (E)Enum.valueOf(defaultValue.getClass(), value.toUpperCase());
|
||||
return (E)Enum.valueOf(defaultValue.getClass(), value.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -589,12 +589,12 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* Java 6 and above
|
||||
*/
|
||||
JAVA_6(6, Opcodes.V1_6, false),
|
||||
JAVA_6(6, Opcodes.V1_6, 0),
|
||||
|
||||
/**
|
||||
* Java 7 and above
|
||||
*/
|
||||
JAVA_7(7, Opcodes.V1_7, false) {
|
||||
JAVA_7(7, Opcodes.V1_7, 0) {
|
||||
|
||||
@Override
|
||||
boolean isSupported() {
|
||||
@@ -606,7 +606,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* Java 8 and above
|
||||
*/
|
||||
JAVA_8(8, Opcodes.V1_8, true) {
|
||||
JAVA_8(8, Opcodes.V1_8, LanguageFeature.METHODS_IN_INTERFACES) {
|
||||
|
||||
@Override
|
||||
boolean isSupported() {
|
||||
@@ -618,30 +618,79 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* Java 9 and above
|
||||
*/
|
||||
JAVA_9(9, CompatibilityLevel.CLASS_V1_9, true) {
|
||||
JAVA_9(9, Opcodes.V9, LanguageFeature.METHODS_IN_INTERFACES | LanguageFeature.PRIVATE_METHODS_IN_INTERFACES) {
|
||||
|
||||
@Override
|
||||
boolean isSupported() {
|
||||
return false;
|
||||
return JavaVersion.current() >= 9.0;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Java 10 and above
|
||||
*/
|
||||
JAVA_10(10, Opcodes.V10, LanguageFeature.METHODS_IN_INTERFACES | LanguageFeature.PRIVATE_METHODS_IN_INTERFACES) {
|
||||
|
||||
@Override
|
||||
boolean isSupported() {
|
||||
return JavaVersion.current() >= 10.0;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Java 10 and above
|
||||
*/
|
||||
JAVA_11(11, Opcodes.V11, LanguageFeature.METHODS_IN_INTERFACES | LanguageFeature.PRIVATE_METHODS_IN_INTERFACES
|
||||
| LanguageFeature.NESTING | LanguageFeature.DYNAMIC_CONSTANTS) {
|
||||
|
||||
@Override
|
||||
boolean isSupported() {
|
||||
return JavaVersion.current() >= 11.0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Temp, until ASM supports Java 9
|
||||
private static final int CLASS_V1_9 = 0 << 16 | 53;
|
||||
/**
|
||||
* Bitmask values for language features supported
|
||||
*/
|
||||
public static class LanguageFeature {
|
||||
|
||||
/**
|
||||
* Language version supports methods in interfaces
|
||||
*/
|
||||
public static final int METHODS_IN_INTERFACES = 1;
|
||||
|
||||
/**
|
||||
* Language version supports private methods in interfaces
|
||||
*/
|
||||
public static final int PRIVATE_METHODS_IN_INTERFACES = 2;
|
||||
|
||||
/**
|
||||
* Native nesting
|
||||
*/
|
||||
public static final int NESTING = 4;
|
||||
|
||||
/**
|
||||
* Native nesting
|
||||
*/
|
||||
public static final int DYNAMIC_CONSTANTS = 8;
|
||||
|
||||
}
|
||||
|
||||
private final int ver;
|
||||
|
||||
private final int classVersion;
|
||||
|
||||
private final boolean supportsMethodsInInterfaces;
|
||||
private final int languageFeatures;
|
||||
|
||||
private CompatibilityLevel maxCompatibleLevel;
|
||||
|
||||
private CompatibilityLevel(int ver, int classVersion, boolean resolveMethodsInInterfaces) {
|
||||
private CompatibilityLevel(int ver, int classVersion, int languageFeatures) {
|
||||
this.ver = ver;
|
||||
this.classVersion = classVersion;
|
||||
this.supportsMethodsInInterfaces = resolveMethodsInInterfaces;
|
||||
this.languageFeatures = languageFeatures;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -667,9 +716,23 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* Get whether this environment supports non-abstract methods in
|
||||
* interfaces, true in Java 1.8 and above
|
||||
*
|
||||
* @deprecated Use {@link #supports(int)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean supportsMethodsInInterfaces() {
|
||||
return this.supportsMethodsInInterfaces;
|
||||
return (this.languageFeatures & LanguageFeature.METHODS_IN_INTERFACES) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the specified {@link LanguageFeature} is supported by
|
||||
* this runtime.
|
||||
*
|
||||
* @param languageFeature language feature (or features) to check
|
||||
* @return true if all specified language features are supported
|
||||
*/
|
||||
public boolean supports(int languageFeature) {
|
||||
return (this.languageFeatures & languageFeature) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -709,6 +772,21 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
|
||||
return level.canElevateTo(this);
|
||||
}
|
||||
|
||||
static String getSupportedVersions() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean comma = false;
|
||||
for (CompatibilityLevel level : CompatibilityLevel.values()) {
|
||||
if (level.isSupported()) {
|
||||
if (comma) {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(level.ver);
|
||||
comma = true;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -752,93 +830,19 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Temporary
|
||||
* Phase setter callback delegate
|
||||
*/
|
||||
static class MixinLogWatcher {
|
||||
static class PhaseConsumer implements IConsumer<Phase> {
|
||||
|
||||
static MixinAppender appender = new MixinAppender();
|
||||
static org.apache.logging.log4j.core.Logger log;
|
||||
static Level oldLevel = null;
|
||||
|
||||
static void begin() {
|
||||
/*
|
||||
* In order to determine when to switch to the INIT phase, Mixin
|
||||
* relies on being able to detect a specific message
|
||||
* ("Validating minecraft") logged to FMLRelaunchLog.
|
||||
* However, this message is logged at the DEBUG level, which may
|
||||
* not be enabled depending on the launcher or game version.
|
||||
*
|
||||
* To ensure that Mixin is always able to detect this message,
|
||||
* we temporarily set the log level of FMLRelaunchLog to 'ALL'.
|
||||
* To minimize the overall impact, the log level is restored
|
||||
* (unless it was changed in the meantime) once MixinAppender
|
||||
* detects the message.
|
||||
*/
|
||||
Logger fmlLog = LogManager.getLogger("FML");
|
||||
if (!(fmlLog instanceof org.apache.logging.log4j.core.Logger)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MixinLogWatcher.log = (org.apache.logging.log4j.core.Logger)fmlLog;
|
||||
MixinLogWatcher.oldLevel = MixinLogWatcher.log.getLevel();
|
||||
|
||||
MixinLogWatcher.appender.start();
|
||||
MixinLogWatcher.log.addAppender(MixinLogWatcher.appender);
|
||||
|
||||
MixinLogWatcher.log.setLevel(Level.ALL);
|
||||
@Override
|
||||
public void accept(Phase phase) {
|
||||
MixinEnvironment.gotoPhase(phase);
|
||||
}
|
||||
|
||||
static void end() {
|
||||
if (MixinLogWatcher.log != null) {
|
||||
// remove appender, we're done watching for messages
|
||||
MixinLogWatcher.log.removeAppender(MixinLogWatcher.appender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary
|
||||
*/
|
||||
static class MixinAppender extends AbstractAppender {
|
||||
|
||||
MixinAppender() {
|
||||
super("MixinLogWatcherAppender", null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(LogEvent event) {
|
||||
if (event.getLevel() != Level.DEBUG || !"Validating minecraft".equals(event.getMessage().getFormattedMessage())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// transition to INIT
|
||||
MixinEnvironment.gotoPhase(Phase.INIT);
|
||||
|
||||
// Only reset the log level if it's still ALL. If something
|
||||
// else changed the log level after we did, we don't want
|
||||
// overwrite that change. No null check is needed here
|
||||
// because the appender will not be injected if the log is
|
||||
// null
|
||||
if (MixinLogWatcher.log.getLevel() == Level.ALL) {
|
||||
MixinLogWatcher.log.setLevel(MixinLogWatcher.oldLevel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Known re-entrant transformers, other re-entrant transformers will
|
||||
* detected automatically
|
||||
*/
|
||||
private static final Set<String> excludeTransformers = Sets.<String>newHashSet(
|
||||
"net.minecraftforge.fml.common.asm.transformers.EventSubscriptionTransformer",
|
||||
"cpw.mods.fml.common.asm.transformers.EventSubscriptionTransformer",
|
||||
"net.minecraftforge.fml.common.asm.transformers.TerminalTransformer",
|
||||
"cpw.mods.fml.common.asm.transformers.TerminalTransformer"
|
||||
);
|
||||
|
||||
/**
|
||||
* Currently active environment
|
||||
*/
|
||||
@@ -869,6 +873,11 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* Performance profiler
|
||||
*/
|
||||
private static final Profiler profiler = new Profiler();
|
||||
|
||||
/**
|
||||
* Active transformer
|
||||
*/
|
||||
private static IMixinTransformer transformer;
|
||||
|
||||
/**
|
||||
* Service
|
||||
@@ -883,7 +892,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
/**
|
||||
* The blackboard key for this environment's configs
|
||||
*/
|
||||
private final String configsKey;
|
||||
private final Keys configsKey;
|
||||
|
||||
/**
|
||||
* This environment's options
|
||||
@@ -915,14 +924,6 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*/
|
||||
private Side side;
|
||||
|
||||
/**
|
||||
* Local transformer chain, this consists of all transformers present at the
|
||||
* init phase with the exclusion of the mixin transformer itself and known
|
||||
* re-entrant transformers. Detected re-entrant transformers will be
|
||||
* subsequently removed.
|
||||
*/
|
||||
private List<ILegacyClassTransformer> transformers;
|
||||
|
||||
/**
|
||||
* Obfuscation context (refmap key to use in this environment)
|
||||
*/
|
||||
@@ -931,7 +932,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
MixinEnvironment(Phase phase) {
|
||||
this.service = MixinService.getService();
|
||||
this.phase = phase;
|
||||
this.configsKey = GlobalProperties.Keys.CONFIGS + "." + this.phase.name.toLowerCase();
|
||||
this.configsKey = Keys.of(GlobalProperties.Keys.CONFIGS + "." + this.phase.name.toLowerCase(Locale.ROOT));
|
||||
|
||||
// Sanity check
|
||||
Object version = this.getVersion();
|
||||
@@ -965,9 +966,10 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
printer.add("SpongePowered MIXIN%s", verbose ? " (Verbose debugging enabled)" : "").centre().hr();
|
||||
printer.kv("Code source", codeSource);
|
||||
printer.kv("Internal Version", version);
|
||||
printer.kv("Java 8 Supported", CompatibilityLevel.JAVA_8.isSupported()).hr();
|
||||
printer.kv("Java Versions Supported", CompatibilityLevel.getSupportedVersions()).hr();
|
||||
printer.kv("Service Name", serviceName);
|
||||
printer.kv("Service Class", this.service.getClass().getName()).hr();
|
||||
printer.kv("Mixin Service Class", this.service.getClass().getName());
|
||||
printer.kv("Global Property Service Class", MixinService.getGlobalPropertyService().getClass().getName()).hr();
|
||||
for (Option option : Option.values()) {
|
||||
StringBuilder indent = new StringBuilder();
|
||||
for (int i = 0; i < option.depth; i++) {
|
||||
@@ -1013,20 +1015,6 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
return mixinConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a mixin configuration to the blackboard
|
||||
*
|
||||
* @param config Name of configuration resource to add
|
||||
* @return fluent interface
|
||||
* @deprecated use Mixins::addConfiguration instead
|
||||
*/
|
||||
@Deprecated
|
||||
public MixinEnvironment addConfiguration(String config) {
|
||||
MixinEnvironment.logger.warn("MixinEnvironment::addConfiguration is deprecated and will be removed. Use Mixins::addConfiguration instead!");
|
||||
Mixins.addConfiguration(config, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
void registerConfig(String config) {
|
||||
List<String> configs = this.getMixinConfigs();
|
||||
if (!configs.contains(config)) {
|
||||
@@ -1034,19 +1022,6 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
Mixins.registerErrorHandlerClass(handlerName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new token provider class to this environment
|
||||
*
|
||||
@@ -1096,7 +1071,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*/
|
||||
@Override
|
||||
public Integer getToken(String token) {
|
||||
token = token.toUpperCase();
|
||||
token = token.toUpperCase(Locale.ROOT);
|
||||
|
||||
for (TokenProviderWrapper provider : this.tokenProviders) {
|
||||
Integer value = provider.getToken(token);
|
||||
@@ -1125,7 +1100,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* @return active mixin transformer instance
|
||||
*/
|
||||
public Object getActiveTransformer() {
|
||||
return GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
|
||||
return MixinEnvironment.transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1133,9 +1108,9 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*
|
||||
* @param transformer Mixin Transformer
|
||||
*/
|
||||
public void setActiveTransformer(ITransformer transformer) {
|
||||
public void setActiveTransformer(IMixinTransformer transformer) {
|
||||
if (transformer != null) {
|
||||
GlobalProperties.put(GlobalProperties.Keys.TRANSFORMER, transformer);
|
||||
MixinEnvironment.transformer = transformer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1260,9 +1235,8 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*/
|
||||
public void audit() {
|
||||
Object activeTransformer = this.getActiveTransformer();
|
||||
if (activeTransformer instanceof MixinTransformer) {
|
||||
MixinTransformer transformer = (MixinTransformer)activeTransformer;
|
||||
transformer.audit(this);
|
||||
if (activeTransformer instanceof IMixinTransformer) {
|
||||
((IMixinTransformer)activeTransformer).audit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1271,59 +1245,24 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
* this environment.
|
||||
*
|
||||
* @return current transformer delegation list (read-only)
|
||||
* @deprecated Do not use this method
|
||||
*/
|
||||
public List<ILegacyClassTransformer> getTransformers() {
|
||||
if (this.transformers == null) {
|
||||
this.buildTransformerDelegationList();
|
||||
}
|
||||
|
||||
return Collections.<ILegacyClassTransformer>unmodifiableList(this.transformers);
|
||||
@Deprecated
|
||||
public List<ITransformer> getTransformers() {
|
||||
MixinEnvironment.logger.warn("MixinEnvironment::getTransformers is deprecated!");
|
||||
return (List<ITransformer>)this.service.getTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a transformer to the transformer exclusions list
|
||||
*
|
||||
* @param name Class transformer exclusion to add
|
||||
* @deprecated Do not use this method
|
||||
*/
|
||||
@Deprecated
|
||||
public void addTransformerExclusion(String name) {
|
||||
MixinEnvironment.excludeTransformers.add(name);
|
||||
|
||||
// Force rebuild of the list
|
||||
this.transformers = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the transformer list to apply to loaded mixin bytecode. Since
|
||||
* generating this list requires inspecting each transformer by name (to
|
||||
* cope with the new wrapper functionality added by FML) we generate the
|
||||
* list just once per environment and cache the result.
|
||||
*/
|
||||
private void buildTransformerDelegationList() {
|
||||
MixinEnvironment.logger.debug("Rebuilding transformer delegation list:");
|
||||
this.transformers = new ArrayList<ILegacyClassTransformer>();
|
||||
for (ITransformer transformer : this.service.getTransformers()) {
|
||||
if (!(transformer instanceof ILegacyClassTransformer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ILegacyClassTransformer legacyTransformer = (ILegacyClassTransformer)transformer;
|
||||
String transformerName = legacyTransformer.getName();
|
||||
boolean include = true;
|
||||
for (String excludeClass : MixinEnvironment.excludeTransformers) {
|
||||
if (transformerName.contains(excludeClass)) {
|
||||
include = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (include && !legacyTransformer.isDelegationExcluded()) {
|
||||
MixinEnvironment.logger.debug(" Adding: {}", transformerName);
|
||||
this.transformers.add(legacyTransformer);
|
||||
} else {
|
||||
MixinEnvironment.logger.debug(" Excluding: {}", transformerName);
|
||||
}
|
||||
}
|
||||
|
||||
MixinEnvironment.logger.debug("Transformer delegation list created with {} entries", this.transformers.size());
|
||||
MixinEnvironment.logger.warn("MixinEnvironment::addTransformerExclusion is deprecated!");
|
||||
this.service.addTransformerExclusion(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -1350,13 +1289,18 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*
|
||||
* @param phase initial phase
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void init(Phase phase) {
|
||||
if (MixinEnvironment.currentPhase == Phase.NOT_INITIALISED) {
|
||||
MixinEnvironment.currentPhase = phase;
|
||||
MixinEnvironment env = MixinEnvironment.getEnvironment(phase);
|
||||
MixinEnvironment.getProfiler().setActive(env.getOption(Option.DEBUG_PROFILER));
|
||||
|
||||
MixinLogWatcher.begin();
|
||||
// AMS - Temp wiring to avoid merging multiphase
|
||||
IMixinService service = MixinService.getService();
|
||||
if (service instanceof MixinServiceAbstract) {
|
||||
((MixinServiceAbstract)service).wire(phase, new PhaseConsumer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1440,20 +1384,24 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
*
|
||||
* @param phase phase to go to
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
static void gotoPhase(Phase phase) {
|
||||
if (phase == null || phase.ordinal < 0) {
|
||||
throw new IllegalArgumentException("Cannot go to the specified phase, phase is null or invalid");
|
||||
}
|
||||
|
||||
IMixinService service = MixinService.getService();
|
||||
if (phase.ordinal > MixinEnvironment.getCurrentPhase().ordinal) {
|
||||
MixinService.getService().beginPhase();
|
||||
}
|
||||
|
||||
if (phase == Phase.DEFAULT) {
|
||||
MixinLogWatcher.end();
|
||||
service.beginPhase();
|
||||
}
|
||||
|
||||
MixinEnvironment.currentPhase = phase;
|
||||
MixinEnvironment.currentEnvironment = MixinEnvironment.getEnvironment(MixinEnvironment.getCurrentPhase());
|
||||
|
||||
// AMS - Temp wiring to avoid merging multiphase
|
||||
if (service instanceof MixinServiceAbstract && phase == Phase.DEFAULT) {
|
||||
((MixinServiceAbstract)service).unwire();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ import java.util.Set;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.launch.GlobalProperties.Keys;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.Config;
|
||||
|
||||
/**
|
||||
@@ -49,7 +52,7 @@ public final class Mixins {
|
||||
/**
|
||||
* GlobalProperties key storing mixin configs which are pending
|
||||
*/
|
||||
private static final String CONFIGS_KEY = GlobalProperties.Keys.CONFIGS + ".queue";
|
||||
private static final Keys CONFIGS_KEY = Keys.of(GlobalProperties.Keys.CONFIGS + ".queue");
|
||||
|
||||
/**
|
||||
* Error handlers for environment
|
||||
@@ -157,6 +160,21 @@ public final class Mixins {
|
||||
}
|
||||
return mixinConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about mixins applied to the specified class in the
|
||||
* current session.
|
||||
*
|
||||
* @param className Name of class to retrieve mixins for
|
||||
* @return Set of applied mixins
|
||||
*/
|
||||
public static Set<IMixinInfo> getMixinsForClass(String className) {
|
||||
ClassInfo classInfo = ClassInfo.fromCache(className);
|
||||
if (classInfo != null) {
|
||||
return classInfo.getAppliedMixins();
|
||||
}
|
||||
return Collections.<IMixinInfo>emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a gloabl error handler class
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.connect;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
|
||||
/**
|
||||
* A connector class is a bootstrap agent for a mixin consumer. It should call
|
||||
* back against {@link Mixins} to register its resources much like previous
|
||||
* "CoreMod" bootstraps.
|
||||
*/
|
||||
public interface IMixinConnector {
|
||||
|
||||
/**
|
||||
* Connect to Mixin
|
||||
*/
|
||||
public abstract void connect();
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.asm.mixin.extensibility;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
/**
|
||||
* <p>A companion plugin for a mixin configuration object. Objects implementing
|
||||
@@ -121,4 +121,5 @@ public interface IMixinConfigPlugin {
|
||||
* @param mixinInfo Information about this mixin
|
||||
*/
|
||||
public abstract void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo);
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ package org.spongepowered.asm.mixin.extensibility;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,10 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
* return the field type and take no arguments) or a setter (must take an
|
||||
* argument of the field type and return void). The annotated method must be
|
||||
* <tt>abstract</tt>.
|
||||
*
|
||||
* <p>The target field for an accessor can be specified as part of the decorated
|
||||
* method name (eg. <tt>setFoo</tt> or <tt>getFoo</tt> to provide accessors for
|
||||
* a target field <tt>foo</tt>) or specified in the annotation value.</p>
|
||||
*
|
||||
* <p>Accessors provide a simple way of gaining access to internal class members
|
||||
* in a target class without needing to resort to access transformers, and
|
||||
|
||||
@@ -26,9 +26,12 @@ package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
* Base class for accessor generators
|
||||
@@ -39,9 +42,23 @@ public abstract class AccessorGenerator {
|
||||
* Accessor info which describes the accessor
|
||||
*/
|
||||
protected final AccessorInfo info;
|
||||
|
||||
public AccessorGenerator(AccessorInfo info) {
|
||||
|
||||
/**
|
||||
* True for static field, false for instance field
|
||||
*/
|
||||
protected final boolean targetIsStatic;
|
||||
|
||||
public AccessorGenerator(AccessorInfo info, boolean isStatic) {
|
||||
this.info = info;
|
||||
this.targetIsStatic = isStatic;
|
||||
}
|
||||
|
||||
protected void checkModifiers() {
|
||||
if (this.info.isStatic() && !this.targetIsStatic) {
|
||||
IMixinContext context = this.info.getContext();
|
||||
throw new InvalidInjectionException(context, String.format("%s is invalid. Accessor method is%s static but the target is not.",
|
||||
this.info, this.info.isStatic() ? "" : " not"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,8 +70,8 @@ public abstract class AccessorGenerator {
|
||||
*/
|
||||
protected final MethodNode createMethod(int maxLocals, int maxStack) {
|
||||
MethodNode method = this.info.getMethod();
|
||||
MethodNode accessor = new MethodNode(Opcodes.ASM5, (method.access & ~Opcodes.ACC_ABSTRACT) | Opcodes.ACC_SYNTHETIC, method.name, method.desc,
|
||||
null, null);
|
||||
MethodNode accessor = new MethodNode(Bytecode.ASM_API_VERSION, (method.access & ~Opcodes.ACC_ABSTRACT) | Opcodes.ACC_SYNTHETIC, method.name,
|
||||
method.desc, null, null);
|
||||
accessor.visibleAnnotations = new ArrayList<AnnotationNode>();
|
||||
accessor.visibleAnnotations.add(this.info.getAnnotation());
|
||||
accessor.maxLocals = maxLocals;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.FieldNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
* Accessor generator for field accessors
|
||||
@@ -43,16 +43,11 @@ public abstract class AccessorGeneratorField extends AccessorGenerator {
|
||||
*/
|
||||
protected final Type targetType;
|
||||
|
||||
/**
|
||||
* True for instance field, false for static field
|
||||
*/
|
||||
protected final boolean isInstanceField;
|
||||
|
||||
public AccessorGeneratorField(AccessorInfo info) {
|
||||
super(info);
|
||||
super(info, Bytecode.isStatic(info.getTargetField()));
|
||||
this.targetField = info.getTargetField();
|
||||
this.targetType = info.getTargetFieldType();
|
||||
this.isInstanceField = (this.targetField.access & Opcodes.ACC_STATIC) == 0;
|
||||
this.checkModifiers();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,11 +24,11 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.FieldInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
/**
|
||||
* Generator for instance field getters
|
||||
@@ -45,10 +45,10 @@ public class AccessorGeneratorFieldGetter extends AccessorGeneratorField {
|
||||
@Override
|
||||
public MethodNode generate() {
|
||||
MethodNode method = this.createMethod(this.targetType.getSize(), this.targetType.getSize());
|
||||
if (this.isInstanceField) {
|
||||
if (!this.targetIsStatic) {
|
||||
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
}
|
||||
int opcode = this.isInstanceField ? Opcodes.GETFIELD : Opcodes.GETSTATIC;
|
||||
int opcode = this.targetIsStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD;
|
||||
method.instructions.add(new FieldInsnNode(opcode, this.info.getClassNode().name, this.targetField.name, this.targetField.desc));
|
||||
method.instructions.add(new InsnNode(this.targetType.getOpcode(Opcodes.IRETURN)));
|
||||
return method;
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.FieldInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
/**
|
||||
* Generator for field setters
|
||||
@@ -44,15 +44,15 @@ public class AccessorGeneratorFieldSetter extends AccessorGeneratorField {
|
||||
*/
|
||||
@Override
|
||||
public MethodNode generate() {
|
||||
int stackSpace = this.isInstanceField ? 1 : 0;
|
||||
int stackSpace = this.targetIsStatic ? 0 : 1; // Stack space for "this"
|
||||
int maxLocals = stackSpace + this.targetType.getSize();
|
||||
int maxStack = stackSpace + this.targetType.getSize();
|
||||
MethodNode method = this.createMethod(maxLocals, maxStack);
|
||||
if (this.isInstanceField) {
|
||||
if (!this.targetIsStatic) {
|
||||
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
}
|
||||
method.instructions.add(new VarInsnNode(this.targetType.getOpcode(Opcodes.ILOAD), stackSpace));
|
||||
int opcode = this.isInstanceField ? Opcodes.PUTFIELD : Opcodes.PUTSTATIC;
|
||||
int opcode = this.targetIsStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD;
|
||||
method.instructions.add(new FieldInsnNode(opcode, this.info.getClassNode().name, this.targetField.name, this.targetField.desc));
|
||||
method.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||
return method;
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
@@ -40,41 +40,43 @@ public class AccessorGeneratorMethodProxy extends AccessorGenerator {
|
||||
/**
|
||||
* The target field, identified by the accessor info
|
||||
*/
|
||||
private final MethodNode targetMethod;
|
||||
protected final MethodNode targetMethod;
|
||||
|
||||
/**
|
||||
* Accessor method argument types (raw, from method)
|
||||
*/
|
||||
private final Type[] argTypes;
|
||||
protected final Type[] argTypes;
|
||||
|
||||
/**
|
||||
* Accessor method return type (raw, from method)
|
||||
*/
|
||||
private final Type returnType;
|
||||
|
||||
/**
|
||||
* True for instance method, false for static method
|
||||
*/
|
||||
private final boolean isInstanceMethod;
|
||||
protected final Type returnType;
|
||||
|
||||
public AccessorGeneratorMethodProxy(AccessorInfo info) {
|
||||
super(info);
|
||||
super(info, Bytecode.isStatic(info.getTargetMethod()));
|
||||
this.targetMethod = info.getTargetMethod();
|
||||
this.argTypes = info.getArgTypes();
|
||||
this.returnType = info.getReturnType();
|
||||
this.checkModifiers();
|
||||
}
|
||||
|
||||
protected AccessorGeneratorMethodProxy(AccessorInfo info, boolean isStatic) {
|
||||
super(info, isStatic);
|
||||
this.targetMethod = info.getTargetMethod();
|
||||
this.argTypes = info.getArgTypes();
|
||||
this.returnType = info.getReturnType();
|
||||
this.isInstanceMethod = !Bytecode.hasFlag(this.targetMethod, Opcodes.ACC_STATIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodNode generate() {
|
||||
int size = Bytecode.getArgsSize(this.argTypes) + this.returnType.getSize() + (this.isInstanceMethod ? 1 : 0);
|
||||
int size = Bytecode.getArgsSize(this.argTypes) + this.returnType.getSize() + (this.targetIsStatic ? 0 : 1);
|
||||
MethodNode method = this.createMethod(size, size);
|
||||
if (this.isInstanceMethod) {
|
||||
if (!this.targetIsStatic) {
|
||||
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
}
|
||||
Bytecode.loadArgs(this.argTypes, method.instructions, this.isInstanceMethod ? 1 : 0);
|
||||
Bytecode.loadArgs(this.argTypes, method.instructions, this.targetIsStatic ? 0 : 1);
|
||||
boolean isPrivate = Bytecode.hasFlag(this.targetMethod, Opcodes.ACC_PRIVATE);
|
||||
int opcode = this.isInstanceMethod ? (isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL) : Opcodes.INVOKESTATIC;
|
||||
int opcode = this.targetIsStatic ? (isPrivate ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL) : Opcodes.INVOKESTATIC;
|
||||
method.instructions.add(new MethodInsnNode(opcode, this.info.getClassNode().name, this.targetMethod.name, this.targetMethod.desc, false));
|
||||
method.instructions.add(new InsnNode(this.returnType.getOpcode(Opcodes.IRETURN)));
|
||||
return method;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.gen;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
/**
|
||||
* Generator for factory methods (constructor invokers)
|
||||
*/
|
||||
public class AccessorGeneratorObjectFactory extends AccessorGeneratorMethodProxy {
|
||||
|
||||
public AccessorGeneratorObjectFactory(AccessorInfo info) {
|
||||
super(info, true);
|
||||
if (!info.isStatic()) {
|
||||
throw new InvalidInjectionException(info.getContext(), String.format("%s is invalid. Factory method must be static.", this.info));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodNode generate() {
|
||||
int returnSize = this.returnType.getSize();
|
||||
// size includes return size x2 since we immediately DUP the value to invoke the ctor on it
|
||||
int size = Bytecode.getArgsSize(this.argTypes) + (returnSize * 2);
|
||||
MethodNode method = this.createMethod(size, size);
|
||||
|
||||
String className = this.info.getClassNode().name;
|
||||
method.instructions.add(new TypeInsnNode(Opcodes.NEW, className));
|
||||
method.instructions.add(new InsnNode(returnSize == 1 ? Opcodes.DUP : Opcodes.DUP2));
|
||||
Bytecode.loadArgs(this.argTypes, method.instructions, 0);
|
||||
method.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, className, Constants.CTOR, this.targetMethod.desc, false));
|
||||
method.instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||
|
||||
assert 1 == 3;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,24 +26,31 @@ package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.FieldNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector.Result;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@@ -86,6 +93,16 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
AccessorGenerator getGenerator(AccessorInfo info) {
|
||||
return new AccessorGeneratorMethodProxy(info);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* An invoker (proxy) method
|
||||
*/
|
||||
OBJECT_FACTORY(ImmutableSet.<String>of("new", "create")) {
|
||||
@Override
|
||||
AccessorGenerator getGenerator(AccessorInfo info) {
|
||||
return new AccessorGeneratorObjectFactory(info);
|
||||
}
|
||||
};
|
||||
|
||||
private final Set<String> expectedPrefixes;
|
||||
@@ -112,17 +129,111 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
* @return string representation of expected prefixes for this accessor
|
||||
* type
|
||||
*/
|
||||
public String getExpectedPrefixes() {
|
||||
return this.expectedPrefixes.toString();
|
||||
public Set<String> getExpectedPrefixes() {
|
||||
return Collections.<String>unmodifiableSet(this.expectedPrefixes);
|
||||
}
|
||||
|
||||
abstract AccessorGenerator getGenerator(AccessorInfo info);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern for matching accessor names (for inflector)
|
||||
* Accessor Name struct
|
||||
*/
|
||||
protected static final Pattern PATTERN_ACCESSOR = Pattern.compile("^(get|set|is|invoke|call)(([A-Z])(.*?))(_\\$md.*)?$");
|
||||
public static final class AccessorName {
|
||||
|
||||
/**
|
||||
* Pattern for matching accessor names (for inflector)
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile("^(" + AccessorName.getPrefixList() + ")(([A-Z])(.*?))(_\\$md.*)?$");
|
||||
|
||||
/**
|
||||
* Name of the accessor method
|
||||
*/
|
||||
public final String methodName;
|
||||
|
||||
/**
|
||||
* Accessor prefix
|
||||
*/
|
||||
public final String prefix;
|
||||
|
||||
/**
|
||||
* Accessor name part
|
||||
*/
|
||||
public final String name;
|
||||
|
||||
private AccessorName(String methodName, String prefix, String name) {
|
||||
this.methodName = methodName;
|
||||
this.prefix = prefix;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an accessor name from the supplied string. If the string matches
|
||||
* the accessor name regex, split the string into the relevant parts
|
||||
*
|
||||
* @param methodName Name of the accessor method
|
||||
* @return Parsed AccessorName struct or null if the name is not a valid
|
||||
* accessor name
|
||||
*/
|
||||
public static AccessorName of(String methodName) {
|
||||
return AccessorName.of(methodName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an accessor name from the supplied string. If the string matches
|
||||
* the accessor name regex, split the string into the relevant parts
|
||||
*
|
||||
* @param methodName Name of the accessor method
|
||||
* @param toMemberCase True if the first character of the name should be
|
||||
* conditionally converted to lowercase. If the name is all
|
||||
* uppercase (eg. if the NAME_IS_A_CONSTANT) the first character
|
||||
* will not be lowercased, regardless of the state of this argument
|
||||
* @return Parsed AccessorName struct or null if the name is not a valid
|
||||
* accessor name
|
||||
*/
|
||||
public static AccessorName of(String methodName, boolean toMemberCase) {
|
||||
Matcher nameMatcher = AccessorName.PATTERN.matcher(methodName);
|
||||
if (nameMatcher.matches()) {
|
||||
String prefix = nameMatcher.group(1);
|
||||
String namePart = nameMatcher.group(2);
|
||||
String firstChar = nameMatcher.group(3);
|
||||
String remainder = nameMatcher.group(4);
|
||||
boolean nameIsUpperCase = AccessorName.isUpperCase(Locale.ROOT, namePart);
|
||||
// If the entire name is upper case, do not lowercase the first char
|
||||
String name = String.format("%s%s", AccessorName.toLowerCaseIf(Locale.ROOT, firstChar, toMemberCase && !nameIsUpperCase), remainder);
|
||||
return new AccessorName(methodName, prefix, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isUpperCase(Locale locale, String string) {
|
||||
return string.toUpperCase(locale).equals(string);
|
||||
}
|
||||
|
||||
private static String toLowerCaseIf(Locale locale, String string, boolean condition) {
|
||||
return condition ? string.toLowerCase(locale) : string;
|
||||
}
|
||||
|
||||
private static String getPrefixList() {
|
||||
List<String> prefixes = new ArrayList<String>();
|
||||
for (AccessorType type : AccessorType.values()) {
|
||||
prefixes.addAll(type.getExpectedPrefixes());
|
||||
}
|
||||
return Joiner.on('|').join(prefixes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation class
|
||||
*/
|
||||
protected final Class<? extends Annotation> annotationClass;
|
||||
|
||||
/**
|
||||
* Accessor method argument types (raw, from method)
|
||||
@@ -134,6 +245,16 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
*/
|
||||
protected final Type returnType;
|
||||
|
||||
/**
|
||||
* Accessor method staticness
|
||||
*/
|
||||
protected final boolean isStatic;
|
||||
|
||||
/**
|
||||
* Name specified in the attached annotation, can be null
|
||||
*/
|
||||
protected final String specifiedName;
|
||||
|
||||
/**
|
||||
* Type of accessor to generate, computed based on the signature of the
|
||||
* target method.
|
||||
@@ -149,7 +270,7 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
* Computed information about the target field or method, name and
|
||||
* descriptor
|
||||
*/
|
||||
protected final MemberInfo target;
|
||||
protected final ITargetSelector target;
|
||||
|
||||
/**
|
||||
* For accessors, stores the discovered target field
|
||||
@@ -167,8 +288,11 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
|
||||
protected AccessorInfo(MixinTargetContext mixin, MethodNode method, Class<? extends Annotation> annotationClass) {
|
||||
super(mixin, method, Annotations.getVisible(method, annotationClass));
|
||||
this.annotationClass = annotationClass;
|
||||
this.argTypes = Type.getArgumentTypes(method.desc);
|
||||
this.returnType = Type.getReturnType(method.desc);
|
||||
this.isStatic = Bytecode.isStatic(method);
|
||||
this.specifiedName = Annotations.<String>getValue(this.annotation);
|
||||
this.type = this.initType();
|
||||
this.targetFieldType = this.initTargetFieldType();
|
||||
this.target = this.initTarget();
|
||||
@@ -200,22 +324,22 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
}
|
||||
}
|
||||
|
||||
protected MemberInfo initTarget() {
|
||||
MemberInfo target = new MemberInfo(this.getTargetName(), null, this.targetFieldType.getDescriptor());
|
||||
protected ITargetSelector initTarget() {
|
||||
MemberInfo target = new MemberInfo(this.getTargetName(this.specifiedName), null, this.targetFieldType.getDescriptor());
|
||||
this.annotation.visit("target", target.toString());
|
||||
return target;
|
||||
}
|
||||
|
||||
protected String getTargetName() {
|
||||
String name = Annotations.<String>getValue(this.annotation);
|
||||
protected String getTargetName(String name) {
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
String inflectedTarget = this.inflectTarget();
|
||||
if (inflectedTarget == null) {
|
||||
throw new InvalidAccessorException(this.mixin, "Failed to inflect target name for " + this + ", supported prefixes: [get, set, is]");
|
||||
throw new InvalidAccessorException(this.mixin, String.format("Failed to inflect target name for %s, supported prefixes: %s",
|
||||
this, this.type.getExpectedPrefixes()));
|
||||
}
|
||||
return inflectedTarget;
|
||||
}
|
||||
return MemberInfo.parse(name, this.mixin).name;
|
||||
return TargetSelector.parseName(name, this.mixin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,31 +359,45 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
* named <tt>getFoo</tt> to be inflected to a target named <tt>foo</tt> for
|
||||
* example.
|
||||
*
|
||||
* @param accessorName Name of the accessor method
|
||||
* @param accessorType Type of accessor being processed, this is calculated
|
||||
* @param name Name of the accessor method
|
||||
* @param type Type of accessor being processed, this is calculated
|
||||
* from the method signature (<tt>void</tt> methods being setters,
|
||||
* methods with return types being getters)
|
||||
* @param accessorDescription description of the accessor to include in
|
||||
* @param description description of the accessor to include in
|
||||
* error messages
|
||||
* @param context Mixin context
|
||||
* @param verbose Emit warnings when accessor prefix doesn't match type
|
||||
* @return inflected target member name or <tt>null</tt> if name cannot be
|
||||
* inflected
|
||||
*/
|
||||
public static String inflectTarget(String accessorName, AccessorType accessorType, String accessorDescription,
|
||||
IMixinContext context, boolean verbose) {
|
||||
Matcher nameMatcher = AccessorInfo.PATTERN_ACCESSOR.matcher(accessorName);
|
||||
if (nameMatcher.matches()) {
|
||||
String prefix = nameMatcher.group(1);
|
||||
String firstChar = nameMatcher.group(3);
|
||||
String remainder = nameMatcher.group(4);
|
||||
// If the entire name is upper case, do not lowercase the first char
|
||||
String name = String.format("%s%s", AccessorInfo.toLowerCase(firstChar, !AccessorInfo.isUpperCase(remainder)), remainder);
|
||||
if (!accessorType.isExpectedPrefix(prefix) && verbose) {
|
||||
LogManager.getLogger("mixin").warn("Unexpected prefix for {}, found [{}] expecting {}", accessorDescription, prefix,
|
||||
accessorType.getExpectedPrefixes());
|
||||
public static String inflectTarget(String name, AccessorType type, String description, IMixinContext context, boolean verbose) {
|
||||
return AccessorInfo.inflectTarget(AccessorName.of(name), type, description, context, verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the name of an accessor method and the accessor type to try and
|
||||
* inflect the name of the target field or method. This allows a method
|
||||
* named <tt>getFoo</tt> to be inflected to a target named <tt>foo</tt> for
|
||||
* example.
|
||||
*
|
||||
* @param name Name of the accessor method
|
||||
* @param type Type of accessor being processed, this is calculated
|
||||
* from the method signature (<tt>void</tt> methods being setters,
|
||||
* methods with return types being getters)
|
||||
* @param description description of the accessor to include in
|
||||
* error messages
|
||||
* @param context Mixin context
|
||||
* @param verbose Emit warnings when accessor prefix doesn't match type
|
||||
* @return inflected target member name or <tt>null</tt> if name cannot be
|
||||
* inflected
|
||||
*/
|
||||
public static String inflectTarget(AccessorName name, AccessorType type, String description, IMixinContext context, boolean verbose) {
|
||||
if (name != null) {
|
||||
if (!type.isExpectedPrefix(name.prefix) && verbose) {
|
||||
LogManager.getLogger("mixin").warn("Unexpected prefix for {}, found [{}] expecting {}", description, name.prefix,
|
||||
type.getExpectedPrefixes());
|
||||
}
|
||||
return MemberInfo.parse(name, context).name;
|
||||
return TargetSelector.parseName(name.name, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -267,7 +405,7 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
/**
|
||||
* Get the inflected/specified target member for this accessor
|
||||
*/
|
||||
public final MemberInfo getTarget() {
|
||||
public final ITargetSelector getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
@@ -305,10 +443,18 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
public final Type[] getArgTypes() {
|
||||
return this.argTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the accessor itself is static
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return this.isStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s->@%s[%s]::%s%s", this.mixin.toString(), Bytecode.getSimpleName(this.annotation), this.type.toString(),
|
||||
String typeString = this.type != null ? this.type.toString() : "UNPARSED_ACCESSOR";
|
||||
return String.format("%s->@%s[%s]::%s%s", this.mixin, Bytecode.getSimpleName(this.annotation), typeString,
|
||||
this.method.name, this.method.desc);
|
||||
}
|
||||
|
||||
@@ -330,12 +476,12 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
*/
|
||||
public MethodNode generate() {
|
||||
MethodNode generatedAccessor = this.type.getGenerator(this).generate();
|
||||
Bytecode.mergeAnnotations(this.method, generatedAccessor);
|
||||
Annotations.merge(this.method, generatedAccessor);
|
||||
return generatedAccessor;
|
||||
}
|
||||
|
||||
private FieldNode findTargetField() {
|
||||
return this.<FieldNode>findTarget(this.classNode.fields);
|
||||
return this.<FieldNode>findTarget(ElementNode.fieldList(this.classNode));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,49 +492,14 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
* @param <TNode> node type
|
||||
* @return best match
|
||||
*/
|
||||
protected <TNode> TNode findTarget(List<TNode> nodes) {
|
||||
TNode exactMatch = null;
|
||||
List<TNode> candidates = new ArrayList<TNode>();
|
||||
|
||||
for (TNode node : nodes) {
|
||||
String desc = AccessorInfo.<TNode>getNodeDesc(node);
|
||||
if (desc == null || !desc.equals(this.target.desc)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = AccessorInfo.<TNode>getNodeName(node);
|
||||
if (name != null) {
|
||||
if (name.equals(this.target.name)) {
|
||||
exactMatch = node;
|
||||
}
|
||||
if (name.equalsIgnoreCase(this.target.name)) {
|
||||
candidates.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exactMatch != null) {
|
||||
if (candidates.size() > 1) {
|
||||
LogManager.getLogger("mixin").debug("{} found an exact match for {} but other candidates were found!", this, this.target);
|
||||
}
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
if (candidates.size() == 1) {
|
||||
return candidates.get(0);
|
||||
}
|
||||
|
||||
String number = candidates.size() == 0 ? "No" : "Multiple";
|
||||
throw new InvalidAccessorException(this, number + " candidates were found matching " + this.target + " in " + this.classNode.name
|
||||
+ " for " + this);
|
||||
}
|
||||
|
||||
private static <TNode> String getNodeDesc(TNode node) {
|
||||
return (node instanceof MethodNode) ? ((MethodNode)node).desc : ((node instanceof FieldNode) ? ((FieldNode)node).desc : null);
|
||||
}
|
||||
protected <TNode> TNode findTarget(List<ElementNode<TNode>> nodes) {
|
||||
Result<TNode> result = TargetSelector.<TNode>run(this.target.configure("orphan"), nodes);
|
||||
|
||||
private static <TNode> String getNodeName(TNode node) {
|
||||
return (node instanceof MethodNode) ? ((MethodNode)node).name : ((node instanceof FieldNode) ? ((FieldNode)node).name : null);
|
||||
try {
|
||||
return result.getSingleResult(true);
|
||||
} catch (IllegalStateException ex) {
|
||||
throw new InvalidAccessorException(this, ex.getMessage() + " matching " + this.target + " in " + this.classNode.name + " for " + this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,12 +520,4 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
throw new InvalidAccessorException(mixin, "Could not parse accessor for unknown type " + type.getName());
|
||||
}
|
||||
|
||||
private static String toLowerCase(String string, boolean condition) {
|
||||
return condition ? string.toLowerCase() : string;
|
||||
}
|
||||
|
||||
private static boolean isUpperCase(String string) {
|
||||
return string.toUpperCase().equals(string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,12 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
* a mixin, the method. The annotated method must be <tt>abstract</tt> and the
|
||||
* signature of the method must match the target method precisely.
|
||||
*
|
||||
* <p>The target method for an accessor can be specified as part of the
|
||||
* decorated method name (eg. <tt>callFoo</tt> to invoke a target method named
|
||||
* <tt>foo()</tt>) or specified in the annotation value. Invokers for
|
||||
* constructors can be created by specifying <tt><init></tt> in the
|
||||
* annotation or the fully-qualified class name.</p>
|
||||
*
|
||||
* <p>Invokers provide a simple way of gaining access to internal class members
|
||||
* in a target class without needing to resort to access transformers, and
|
||||
* without the usual need to {@link Shadow} a target method. This can both
|
||||
@@ -66,7 +72,8 @@ public @interface Invoker {
|
||||
*
|
||||
* <p>However sometimes it maye be desirable to name an accessor method
|
||||
* differently to the target method. In this case you may specify the method
|
||||
* using its name.</p>
|
||||
* using its name. Use <tt><init></tt> or the fully qualified name of
|
||||
* the target class to invoke a constructor.</p>
|
||||
*
|
||||
* @return name for the target method, or empty string to inflect using the
|
||||
* annotated method name
|
||||
|
||||
@@ -24,42 +24,98 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.gen;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector.Result;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
/**
|
||||
* Information about an invoker
|
||||
*/
|
||||
public class InvokerInfo extends AccessorInfo {
|
||||
|
||||
class InvokerInfo extends AccessorInfo {
|
||||
|
||||
public InvokerInfo(MixinTargetContext mixin, MethodNode method) {
|
||||
super(mixin, method, Invoker.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AccessorType initType() {
|
||||
if (this.specifiedName != null) {
|
||||
String mappedReference = this.mixin.getReferenceMapper().remap(this.mixin.getClassRef(), this.specifiedName);
|
||||
return this.initType(mappedReference.replace('.', '/'), this.mixin.getTargetClassRef());
|
||||
}
|
||||
|
||||
AccessorName accessorName = AccessorName.of(this.method.name, false);
|
||||
if (accessorName != null) {
|
||||
for (String prefix : AccessorType.OBJECT_FACTORY.getExpectedPrefixes()) {
|
||||
if (prefix.equals(accessorName.prefix)) {
|
||||
return this.initType(accessorName.name, this.mixin.getTargetClassInfo().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AccessorType.METHOD_PROXY;
|
||||
}
|
||||
|
||||
private AccessorType initType(String targetName, String targetClassName) {
|
||||
if (Constants.CTOR.equals(targetName) || targetClassName.equals(targetName)) {
|
||||
if (!this.returnType.equals(this.mixin.getTargetClassInfo().getType())) {
|
||||
throw new InvalidAccessorException(this.mixin,
|
||||
String.format("%s appears to have an invalid return type. %s requires matching return type. Found %s expected %s",
|
||||
this, AccessorType.OBJECT_FACTORY, Bytecode.getSimpleName(this.returnType), this.mixin.getTargetClassInfo().getSimpleName()));
|
||||
}
|
||||
if (!this.isStatic) {
|
||||
throw new InvalidAccessorException(this.mixin, String.format("%s for %s must be static", this, AccessorType.OBJECT_FACTORY,
|
||||
Bytecode.getSimpleName(this.returnType)));
|
||||
}
|
||||
|
||||
return AccessorType.OBJECT_FACTORY;
|
||||
}
|
||||
return AccessorType.METHOD_PROXY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Type initTargetFieldType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MemberInfo initTarget() {
|
||||
return new MemberInfo(this.getTargetName(), null, this.method.desc);
|
||||
protected ITargetSelector initTarget() {
|
||||
if (this.type == AccessorType.OBJECT_FACTORY) {
|
||||
return new MemberInfo(Constants.CTOR, null, Bytecode.changeDescriptorReturnType(this.method.desc, "V"));
|
||||
}
|
||||
|
||||
return new MemberInfo(this.getTargetName(this.specifiedName), null, this.method.desc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void locate() {
|
||||
this.targetMethod = this.findTargetMethod();
|
||||
}
|
||||
|
||||
private MethodNode findTargetMethod() {
|
||||
return this.<MethodNode>findTarget(this.classNode.methods);
|
||||
Result<MethodNode> result = TargetSelector.<MethodNode>run(this.target.configure("orphan"), ElementNode.methodList(this.classNode));
|
||||
|
||||
try {
|
||||
return result.getSingleResult(true);
|
||||
} catch (IllegalStateException ex) {
|
||||
String message = ex.getMessage() + " matching " + this.target + " in " + this.classNode.name + " for " + this;
|
||||
if (this.type == AccessorType.METHOD_PROXY && this.specifiedName != null && this.target instanceof ITargetSelectorByName) {
|
||||
String name = ((ITargetSelectorByName)this.target).getName();
|
||||
if (name != null && (name.contains(".") || name.contains("/"))) {
|
||||
throw new InvalidAccessorException(this, "Invalid factory invoker failed to match the target class. " + message);
|
||||
}
|
||||
}
|
||||
throw new InvalidAccessorException(this, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -200,4 +200,5 @@ public @interface At {
|
||||
* obfuscation mappings for this annotation
|
||||
*/
|
||||
public boolean remap() default true;
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.asm.mixin.injection;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
/**
|
||||
* Annotation for specifying the injection point for an {@link ModifyConstant}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ 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.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -56,8 +57,8 @@ public @interface Inject {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
|
||||
@@ -39,12 +39,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInjector;
|
||||
import org.spongepowered.asm.mixin.injection.modify.AfterStoreLocal;
|
||||
import org.spongepowered.asm.mixin.injection.modify.BeforeLoadLocal;
|
||||
import org.spongepowered.asm.mixin.injection.points.*;
|
||||
@@ -754,4 +755,5 @@ public abstract class InjectionPoint {
|
||||
|
||||
InjectionPoint.types.put(code.value(), type);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -74,8 +75,8 @@ public @interface ModifyArg {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
@@ -92,7 +93,7 @@ public @interface ModifyArg {
|
||||
/**
|
||||
* An {@link At} annotation which describes the {@link InjectionPoint} in
|
||||
* the target method. The specified {@link InjectionPoint} <i>must only</i>
|
||||
* return {@link org.spongepowered.asm.lib.tree.MethodInsnNode} instances
|
||||
* return {@link org.objectweb.asm.tree.MethodInsnNode} instances
|
||||
* and an exception will be thrown if this is not the case.
|
||||
*
|
||||
* @return {@link At} which identifies the target method invocation
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -79,8 +80,8 @@ public @interface ModifyArgs {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
@@ -97,7 +98,7 @@ public @interface ModifyArgs {
|
||||
/**
|
||||
* An {@link At} annotation which describes the {@link InjectionPoint} in
|
||||
* the target method. The specified {@link InjectionPoint} <i>must only</i>
|
||||
* return {@link org.spongepowered.asm.lib.tree.MethodInsnNode} instances
|
||||
* return {@link org.objectweb.asm.tree.MethodInsnNode} instances
|
||||
* and an exception will be thrown if this is not the case.
|
||||
*
|
||||
* @return {@link At} which identifies the target method invocation
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -61,8 +62,8 @@ public @interface ModifyConstant {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -69,8 +70,8 @@ public @interface ModifyVariable {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
@@ -87,7 +88,7 @@ public @interface ModifyVariable {
|
||||
/**
|
||||
* An {@link At} annotation which describes the {@link InjectionPoint} in
|
||||
* the target method. The specified {@link InjectionPoint} <i>must only</i>
|
||||
* return {@link org.spongepowered.asm.lib.tree.MethodInsnNode} instances
|
||||
* return {@link org.objectweb.asm.tree.MethodInsnNode} instances
|
||||
* and an exception will be thrown if this is not the case.
|
||||
*
|
||||
* @return {@link At} which identifies the target method invocation
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
@@ -228,8 +229,8 @@ public @interface Redirect {
|
||||
|
||||
/**
|
||||
* String representation of one or more
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo
|
||||
* MemberInfo} which identify the target methods.
|
||||
* {@link ITargetSelector target selectors} which identify the target
|
||||
* methods.
|
||||
*
|
||||
* @return target method(s) for this injector
|
||||
*/
|
||||
@@ -246,7 +247,7 @@ public @interface Redirect {
|
||||
/**
|
||||
* An {@link At} annotation which describes the {@link InjectionPoint} in
|
||||
* the target method. The specified {@link InjectionPoint} <i>must only</i>
|
||||
* return {@link org.spongepowered.asm.lib.tree.MethodInsnNode} and an
|
||||
* return {@link org.objectweb.asm.tree.MethodInsnNode} and an
|
||||
* exception will be thrown if this is not the case.
|
||||
*
|
||||
* @return {@link At} which identifies the target method invocation
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.callback;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
@@ -128,14 +128,14 @@ public class CallbackInfo implements Cancellable {
|
||||
}
|
||||
|
||||
if (returnType.getSort() == Type.OBJECT || returnType.getSort() == Type.ARRAY) {
|
||||
return String.format("(%sZ%s)V", Constants.STRING, Constants.OBJECT);
|
||||
return String.format("(%sZ%s)V", Constants.STRING_DESC, Constants.OBJECT_DESC);
|
||||
}
|
||||
|
||||
return String.format("(%sZ%s)V", Constants.STRING, returnType.getDescriptor());
|
||||
return String.format("(%sZ%s)V", Constants.STRING_DESC, returnType.getDescriptor());
|
||||
}
|
||||
|
||||
static String getConstructorDescriptor() {
|
||||
return String.format("(%sZ)V", Constants.STRING);
|
||||
return String.format("(%sZ)V", Constants.STRING_DESC);
|
||||
}
|
||||
|
||||
static String getIsCancelledMethodName() {
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.callback;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
/**
|
||||
@@ -134,7 +134,7 @@ public class CallbackInfoReturnable<R> extends CallbackInfo {
|
||||
|
||||
static String getReturnDescriptor(Type returnType) {
|
||||
if (returnType.getSort() == Type.OBJECT || returnType.getSort() == Type.ARRAY) {
|
||||
return String.format("()%s", Constants.OBJECT);
|
||||
return String.format("()%s", Constants.OBJECT_DESC);
|
||||
}
|
||||
|
||||
return String.format("()%s", returnType.getDescriptor());
|
||||
|
||||
@@ -30,9 +30,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.*;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.*;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.Surrogate;
|
||||
@@ -370,7 +370,7 @@ public class CallbackInjector extends Injector {
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.code.Injector#addTargetNode(
|
||||
* org.spongepowered.asm.mixin.injection.struct.Target, java.util.List,
|
||||
* org.spongepowered.asm.lib.tree.AbstractInsnNode, java.util.Set)
|
||||
* org.objectweb.asm.tree.AbstractInsnNode, java.util.Set)
|
||||
*/
|
||||
@Override
|
||||
protected void addTargetNode(Target target, List<InjectionNode> myNodes, AbstractInsnNode node, Set<InjectionPoint> nominators) {
|
||||
@@ -624,7 +624,8 @@ public class CallbackInjector extends Injector {
|
||||
return;
|
||||
}
|
||||
|
||||
callback.add(new InsnNode(Opcodes.DUP));
|
||||
int dupCode = callback.target.returnType.getSize() == 1 ? Opcodes.DUP : Opcodes.DUP2;
|
||||
callback.add(new InsnNode(dupCode));
|
||||
callback.add(new VarInsnNode(callback.target.returnType.getOpcode(Opcodes.ISTORE), callback.marshalVar()));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,16 +35,16 @@ import java.util.TreeMap;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.LdcInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
|
||||
@@ -55,6 +55,7 @@ import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.TypeLookup;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Bytecode.DelegateInitialiser;
|
||||
|
||||
@@ -154,7 +155,7 @@ public abstract class Injector {
|
||||
|
||||
this.methodArgs = Type.getArgumentTypes(this.methodNode.desc);
|
||||
this.returnType = Type.getReturnType(this.methodNode.desc);
|
||||
this.isStatic = Bytecode.methodIsStatic(this.methodNode);
|
||||
this.isStatic = Bytecode.isStatic(this.methodNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -376,7 +377,7 @@ public abstract class Injector {
|
||||
*/
|
||||
public static boolean canCoerce(Type from, Type to) {
|
||||
if (from.getSort() == Type.OBJECT && to.getSort() == Type.OBJECT) {
|
||||
return Injector.canCoerce(ClassInfo.forType(from), ClassInfo.forType(to));
|
||||
return Injector.canCoerce(ClassInfo.forType(from, TypeLookup.ELEMENT_TYPE), ClassInfo.forType(to, TypeLookup.ELEMENT_TYPE));
|
||||
}
|
||||
|
||||
return Injector.canCoerce(from.getDescriptor(), to.getDescriptor());
|
||||
|
||||
@@ -27,9 +27,9 @@ package org.spongepowered.asm.mixin.injection.code;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
|
||||
@@ -31,10 +31,10 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
@@ -54,7 +54,7 @@ public final class MethodSlice {
|
||||
|
||||
/**
|
||||
* A read-only wrapper for an {@link InsnList} which only allows the segment
|
||||
* identified by {@link #start} and {@link #end} to be accessed. In essence
|
||||
* identified by <tt>start</tt> and <tt>end</tt> to be accessed. In essence
|
||||
* this class provides a <em>view</em> of the underlying InsnList.
|
||||
*/
|
||||
static final class InsnListSlice extends ReadOnlyInsnList {
|
||||
@@ -255,7 +255,7 @@ public final class MethodSlice {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.code.ReadOnlyInsnList
|
||||
* #contains(org.spongepowered.asm.lib.tree.AbstractInsnNode)
|
||||
* #contains(org.objectweb.asm.tree.AbstractInsnNode)
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(AbstractInsnNode insn) {
|
||||
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.asm.mixin.injection.code;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidSliceException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
@@ -26,8 +26,8 @@ package org.spongepowered.asm.mixin.injection.code;
|
||||
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
|
||||
/**
|
||||
* Read-only wrapper for InsnList, defensively passed to InjectionPoint
|
||||
|
||||
@@ -26,12 +26,12 @@ package org.spongepowered.asm.mixin.injection.invoke;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
|
||||
@@ -27,9 +27,9 @@ package org.spongepowered.asm.mixin.injection.invoke;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.invoke;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.ArgsClassGenerator;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
@@ -83,7 +83,7 @@ public class ModifyArgsInjector extends InvokeInjector {
|
||||
+ targetMethod.name + targetMethod.desc + " with no arguments!");
|
||||
}
|
||||
|
||||
String clArgs = this.argsClassGenerator.getClassRef(targetMethod.desc);
|
||||
String clArgs = this.argsClassGenerator.getArgsClass(targetMethod.desc, this.info.getContext().getMixin()).getName();
|
||||
boolean withArgs = this.verifyTarget(target);
|
||||
|
||||
InsnList insns = new InsnList();
|
||||
|
||||
+9
-9
@@ -25,15 +25,15 @@
|
||||
package org.spongepowered.asm.mixin.injection.invoke;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
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.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.spongepowered.asm.lib.tree.JumpInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.LocalVariableNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LocalVariableNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.util.InsnFinder;
|
||||
|
||||
@@ -29,9 +29,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.*;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.*;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
|
||||
+130
-116
@@ -27,25 +27,28 @@ package org.spongepowered.asm.mixin.injection.invoke.arg;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.ClassVisitor;
|
||||
import org.spongepowered.asm.lib.ClassWriter;
|
||||
import org.spongepowered.asm.lib.Label;
|
||||
import org.spongepowered.asm.lib.MethodVisitor;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.util.CheckClassAdapter;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.util.CheckClassAdapter;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.transformer.SyntheticClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IClassGenerator;
|
||||
import org.spongepowered.asm.service.ISyntheticClassInfo;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.IConsumer;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
import org.spongepowered.asm.util.asm.MethodVisitorEx;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
/**
|
||||
* Class generator which creates subclasses of {@link Args} to be used by the
|
||||
* {@link ModifyArgs} injector. The subclasses contain getter and setter logic
|
||||
@@ -82,6 +85,43 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
|
||||
private static final String ACE = "org/spongepowered/asm/mixin/injection/invoke/arg/ArgumentCountException";
|
||||
private static final String ACE_CTOR_DESC = "(IILjava/lang/String;)V";
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Synthetic class info for args class
|
||||
*/
|
||||
class ArgsClassInfo extends SyntheticClassInfo {
|
||||
|
||||
final String desc;
|
||||
|
||||
final Type[] args;
|
||||
|
||||
int loaded = 0;
|
||||
|
||||
ArgsClassInfo(IMixinInfo mixin, String name, String desc) {
|
||||
super(mixin, name);
|
||||
this.desc = desc;
|
||||
this.args = Type.getArgumentTypes(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return this.loaded > 0;
|
||||
}
|
||||
|
||||
String getSignature() {
|
||||
return new SignaturePrinter("", null, this.args).setFullyQualified(true).getFormattedArgs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthetic class registry
|
||||
*/
|
||||
private final IConsumer<ISyntheticClassInfo> registry;
|
||||
|
||||
/**
|
||||
* The next subclass number, classes generated in sequence eg.
|
||||
@@ -90,18 +130,24 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
private int nextIndex = 1;
|
||||
|
||||
/**
|
||||
* Map of descriptors to generated class names
|
||||
* Map of descriptors to generated class infos
|
||||
*/
|
||||
private final BiMap<String, String> classNames = HashBiMap.<String, String>create();
|
||||
private final Map<String, ArgsClassInfo> descToClass = new HashMap<String, ArgsClassInfo>();
|
||||
|
||||
/**
|
||||
* Generated bytes. Technically a generator shouldn't have to return class
|
||||
* bytes for a class more than once, but this saves the class being
|
||||
* regenerated if anything causes a second invocation of {@link #generate}
|
||||
* for the same class
|
||||
* Map of class names to generated class infos
|
||||
*/
|
||||
private final Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
||||
private final Map<String, ArgsClassInfo> nameToClass = new HashMap<String, ArgsClassInfo>();
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
*
|
||||
* @param registry sythetic class registry
|
||||
*/
|
||||
public ArgsClassGenerator(IConsumer<ISyntheticClassInfo> registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or generate) the class name for the specified descriptor. The class
|
||||
* will not be generated until it is used. Calling this method simply
|
||||
@@ -109,89 +155,59 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
*
|
||||
* @param desc Descriptor of the <em>target</em> method, the return type is
|
||||
* ignored for the purposes of generating Args subclasses
|
||||
* @param mixin Mixin which requires the class. Only the first mixin to
|
||||
* request a class will be registered against it but this is for
|
||||
* debugging only anyway
|
||||
* @return name of the Args subclass to use
|
||||
*/
|
||||
public String getClassName(String desc) {
|
||||
public ISyntheticClassInfo getArgsClass(String desc, IMixinInfo mixin) {
|
||||
String voidDesc = Bytecode.changeDescriptorReturnType(desc, "V");
|
||||
String name = this.classNames.get(voidDesc);
|
||||
if (name == null) {
|
||||
name = String.format("%s%d", ArgsClassGenerator.CLASS_NAME_BASE, this.nextIndex++);
|
||||
this.classNames.put(voidDesc, name);
|
||||
ArgsClassInfo info = this.descToClass.get(voidDesc);
|
||||
if (info == null) {
|
||||
String name = String.format("%s%d", ArgsClassGenerator.CLASS_NAME_BASE, this.nextIndex++);
|
||||
ArgsClassGenerator.logger.debug("ArgsClassGenerator assigning {} for descriptor {}", name, voidDesc);
|
||||
info = new ArgsClassInfo(mixin, name, voidDesc);
|
||||
this.descToClass.put(voidDesc, info);
|
||||
this.nameToClass.put(name, info);
|
||||
this.registry.accept(info);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or generate) the class name for the specified descriptor in internal
|
||||
* format (reference). The class will not be generated until it is used.
|
||||
* Calling this method simply allocates a name for the specified descriptor.
|
||||
*
|
||||
* @param desc Descriptor of the <em>target</em> method, with the return
|
||||
* type changed to void (V)
|
||||
* @return reference of the Args subclass to use
|
||||
*/
|
||||
public String getClassRef(String desc) {
|
||||
return this.getClassName(desc).replace('.', '/');
|
||||
return info;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.IClassGenerator#generate
|
||||
* (java.lang.String)
|
||||
* @see org.spongepowered.asm.mixin.transformer.ext.IClassGenerator
|
||||
* #generate(java.lang.String, org.objectweb.asm.tree.ClassNode)
|
||||
*/
|
||||
@Override
|
||||
public byte[] generate(String name) {
|
||||
return this.getBytes(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch or generate class bytes for the specified class name. Returns null
|
||||
* if this generator does not have bytes for the specified class.
|
||||
*
|
||||
* @param name Class name
|
||||
* @return class bytes or null
|
||||
*/
|
||||
public byte[] getBytes(String name) {
|
||||
byte[] bytes = this.classBytes.get(name);
|
||||
if (bytes == null) {
|
||||
String desc = this.classNames.inverse().get(name);
|
||||
if (desc == null) {
|
||||
return null;
|
||||
}
|
||||
bytes = this.generateClass(name, desc);
|
||||
this.classBytes.put(name, bytes);
|
||||
public boolean generate(String name, ClassNode classNode) {
|
||||
ArgsClassInfo info = this.nameToClass.get(name);
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an {@link Args} subclass
|
||||
*
|
||||
* @param name Class name to generate
|
||||
* @param desc Argument descriptor (return type ignored)
|
||||
* @return generated class
|
||||
*/
|
||||
private byte[] generateClass(String name, String desc) {
|
||||
String ref = name.replace('.', '/');
|
||||
Type[] args = Type.getArgumentTypes(desc);
|
||||
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
ClassVisitor visitor = writer;
|
||||
if (info.loaded > 0) {
|
||||
ArgsClassGenerator.logger.debug("ArgsClassGenerator is re-generating {}, already did this {} times!", name, info.loaded);
|
||||
}
|
||||
|
||||
ClassVisitor visitor = classNode;
|
||||
if (MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_VERIFY)) {
|
||||
visitor = new CheckClassAdapter(writer);
|
||||
visitor = new CheckClassAdapter(classNode);
|
||||
}
|
||||
|
||||
visitor.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_SYNTHETIC, ref, null, ArgsClassGenerator.ARGS_REF, null);
|
||||
visitor.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_SYNTHETIC, info.getName(), null,
|
||||
ArgsClassGenerator.ARGS_REF, null);
|
||||
visitor.visitSource(name.substring(name.lastIndexOf('.') + 1) + ".java", null);
|
||||
|
||||
this.generateCtor(ref, desc, args, visitor);
|
||||
this.generateToString(ref, desc, args, visitor);
|
||||
this.generateFactory(ref, desc, args, visitor);
|
||||
this.generateSetters(ref, desc, args, visitor);
|
||||
this.generateGetters(ref, desc, args, visitor);
|
||||
this.generateCtor(info, visitor);
|
||||
this.generateToString(info, visitor);
|
||||
this.generateFactory(info, visitor);
|
||||
this.generateSetters(info, visitor);
|
||||
this.generateGetters(info, visitor);
|
||||
|
||||
visitor.visitEnd();
|
||||
info.loaded++;
|
||||
|
||||
return writer.toByteArray();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +219,7 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateCtor(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
private void generateCtor(ArgsClassInfo info, ClassVisitor writer) {
|
||||
MethodVisitor ctor = writer.visitMethod(Opcodes.ACC_PRIVATE, Constants.CTOR, ArgsClassGenerator.CTOR_DESC, null, null);
|
||||
ctor.visitCode();
|
||||
ctor.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
@@ -222,10 +238,10 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateToString(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
private void generateToString(ArgsClassInfo info, ClassVisitor writer) {
|
||||
MethodVisitor toString = writer.visitMethod(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
|
||||
toString.visitCode();
|
||||
toString.visitLdcInsn("Args" + ArgsClassGenerator.getSignature(args));
|
||||
toString.visitLdcInsn("Args" + info.getSignature());
|
||||
toString.visitInsn(Opcodes.ARETURN);
|
||||
toString.visitMaxs(1, 1);
|
||||
toString.visitEnd();
|
||||
@@ -242,8 +258,9 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateFactory(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
String factoryDesc = Bytecode.changeDescriptorReturnType(desc, "L" + ref + ";");
|
||||
private void generateFactory(ArgsClassInfo info, ClassVisitor writer) {
|
||||
String ref = info.getName();
|
||||
String factoryDesc = Bytecode.changeDescriptorReturnType(info.desc, "L" + ref + ";");
|
||||
MethodVisitorEx of = new MethodVisitorEx(writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "of", factoryDesc, null, null));
|
||||
of.visitCode();
|
||||
|
||||
@@ -252,14 +269,14 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
of.visitInsn(Opcodes.DUP);
|
||||
|
||||
// Create Object[] array to contain args
|
||||
of.visitConstant((byte)args.length);
|
||||
of.visitConstant((byte)info.args.length);
|
||||
of.visitTypeInsn(Opcodes.ANEWARRAY, ArgsClassGenerator.OBJECT);
|
||||
|
||||
// Iterate over args and stuff them into the array
|
||||
byte argIndex = 0;
|
||||
for (Type arg : args) {
|
||||
for (byte index = 0, argIndex = 0; index < info.args.length; index++) {
|
||||
Type arg = info.args[index];
|
||||
of.visitInsn(Opcodes.DUP);
|
||||
of.visitConstant(argIndex);
|
||||
of.visitConstant(index);
|
||||
of.visitVarInsn(arg.getOpcode(Opcodes.ILOAD), argIndex);
|
||||
ArgsClassGenerator.box(of, arg);
|
||||
of.visitInsn(Opcodes.AASTORE);
|
||||
@@ -272,7 +289,7 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
// Return the new object
|
||||
of.visitInsn(Opcodes.ARETURN);
|
||||
|
||||
of.visitMaxs(6, Bytecode.getArgsSize(args));
|
||||
of.visitMaxs(6, Bytecode.getArgsSize(info.args));
|
||||
of.visitEnd();
|
||||
}
|
||||
|
||||
@@ -287,9 +304,9 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateGetters(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
private void generateGetters(ArgsClassInfo info, ClassVisitor writer) {
|
||||
byte argIndex = 0;
|
||||
for (Type arg : args) {
|
||||
for (Type arg : info.args) {
|
||||
String name = ArgsClassGenerator.GETTER_PREFIX + argIndex;
|
||||
String sig = "()" + arg.getDescriptor();
|
||||
MethodVisitorEx get = new MethodVisitorEx(writer.visitMethod(Opcodes.ACC_PUBLIC, name, sig, null, null));
|
||||
@@ -297,7 +314,7 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
|
||||
// Read the value from the values field
|
||||
get.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
get.visitFieldInsn(Opcodes.GETFIELD, ref, ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
get.visitFieldInsn(Opcodes.GETFIELD, info.getName(), ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
get.visitConstant(argIndex);
|
||||
get.visitInsn(Opcodes.AALOAD);
|
||||
|
||||
@@ -322,9 +339,9 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateSetters(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
this.generateIndexedSetter(ref, desc, args, writer);
|
||||
this.generateMultiSetter(ref, desc, args, writer);
|
||||
private void generateSetters(ArgsClassInfo info, ClassVisitor writer) {
|
||||
this.generateIndexedSetter(info, writer);
|
||||
this.generateMultiSetter(info, writer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,23 +355,23 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateIndexedSetter(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
private void generateIndexedSetter(ArgsClassInfo info, ClassVisitor writer) {
|
||||
MethodVisitorEx set = new MethodVisitorEx(writer.visitMethod(Opcodes.ACC_PUBLIC,
|
||||
ArgsClassGenerator.SET, ArgsClassGenerator.SET_DESC, null, null));
|
||||
set.visitCode();
|
||||
|
||||
Label store = new Label(), checkNull = new Label();
|
||||
Label[] labels = new Label[args.length];
|
||||
Label[] labels = new Label[info.args.length];
|
||||
for (int label = 0; label < labels.length; label++) {
|
||||
labels[label] = new Label();
|
||||
}
|
||||
|
||||
// Put the values array on the stack to begin with
|
||||
set.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
set.visitFieldInsn(Opcodes.GETFIELD, ref, ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
set.visitFieldInsn(Opcodes.GETFIELD, info.getName(), ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
|
||||
// Each argument index will jump to its own label
|
||||
for (byte index = 0; index < args.length; index++) {
|
||||
for (byte index = 0; index < info.args.length; index++) {
|
||||
set.visitVarInsn(Opcodes.ILOAD, 1);
|
||||
set.visitConstant(index);
|
||||
set.visitJumpInsn(Opcodes.IF_ICMPEQ, labels[index]);
|
||||
@@ -366,12 +383,12 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
// For each arg we do a CHECKCAST to ensure the supplied type is
|
||||
// assignable to the arg type, we leave the index and value on the stack
|
||||
// and jump to the next stage
|
||||
for (int index = 0; index < args.length; index++) {
|
||||
String boxingType = Bytecode.getBoxingType(args[index]);
|
||||
for (int index = 0; index < info.args.length; index++) {
|
||||
String boxingType = Bytecode.getBoxingType(info.args[index]);
|
||||
set.visitLabel(labels[index]);
|
||||
set.visitVarInsn(Opcodes.ILOAD, 1);
|
||||
set.visitVarInsn(Opcodes.ALOAD, 2);
|
||||
set.visitTypeInsn(Opcodes.CHECKCAST, boxingType != null ? boxingType : args[index].getInternalName());
|
||||
set.visitTypeInsn(Opcodes.CHECKCAST, boxingType != null ? boxingType : info.args[index].getInternalName());
|
||||
set.visitJumpInsn(Opcodes.GOTO, boxingType != null ? checkNull : store);
|
||||
}
|
||||
|
||||
@@ -401,7 +418,7 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
* @param args Parsed argument list from descriptor
|
||||
* @param writer Class writer
|
||||
*/
|
||||
private void generateMultiSetter(String ref, String desc, Type[] args, ClassVisitor writer) {
|
||||
private void generateMultiSetter(ArgsClassInfo info, ClassVisitor writer) {
|
||||
MethodVisitorEx set = new MethodVisitorEx(writer.visitMethod(Opcodes.ACC_PUBLIC,
|
||||
ArgsClassGenerator.SETALL, ArgsClassGenerator.SETALL_DESC, null, null));
|
||||
set.visitCode();
|
||||
@@ -413,17 +430,18 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
set.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
set.visitInsn(Opcodes.ARRAYLENGTH);
|
||||
set.visitInsn(Opcodes.DUP);
|
||||
set.visitConstant((byte)args.length);
|
||||
set.visitConstant((byte)info.args.length);
|
||||
|
||||
// If the lengths are the same, proceed with assignment
|
||||
set.visitJumpInsn(Opcodes.IF_ICMPEQ, lengthOk);
|
||||
|
||||
// Otherwise prepare and throw an ArgumentCountException
|
||||
set.visitTypeInsn(Opcodes.NEW, ArgsClassGenerator.ACE);
|
||||
set.visitInsn(Opcodes.DUP);
|
||||
set.visitInsn(Opcodes.DUP2_X1);
|
||||
set.visitInsn(Opcodes.POP2);
|
||||
set.visitConstant((byte)args.length);
|
||||
set.visitLdcInsn(ArgsClassGenerator.getSignature(args));
|
||||
set.visitConstant((byte)info.args.length);
|
||||
set.visitLdcInsn(info.getSignature());
|
||||
|
||||
set.visitMethodInsn(Opcodes.INVOKESPECIAL, ArgsClassGenerator.ACE, Constants.CTOR, ArgsClassGenerator.ACE_CTOR_DESC, false);
|
||||
set.visitInsn(Opcodes.ATHROW);
|
||||
@@ -433,9 +451,9 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
|
||||
// Put the values array on the stack to begin with
|
||||
set.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
set.visitFieldInsn(Opcodes.GETFIELD, ref, ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
set.visitFieldInsn(Opcodes.GETFIELD, info.getName(), ArgsClassGenerator.VALUES_FIELD, ArgsClassGenerator.OBJECT_ARRAY);
|
||||
|
||||
for (byte index = 0; index < args.length; index++) {
|
||||
for (byte index = 0; index < info.args.length; index++) {
|
||||
// Dup the member array reference and target index
|
||||
set.visitInsn(Opcodes.DUP);
|
||||
set.visitConstant(index);
|
||||
@@ -446,8 +464,8 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
set.visitInsn(Opcodes.AALOAD);
|
||||
|
||||
// Check the argument type
|
||||
String boxingType = Bytecode.getBoxingType(args[index]);
|
||||
set.visitTypeInsn(Opcodes.CHECKCAST, boxingType != null ? boxingType : args[index].getInternalName());
|
||||
String boxingType = Bytecode.getBoxingType(info.args[index]);
|
||||
set.visitTypeInsn(Opcodes.CHECKCAST, boxingType != null ? boxingType : info.args[index].getInternalName());
|
||||
|
||||
// For primitives, check the value is not null
|
||||
if (boxingType != null) {
|
||||
@@ -525,9 +543,5 @@ public final class ArgsClassGenerator implements IClassGenerator {
|
||||
method.visitTypeInsn(Opcodes.CHECKCAST, var.getInternalName());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSignature(Type[] args) {
|
||||
return new SignaturePrinter("", null, args).setFullyQualified(true).getFormattedArgs();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,13 +26,13 @@ package org.spongepowered.asm.mixin.injection.invoke.util;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.analysis.Analyzer;
|
||||
import org.spongepowered.asm.lib.tree.analysis.AnalyzerException;
|
||||
import org.spongepowered.asm.lib.tree.analysis.BasicInterpreter;
|
||||
import org.spongepowered.asm.lib.tree.analysis.BasicValue;
|
||||
import org.spongepowered.asm.lib.tree.analysis.Frame;
|
||||
import org.spongepowered.asm.lib.tree.analysis.Interpreter;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.analysis.Analyzer;
|
||||
import org.objectweb.asm.tree.analysis.AnalyzerException;
|
||||
import org.objectweb.asm.tree.analysis.BasicInterpreter;
|
||||
import org.objectweb.asm.tree.analysis.BasicValue;
|
||||
import org.objectweb.asm.tree.analysis.Frame;
|
||||
import org.objectweb.asm.tree.analysis.Interpreter;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.modify;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
|
||||
@@ -27,10 +27,10 @@ package org.spongepowered.asm.mixin.injection.modify;
|
||||
import java.util.Collection;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.modify.ModifyVariableInjector.ContextualInjectionPoint;
|
||||
|
||||
+6
-6
@@ -31,10 +31,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.LocalVariableNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.LocalVariableNode;
|
||||
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator.Context.Local;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
@@ -122,7 +122,7 @@ public class LocalVariableDiscriminator {
|
||||
private final boolean isStatic;
|
||||
|
||||
public Context(Type returnType, boolean argsOnly, Target target, AbstractInsnNode node) {
|
||||
this.isStatic = Bytecode.methodIsStatic(target.method);
|
||||
this.isStatic = Bytecode.isStatic(target.method);
|
||||
this.returnType = returnType;
|
||||
this.target = target;
|
||||
this.node = node;
|
||||
@@ -147,7 +147,7 @@ public class LocalVariableDiscriminator {
|
||||
|
||||
Local[] lvt = new Local[this.baseArgIndex + target.arguments.length];
|
||||
if (!this.isStatic) {
|
||||
lvt[0] = new Local("this", Type.getType(target.classNode.name));
|
||||
lvt[0] = new Local("this", Type.getObjectType(target.classNode.name));
|
||||
}
|
||||
for (int local = this.baseArgIndex; local < lvt.length; local++) {
|
||||
Type arg = target.arguments[local - this.baseArgIndex];
|
||||
|
||||
+6
-6
@@ -27,12 +27,12 @@ package org.spongepowered.asm.mixin.injection.modify;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
|
||||
@@ -26,14 +26,15 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.VarInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
|
||||
/**
|
||||
@@ -47,7 +48,7 @@ import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
* <dl>
|
||||
* <dt>target</dt>
|
||||
* <dd>A
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo MemberInfo}
|
||||
* {@link ITargetSelector Target Selector}
|
||||
* which identifies the target method</dd>
|
||||
* <dt>ordinal</dt>
|
||||
* <dd>The ordinal position of the method invocation to match. For example if
|
||||
@@ -88,4 +89,5 @@ public class AfterInvoke extends BeforeInvoke {
|
||||
nodes.add(insn);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,17 +29,18 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.FrameNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.LabelNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.FrameNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.Constant.Condition;
|
||||
@@ -187,9 +188,9 @@ public class BeforeConstant extends InjectionPoint {
|
||||
}
|
||||
|
||||
List<Condition> conditions = new ArrayList<Condition>();
|
||||
String strConditions = data.get("expandZeroConditions", "").toLowerCase();
|
||||
String strConditions = data.get("expandZeroConditions", "").toLowerCase(Locale.ROOT);
|
||||
for (Condition condition : Condition.values()) {
|
||||
if (strConditions.contains(condition.name().toLowerCase())) {
|
||||
if (strConditions.contains(condition.name().toLowerCase(Locale.ROOT))) {
|
||||
conditions.add(condition);
|
||||
}
|
||||
}
|
||||
@@ -281,7 +282,7 @@ public class BeforeConstant extends InjectionPoint {
|
||||
Object value = Bytecode.getConstant(insn);
|
||||
if (value == null) {
|
||||
this.log(" BeforeConstant found NULL constant: nullValue = {}", this.nullValue);
|
||||
return this.nullValue || Constants.OBJECT.equals(this.matchByType);
|
||||
return this.nullValue || Constants.OBJECT_DESC.equals(this.matchByType);
|
||||
} else if (value instanceof Integer) {
|
||||
this.log(" BeforeConstant found INTEGER constant: value = {}, intValue = {}", value, this.intValue);
|
||||
return value.equals(this.intValue) || "I".equals(this.matchByType);
|
||||
@@ -296,10 +297,10 @@ public class BeforeConstant extends InjectionPoint {
|
||||
return value.equals(this.doubleValue) || "D".equals(this.matchByType);
|
||||
} else if (value instanceof String) {
|
||||
this.log(" BeforeConstant found STRING constant: value = {}, stringValue = {}", value, this.stringValue);
|
||||
return value.equals(this.stringValue) || Constants.STRING.equals(this.matchByType);
|
||||
return value.equals(this.stringValue) || Constants.STRING_DESC.equals(this.matchByType);
|
||||
} else if (value instanceof Type) {
|
||||
this.log(" BeforeConstant found CLASS constant: value = {}, typeValue = {}", value, this.typeValue);
|
||||
return value.equals(this.typeValue) || Constants.CLASS.equals(this.matchByType);
|
||||
return value.equals(this.typeValue) || Constants.CLASS_DESC.equals(this.matchByType);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -27,16 +27,16 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
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.InsnList;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,8 @@ import org.spongepowered.asm.util.Bytecode;
|
||||
*
|
||||
* <dl>
|
||||
* <dt>target</dt>
|
||||
* <dd>A {@link MemberInfo MemberInfo} which identifies the target field.</dd>
|
||||
* <dd>A {@link ITargetSelector Target Selector} which identifies the target
|
||||
* field.</dd>
|
||||
* <dt>opcode</dt>
|
||||
* <dd>The {@link Opcodes opcode} of the field access, must be one of
|
||||
* GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.</dd>
|
||||
|
||||
@@ -27,11 +27,11 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
import java.util.Collection;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.IInjectionPointContext;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
|
||||
@@ -26,16 +26,19 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
@@ -48,7 +51,8 @@ import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
*
|
||||
* <dl>
|
||||
* <dt>target</dt>
|
||||
* <dd>A {@link MemberInfo MemberInfo} which identifies the target method</dd>
|
||||
* <dd>A {@link ITargetSelector Target Selector} which identifies the target
|
||||
* method</dd>
|
||||
* <dt>ordinal</dt>
|
||||
* <dd>The ordinal position of the method invocation to match. For example if
|
||||
* the method is invoked 3 times and you want to match the 3rd then you can
|
||||
@@ -80,7 +84,7 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
|
||||
}
|
||||
|
||||
protected final MemberInfo target;
|
||||
protected final ITargetSelector target;
|
||||
|
||||
/**
|
||||
* This option enables a fallback "permissive" search to occur if initial
|
||||
@@ -130,7 +134,7 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
|
||||
private String getClassName() {
|
||||
AtCode atCode = this.getClass().<AtCode>getAnnotation(AtCode.class);
|
||||
return String.format("@At(%s)", atCode != null ? atCode.value() : this.getClass().getSimpleName().toUpperCase());
|
||||
return String.format("@At(%s)", atCode != null ? atCode.value() : this.getClass().getSimpleName().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,14 +150,16 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.InjectionPoint
|
||||
* #find(java.lang.String, org.spongepowered.asm.lib.tree.InsnList,
|
||||
* #find(java.lang.String, org.objectweb.asm.tree.InsnList,
|
||||
* java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
this.log("{} is searching for an injection point in method with descriptor {}", this.className, desc);
|
||||
|
||||
if (!this.find(desc, insns, nodes, this.target, SearchType.STRICT) && this.target.desc != null && this.allowPermissive) {
|
||||
boolean hasDescriptor = this.target instanceof ITargetSelectorByName && ((ITargetSelectorByName)this.target).getDesc() == null;
|
||||
|
||||
if (!this.find(desc, insns, nodes, this.target, SearchType.STRICT) && hasDescriptor && this.allowPermissive) {
|
||||
this.logger.warn("STRICT match for {} using \"{}\" in {} returned 0 results, attempting permissive search. "
|
||||
+ "To inhibit permissive search set mixin.env.allowPermissiveMatch=false", this.className, this.target, this.context);
|
||||
return this.find(desc, insns, nodes, this.target, SearchType.PERMISSIVE);
|
||||
@@ -161,12 +167,12 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes, MemberInfo member, SearchType searchType) {
|
||||
if (member == null) {
|
||||
protected boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes, ITargetSelector selector, SearchType searchType) {
|
||||
if (selector == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MemberInfo target = searchType == SearchType.PERMISSIVE ? member.transform(null) : member;
|
||||
ITargetSelector target = searchType == SearchType.PERMISSIVE ? selector.configure("permissive") : selector;
|
||||
|
||||
int ordinal = 0;
|
||||
int found = 0;
|
||||
@@ -179,10 +185,10 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
MemberInfo nodeInfo = new MemberInfo(insn);
|
||||
this.log("{} is considering insn {}", this.className, nodeInfo);
|
||||
|
||||
if (target.matches(nodeInfo.owner, nodeInfo.name, nodeInfo.desc)) {
|
||||
if (target.match(insn).isExactMatch()) {
|
||||
this.log("{} > found a matching insn, checking preconditions...", this.className);
|
||||
|
||||
if (this.matchesInsn(nodeInfo, ordinal)) {
|
||||
if (this.matchesOrdinal(ordinal)) {
|
||||
this.log("{} > > > found a matching insn at ordinal {}", this.className, ordinal);
|
||||
|
||||
if (this.addInsn(insns, nodes, insn)) {
|
||||
@@ -203,7 +209,7 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
|
||||
if (searchType == SearchType.PERMISSIVE && found > 1) {
|
||||
this.logger.warn("A permissive match for {} using \"{}\" in {} matched {} instructions, this may cause unexpected behaviour. "
|
||||
+ "To inhibit permissive search set mixin.env.allowPermissiveMatch=false", this.className, member, this.context, found);
|
||||
+ "To inhibit permissive search set mixin.env.allowPermissiveMatch=false", this.className, selector, this.context, found);
|
||||
}
|
||||
|
||||
return found > 0;
|
||||
@@ -222,7 +228,7 @@ public class BeforeInvoke extends InjectionPoint {
|
||||
// stub for subclasses
|
||||
}
|
||||
|
||||
protected boolean matchesInsn(MemberInfo nodeInfo, int ordinal) {
|
||||
protected boolean matchesOrdinal(int ordinal) {
|
||||
this.log("{} > > comparing target ordinal {} with current ordinal {}", this.className, this.ordinal, ordinal);
|
||||
return this.ordinal == -1 || this.ordinal == ordinal;
|
||||
}
|
||||
|
||||
@@ -29,15 +29,18 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorConstructor;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionPointException;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
@@ -108,9 +111,14 @@ public class BeforeNew extends InjectionPoint {
|
||||
|
||||
this.ordinal = data.getOrdinal();
|
||||
String target = Strings.emptyToNull(data.get("class", data.get("target", "")).replace('.', '/'));
|
||||
MemberInfo member = MemberInfo.parseAndValidate(target, data.getContext());
|
||||
this.target = member.toCtorType();
|
||||
this.desc = member.toCtorDesc();
|
||||
ITargetSelector member = TargetSelector.parseAndValidate(target, data.getContext());
|
||||
if (!(member instanceof ITargetSelectorConstructor)) {
|
||||
throw new InvalidInjectionPointException(data.getContext(), "Failed parsing @At(\"NEW\") target descriptor \"%s\" on %s",
|
||||
target, data.getDescription());
|
||||
}
|
||||
ITargetSelectorConstructor targetSelector = (ITargetSelectorConstructor)member;
|
||||
this.target = targetSelector.toCtorType();
|
||||
this.desc = targetSelector.toCtorDesc();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,11 +27,11 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
import java.util.Collection;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.InsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.IInjectionPointContext;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
|
||||
@@ -26,12 +26,13 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
|
||||
/**
|
||||
* <p>Like {@link BeforeInvoke}, this injection point searches for
|
||||
@@ -54,7 +55,7 @@ import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
* <dl>
|
||||
* <dt>target</dt>
|
||||
* <dd>A
|
||||
* {@link org.spongepowered.asm.mixin.injection.struct.MemberInfo MemberInfo}
|
||||
* {@link ITargetSelector Target Selector}
|
||||
* which identifies the target method, the method <b>must</b> be specified
|
||||
* with a signature which accepts a single string and returns void,
|
||||
* eg. <code>(Ljava/lang/String;)V</code></dd>
|
||||
@@ -104,7 +105,7 @@ public class BeforeStringInvoke extends BeforeInvoke {
|
||||
throw new IllegalArgumentException(this.getClass().getSimpleName() + " requires named argument \"ldc\" to specify the desired target");
|
||||
}
|
||||
|
||||
if (!STRING_VOID_SIG.equals(this.target.desc)) {
|
||||
if (!(this.target instanceof ITargetSelectorByName) || !STRING_VOID_SIG.equals(((ITargetSelectorByName)this.target).getDesc())) {
|
||||
throw new IllegalArgumentException(this.getClass().getSimpleName() + " requires target method with with signature " + STRING_VOID_SIG);
|
||||
}
|
||||
}
|
||||
@@ -131,8 +132,8 @@ public class BeforeStringInvoke extends BeforeInvoke {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesInsn(MemberInfo nodeInfo, int ordinal) {
|
||||
protected boolean matchesOrdinal(int ordinal) {
|
||||
this.log("{} > > found LDC \"{}\" = {}", this.className, this.ldcValue, this.foundLdc);
|
||||
return this.foundLdc && super.matchesInsn(nodeInfo, ordinal);
|
||||
return this.foundLdc && super.matchesOrdinal(ordinal);
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,10 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
import java.util.Collection;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
|
||||
@@ -26,8 +26,8 @@ package org.spongepowered.asm.mixin.injection.points;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.AtCode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionPointData;
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
/**
|
||||
* Target Selectors are used to identify target members in a class, with the
|
||||
* criteria for selection being specified in a single string, effectively
|
||||
* defining the query parameters. They are used by injectors and other
|
||||
* components which need to identify a target element using a string.
|
||||
*
|
||||
* <h4>Explicit Target Selectors</h4>
|
||||
*
|
||||
* <p><b>Explicit</b> Target Selectors are handled internally using
|
||||
* {@link MemberInfo} structs, see the javadoc for {@link MemberInfo} for the
|
||||
* supported variants and examples.</p>
|
||||
*/
|
||||
public interface ITargetSelector {
|
||||
|
||||
/**
|
||||
* Configure and return a modified version of this selector by consuming the
|
||||
* supplied arguments. Results from this method should be idempotent in
|
||||
* terms of the configuration of the returned object, but do not have to
|
||||
* necessarily return the same object if the callee already matches the
|
||||
* supplied configuration, though this is generally the case.
|
||||
*
|
||||
* <p>In other words, calling <tt>configure("foo")</tt> when this object is
|
||||
* <i>already</i> configured according to "foo" may simply return this
|
||||
* object, or might return an identically-configured copy.</p>
|
||||
*
|
||||
* @param args Configuration arguments
|
||||
* @return Configured selector, may return this selector if the specified
|
||||
* condition is already satisfied
|
||||
*/
|
||||
public abstract ITargetSelector configure(String... args);
|
||||
|
||||
/**
|
||||
* Perform basic sanity-check validation of the selector, checks that the
|
||||
* parsed out parameters are basically sane
|
||||
*
|
||||
* @return fluent (this selector)
|
||||
*
|
||||
* @throws InvalidSelectorException if any sanity check fails
|
||||
*/
|
||||
public abstract ITargetSelector validate() throws InvalidSelectorException;
|
||||
|
||||
/**
|
||||
* Attach this selector to the specified context. Should return this
|
||||
* selector unmodified if all is well, or a new selector to be used for
|
||||
* further processing of the supplied context. If the supplied context is
|
||||
* invalid, an {@link InvalidSelectorException} is thrown.
|
||||
*
|
||||
* @param context Context to attach to
|
||||
* @return Attached selector
|
||||
*/
|
||||
public abstract ITargetSelector attach(IMixinContext context) throws InvalidSelectorException;
|
||||
|
||||
/**
|
||||
* Number of candidates which this selector should match
|
||||
*/
|
||||
public abstract int getMatchCount();
|
||||
|
||||
/**
|
||||
* Test whether this selector matches the supplied element node
|
||||
*
|
||||
* @param node node node to test
|
||||
* @param <TNode> node type
|
||||
* @return true if this selector can match the supplied field
|
||||
*/
|
||||
public abstract <TNode> MatchResult match(ElementNode<TNode> node);
|
||||
|
||||
/**
|
||||
* Test whether this selector matches the supplied instruction node
|
||||
*
|
||||
* @param insn instruction node to test
|
||||
* @return true if this selector can match the supplied instruction
|
||||
*/
|
||||
public abstract MatchResult match(AbstractInsnNode insn);
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
/**
|
||||
* A target selector which selects elements directly by name.
|
||||
*/
|
||||
public interface ITargetSelectorByName extends ITargetSelector {
|
||||
|
||||
/**
|
||||
* Get the member owner, can be null
|
||||
*/
|
||||
public abstract String getOwner();
|
||||
|
||||
/**
|
||||
* Get the member name, can be null
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Get the member descriptor, can be null
|
||||
*/
|
||||
public abstract String getDesc();
|
||||
|
||||
/**
|
||||
* Get whether this reference is fully qualified
|
||||
*
|
||||
* @return true if all components of this reference are non-null
|
||||
*/
|
||||
public abstract boolean isFullyQualified();
|
||||
|
||||
/**
|
||||
* Get whether this target selector is definitely a field, the output of
|
||||
* this method is undefined if {@link #isFullyQualified} returns false.
|
||||
*
|
||||
* @return true if this is definitely a field
|
||||
*/
|
||||
public abstract boolean isField();
|
||||
|
||||
/**
|
||||
* Get whether this member represents a constructor
|
||||
*
|
||||
* @return true if member name is <tt><init></tt>
|
||||
*/
|
||||
public abstract boolean isConstructor();
|
||||
|
||||
/**
|
||||
* Get whether this selector represents a class initialiser
|
||||
*
|
||||
* @return true if member name is <tt><clinit></tt>
|
||||
*/
|
||||
public abstract boolean isClassInitialiser();
|
||||
|
||||
/**
|
||||
* Get whether this selector represents a constructor or class initialiser
|
||||
*
|
||||
* @return true if member name is <tt><init></tt> or
|
||||
* <tt><clinit></tt>
|
||||
*/
|
||||
public abstract boolean isInitialiser();
|
||||
|
||||
/**
|
||||
* Get a representation of this selector as a complete descriptor
|
||||
*/
|
||||
public abstract String toDescriptor();
|
||||
|
||||
/**
|
||||
* Test whether this selector matches the supplied values. Null values are
|
||||
* ignored.
|
||||
|
||||
* @param owner Owner to compare with, null to skip
|
||||
* @param name Name to compare with, null to skip
|
||||
* @param desc Signature to compare with, null to skip
|
||||
* @return true if all non-null values in this reference match non-null
|
||||
* arguments supplied to this method
|
||||
*/
|
||||
public abstract MatchResult matches(String owner, String name, String desc);
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
/**
|
||||
* A target selector which can identify constructor types
|
||||
*/
|
||||
public interface ITargetSelectorConstructor extends ITargetSelectorByName {
|
||||
|
||||
/**
|
||||
* Returns the <em>constructor type</em> represented by this selector
|
||||
*/
|
||||
public abstract String toCtorType();
|
||||
|
||||
/**
|
||||
* Returns the <em>constructor descriptor</em> represented by this
|
||||
* selector, returns null if no descriptor is present.
|
||||
*/
|
||||
public abstract String toCtorDesc();
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
|
||||
/**
|
||||
* A target selector which can be remapped at compile time via an obfuscation
|
||||
* service
|
||||
*/
|
||||
public interface ITargetSelectorRemappable extends ITargetSelectorByName {
|
||||
|
||||
/**
|
||||
* Returns this selector as a {@link MappingField} or
|
||||
* {@link MappingMethod}
|
||||
*/
|
||||
public abstract IMapping<?> asMapping();
|
||||
|
||||
/**
|
||||
* Returns this selector as a mapping method
|
||||
*/
|
||||
public abstract MappingMethod asMethodMapping();
|
||||
|
||||
/**
|
||||
* Returns this selector as a mapping field
|
||||
*/
|
||||
public abstract MappingField asFieldMapping();
|
||||
|
||||
/**
|
||||
* Create a new version of this member with a different owner
|
||||
*
|
||||
* @param newOwner New owner for this member
|
||||
*/
|
||||
public abstract ITargetSelectorRemappable move(String newOwner);
|
||||
|
||||
/**
|
||||
* Create a new version of this member with a different descriptor
|
||||
*
|
||||
* @param newDesc New descriptor for this member
|
||||
*/
|
||||
public abstract ITargetSelectorRemappable transform(String newDesc);
|
||||
|
||||
/**
|
||||
* Create a remapped version of this member using the supplied method data
|
||||
*
|
||||
* @param srgMethod SRG method data to use
|
||||
* @param setOwner True to set the owner as well as the name
|
||||
* @return New MethodInfo with remapped values
|
||||
*/
|
||||
public abstract ITargetSelectorRemappable remapUsing(MappingMethod srgMethod, boolean setOwner);
|
||||
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
|
||||
/**
|
||||
* Exception to be thrown from {@link ITargetSelector#validate} when a target
|
||||
* selector fails verification
|
||||
*/
|
||||
public class InvalidSelectorException extends MixinException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidSelectorException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidSelectorException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidSelectorException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
/**
|
||||
* Result of a {@link ITargetSelector target selector} <em>match</em> operation
|
||||
* which describes the type of match.
|
||||
*/
|
||||
public enum MatchResult {
|
||||
|
||||
/**
|
||||
* No result, the selector does not match the candidate
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* Matches only in the weakest sense, use this result only if all else fails
|
||||
* and nothing else matches at all
|
||||
*/
|
||||
WEAK,
|
||||
|
||||
/**
|
||||
* A confident match, but not an exact match. It may be that other optional
|
||||
* parts of the selector did not match the candidate. For example this could
|
||||
* mean that the selector matched case-insensitively. This is the best
|
||||
* result if an {@link #EXACT_MATCH} match is not found.
|
||||
*/
|
||||
MATCH,
|
||||
|
||||
/**
|
||||
* All parts, including optional parts of the selector matched the candidate
|
||||
* and this result is the best. If more than one <tt>EXACT_MATCH</tt> is
|
||||
* returned from a query, the first one should be used.
|
||||
*/
|
||||
EXACT_MATCH;
|
||||
|
||||
|
||||
/**
|
||||
* Get whether this match level represents a level which is the
|
||||
* same or greater than the supplied level
|
||||
*
|
||||
* @param other level to compare to
|
||||
* @return true if greater or equal
|
||||
*/
|
||||
public boolean isAtLeast(MatchResult other) {
|
||||
return other == null || other.ordinal() <= this.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this match succeeded
|
||||
*/
|
||||
public boolean isMatch() {
|
||||
return this.ordinal() >= MatchResult.MATCH.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this is an exact match
|
||||
*/
|
||||
public boolean isExactMatch() {
|
||||
return this == MatchResult.EXACT_MATCH;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.selectors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapper;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
/**
|
||||
* Utility class for parsing selectors
|
||||
*/
|
||||
public final class TargetSelector {
|
||||
|
||||
/**
|
||||
* Query result struct
|
||||
*
|
||||
* @param <TNode> Node type
|
||||
*/
|
||||
public static class Result<TNode> {
|
||||
|
||||
/**
|
||||
* Any exact match returned by the query
|
||||
*/
|
||||
public final TNode exactMatch;
|
||||
|
||||
/**
|
||||
* All candidates returned by the query
|
||||
*/
|
||||
public final List<TNode> candidates;
|
||||
|
||||
Result(TNode exactMatch, List<TNode> candidates) {
|
||||
this.exactMatch = exactMatch;
|
||||
this.candidates = candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get only a single result from this handle. Preferentially returns an
|
||||
* exact match if one was found, or returns the first result if only one
|
||||
* result was found or if <tt>strict</tt> is <tt>false</tt>. If <tt>
|
||||
* strict</tt> is <tt>true</tt> and more than one candidate was found, a
|
||||
* {@link IllegalStateException} is thrown. If no results are found then
|
||||
* the exception is also thrown.
|
||||
*
|
||||
* @param strict True to only return the first (non-exact) result
|
||||
* <b>if</b> exactly one result was found. If more than one
|
||||
* candidate was found, throws {@link IllegalStateException}
|
||||
*/
|
||||
public TNode getSingleResult(boolean strict) {
|
||||
int resultCount = this.candidates.size();
|
||||
if (this.exactMatch != null) {
|
||||
return this.exactMatch;
|
||||
}
|
||||
if (resultCount == 1 || !strict) {
|
||||
return this.candidates.get(0);
|
||||
}
|
||||
throw new IllegalStateException((resultCount == 0 ? "No" : "Multiple") + " candidates were found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TargetSelector() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a target selector from a string and perform validation
|
||||
*
|
||||
* @param string String to parse target selector from
|
||||
* @return parsed target selector
|
||||
*/
|
||||
public static ITargetSelector parseAndValidate(String string) throws InvalidMemberDescriptorException {
|
||||
return TargetSelector.parse(string, null, null).validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a target selector from a string and perform validation
|
||||
*
|
||||
* @param string String to parse target selector from
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed target selector
|
||||
*/
|
||||
public static ITargetSelector parseAndValidate(String string, IMixinContext context) throws InvalidMemberDescriptorException {
|
||||
return TargetSelector.parse(string, context.getReferenceMapper(), context.getClassRef()).validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a target selector from a string
|
||||
*
|
||||
* @param string String to parse target selector from
|
||||
* @return parsed target selector
|
||||
*/
|
||||
public static ITargetSelector parse(String string) {
|
||||
return TargetSelector.parse(string, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a target selector from a string
|
||||
*
|
||||
* @param string String to parse target selector from
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed target selector
|
||||
*/
|
||||
public static ITargetSelector parse(String string, IMixinContext context) {
|
||||
return TargetSelector.parse(string, context.getReferenceMapper(), context.getClassRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a target selector from the supplied name, and then return the name
|
||||
* of the match. This is used mainly to remap input names in the same
|
||||
* context as a selector without needing the selector itself. If the
|
||||
* supplied name does not successfully parse to a name-based selector, then
|
||||
* the name is returned unchanged.
|
||||
*
|
||||
* @param name Name to parse
|
||||
* @param context Mixin context
|
||||
* @return remapped name or original name
|
||||
*/
|
||||
public static String parseName(String name, IMixinContext context) {
|
||||
ITargetSelector selector = TargetSelector.parse(name, context);
|
||||
if (!(selector instanceof ITargetSelectorByName)) {
|
||||
return name;
|
||||
}
|
||||
String mappedName = ((ITargetSelectorByName)selector).getName();
|
||||
return mappedName != null ? mappedName : name;
|
||||
}
|
||||
|
||||
private static ITargetSelector parse(String input, IReferenceMapper refMapper, String mixinClass) {
|
||||
return MemberInfo.parse(input, refMapper, mixinClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run query on supplied target nodes
|
||||
*
|
||||
* @param target Target selector
|
||||
* @param nodes Node collection to enumerate
|
||||
* @param <TNode> Node type
|
||||
* @return query result
|
||||
*/
|
||||
public static <TNode> Result<TNode> run(ITargetSelector target, List<ElementNode<TNode>> nodes) {
|
||||
List<TNode> candidates = new ArrayList<TNode>();
|
||||
TNode exactMatch = TargetSelector.runSelector(target, nodes, candidates);
|
||||
return new Result<TNode>(exactMatch, candidates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run query on supplied target nodes
|
||||
*
|
||||
* @param targets Target selector
|
||||
* @param nodes Node collection to enumerate
|
||||
* @param <TNode> Node type
|
||||
* @return query result
|
||||
*/
|
||||
public static <TNode> Result<TNode> run(Iterable<ITargetSelector> targets, List<ElementNode<TNode>> nodes) {
|
||||
TNode exactMatch = null;
|
||||
List<TNode> candidates = new ArrayList<TNode>();
|
||||
|
||||
for (ITargetSelector target : targets) {
|
||||
TNode selectorExactMatch = TargetSelector.runSelector(target, nodes, candidates);
|
||||
if (exactMatch == null) {
|
||||
exactMatch = selectorExactMatch;
|
||||
}
|
||||
}
|
||||
|
||||
return new Result<TNode>(exactMatch, candidates);
|
||||
}
|
||||
|
||||
private static <TNode> TNode runSelector(ITargetSelector target, List<ElementNode<TNode>> nodes, List<TNode> candidates) {
|
||||
TNode exactMatch = null;
|
||||
for (ElementNode<TNode> element : nodes) {
|
||||
MatchResult match = target.match(element);
|
||||
if (match.isMatch()) {
|
||||
TNode node = element.get();
|
||||
if (!candidates.contains(node)) {
|
||||
candidates.add(node);
|
||||
}
|
||||
if (exactMatch == null && match.isExactMatch()) {
|
||||
exactMatch = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return exactMatch;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -24,12 +24,13 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInjector;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
@@ -38,6 +39,7 @@ import com.google.common.base.Strings;
|
||||
/**
|
||||
* Information about a callback to inject, usually specified by {@link Inject}
|
||||
*/
|
||||
@AnnotationType(Inject.class)
|
||||
public class CallbackInjectionInfo extends InjectionInfo {
|
||||
|
||||
protected CallbackInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
|
||||
@@ -24,47 +24,46 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
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.MethodNode;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.Dynamic;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
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.ISliceContext;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.code.InjectorTarget;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlice;
|
||||
import org.spongepowered.asm.mixin.injection.code.MethodSlices;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.InvalidSelectorException;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionError;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.struct.SpecialMethodInfo;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinError;
|
||||
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.Annotations;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
@@ -74,6 +73,97 @@ import com.google.common.base.Strings;
|
||||
*/
|
||||
public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceContext {
|
||||
|
||||
/**
|
||||
* Decoration for subclasses which indicates the injector annotation that
|
||||
* the subclass handles
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@java.lang.annotation.Target(ElementType.TYPE)
|
||||
public @interface AnnotationType {
|
||||
|
||||
/**
|
||||
* The injector annotation this InjectionInfo can handle
|
||||
*/
|
||||
public Class<? extends Annotation> value();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Decoration for subclasses which specifies the prefix to use when
|
||||
* conforming annotated handler methods
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@java.lang.annotation.Target(ElementType.TYPE)
|
||||
public @interface HandlerPrefix {
|
||||
|
||||
/**
|
||||
* String prefix for conforming handler methods
|
||||
*/
|
||||
public String value();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An injector registration entry
|
||||
*/
|
||||
static class InjectorEntry {
|
||||
|
||||
final Class<? extends Annotation> annotationType;
|
||||
|
||||
final Class<? extends InjectionInfo> type;
|
||||
|
||||
final Constructor<? extends InjectionInfo> ctor;
|
||||
|
||||
final String simpleName;
|
||||
|
||||
final String prefix;
|
||||
|
||||
InjectorEntry(Class<? extends Annotation> annotationType, Class<? extends InjectionInfo> type) throws NoSuchMethodException {
|
||||
this.annotationType = annotationType;
|
||||
this.type = type;
|
||||
this.ctor = type.getDeclaredConstructor(MixinTargetContext.class, MethodNode.class, AnnotationNode.class);
|
||||
this.simpleName = annotationType.getSimpleName() + ";";
|
||||
|
||||
HandlerPrefix handlerPrefix = type.<HandlerPrefix>getAnnotation(HandlerPrefix.class);
|
||||
this.prefix = handlerPrefix != null ? handlerPrefix.value() : InjectionInfo.DEFAULT_PREFIX;
|
||||
}
|
||||
|
||||
InjectionInfo create(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
try {
|
||||
return this.ctor.newInstance(mixin, method, annotation);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new MixinError("Failed to instantiate injector metaclass [" + this.type + "] for annotation " + annotation.desc, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default conform prefix for handler methods
|
||||
*/
|
||||
public static final String DEFAULT_PREFIX = "handler";
|
||||
|
||||
/**
|
||||
* Registry of subclasses
|
||||
*/
|
||||
private static Map<String, InjectorEntry> registry = new LinkedHashMap<String, InjectorEntry>();
|
||||
|
||||
/**
|
||||
* Registered annotations, baked and used to call
|
||||
* Annotations::getSingleVisible efficiently
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static Class<? extends Annotation>[] registeredAnnotations = new Class[0];
|
||||
|
||||
static {
|
||||
// Standard injectors
|
||||
InjectionInfo.register(CallbackInjectionInfo.class); // @Inject
|
||||
InjectionInfo.register(ModifyArgInjectionInfo.class); // @ModifyArg
|
||||
InjectionInfo.register(ModifyArgsInjectionInfo.class); // @ModifyArgs
|
||||
InjectionInfo.register(RedirectInjectionInfo.class); // @Redirect
|
||||
InjectionInfo.register(ModifyVariableInjectionInfo.class); // @ModifyVariable
|
||||
InjectionInfo.register(ModifyConstantInjectionInfo.class); // @ModifyConstant
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotated method is static
|
||||
*/
|
||||
@@ -153,7 +243,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
|
||||
protected InjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation, String atKey) {
|
||||
super(mixin, method, annotation);
|
||||
this.isStatic = Bytecode.methodIsStatic(method);
|
||||
this.isStatic = Bytecode.isStatic(method);
|
||||
this.slices = MethodSlices.parse(this);
|
||||
this.atKey = atKey;
|
||||
this.readAnnotation();
|
||||
@@ -175,28 +265,30 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
this.injector = this.parseInjector(this.annotation);
|
||||
}
|
||||
|
||||
protected Set<MemberInfo> parseTargets(String type) {
|
||||
protected Set<ITargetSelector> parseTargets(String type) {
|
||||
List<String> methods = Annotations.<String>getValue(this.annotation, "method", false);
|
||||
if (methods == null) {
|
||||
throw new InvalidInjectionException(this, String.format("%s annotation on %s is missing method name", type, this.method.name));
|
||||
}
|
||||
|
||||
Set<MemberInfo> members = new LinkedHashSet<MemberInfo>();
|
||||
Set<ITargetSelector> selectors = new LinkedHashSet<ITargetSelector>();
|
||||
for (String method : methods) {
|
||||
try {
|
||||
MemberInfo targetMember = MemberInfo.parseAndValidate(method, this.mixin);
|
||||
if (targetMember.owner != null && !targetMember.owner.equals(this.mixin.getTargetClassRef())) {
|
||||
throw new InvalidInjectionException(this,
|
||||
String.format("%s annotation on %s specifies a target class '%s', which is not supported", type, this.method.name,
|
||||
targetMember.owner));
|
||||
}
|
||||
members.add(targetMember);
|
||||
selectors.add(TargetSelector.parseAndValidate(method, this.mixin).attach(this.mixin));
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
throw new InvalidInjectionException(this, String.format("%s annotation on %s, has invalid target descriptor: \"%s\". %s", type,
|
||||
this.method.name, method, this.mixin.getReferenceMapper().getStatus()));
|
||||
} catch (TargetNotSupportedException ex) {
|
||||
throw new InvalidInjectionException(this,
|
||||
String.format("%s annotation on %s specifies a target class '%s', which is not supported", type, this.method.name,
|
||||
ex.getMessage()));
|
||||
} catch (InvalidSelectorException ex) {
|
||||
throw new InvalidInjectionException(this,
|
||||
String.format("%s annotation on %s is decorated with an invalid selector: %s", type, this.method.name,
|
||||
ex.getMessage()));
|
||||
}
|
||||
}
|
||||
return members;
|
||||
return selectors;
|
||||
}
|
||||
|
||||
protected List<AnnotationNode> readInjectionPoints(String type) {
|
||||
@@ -365,7 +457,7 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
* @return new method
|
||||
*/
|
||||
public MethodNode addMethod(int access, String name, String desc) {
|
||||
MethodNode method = new MethodNode(Opcodes.ASM5, access | Opcodes.ACC_SYNTHETIC, name, desc, null, null);
|
||||
MethodNode method = new MethodNode(Bytecode.ASM_API_VERSION, access | Opcodes.ACC_SYNTHETIC, name, desc, null, null);
|
||||
this.injectedMethods.add(method);
|
||||
return method;
|
||||
}
|
||||
@@ -382,10 +474,10 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
/**
|
||||
* Finds methods in the target class which match searchFor
|
||||
*
|
||||
* @param searchFor members to search for
|
||||
* @param selectors members to search for
|
||||
* @param type annotation type
|
||||
*/
|
||||
private void findMethods(Set<MemberInfo> searchFor, String type) {
|
||||
private void findMethods(Set<ITargetSelector> selectors, String type) {
|
||||
this.targets.clear();
|
||||
|
||||
// When remapping refmap is enabled this implies we are in a development
|
||||
@@ -394,32 +486,35 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
// descriptor if this happens.
|
||||
int passes = this.mixin.getEnvironment().getOption(Option.REFMAP_REMAP) ? 2 : 1;
|
||||
|
||||
for (MemberInfo member : searchFor) {
|
||||
for (ITargetSelector selector : selectors) {
|
||||
int matchCount = selector.getMatchCount();
|
||||
for (int count = 0, pass = 0; pass < passes && count < 1; pass++) {
|
||||
int ordinal = 0;
|
||||
for (MethodNode target : this.classNode.methods) {
|
||||
if (member.matches(target.name, target.desc, ordinal)) {
|
||||
if (selector.match(ElementNode.of(this.classNode, target)).isExactMatch()) {
|
||||
boolean isMixinMethod = Annotations.getVisible(target, MixinMerged.class) != null;
|
||||
if (member.matchAll && (Bytecode.methodIsStatic(target) != this.isStatic || target == this.method || isMixinMethod)) {
|
||||
if (matchCount > 1 && (Bytecode.isStatic(target) != this.isStatic || target == this.method || isMixinMethod)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.checkTarget(target);
|
||||
this.targets.add(target);
|
||||
ordinal++;
|
||||
count++;
|
||||
|
||||
if (count >= matchCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass ignores descriptor
|
||||
member = member.transform(null);
|
||||
selector = selector.configure("permissive");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.targets.size() == 0) {
|
||||
throw new InvalidInjectionException(this,
|
||||
String.format("%s annotation on %s could not find any targets matching %s in the target class %s. %s%s",
|
||||
type, this.method.name, InjectionInfo.namesOf(searchFor), this.mixin.getTarget(),
|
||||
type, this.method.name, InjectionInfo.namesOf(selectors), this.mixin.getTarget(),
|
||||
this.mixin.getReferenceMapper().getStatus(), this.getDynamicInfo()));
|
||||
}
|
||||
}
|
||||
@@ -468,18 +563,10 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
return null;
|
||||
}
|
||||
|
||||
if (annotation.desc.endsWith(Inject.class.getSimpleName() + ";")) {
|
||||
return new CallbackInjectionInfo(mixin, method, annotation);
|
||||
} else if (annotation.desc.endsWith(ModifyArg.class.getSimpleName() + ";")) {
|
||||
return new ModifyArgInjectionInfo(mixin, method, annotation);
|
||||
} else if (annotation.desc.endsWith(ModifyArgs.class.getSimpleName() + ";")) {
|
||||
return new ModifyArgsInjectionInfo(mixin, method, annotation);
|
||||
} else if (annotation.desc.endsWith(Redirect.class.getSimpleName() + ";")) {
|
||||
return new RedirectInjectionInfo(mixin, method, annotation);
|
||||
} else if (annotation.desc.endsWith(ModifyVariable.class.getSimpleName() + ";")) {
|
||||
return new ModifyVariableInjectionInfo(mixin, method, annotation);
|
||||
} else if (annotation.desc.endsWith(ModifyConstant.class.getSimpleName() + ";")) {
|
||||
return new ModifyConstantInjectionInfo(mixin, method, annotation);
|
||||
for (InjectorEntry injector : InjectionInfo.registry.values()) {
|
||||
if (annotation.desc.endsWith(injector.simpleName)) {
|
||||
return injector.create(mixin, method, annotation);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -494,18 +581,10 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
* @param method mixin method
|
||||
* @return annotation or null
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static AnnotationNode getInjectorAnnotation(IMixinInfo mixin, MethodNode method) {
|
||||
AnnotationNode annotation = null;
|
||||
try {
|
||||
annotation = Annotations.getSingleVisible(method,
|
||||
Inject.class,
|
||||
ModifyArg.class,
|
||||
ModifyArgs.class,
|
||||
Redirect.class,
|
||||
ModifyVariable.class,
|
||||
ModifyConstant.class
|
||||
);
|
||||
annotation = Annotations.getSingleVisible(method, InjectionInfo.registeredAnnotations);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new InvalidMixinException(mixin, String.format("Error parsing annotations on %s in %s: %s", method.name, mixin.getClassName(),
|
||||
ex.getMessage()));
|
||||
@@ -520,20 +599,17 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
* @return conform prefix
|
||||
*/
|
||||
public static String getInjectorPrefix(AnnotationNode annotation) {
|
||||
if (annotation != null) {
|
||||
if (annotation.desc.endsWith(ModifyArg.class.getSimpleName() + ";")) {
|
||||
return "modify";
|
||||
} else if (annotation.desc.endsWith(ModifyArgs.class.getSimpleName() + ";")) {
|
||||
return "args";
|
||||
} else if (annotation.desc.endsWith(Redirect.class.getSimpleName() + ";")) {
|
||||
return "redirect";
|
||||
} else if (annotation.desc.endsWith(ModifyVariable.class.getSimpleName() + ";")) {
|
||||
return "localvar";
|
||||
} else if (annotation.desc.endsWith(ModifyConstant.class.getSimpleName() + ";")) {
|
||||
return "constant";
|
||||
if (annotation == null) {
|
||||
return InjectionInfo.DEFAULT_PREFIX;
|
||||
}
|
||||
|
||||
for (InjectorEntry injector : InjectionInfo.registry.values()) {
|
||||
if (annotation.desc.endsWith(injector.simpleName)) {
|
||||
return injector.prefix;
|
||||
}
|
||||
}
|
||||
return "handler";
|
||||
|
||||
return InjectionInfo.DEFAULT_PREFIX;
|
||||
}
|
||||
|
||||
static String describeInjector(IMixinContext mixin, AnnotationNode annotation, MethodNode method) {
|
||||
@@ -543,13 +619,13 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
/**
|
||||
* Print the names of the specified members as a human-readable list
|
||||
*
|
||||
* @param members members to print
|
||||
* @param selectors members to print
|
||||
* @return human-readable list of member names
|
||||
*/
|
||||
private static String namesOf(Collection<MemberInfo> members) {
|
||||
int index = 0, count = members.size();
|
||||
private static String namesOf(Collection<ITargetSelector> selectors) {
|
||||
int index = 0, count = selectors.size();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (MemberInfo member : members) {
|
||||
for (ITargetSelector selector : selectors) {
|
||||
if (index > 0) {
|
||||
if (index == (count - 1)) {
|
||||
sb.append(" or ");
|
||||
@@ -557,10 +633,47 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append('\'').append(member.name).append('\'');
|
||||
sb.append('\'').append(selector.toString()).append('\'');
|
||||
index++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an injector info class. The supplied class must be decorated
|
||||
* with an {@link AnnotationType} annotation for registration purposes.
|
||||
*
|
||||
* @param type injection info subclass to register
|
||||
*/
|
||||
public static void register(Class<? extends InjectionInfo> type) {
|
||||
AnnotationType annotationType = type.<AnnotationType>getAnnotation(AnnotationType.class);
|
||||
if (annotationType == null) {
|
||||
throw new IllegalArgumentException("Injection info class " + type + " is not annotated with @AnnotationType");
|
||||
}
|
||||
|
||||
Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
InjectorEntry entry;
|
||||
try {
|
||||
entry = new InjectorEntry(annotationType.value(), type);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new MixinError("InjectionInfo class " + type.getName() + " is missing a valid constructor");
|
||||
}
|
||||
InjectorEntry existing = InjectionInfo.registry.get(entry.simpleName);
|
||||
if (existing != null && !existing.type.equals(type)) {
|
||||
logger.debug("WARNING: Overriding InjectionInfo for {} with {} (previously {})", annotationType.value().getSimpleName(), type.getName(),
|
||||
existing.type.getName());
|
||||
} else {
|
||||
logger.debug("Registering new injector for {} with {}", annotationType.value().getSimpleName(), type.getName());
|
||||
}
|
||||
|
||||
InjectionInfo.registry.put(entry.simpleName, entry);
|
||||
|
||||
ArrayList<Class<? extends Annotation>> annotations = new ArrayList<Class<? extends Annotation>>();
|
||||
for (InjectorEntry injector : InjectionInfo.registry.values()) {
|
||||
annotations.add(injector.annotationType);
|
||||
}
|
||||
InjectionInfo.registeredAnnotations = annotations.toArray(InjectionInfo.registeredAnnotations);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
|
||||
+23
-14
@@ -30,13 +30,15 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.Selector;
|
||||
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.TargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionPointException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
|
||||
@@ -251,33 +253,40 @@ public class InjectionPointData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supplied value from the named args as a {@link MemberInfo},
|
||||
* throws an exception if the argument cannot be parsed as a MemberInfo.
|
||||
* Get the supplied value from the named args as a target selector,
|
||||
* throws an exception if the argument cannot be parsed as a target selector
|
||||
*
|
||||
* @param key argument name
|
||||
* @return argument value as a MemberInfo
|
||||
* @return argument value as a target selector
|
||||
*/
|
||||
public MemberInfo get(String key) {
|
||||
public ITargetSelector get(String key) {
|
||||
try {
|
||||
return MemberInfo.parseAndValidate(this.get(key, ""), this.context);
|
||||
return TargetSelector.parseAndValidate(this.get(key, ""), this.context);
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
throw new InvalidInjectionPointException(this.context, "Failed parsing @At(\"%s\").%s descriptor \"%s\" on %s",
|
||||
this.at, key, this.target, InjectionInfo.describeInjector(this.context, this.parent, this.method));
|
||||
this.at, key, this.target, this.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target value specified on the injector
|
||||
*/
|
||||
public MemberInfo getTarget() {
|
||||
public ITargetSelector getTarget() {
|
||||
try {
|
||||
return MemberInfo.parseAndValidate(this.target, this.context);
|
||||
return TargetSelector.parseAndValidate(this.target, this.context);
|
||||
} catch (InvalidMemberDescriptorException ex) {
|
||||
throw new InvalidInjectionPointException(this.context, "Failed parsing @At(\"%s\") descriptor \"%s\" on %s",
|
||||
this.at, this.target, InjectionInfo.describeInjector(this.context, this.parent, this.method));
|
||||
throw new InvalidInjectionPointException(this.context, "Failed parsing @At(\"%s\").target descriptor \"%s\" on %s",
|
||||
this.at, this.target, this.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a description of this injector for use in error messages
|
||||
*/
|
||||
public String getDescription() {
|
||||
return InjectionInfo.describeInjector(this.context, this.parent, this.method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ordinal specified on the injection point
|
||||
*/
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.Group;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InjectionValidationException;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
+2
-2
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.InvalidSelectorException;
|
||||
|
||||
/**
|
||||
* Thrown when a {@link MemberInfo} fails basic syntax validation
|
||||
*/
|
||||
public class InvalidMemberDescriptorException extends MixinException {
|
||||
public class InvalidMemberDescriptorException extends InvalidSelectorException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -24,27 +24,36 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
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.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorByName;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorConstructor;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.InvalidSelectorException;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.MatchResult;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
import org.spongepowered.asm.util.asm.ElementNode;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* <p>Information bundle about a member (method or field) parsed from a String
|
||||
* token in another annotation, this is used where target members need to be
|
||||
* specified as Strings in order to parse the String representation to something
|
||||
* useful.</p>
|
||||
* <p>Target selector, also used as a general-purpose information bundle about a
|
||||
* member (method or field) parsed from a String token in another annotation,
|
||||
* this is used where target members need to be specified as Strings in order to
|
||||
* parse the String representation to something useful. See
|
||||
* {@link ITargetSelector} for other supported selector types.</p>
|
||||
*
|
||||
* <p>Some examples:</p>
|
||||
* <blockquote><pre>
|
||||
@@ -80,27 +89,27 @@ import com.google.common.base.Strings;
|
||||
* foo.bar.Baz.func_1234_a(DDD)V</pre>
|
||||
* </blockquote>
|
||||
*/
|
||||
public final class MemberInfo {
|
||||
public final class MemberInfo implements ITargetSelectorRemappable, ITargetSelectorConstructor {
|
||||
|
||||
/**
|
||||
* Member owner in internal form but without L;, can be null
|
||||
*/
|
||||
public final String owner;
|
||||
private final String owner;
|
||||
|
||||
/**
|
||||
* Member name, can be null to match any member
|
||||
*/
|
||||
public final String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Member descriptor, can be null
|
||||
*/
|
||||
public final String desc;
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* True to match all matching members, not just the first
|
||||
*/
|
||||
public final boolean matchAll;
|
||||
private final boolean matchAll;
|
||||
|
||||
/**
|
||||
* Force this member to report as a field
|
||||
@@ -252,6 +261,26 @@ public final class MemberInfo {
|
||||
this.unparsed = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMatchCount() {
|
||||
return this.matchAll ? Integer.MAX_VALUE : 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@@ -287,6 +316,7 @@ public final class MemberInfo {
|
||||
/**
|
||||
* Returns this MemberInfo as a java-style descriptor
|
||||
*/
|
||||
@Override
|
||||
public String toDescriptor() {
|
||||
if (this.desc == null) {
|
||||
return "";
|
||||
@@ -298,6 +328,7 @@ public final class MemberInfo {
|
||||
/**
|
||||
* Returns the <em>constructor type</em> represented by this MemberInfo
|
||||
*/
|
||||
@Override
|
||||
public String toCtorType() {
|
||||
if (this.unparsed == null) {
|
||||
return null;
|
||||
@@ -318,17 +349,14 @@ public final class MemberInfo {
|
||||
|
||||
return this.desc != null ? this.desc : this.unparsed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <em>constructor descriptor</em> represented by this
|
||||
* MemberInfo, returns null if no descriptor is present.
|
||||
*/
|
||||
@Override
|
||||
public String toCtorDesc() {
|
||||
if (this.desc != null && this.desc.startsWith("(") && this.desc.indexOf(')') > -1) {
|
||||
return this.desc.substring(0, this.desc.indexOf(')') + 1) + "V";
|
||||
}
|
||||
|
||||
return null;
|
||||
return Bytecode.changeDescriptorReturnType(this.desc, "V");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +364,7 @@ public final class MemberInfo {
|
||||
* returns null if the descriptor is absent or if this MemberInfo represents
|
||||
* a field
|
||||
*/
|
||||
public String getReturnType() {
|
||||
private String getReturnType() {
|
||||
if (this.desc == null || this.desc.indexOf(')') == -1 || this.desc.indexOf('(') != 0 ) {
|
||||
return null;
|
||||
}
|
||||
@@ -352,6 +380,7 @@ public final class MemberInfo {
|
||||
* Returns this MemberInfo as a {@link MappingField} or
|
||||
* {@link MappingMethod}
|
||||
*/
|
||||
@Override
|
||||
public IMapping<?> asMapping() {
|
||||
return this.isField() ? this.asFieldMapping() : this.asMethodMapping();
|
||||
}
|
||||
@@ -359,6 +388,7 @@ public final class MemberInfo {
|
||||
/**
|
||||
* Returns this MemberInfo as a mapping method
|
||||
*/
|
||||
@Override
|
||||
public MappingMethod asMethodMapping() {
|
||||
if (!this.isFullyQualified()) {
|
||||
throw new MixinException("Cannot convert unqualified reference " + this + " to MethodMapping");
|
||||
@@ -374,6 +404,7 @@ public final class MemberInfo {
|
||||
/**
|
||||
* Returns this MemberInfo as a mapping field
|
||||
*/
|
||||
@Override
|
||||
public MappingField asFieldMapping() {
|
||||
if (!this.isField()) {
|
||||
throw new MixinException("Cannot convert non-field reference " + this + " to FieldMapping");
|
||||
@@ -382,11 +413,7 @@ public final class MemberInfo {
|
||||
return new MappingField(this.owner, this.name, this.desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this reference is fully qualified
|
||||
*
|
||||
* @return true if all components of this reference are non-null
|
||||
*/
|
||||
@Override
|
||||
public boolean isFullyQualified() {
|
||||
return this.owner != null && this.name != null && this.desc != null;
|
||||
}
|
||||
@@ -397,6 +424,7 @@ public final class MemberInfo {
|
||||
*
|
||||
* @return true if this is definitely a field
|
||||
*/
|
||||
@Override
|
||||
public boolean isField() {
|
||||
return this.forceField || (this.desc != null && !this.desc.startsWith("("));
|
||||
}
|
||||
@@ -406,6 +434,7 @@ public final class MemberInfo {
|
||||
*
|
||||
* @return true if member name is <tt><init></tt>
|
||||
*/
|
||||
@Override
|
||||
public boolean isConstructor() {
|
||||
return Constants.CTOR.equals(this.name);
|
||||
}
|
||||
@@ -415,6 +444,7 @@ public final class MemberInfo {
|
||||
*
|
||||
* @return true if member name is <tt><clinit></tt>
|
||||
*/
|
||||
@Override
|
||||
public boolean isClassInitialiser() {
|
||||
return Constants.CLINIT.equals(this.name);
|
||||
}
|
||||
@@ -425,6 +455,7 @@ public final class MemberInfo {
|
||||
* @return true if member name is <tt><init></tt> or
|
||||
* <tt><clinit></tt>
|
||||
*/
|
||||
@Override
|
||||
public boolean isInitialiser() {
|
||||
return this.isConstructor() || this.isClassInitialiser();
|
||||
}
|
||||
@@ -437,6 +468,7 @@ public final class MemberInfo {
|
||||
*
|
||||
* @throws InvalidMemberDescriptorException if any validation check fails
|
||||
*/
|
||||
@Override
|
||||
public MemberInfo validate() throws InvalidMemberDescriptorException {
|
||||
// Extremely naive class name validation, just to spot really egregious errors
|
||||
if (this.owner != null) {
|
||||
@@ -486,90 +518,73 @@ public final class MemberInfo {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this MemberInfo matches the supplied values. Null values are
|
||||
* ignored.
|
||||
|
||||
* @param owner Owner to compare with, null to skip
|
||||
* @param name Name to compare with, null to skip
|
||||
* @param desc Signature to compare with, null to skip
|
||||
* @return true if all non-null values in this reference match non-null
|
||||
* arguments supplied to this method
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
|
||||
* #match(org.spongepowered.asm.util.asm.ElementNode)
|
||||
*/
|
||||
public boolean matches(String owner, String name, String desc) {
|
||||
return this.matches(owner, name, desc, 0);
|
||||
@Override
|
||||
public <TNode> MatchResult match(ElementNode<TNode> node) {
|
||||
return node == null ? MatchResult.NONE : this.matches(node.getOwnerName(), node.getName(), node.getDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this MemberInfo matches the supplied values at the specified
|
||||
* ordinal. Null values are ignored.
|
||||
*
|
||||
* @param owner Owner to compare with, null to skip
|
||||
* @param name Name to compare with, null to skip
|
||||
* @param desc Signature to compare with, null to skip
|
||||
* @param ordinal ordinal position within the class, used to honour the
|
||||
* matchAll semantics
|
||||
* @return true if all non-null values in this reference match non-null
|
||||
* arguments supplied to this method
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
|
||||
* #matches(org.objectweb.asm.tree.AbstractInsnNode)
|
||||
*/
|
||||
public boolean matches(String owner, String name, String desc, int ordinal) {
|
||||
if (this.desc != null && desc != null && !this.desc.equals(desc)) {
|
||||
return false;
|
||||
@Override
|
||||
public MatchResult match(AbstractInsnNode insn) {
|
||||
if (insn instanceof MethodInsnNode) {
|
||||
MethodInsnNode method = (MethodInsnNode)insn;
|
||||
return this.matches(method.owner, method.name, method.desc);
|
||||
} else if (insn instanceof FieldInsnNode) {
|
||||
FieldInsnNode field = (FieldInsnNode)insn;
|
||||
return this.matches(field.owner, field.name, field.desc);
|
||||
}
|
||||
if (this.name != null && name != null && !this.name.equals(name)) {
|
||||
return false;
|
||||
return MatchResult.NONE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
|
||||
* #matches(java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public MatchResult matches(String owner, String name, String desc) {
|
||||
if (this.desc != null && desc != null && !this.desc.equals(desc)) {
|
||||
return MatchResult.NONE;
|
||||
}
|
||||
if (this.owner != null && owner != null && !this.owner.equals(owner)) {
|
||||
return false;
|
||||
return MatchResult.NONE;
|
||||
}
|
||||
return ordinal == 0 || this.matchAll;
|
||||
if (this.name != null && name != null) {
|
||||
if (this.name.equals(name)) {
|
||||
return MatchResult.EXACT_MATCH;
|
||||
}
|
||||
if (this.name.equalsIgnoreCase(name)) {
|
||||
return MatchResult.MATCH;
|
||||
}
|
||||
return MatchResult.NONE;
|
||||
}
|
||||
return MatchResult.EXACT_MATCH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this MemberInfo matches the supplied values. Null values are
|
||||
* ignored.
|
||||
|
||||
* @param name Name to compare with, null to skip
|
||||
* @param desc Signature to compare with, null to skip
|
||||
* @return true if all non-null values in this reference match non-null
|
||||
* arguments supplied to this method
|
||||
*/
|
||||
public boolean matches(String name, String desc) {
|
||||
return this.matches(name, desc, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether this MemberInfo matches the supplied values at the specified
|
||||
* ordinal. Null values are ignored.
|
||||
*
|
||||
* @param name Name to compare with, null to skip
|
||||
* @param desc Signature to compare with, null to skip
|
||||
* @param ordinal ordinal position within the class, used to honour the
|
||||
* matchAll semantics
|
||||
* @return true if all non-null values in this reference match non-null
|
||||
* arguments supplied to this method
|
||||
*/
|
||||
public boolean matches(String name, String desc, int ordinal) {
|
||||
return (this.name == null || this.name.equals(name))
|
||||
&& (this.desc == null || (desc != null && desc.equals(this.desc)))
|
||||
&& (ordinal == 0 || this.matchAll);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || obj.getClass() != MemberInfo.class) {
|
||||
if (obj == null || !(obj instanceof ITargetSelectorByName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MemberInfo other = (MemberInfo)obj;
|
||||
return this.matchAll == other.matchAll && this.forceField == other.forceField
|
||||
&& Objects.equal(this.owner, other.owner)
|
||||
&& Objects.equal(this.name, other.name)
|
||||
&& Objects.equal(this.desc, other.desc);
|
||||
ITargetSelectorByName other = (ITargetSelectorByName)obj;
|
||||
boolean otherForceField = other instanceof MemberInfo ? ((MemberInfo)other).forceField : other.isField();
|
||||
boolean otherMatchAll = other.getMatchCount() == Integer.MAX_VALUE;
|
||||
|
||||
return this.matchAll == otherMatchAll && this.forceField == otherForceField
|
||||
&& Objects.equal(this.owner, other.getOwner())
|
||||
&& Objects.equal(this.name, other.getName())
|
||||
&& Objects.equal(this.desc, other.getDesc());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -580,12 +595,50 @@ public final class MemberInfo {
|
||||
return Objects.hashCode(this.matchAll, this.owner, this.name, this.desc);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
|
||||
* #configure(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public ITargetSelector configure(String... args) {
|
||||
ITargetSelectorRemappable configured = this;
|
||||
for (String arg : args) {
|
||||
if (arg == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.startsWith("move:")) {
|
||||
configured = configured.move(Strings.emptyToNull(arg.substring(5)));
|
||||
} else if (arg.startsWith("transform:")) {
|
||||
configured = configured.transform(Strings.emptyToNull(arg.substring(10)));
|
||||
} else if ("permissive".equals(arg)) {
|
||||
configured = configured.transform(null);
|
||||
} else if ("orphan".equals(arg)) {
|
||||
configured = configured.move(null);
|
||||
}
|
||||
}
|
||||
return configured;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.injection.selectors.ITargetSelector
|
||||
* #attach(org.spongepowered.asm.mixin.refmap.IMixinContext)
|
||||
*/
|
||||
@Override
|
||||
public ITargetSelector attach(IMixinContext context) throws InvalidSelectorException {
|
||||
if (this.owner != null && !this.owner.equals(context.getTargetClassRef())) {
|
||||
throw new TargetNotSupportedException(this.owner);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new version of this member with a different owner
|
||||
*
|
||||
* @param newOwner New owner for this member
|
||||
*/
|
||||
public MemberInfo move(String newOwner) {
|
||||
@Override
|
||||
public ITargetSelectorRemappable move(String newOwner) {
|
||||
if ((newOwner == null && this.owner == null) || (newOwner != null && newOwner.equals(this.owner))) {
|
||||
return this;
|
||||
}
|
||||
@@ -597,7 +650,8 @@ public final class MemberInfo {
|
||||
*
|
||||
* @param newDesc New descriptor for this member
|
||||
*/
|
||||
public MemberInfo transform(String newDesc) {
|
||||
@Override
|
||||
public ITargetSelectorRemappable transform(String newDesc) {
|
||||
if ((newDesc == null && this.desc == null) || (newDesc != null && newDesc.equals(this.desc))) {
|
||||
return this;
|
||||
}
|
||||
@@ -611,67 +665,26 @@ public final class MemberInfo {
|
||||
* @param setOwner True to set the owner as well as the name
|
||||
* @return New MethodInfo with remapped values
|
||||
*/
|
||||
public MemberInfo remapUsing(MappingMethod srgMethod, boolean setOwner) {
|
||||
@Override
|
||||
public ITargetSelectorRemappable remapUsing(MappingMethod srgMethod, boolean setOwner) {
|
||||
return new MemberInfo(this, srgMethod, setOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MemberInfo from a string and perform validation
|
||||
*
|
||||
* @param string String to parse MemberInfo from
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parseAndValidate(String string) throws InvalidMemberDescriptorException {
|
||||
return MemberInfo.parse(string, null, null).validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MemberInfo from a string and perform validation
|
||||
*
|
||||
* @param string String to parse MemberInfo from
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parseAndValidate(String string, IMixinContext context) throws InvalidMemberDescriptorException {
|
||||
return MemberInfo.parse(string, context.getReferenceMapper(), context.getClassRef()).validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MemberInfo from a string
|
||||
*
|
||||
* @param string String to parse MemberInfo from
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parse(String string) {
|
||||
return MemberInfo.parse(string, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MemberInfo from a string
|
||||
*
|
||||
* @param string String to parse MemberInfo from
|
||||
* @param context Context to use for reference mapping
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
public static MemberInfo parse(String string, IMixinContext context) {
|
||||
return MemberInfo.parse(string, context.getReferenceMapper(), context.getClassRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MemberInfo from a string
|
||||
*
|
||||
* @param input String to parse MemberInfo from
|
||||
* @param refMapper Reference mapper to use
|
||||
* @param mixinClass Mixin class to use for remapping
|
||||
* @param className Class context to use for remapping
|
||||
* @return parsed MemberInfo
|
||||
*/
|
||||
private static MemberInfo parse(String input, IReferenceMapper refMapper, String mixinClass) {
|
||||
public static MemberInfo parse(String input, IReferenceMapper refMapper, String className) {
|
||||
String desc = null;
|
||||
String owner = null;
|
||||
String name = Strings.nullToEmpty(input).replaceAll("\\s", "");
|
||||
|
||||
if (refMapper != null) {
|
||||
name = refMapper.remap(mixinClass, name);
|
||||
name = refMapper.remap(className, name);
|
||||
}
|
||||
|
||||
int lastDotPos = name.lastIndexOf('.');
|
||||
|
||||
+6
-2
@@ -24,17 +24,21 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.ModifyArgInjector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
/**
|
||||
* Information about a {@link ModifyArg} injector
|
||||
*/
|
||||
@AnnotationType(ModifyArg.class)
|
||||
@HandlerPrefix("modify")
|
||||
public class ModifyArgInjectionInfo extends InjectionInfo {
|
||||
|
||||
public ModifyArgInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
|
||||
+6
-2
@@ -24,16 +24,20 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.ModifyArgsInjector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
/**
|
||||
* Information about a {@link ModifyArgs} injector
|
||||
*/
|
||||
@AnnotationType(ModifyArgs.class)
|
||||
@HandlerPrefix("args")
|
||||
public class ModifyArgsInjectionInfo extends InjectionInfo {
|
||||
|
||||
public ModifyArgsInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
|
||||
+8
-3
@@ -26,13 +26,16 @@ package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.ModifyConstantInjector;
|
||||
import org.spongepowered.asm.mixin.injection.points.BeforeConstant;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
@@ -41,6 +44,8 @@ import com.google.common.collect.ImmutableList;
|
||||
/**
|
||||
* Information about a constant modifier injector
|
||||
*/
|
||||
@AnnotationType(ModifyConstant.class)
|
||||
@HandlerPrefix("constant")
|
||||
public class ModifyConstantInjectionInfo extends InjectionInfo {
|
||||
|
||||
private static final String CONSTANT_ANNOTATION_CLASS = Constant.class.getName().replace('.', '/');
|
||||
|
||||
+6
-2
@@ -24,17 +24,21 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.modify.LocalVariableDiscriminator;
|
||||
import org.spongepowered.asm.mixin.injection.modify.ModifyVariableInjector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
/**
|
||||
* Information about a {@link ModifyVariable} injector
|
||||
*/
|
||||
@AnnotationType(ModifyVariable.class)
|
||||
@HandlerPrefix("localvar")
|
||||
public class ModifyVariableInjectionInfo extends InjectionInfo {
|
||||
|
||||
public ModifyVariableInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
|
||||
+7
-2
@@ -24,15 +24,20 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.RedirectInjector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
/**
|
||||
* Information about a redirector injector
|
||||
*/
|
||||
@AnnotationType(Redirect.class)
|
||||
@HandlerPrefix("redirect")
|
||||
public class RedirectInjectionInfo extends InjectionInfo {
|
||||
|
||||
public RedirectInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
|
||||
|
||||
@@ -28,17 +28,17 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.lib.Label;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.LabelNode;
|
||||
import org.spongepowered.asm.lib.tree.LocalVariableNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.lib.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.LocalVariableNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
@@ -141,7 +141,7 @@ public class Target implements Comparable<Target>, Iterable<AbstractInsnNode> {
|
||||
this.classNode = classNode;
|
||||
this.method = method;
|
||||
this.insns = method.instructions;
|
||||
this.isStatic = Bytecode.methodIsStatic(method);
|
||||
this.isStatic = Bytecode.isStatic(method);
|
||||
this.isCtor = method.name.equals(Constants.CTOR);
|
||||
this.arguments = Type.getArgumentTypes(method.desc);
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.injection.struct;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.selectors.ITargetSelector;
|
||||
import org.spongepowered.asm.mixin.injection.selectors.InvalidSelectorException;
|
||||
|
||||
/**
|
||||
* Exception thrown when target selector is not valid for the supplied target
|
||||
* context during {@link ITargetSelector#attach}
|
||||
*/
|
||||
public class TargetNotSupportedException extends InvalidSelectorException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TargetNotSupportedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TargetNotSupportedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TargetNotSupportedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,10 +24,12 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.injection.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinError;
|
||||
|
||||
/**
|
||||
* Error to throw for critical injection problems
|
||||
*/
|
||||
public class InjectionError extends Error {
|
||||
public class InjectionError extends MixinError {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.refmap;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
|
||||
@@ -31,13 +31,13 @@ import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.service.IMixinService;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParseException;
|
||||
@@ -216,7 +216,11 @@ public final class ReferenceMapper implements IReferenceMapper, Serializable {
|
||||
* @return replaced value, per the contract of {@link Map#put}
|
||||
*/
|
||||
public String addMapping(String context, String className, String reference, String newReference) {
|
||||
if (this.readOnly || reference == null || newReference == null || reference.equals(newReference)) {
|
||||
if (this.readOnly || reference == null || newReference == null) {
|
||||
return null;
|
||||
}
|
||||
String conformedReference = reference.replaceAll("\\s", "");
|
||||
if (conformedReference.equals(newReference)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Map<String, String>> mappings = this.mappings;
|
||||
@@ -232,7 +236,7 @@ public final class ReferenceMapper implements IReferenceMapper, Serializable {
|
||||
classMappings = new HashMap<String, String>();
|
||||
mappings.put(className, classMappings);
|
||||
}
|
||||
return classMappings.put(reference, newReference);
|
||||
return classMappings.put(conformedReference, newReference);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +271,7 @@ public final class ReferenceMapper implements IReferenceMapper, Serializable {
|
||||
} catch (Exception ex) {
|
||||
logger.error("Failed reading REFMAP JSON from " + resourcePath + ": " + ex.getClass().getName() + " " + ex.getMessage());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
Closeables.closeQuietly(reader);
|
||||
}
|
||||
|
||||
return ReferenceMapper.DEFAULT_MAPPER;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.tree.FieldInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
@@ -185,7 +185,7 @@ public abstract class MemberRef {
|
||||
*/
|
||||
public static final class Handle extends MemberRef {
|
||||
|
||||
private org.spongepowered.asm.lib.Handle handle;
|
||||
private org.objectweb.asm.Handle handle;
|
||||
|
||||
/**
|
||||
* Creates a member reference initially referring to the member referred
|
||||
@@ -194,7 +194,7 @@ public abstract class MemberRef {
|
||||
*
|
||||
* @param handle Initial method handle.
|
||||
*/
|
||||
public Handle(org.spongepowered.asm.lib.Handle handle) {
|
||||
public Handle(org.objectweb.asm.Handle handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public abstract class MemberRef {
|
||||
*
|
||||
* @return Method handle representing this object
|
||||
*/
|
||||
public org.spongepowered.asm.lib.Handle getMethodHandle() {
|
||||
public org.objectweb.asm.Handle getMethodHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public abstract class MemberRef {
|
||||
throw new MixinTransformerError("Invalid opcode " + Bytecode.getOpcodeName(opcode) + " for method handle " + this.handle + ".");
|
||||
}
|
||||
boolean itf = tag == Opcodes.H_INVOKEINTERFACE;
|
||||
this.handle = new org.spongepowered.asm.lib.Handle(tag, this.handle.getOwner(), this.handle.getName(), this.handle.getDesc(), itf);
|
||||
this.handle = new org.objectweb.asm.Handle(tag, this.handle.getOwner(), this.handle.getName(), this.handle.getDesc(), itf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,7 +253,7 @@ public abstract class MemberRef {
|
||||
@Override
|
||||
public void setOwner(String owner) {
|
||||
boolean itf = this.handle.getTag() == Opcodes.H_INVOKEINTERFACE;
|
||||
this.handle = new org.spongepowered.asm.lib.Handle(this.handle.getTag(), owner, this.handle.getName(), this.handle.getDesc(), itf);
|
||||
this.handle = new org.objectweb.asm.Handle(this.handle.getTag(), owner, this.handle.getName(), this.handle.getDesc(), itf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -264,7 +264,7 @@ public abstract class MemberRef {
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
boolean itf = this.handle.getTag() == Opcodes.H_INVOKEINTERFACE;
|
||||
this.handle = new org.spongepowered.asm.lib.Handle(this.handle.getTag(), this.handle.getOwner(), name, this.handle.getDesc(), itf);
|
||||
this.handle = new org.objectweb.asm.Handle(this.handle.getTag(), this.handle.getOwner(), name, this.handle.getDesc(), itf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -275,7 +275,7 @@ public abstract class MemberRef {
|
||||
@Override
|
||||
public void setDesc(String desc) {
|
||||
boolean itf = this.handle.getTag() == Opcodes.H_INVOKEINTERFACE;
|
||||
this.handle = new org.spongepowered.asm.lib.Handle(this.handle.getTag(), this.handle.getOwner(), this.handle.getName(), desc, itf);
|
||||
this.handle = new org.objectweb.asm.Handle(this.handle.getTag(), this.handle.getOwner(), this.handle.getName(), desc, itf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.LineNumberNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.LineNumberNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.struct;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.injection.IInjectionPointContext;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
|
||||
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.asm.mixin.throwables;
|
||||
/**
|
||||
* Error to throw for required mixins when mixing of the mixin fails
|
||||
*/
|
||||
public class MixinApplyError extends Error {
|
||||
public class MixinApplyError extends MixinError {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* 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.throwables;
|
||||
|
||||
/**
|
||||
* An internal error in mixin, not an invalid mixin or user state, but
|
||||
* something wrong in Mixin's state which isn't the user's fault
|
||||
*/
|
||||
public class MixinError extends Error {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MixinError() {
|
||||
}
|
||||
|
||||
public MixinError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MixinError(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public MixinError(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.throwables;
|
||||
|
||||
import org.spongepowered.asm.mixin.transformer.ActivityStack;
|
||||
|
||||
/**
|
||||
* Base class for all mixin processor exceptions
|
||||
*/
|
||||
@@ -31,19 +33,50 @@ public class MixinException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MixinException() {
|
||||
}
|
||||
private String activityDescriptor;
|
||||
|
||||
public MixinException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MixinException(String message, ActivityStack context) {
|
||||
super(message);
|
||||
this.activityDescriptor = context != null ? context.toString() : null;
|
||||
}
|
||||
|
||||
public MixinException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public MixinException(Throwable cause, ActivityStack context) {
|
||||
super(cause);
|
||||
this.activityDescriptor = context != null ? context.toString() : null;
|
||||
}
|
||||
|
||||
public MixinException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MixinException(String message, Throwable cause, ActivityStack context) {
|
||||
super(message, cause);
|
||||
this.activityDescriptor = context != null ? context.toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate this exception with additional upstream activity context
|
||||
*
|
||||
* @param upstreamContext Upstream activity stack to decorate
|
||||
*/
|
||||
public void prepend(ActivityStack upstreamContext) {
|
||||
String strContext = upstreamContext.toString();
|
||||
this.activityDescriptor = this.activityDescriptor != null ? strContext + ActivityStack.GLUE_STRING + this.activityDescriptor
|
||||
: ActivityStack.GLUE_STRING + strContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
String message = super.getMessage();
|
||||
return this.activityDescriptor != null ? message + " [" + this.activityDescriptor + "]" : message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ package org.spongepowered.asm.mixin.throwables;
|
||||
/**
|
||||
* Error to throw for required configs when initialising of the config fails
|
||||
*/
|
||||
public class MixinPrepareError extends Error {
|
||||
public class MixinPrepareError extends MixinError {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
Loaded 100 of 246 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user