mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Further AP refactor, support injectors and shadows in multitarget mixins
This commit is contained in:
1 parent
8d87440faf
commit
ea44243240
17 files changed
+587
-144
No files matched your search
@@ -266,7 +266,7 @@ public class MemberInfo {
|
||||
throw new MixinException("Cannot convert a non-method reference " + this + " to MethodMapping");
|
||||
}
|
||||
|
||||
return new MappingMethod(this.owner + "/" + this.name, this.desc);
|
||||
return new MappingMethod(this.owner, this.name, this.desc);
|
||||
}
|
||||
|
||||
public MappingField asFieldMapping() {
|
||||
|
||||
@@ -176,10 +176,11 @@ public final class ReferenceMapper implements Serializable {
|
||||
* @param className Class which owns this mapping, cannot be null
|
||||
* @param reference Reference to remap, cannot be null
|
||||
* @param newReference Remapped value, cannot be null
|
||||
* @return replaced value, per the contract of {@link Map#put}
|
||||
*/
|
||||
public void addMapping(String context, String className, String reference, String newReference) {
|
||||
public String addMapping(String context, String className, String reference, String newReference) {
|
||||
if (this.readOnly || reference == null || newReference == null || reference.equals(newReference)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
Map<String, Map<String, String>> mappings = this.mappings;
|
||||
if (context != null) {
|
||||
@@ -194,7 +195,7 @@ public final class ReferenceMapper implements Serializable {
|
||||
classMappings = new HashMap<String, String>();
|
||||
mappings.put(className, classMappings);
|
||||
}
|
||||
classMappings.put(reference, newReference);
|
||||
return classMappings.put(reference, newReference);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,24 +41,82 @@ public interface IMapping<TMapping> {
|
||||
PACKAGE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mapping type (field, method, class, package)
|
||||
*/
|
||||
public abstract Type getType();
|
||||
|
||||
/**
|
||||
* Create a clone of this mapping with a new owner
|
||||
*
|
||||
* @param newOwner new owner
|
||||
* @return cloned mapping
|
||||
*/
|
||||
public abstract TMapping move(String newOwner);
|
||||
|
||||
/**
|
||||
* Create a clone of this mapping with a new name
|
||||
*
|
||||
* @param newName new name
|
||||
* @return cloned mapping
|
||||
*/
|
||||
public abstract TMapping remap(String newName);
|
||||
|
||||
/**
|
||||
* Create a clone of this mapping with a new descriptor
|
||||
*
|
||||
* @param newDesc new descriptor
|
||||
* @return cloned mapping
|
||||
*/
|
||||
public abstract TMapping transform(String newDesc);
|
||||
|
||||
/**
|
||||
* Create a clone of this mapping
|
||||
*
|
||||
* @return cloned mapping
|
||||
*/
|
||||
public abstract TMapping copy();
|
||||
|
||||
/**
|
||||
* Get the mapping name, for method mappings this includes the owner
|
||||
*
|
||||
* @return the mapping name, includes the owner for method mappings
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Get the base name of this member, for example the bare field, method or
|
||||
* class name
|
||||
*
|
||||
* @return the base name of this mapping
|
||||
*/
|
||||
public abstract String getSimpleName();
|
||||
|
||||
/**
|
||||
* Get the owner of this member, for fields and methods this is the class
|
||||
* name, for classes it is the package name, for packages it is undefined.
|
||||
* Can return null.
|
||||
*
|
||||
* @return the parent of this mapping
|
||||
*/
|
||||
public abstract String getOwner();
|
||||
|
||||
/**
|
||||
* Get the descriptor of this member, for example the method descriptor or
|
||||
* field type. For classes and packages this is undefined. Can return null
|
||||
* since not all mapping types support descriptors.
|
||||
*
|
||||
* @return the mapping descriptor
|
||||
*/
|
||||
public abstract String getDesc();
|
||||
|
||||
/**
|
||||
* Get a representation of this mapping for serialisation. Individual
|
||||
* writers are free to use their own mappings, this method is for
|
||||
* convenience only.
|
||||
*
|
||||
* @return string representation of this mapping
|
||||
*/
|
||||
public abstract String serialise();
|
||||
|
||||
}
|
||||
@@ -33,16 +33,17 @@ import com.google.common.base.Objects;
|
||||
*/
|
||||
public class MappingMethod implements IMapping<MappingMethod> {
|
||||
|
||||
private final String owner;
|
||||
private final String name;
|
||||
private final String desc;
|
||||
|
||||
public MappingMethod(String name, String desc) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
public MappingMethod(String fullyQualifiedName, String desc) {
|
||||
this(MappingMethod.getOwnerFromName(fullyQualifiedName), MappingMethod.getBaseName(fullyQualifiedName), desc);
|
||||
}
|
||||
|
||||
|
||||
public MappingMethod(String owner, String simpleName, String desc) {
|
||||
this.name = MappingMethod.createName(owner, simpleName);
|
||||
this.owner = owner;
|
||||
this.name = simpleName;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@@ -53,25 +54,20 @@ public class MappingMethod implements IMapping<MappingMethod> {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
if (this.name == null) {
|
||||
return null;
|
||||
}
|
||||
return (this.owner != null ? this.owner + "/" : "") + this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSimpleName() {
|
||||
if (this.name == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = this.name.lastIndexOf('/');
|
||||
return pos > -1 ? this.name.substring(pos + 1) : this.name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
if (this.name == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = this.name.lastIndexOf('/');
|
||||
return pos > -1 ? this.name.substring(0, pos) : null;
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,12 +87,12 @@ public class MappingMethod implements IMapping<MappingMethod> {
|
||||
|
||||
@Override
|
||||
public MappingMethod transform(String newDesc) {
|
||||
return new MappingMethod(this.getName(), newDesc);
|
||||
return new MappingMethod(this.getOwner(), this.getSimpleName(), newDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod copy() {
|
||||
return new MappingMethod(this.getName(), this.getDesc());
|
||||
return new MappingMethod(this.getOwner(), this.getSimpleName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,11 +118,23 @@ public class MappingMethod implements IMapping<MappingMethod> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s", this.name, this.desc);
|
||||
return String.format("%s %s", this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
private static String createName(String owner, String simpleName) {
|
||||
return (owner != null ? owner + "/" : "") + simpleName;
|
||||
private static String getBaseName(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = name.lastIndexOf('/');
|
||||
return pos > -1 ? name.substring(pos + 1) : name;
|
||||
}
|
||||
|
||||
private static String getOwnerFromName(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = name.lastIndexOf('/');
|
||||
return pos > -1 ? name.substring(0, pos) : null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user