mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-26 22:03:10 +00:00
Refactor some elements of mixin service into new smaller components
The main goal here is to reduce the amount of boilerplate required when providing out simple implementations of the mixin service. Some mixin end users are using extremely simple environments and this reduces the boilerplate code in those implementations.
This commit is contained in:
1 parent
22909dcfa2
commit
03e8ad59f0
9 files changed
+235
-168
No files matched your search
+24
-4
@@ -29,6 +29,8 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.service.IClassTracker;
|
||||
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
@@ -37,7 +39,7 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
* them to perform some validation tasks, and insert entries for mixin "classes"
|
||||
* into the invalid classes set.
|
||||
*/
|
||||
final class LaunchClassLoaderUtil {
|
||||
final class LaunchClassLoaderUtil implements IClassTracker {
|
||||
|
||||
private static final String CACHED_CLASSES_FIELD = "cachedClasses";
|
||||
private static final String INVALID_CLASSES_FIELD = "invalidClasses";
|
||||
@@ -67,7 +69,7 @@ final class LaunchClassLoaderUtil {
|
||||
this.classLoaderExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.CLASS_LOADER_EXCEPTIONS_FIELD);
|
||||
this.transformerExceptions = LaunchClassLoaderUtil.<Set<String>>getField(classLoader, LaunchClassLoaderUtil.TRANSFORMER_EXCEPTIONS_FIELD);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the classloader
|
||||
*/
|
||||
@@ -82,10 +84,27 @@ final class LaunchClassLoaderUtil {
|
||||
* @param name class name
|
||||
* @return true if the class name exists in the cache
|
||||
*/
|
||||
boolean isClassLoaded(String name) {
|
||||
@Override
|
||||
public boolean isClassLoaded(String name) {
|
||||
return this.cachedClasses.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#getClassRestrictions(
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getClassRestrictions(String className) {
|
||||
String restrictions = "";
|
||||
if (this.isClassClassLoaderExcluded(className, null)) {
|
||||
restrictions = "PACKAGE_CLASSLOADER_EXCLUSION";
|
||||
}
|
||||
if (this.isClassTransformerExcluded(className, null)) {
|
||||
restrictions = (restrictions.length() > 0 ? restrictions + "," : "") + "PACKAGE_TRANSFORMER_EXCLUSION";
|
||||
}
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the specified name or transformedName exist in either of the
|
||||
* exclusion lists
|
||||
@@ -143,7 +162,8 @@ final class LaunchClassLoaderUtil {
|
||||
*
|
||||
* @param name class name
|
||||
*/
|
||||
void registerInvalidClass(String name) {
|
||||
@Override
|
||||
public void registerInvalidClass(String name) {
|
||||
if (this.invalidClasses != null) {
|
||||
this.invalidClasses.add(name);
|
||||
}
|
||||
|
||||
+19
-35
@@ -52,8 +52,10 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.service.IClassBytecodeProvider;
|
||||
import org.spongepowered.asm.service.IClassProvider;
|
||||
import org.spongepowered.asm.service.IClassTracker;
|
||||
import org.spongepowered.asm.service.ILegacyClassTransformer;
|
||||
import org.spongepowered.asm.service.ITransformer;
|
||||
import org.spongepowered.asm.service.ITransformerProvider;
|
||||
import org.spongepowered.asm.service.MixinServiceAbstract;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.perf.Profiler;
|
||||
@@ -72,7 +74,7 @@ import net.minecraft.launchwrapper.Launch;
|
||||
/**
|
||||
* Mixin service for launchwrapper
|
||||
*/
|
||||
public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements IClassProvider, IClassBytecodeProvider {
|
||||
public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements IClassProvider, IClassBytecodeProvider, ITransformerProvider {
|
||||
|
||||
// Blackboard keys
|
||||
public static final Keys BLACKBOARD_KEY_TWEAKCLASSES = Keys.of("TweakClasses");
|
||||
@@ -259,6 +261,22 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#getTransformerProvider()
|
||||
*/
|
||||
@Override
|
||||
public ITransformerProvider getTransformerProvider() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#getClassTracker()
|
||||
*/
|
||||
@Override
|
||||
public IClassTracker getClassTracker() {
|
||||
return this.classLoaderUtil;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IClassProvider#findClass(
|
||||
* java.lang.String)
|
||||
@@ -315,40 +333,6 @@ public class MixinServiceLaunchWrapper extends MixinServiceAbstract implements I
|
||||
return Launch.classLoader.getResourceAsStream(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#registerInvalidClass(
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void registerInvalidClass(String className) {
|
||||
this.classLoaderUtil.registerInvalidClass(className);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#isClassLoaded(
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isClassLoaded(String className) {
|
||||
return this.classLoaderUtil.isClassLoaded(className);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IMixinService#getClassRestrictions(
|
||||
* java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getClassRestrictions(String className) {
|
||||
String restrictions = "";
|
||||
if (this.classLoaderUtil.isClassClassLoaderExcluded(className, null)) {
|
||||
restrictions = "PACKAGE_CLASSLOADER_EXCLUSION";
|
||||
}
|
||||
if (this.classLoaderUtil.isClassTransformerExcluded(className, null)) {
|
||||
restrictions = (restrictions.length() > 0 ? restrictions + "," : "") + "PACKAGE_TRANSFORMER_EXCLUSION";
|
||||
}
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.service.IClassProvider#getClassPath()
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user