mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Refactor AP to support different mapping environments, closes #141
This commit is contained in:
1 parent
6a8f127ed5
commit
8d87440faf
48 files changed
+2988
-1003
No files matched your search
@@ -62,7 +62,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.5.14";
|
||||
public static final String VERSION = "0.5.15";
|
||||
|
||||
// Consts
|
||||
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
|
||||
|
||||
@@ -31,7 +31,9 @@ import org.spongepowered.asm.lib.tree.MethodInsnNode;
|
||||
import org.spongepowered.asm.mixin.refmap.IReferenceMapperContext;
|
||||
import org.spongepowered.asm.mixin.refmap.ReferenceMapper;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.obfuscation.SrgMethod;
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
/**
|
||||
@@ -95,6 +97,11 @@ public class MemberInfo {
|
||||
* True to match all matching members, not just the first
|
||||
*/
|
||||
public final boolean matchAll;
|
||||
|
||||
/**
|
||||
* Force this member to report as a field
|
||||
*/
|
||||
private final boolean forceField;
|
||||
|
||||
/**
|
||||
* ctor
|
||||
@@ -134,10 +141,11 @@ public class MemberInfo {
|
||||
throw new IllegalArgumentException("Attempt to instance a MemberInfo with an invalid owner format");
|
||||
}
|
||||
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.matchAll = matchAll;
|
||||
this.forceField = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +156,7 @@ public class MemberInfo {
|
||||
*/
|
||||
public MemberInfo(AbstractInsnNode insn) {
|
||||
this.matchAll = false;
|
||||
this.forceField = false;
|
||||
|
||||
if (insn instanceof MethodInsnNode) {
|
||||
MethodInsnNode methodNode = (MethodInsnNode) insn;
|
||||
@@ -165,27 +174,29 @@ public class MemberInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise a MemberInfo using the supplied SrgMethod object
|
||||
* Initialise a MemberInfo using the supplied mapping object
|
||||
*
|
||||
* @param srgMethod SrgMethod object to copy values from
|
||||
* @param mapping Mapping object to copy values from
|
||||
*/
|
||||
public MemberInfo(SrgMethod srgMethod) {
|
||||
this.owner = srgMethod.getOwner();
|
||||
this.name = srgMethod.getSimpleName();
|
||||
this.desc = srgMethod.getDesc();
|
||||
public MemberInfo(IMapping<?> mapping) {
|
||||
this.owner = mapping.getOwner();
|
||||
this.name = mapping.getSimpleName();
|
||||
this.desc = mapping.getDesc();
|
||||
this.matchAll = false;
|
||||
this.forceField = mapping.getType() == IMapping.Type.FIELD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise a remapped MemberInfo using the supplied SrgMethod object
|
||||
* Initialise a remapped MemberInfo using the supplied mapping object
|
||||
*
|
||||
* @param srgMethod SrgMethod object to copy values from
|
||||
* @param method mapping method object to copy values from
|
||||
*/
|
||||
private MemberInfo(MemberInfo remapped, SrgMethod srgMethod, boolean setOwner) {
|
||||
this.owner = setOwner ? srgMethod.getOwner() : remapped.owner;
|
||||
this.name = srgMethod.getSimpleName();
|
||||
this.desc = srgMethod.getDesc();
|
||||
private MemberInfo(MemberInfo remapped, MappingMethod method, boolean setOwner) {
|
||||
this.owner = setOwner ? method.getOwner() : remapped.owner;
|
||||
this.name = method.getSimpleName();
|
||||
this.desc = method.getDesc();
|
||||
this.matchAll = remapped.matchAll;
|
||||
this.forceField = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,6 +210,7 @@ public class MemberInfo {
|
||||
this.name = original.name;
|
||||
this.desc = original.desc;
|
||||
this.matchAll = original.matchAll;
|
||||
this.forceField = original.forceField;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -218,7 +230,9 @@ public class MemberInfo {
|
||||
* Return this MemberInfo as an SRG mapping
|
||||
*
|
||||
* @return SRG representation of this MemberInfo
|
||||
* @deprecated use m.asMethodMapping().serialise() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public String toSrg() {
|
||||
if (!this.isFullyQualified()) {
|
||||
throw new MixinException("Cannot convert unqualified reference to SRG mapping");
|
||||
@@ -239,16 +253,28 @@ public class MemberInfo {
|
||||
return new SignaturePrinter(this).setFullyQualified(true).toDescriptor();
|
||||
}
|
||||
|
||||
public SrgMethod asSrgMethod() {
|
||||
public IMapping<?> asMapping() {
|
||||
return this.isField() ? this.asFieldMapping() : this.asMethodMapping();
|
||||
}
|
||||
|
||||
public MappingMethod asMethodMapping() {
|
||||
if (!this.isFullyQualified()) {
|
||||
throw new MixinException("Cannot convert unqualified reference to SrgMethod");
|
||||
throw new MixinException("Cannot convert unqualified reference " + this + " to MethodMapping");
|
||||
}
|
||||
|
||||
if (this.isField()) {
|
||||
throw new MixinException("Cannot convert a non-method reference to SrgMethod");
|
||||
throw new MixinException("Cannot convert a non-method reference " + this + " to MethodMapping");
|
||||
}
|
||||
|
||||
return new SrgMethod(this.owner + "/" + this.name, this.desc);
|
||||
return new MappingMethod(this.owner + "/" + this.name, this.desc);
|
||||
}
|
||||
|
||||
public MappingField asFieldMapping() {
|
||||
if (!this.isField()) {
|
||||
throw new MixinException("Cannot convert non-field reference " + this + " to FieldMapping");
|
||||
}
|
||||
|
||||
return new MappingField(this.owner, this.name, this.desc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +293,7 @@ public class MemberInfo {
|
||||
* @return true if this is definitely a field
|
||||
*/
|
||||
public boolean isField() {
|
||||
return this.desc != null && !this.desc.startsWith("(");
|
||||
return this.forceField || (this.desc != null && !this.desc.startsWith("("));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +442,7 @@ public class MemberInfo {
|
||||
* @param setOwner True to set the owner as well as the name
|
||||
* @return New MethodInfo with remapped values
|
||||
*/
|
||||
public MemberInfo remapUsing(SrgMethod srgMethod, boolean setOwner) {
|
||||
public MemberInfo remapUsing(MappingMethod srgMethod, boolean setOwner) {
|
||||
return new MemberInfo(this, srgMethod, setOwner);
|
||||
}
|
||||
|
||||
@@ -512,14 +538,7 @@ public class MemberInfo {
|
||||
return new MemberInfo(name, owner, desc, matchAll);
|
||||
}
|
||||
|
||||
public static MemberInfo fromSrgField(String srgName, String desc) {
|
||||
int slashPos = srgName.lastIndexOf('/');
|
||||
String owner = srgName.substring(0, slashPos);
|
||||
String name = srgName.substring(slashPos + 1);
|
||||
return new MemberInfo(name, owner, desc, false);
|
||||
}
|
||||
|
||||
public static MemberInfo fromSrgMethod(SrgMethod srgMethod) {
|
||||
return new MemberInfo(srgMethod);
|
||||
public static MemberInfo fromMapping(IMapping<?> mapping) {
|
||||
return new MemberInfo(mapping);
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.obfuscation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import joptsimple.internal.Strings;
|
||||
|
||||
/**
|
||||
* Ported from <strong>Srg2Source</strong> (
|
||||
* <a href=\"https://github.com/MinecraftForge/Srg2Source\">
|
||||
* github.com/MinecraftForge/Srg2Source</a>).
|
||||
*/
|
||||
public class SrgContainer {
|
||||
|
||||
private final BiMap<String, String> packageMap = HashBiMap.create();
|
||||
private final BiMap<String, String> classMap = HashBiMap.create();
|
||||
private final BiMap<SrgField, SrgField> fieldMap = HashBiMap.create();
|
||||
private final BiMap<SrgMethod, SrgMethod> methodMap = HashBiMap.create();
|
||||
|
||||
public void readSrg(File srg) throws IOException {
|
||||
for (String line : Files.readLines(srg, Charset.defaultCharset())) {
|
||||
if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String type = line.substring(0, 2);
|
||||
String[] args = line.substring(4).split(" ");
|
||||
|
||||
if (type.equals("PK")) {
|
||||
this.packageMap.forcePut(args[0], args[1]);
|
||||
} else if (type.equals("CL")) {
|
||||
this.classMap.forcePut(args[0], args[1]);
|
||||
} else if (type.equals("FD")) {
|
||||
this.fieldMap.forcePut(new SrgField(args[0]), new SrgField(args[1]));
|
||||
} else if (type.equals("MD")) {
|
||||
this.methodMap.forcePut(new SrgMethod(args[0], args[1]), new SrgMethod(args[2], args[3]));
|
||||
} else {
|
||||
throw new MixinException("Invalid SRG file: " + srg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SrgMethod getMethodMapping(SrgMethod methodName) {
|
||||
return this.methodMap.get(methodName);
|
||||
}
|
||||
|
||||
public SrgField getFieldMapping(SrgField fieldName) {
|
||||
return this.fieldMap.get(fieldName);
|
||||
}
|
||||
|
||||
public String getClassMapping(String className) {
|
||||
return this.classMap.get(className);
|
||||
}
|
||||
|
||||
public String getPackageMapping(String packageName) {
|
||||
return this.packageMap.get(packageName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.obfuscation.mapping;
|
||||
|
||||
/**
|
||||
* Base class for member mapping entries
|
||||
*
|
||||
* @param <TMapping> type of this member, for transformation method return types
|
||||
*/
|
||||
public interface IMapping<TMapping> {
|
||||
|
||||
/**
|
||||
* Type of mapping
|
||||
*/
|
||||
public enum Type {
|
||||
FIELD,
|
||||
METHOD,
|
||||
CLASS,
|
||||
PACKAGE
|
||||
}
|
||||
|
||||
public abstract Type getType();
|
||||
|
||||
public abstract TMapping move(String newOwner);
|
||||
|
||||
public abstract TMapping remap(String newName);
|
||||
|
||||
public abstract TMapping transform(String newDesc);
|
||||
|
||||
public abstract TMapping copy();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract String getSimpleName();
|
||||
|
||||
public abstract String getOwner();
|
||||
|
||||
public abstract String getDesc();
|
||||
|
||||
public abstract String serialise();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.obfuscation.mapping.common;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* Stores information about a field mapping during AP runs
|
||||
*/
|
||||
public class MappingField implements IMapping<MappingField> {
|
||||
|
||||
private final String owner;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String desc;
|
||||
|
||||
public MappingField(String owner, String name) {
|
||||
this(owner, name, null);
|
||||
}
|
||||
|
||||
public MappingField(String owner, String name, String desc) {
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.FIELD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getSimpleName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField move(String newOwner) {
|
||||
return new MappingField(newOwner, this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField remap(String newName) {
|
||||
return new MappingField(this.getOwner(), newName, this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField transform(String newDesc) {
|
||||
return new MappingField(this.getOwner(), this.getName(), newDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingField copy() {
|
||||
return new MappingField(this.getOwner(), this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof MappingField) {
|
||||
return Objects.equal(this.toString(), ((MappingField)obj).toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialise() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("L%s;%s:%s", this.getOwner(), this.getName(), Strings.nullToEmpty(this.getDesc()));
|
||||
}
|
||||
}
|
||||
+41
-13
@@ -22,32 +22,41 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.obfuscation;
|
||||
package org.spongepowered.asm.obfuscation.mapping.common;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.mapping.IMapping;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* Stores information about an SRG method mapping during AP runs
|
||||
* Stores information about a method mapping during AP runs
|
||||
*/
|
||||
public final class SrgMethod {
|
||||
public class MappingMethod implements IMapping<MappingMethod> {
|
||||
|
||||
private final String name;
|
||||
private final String desc;
|
||||
|
||||
public SrgMethod(String name, String desc) {
|
||||
public MappingMethod(String name, String desc) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public SrgMethod(String owner, String simpleName, String desc) {
|
||||
this.name = SrgMethod.createName(owner, simpleName);
|
||||
public MappingMethod(String owner, String simpleName, String desc) {
|
||||
this.name = MappingMethod.createName(owner, simpleName);
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.METHOD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSimpleName() {
|
||||
if (this.name == null) {
|
||||
return null;
|
||||
@@ -56,6 +65,7 @@ public final class SrgMethod {
|
||||
return pos > -1 ? this.name.substring(pos + 1) : this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
if (this.name == null) {
|
||||
return null;
|
||||
@@ -64,21 +74,34 @@ public final class SrgMethod {
|
||||
return pos > -1 ? this.name.substring(0, pos) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
public SrgMethod move(String newOwner) {
|
||||
return new SrgMethod(newOwner, this.getSimpleName(), this.desc);
|
||||
@Override
|
||||
public MappingMethod move(String newOwner) {
|
||||
return new MappingMethod(newOwner, this.getSimpleName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod remap(String newName) {
|
||||
return new MappingMethod(this.getOwner(), newName, this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingMethod transform(String newDesc) {
|
||||
return new MappingMethod(this.getName(), newDesc);
|
||||
}
|
||||
|
||||
public SrgMethod copy() {
|
||||
return new SrgMethod(this.name, this.desc);
|
||||
@Override
|
||||
public MappingMethod copy() {
|
||||
return new MappingMethod(this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.name, this.desc);
|
||||
return Objects.hashCode(this.getName(), this.getDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,11 +109,16 @@ public final class SrgMethod {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof SrgMethod) {
|
||||
return Objects.equal(this.name, ((SrgMethod)obj).name) && Objects.equal(this.desc, ((SrgMethod)obj).desc);
|
||||
if (obj instanceof MappingMethod) {
|
||||
return Objects.equal(this.name, ((MappingMethod)obj).name) && Objects.equal(this.desc, ((MappingMethod)obj).desc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialise() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
+28
-50
@@ -22,68 +22,46 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.obfuscation;
|
||||
package org.spongepowered.asm.obfuscation.mapping.mcp;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
|
||||
/**
|
||||
* Stores information about an SRG field mapping during AP runs
|
||||
* An SRG field mapping
|
||||
*/
|
||||
public final class SrgField {
|
||||
public class MappingFieldSrg extends MappingField {
|
||||
|
||||
private final String mapping;
|
||||
private final String srg;
|
||||
|
||||
public SrgField(String mapping) {
|
||||
this.mapping = mapping;
|
||||
public MappingFieldSrg(String srg) {
|
||||
super(MappingFieldSrg.getOwnerFromSrg(srg), MappingFieldSrg.getNameFromSrg(srg), null);
|
||||
this.srg = srg;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (this.mapping == null) {
|
||||
public MappingFieldSrg(MappingField field) {
|
||||
super(field.getOwner(), field.getName(), null);
|
||||
this.srg = field.getOwner() + "/" + field.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialise() {
|
||||
return this.srg;
|
||||
}
|
||||
|
||||
private static String getNameFromSrg(String srg) {
|
||||
if (srg == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = this.mapping.lastIndexOf('/');
|
||||
return pos > -1 ? this.mapping.substring(pos + 1) : this.mapping;
|
||||
int pos = srg.lastIndexOf('/');
|
||||
return pos > -1 ? srg.substring(pos + 1) : srg;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
if (this.mapping == null) {
|
||||
|
||||
private static String getOwnerFromSrg(String srg) {
|
||||
if (srg == null) {
|
||||
return null;
|
||||
}
|
||||
int pos = this.mapping.lastIndexOf('/');
|
||||
return pos > -1 ? this.mapping.substring(0, pos) : null;
|
||||
int pos = srg.lastIndexOf('/');
|
||||
return pos > -1 ? srg.substring(0, pos) : null;
|
||||
}
|
||||
|
||||
public String getMapping() {
|
||||
return this.mapping;
|
||||
}
|
||||
|
||||
public SrgField move(String newOwner) {
|
||||
return new SrgField((newOwner != null ? newOwner + "/" : "") + this.getName());
|
||||
}
|
||||
|
||||
public SrgField copy() {
|
||||
return new SrgField(this.mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof SrgField) {
|
||||
return Objects.equal(this.mapping, ((SrgField)obj).mapping);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.mapping;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user