chore: moved exception from lll-processor

This commit is contained in:
zaaarf 2023-02-27 17:07:06 +01:00
parent cf537274ee
commit fe928a0fb0
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 26 additions and 11 deletions

View file

@ -0,0 +1,10 @@
package ftbsc.lll.exceptions;
/**
* Thrown upon failure to find the requested mapping within a loaded SrgMapper.
*/
public class MappingNotFoundException extends RuntimeException {
public MappingNotFoundException(String mapping) {
super("Could not find mapping for " + mapping + "!");
}
}

View file

@ -1,5 +1,7 @@
package ftbsc.lll.tools;
import ftbsc.lll.exceptions.MappingNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@ -44,11 +46,14 @@ public class SrgMapper {
/**
* Gets the SRG-obfuscated name of the class.
* @param mcp the MCP (deobfuscated) internal name of the desired class
* @return the SRG name of the class, or null if it wasn't found
* @return the SRG name of the class
* @throws MappingNotFoundException if no mapping is found
*/
public String getSrgClass(String mcp) {
ObfuscationData data = mapper.get(mcp);
return data == null ? null : data.srgName;
if(data == null)
throw new MappingNotFoundException(mcp);
else return data.srgName;
}
/**
@ -57,24 +62,26 @@ public class SrgMapper {
* with a space, because that's how it is in .tsrg files.
* @param mcpClass the MCP (deobfuscated) internal name of the container class
* @param member the field name or method signature
* @return the SRG name of the given member, or null if it wasn't found
* @return the SRG name of the given member
* @throws MappingNotFoundException if no mapping is found
*/
public String getSrgMember(String mcpClass, String member) {
ObfuscationData data = mapper.get(mcpClass);
if(data == null)
return null;
throw new MappingNotFoundException(mcpClass + "::" + member);
return data.members.get(member);
}
/**
* Used internally. Gets the obfuscation data corresponding to the given SRG name.
* @return the desired ObfuscationData object, or null if it wasn't found
* @return the desired {@link ObfuscationData} object
* @throws MappingNotFoundException if no {@link ObfuscationData} object is found
*/
private ObfuscationData getObfuscationData(String srg) {
for(ObfuscationData s : mapper.values())
if(s.srgName.equals(srg))
return s;
return null;
throw new MappingNotFoundException(srg);
}
/**
@ -82,11 +89,11 @@ public class SrgMapper {
* Due to how it's implemented, it's considerably less efficient than its
* opposite operation.
* @param srg the SRG-obfuscated internal name of the desired class
* @return the MCP name of the class, or null if it wasn't found
* @return the MCP name of the class
*/
public String getMcpClass(String srg) {
ObfuscationData data = getObfuscationData(srg);
return data == null ? null : data.mcpName;
return data.mcpName;
}
/**
@ -95,12 +102,10 @@ public class SrgMapper {
* opposite operation.
* @param srgClass the SRG-obfuscated internal name of the container class
* @param member the field name or method signature
* @return the MCP name of the given member, or null if it wasn't found
* @return the MCP name of the given member
*/
public String getMcpMember(String srgClass, String member) {
ObfuscationData data = getObfuscationData(srgClass);
if(data == null)
return null;
for(String mcp : data.members.keySet())
if(data.members.get(mcp).equals(member))
return mcp;