Quick code format in preparation for repackage.

This commit is contained in:
md_5 2013-04-20 12:01:28 +10:00
parent 41244d37e1
commit a318ec4ce6
18 changed files with 134 additions and 125 deletions

View File

@ -42,11 +42,12 @@ import java.util.Map;
* *
* Access change format: * Access change format:
* *
* - visibility upgrade (required) * - visibility upgrade (required) -- public, protected, private ('*', no
* -- public, protected, private ('*', no change), or default (package-private) * change), or default (package-private) -- additional optional flag(s),
* -- additional optional flag(s), preceded by '+' to set, '-' to clear * preceded by '+' to set, '-' to clear
* *
* Example: public-final+synchronized = upgrade to public, clear final, set synchronized * Example: public-final+synchronized = upgrade to public, clear final, set
* synchronized
* *
* @see AccessMap * @see AccessMap
*/ */
@ -56,7 +57,6 @@ public class AccessChange {
private int clear; // bits to clear to 0 private int clear; // bits to clear to 0
private int set; // bits to set to 1 (overrides clear) private int set; // bits to set to 1 (overrides clear)
private int vis; // desired visibility increase private int vis; // desired visibility increase
private final static Map<String, Integer> accessCodes = new HashMap<String, Integer>(); private final static Map<String, Integer> accessCodes = new HashMap<String, Integer>();
static { static {
@ -85,16 +85,14 @@ public class AccessChange {
accessCodes.put("enum", Opcodes.ACC_ENUM); accessCodes.put("enum", Opcodes.ACC_ENUM);
accessCodes.put("deprecated", Opcodes.ACC_DEPRECATED); accessCodes.put("deprecated", Opcodes.ACC_DEPRECATED);
} }
private final static BiMap<Integer, Integer> visibilityOrder = HashBiMap.create(); private final static BiMap<Integer, Integer> visibilityOrder = HashBiMap.create();
static { static {
visibilityOrder.put(Opcodes.ACC_PRIVATE, 100); visibilityOrder.put(Opcodes.ACC_PRIVATE, 100);
visibilityOrder.put(0, 200); // default package-private visibilityOrder.put(0, 200); // default package-private
visibilityOrder.put(Opcodes.ACC_PROTECTED, 300); visibilityOrder.put(Opcodes.ACC_PROTECTED, 300);
visibilityOrder.put(Opcodes.ACC_PUBLIC, 400); visibilityOrder.put(Opcodes.ACC_PUBLIC, 400);
} }
private final static int MASK_ALL_VISIBILITY = Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED; private final static int MASK_ALL_VISIBILITY = Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED;
public AccessChange(String s) { public AccessChange(String s) {
@ -116,7 +114,7 @@ public class AccessChange {
// Modifiers // Modifiers
for (int i = 1; i < parts.length; ++i) { for (int i = 1; i < parts.length; ++i) {
if (parts[i].length() < 2) { if (parts[i].length() < 2) {
throw new IllegalArgumentException("Invalid modifier length "+parts[i]+" in access string: " + s); throw new IllegalArgumentException("Invalid modifier length " + parts[i] + " in access string: " + s);
} }
// Name // Name
@ -125,15 +123,20 @@ public class AccessChange {
int modifier; int modifier;
if (!accessCodes.containsKey(modifierString)) { if (!accessCodes.containsKey(modifierString)) {
throw new IllegalArgumentException("Invalid modifier string "+modifierString+" in access string: " + s); throw new IllegalArgumentException("Invalid modifier string " + modifierString + " in access string: " + s);
} }
modifier = accessCodes.get(modifierString); modifier = accessCodes.get(modifierString);
// Toggle // Toggle
switch (actionChar) { switch (actionChar) {
case '+': set |= modifier; break; case '+':
case '-': clear |= modifier; break; set |= modifier;
default: throw new IllegalArgumentException("Invalid action "+actionChar+" in access string: " + s); break;
case '-':
clear |= modifier;
break;
default:
throw new IllegalArgumentException("Invalid action " + actionChar + " in access string: " + s);
} }
} }
} }
@ -168,7 +171,7 @@ public class AccessChange {
* @return The greater visibility of the two arguments * @return The greater visibility of the two arguments
*/ */
private static int upgradeVisibility(int existing, int desired) { private static int upgradeVisibility(int existing, int desired) {
if (!visibilityOrder.containsKey(existing) || !visibilityOrder.containsKey(desired)) { if (!visibilityOrder.containsKey(existing) || !visibilityOrder.containsKey(desired)) {
throw new IllegalArgumentException("Unrecognized visibility: " + existing + " or " + desired); throw new IllegalArgumentException("Unrecognized visibility: " + existing + " or " + desired);
} }
@ -181,7 +184,9 @@ public class AccessChange {
} }
/** /**
* Set visibility on access flags, overwriting existing, preserving other flags * Set visibility on access flags, overwriting existing, preserving other
* flags
*
* @param access * @param access
* @param visibility * @param visibility
* @return * @return

View File

@ -38,25 +38,20 @@ import java.util.Map;
/** /**
* Access mapper - for modifying access flags on symbols * Access mapper - for modifying access flags on symbols
* *
* Supports loading _at.cfg files in the following format: * Supports loading _at.cfg files in the following format: - comments beginning
* - comments beginning with '#' extending to end of line * with '#' extending to end of line - symbol pattern, space, then access
* - symbol pattern, space, then access changes * changes
* *
* Symbol pattern format: * Symbol pattern format: foo class foo/bar field foo/bar ()desc method foo/*
* foo class * fields in class foo/* ()desc methods in class * all classes
* foo/bar field * *<nobr/>/* all fields
* foo/bar ()desc method * *<nobr/>/*() all methods ** all classes, fields, and methods
* foo/* fields in class
* foo/* ()desc methods in class
* * all classes
* *<nobr/>/* all fields
* *<nobr/>/*() all methods
* ** all classes, fields, and methods
* *
* Internal ('/') and source ('.') conventions are accepted, * Internal ('/') and source ('.') conventions are accepted, and the space
* and the space preceding the method descriptor is optional. * preceding the method descriptor is optional.
* *
* Access change format: visibility (required) + access flags * Access change format: visibility (required) + access flags
*
* @see AccessChange * @see AccessChange
* *
*/ */
@ -80,7 +75,7 @@ public class AccessMap {
if (n != -1) { if (n != -1) {
line = line.substring(0, n); line = line.substring(0, n);
} }
if (line.isEmpty()){ if (line.isEmpty()) {
continue; continue;
} }
@ -95,10 +90,8 @@ public class AccessMap {
/** /**
* Load an access transformer into this AccessMap. * Load an access transformer into this AccessMap.
* *
* @param filename Location of AT data, one of: * @param filename Location of AT data, one of: - local filename - remote
* - local filename * HTTP URL - "pattern:" followed by one transformer line
* - remote HTTP URL
* - "pattern:" followed by one transformer line
* @throws IOException * @throws IOException
*/ */
public void loadAccessTransformer(String filename) throws IOException { public void loadAccessTransformer(String filename) throws IOException {
@ -146,7 +139,7 @@ public class AccessMap {
public void addAccessChange(String key, AccessChange accessChange) { public void addAccessChange(String key, AccessChange accessChange) {
if (map.containsKey(key)) { if (map.containsKey(key)) {
System.out.println("INFO: merging AccessMap "+key+" from "+map.get(key)+" with "+accessChange); System.out.println("INFO: merging AccessMap " + key + " from " + map.get(key) + " with " + accessChange);
map.get(key).merge(accessChange); map.get(key).merge(accessChange);
} }
map.put(key, accessChange); map.put(key, accessChange);
@ -177,7 +170,7 @@ public class AccessMap {
return access; return access;
} }
public int applyMethodAccess(String className, String methodName, String methodDesc, int access) { public int applyMethodAccess(String className, String methodName, String methodDesc, int access) {
int old = access; int old = access;
access = apply("**", access); access = apply("**", access);

View File

@ -37,8 +37,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* For reading a .srg through MCP's fields.csv and methods.csv * For reading a .srg through MCP's fields.csv and methods.csv Maps func_### and
* Maps func_### and field_### in input srg to "descriptive" names * field_### in input srg to "descriptive" names
*/ */
public class CSVMappingTransformer extends JarMappingLoadTransformer { public class CSVMappingTransformer extends JarMappingLoadTransformer {

View File

@ -40,7 +40,6 @@ public class ChainTransformer extends JarMappingLoadTransformer {
} }
// TODO: make this less lame // TODO: make this less lame
@Override @Override
public String transformClassName(String className) { public String transformClassName(String className) {
return jarRemapper.map(className); return jarRemapper.map(className);

View File

@ -36,7 +36,8 @@ public interface IInheritanceProvider {
* Get the superclass and implemented interfaces of a class * Get the superclass and implemented interfaces of a class
* *
* @param className * @param className
* @return List of interfaces, or null if no information is available and other providers should be checked * @return List of interfaces, or null if no information is available and
* other providers should be checked
*/ */
List<String> getParents(String className); List<String> getParents(String className);
} }

View File

@ -40,7 +40,6 @@ import java.util.*;
public class InheritanceMap implements IInheritanceProvider { public class InheritanceMap implements IInheritanceProvider {
private final Map<String, ArrayList<String>> inheritanceMap = new HashMap<String, ArrayList<String>>(); private final Map<String, ArrayList<String>> inheritanceMap = new HashMap<String, ArrayList<String>>();
public static final InheritanceMap EMPTY = new InheritanceMap(); public static final InheritanceMap EMPTY = new InheritanceMap();
/** /**
@ -51,12 +50,12 @@ public class InheritanceMap implements IInheritanceProvider {
List<String> parents = inheritanceProvider.getParents(className); List<String> parents = inheritanceProvider.getParents(className);
if (parents == null) { if (parents == null) {
System.out.println("No inheritance information found for "+className); System.out.println("No inheritance information found for " + className);
} else { } else {
ArrayList<String> filteredParents = new ArrayList<String>(); ArrayList<String> filteredParents = new ArrayList<String>();
// Include only classes requested // Include only classes requested
for (String parent: parents) { for (String parent : parents) {
if (classes.contains(parent)) { if (classes.contains(parent)) {
filteredParents.add(parent); filteredParents.add(parent);
} }
@ -99,14 +98,14 @@ public class InheritanceMap implements IInheritanceProvider {
if (classMap == null) { if (classMap == null) {
setParents(className, new ArrayList<String>(parents)); setParents(className, new ArrayList<String>(parents));
} else { } else {
String remappedClassName = JarRemapper.mapTypeName(className, /*packageMap*/null, classMap, /*defaultIfUnmapped*/null); String remappedClassName = JarRemapper.mapTypeName(className, /*packageMap*/ null, classMap, /*defaultIfUnmapped*/ null);
if (remappedClassName == null) { if (remappedClassName == null) {
throw new IOException("Inheritance map input class not remapped: " + className); throw new IOException("Inheritance map input class not remapped: " + className);
} }
ArrayList<String> remappedParents = new ArrayList<String>(); ArrayList<String> remappedParents = new ArrayList<String>();
for (String parent : parents) { for (String parent : parents) {
String remappedParent = JarRemapper.mapTypeName(parent, /*packageMap*/null, classMap, /*defaultIfUnmapped*/null); String remappedParent = JarRemapper.mapTypeName(parent, /*packageMap*/ null, classMap, /*defaultIfUnmapped*/ null);
if (remappedParent == null) { if (remappedParent == null) {
throw new IOException("Inheritance map parent class not remapped: " + parent); throw new IOException("Inheritance map parent class not remapped: " + parent);
} }

View File

@ -35,6 +35,7 @@ import java.util.List;
* Lookup inheritance information from multiple sources, in order * Lookup inheritance information from multiple sources, in order
*/ */
public class InheritanceProviders implements IInheritanceProvider { public class InheritanceProviders implements IInheritanceProvider {
private List<IInheritanceProvider> inheritanceProviders; private List<IInheritanceProvider> inheritanceProviders;
public InheritanceProviders() { public InheritanceProviders() {

View File

@ -47,9 +47,10 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
/** /**
* This class wraps one or more {@link JarFile}s enabling quick access to the jar's main * This class wraps one or more {@link JarFile}s enabling quick access to the
* class, as well as the ability to get the {@link InputStream} of a class file, * jar's main class, as well as the ability to get the {@link InputStream} of a
* and speedy lookups to see if the jar contains the specified class. * class file, and speedy lookups to see if the jar contains the specified
* class.
*/ */
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
@ -138,10 +139,10 @@ public class Jar {
String name = entry.getName(); String name = entry.getName();
/* /*
if (jarForResource.containsKey(name)) { if (jarForResource.containsKey(name)) {
System.out.println("INFO: overwriting "+entry.getName()+" from "+jarForResource.get(name).getName()+" with "+jarFile.getName()); System.out.println("INFO: overwriting "+entry.getName()+" from "+jarForResource.get(name).getName()+" with "+jarFile.getName());
} }
*/ */
jarForResource.put(name, jarFile); jarForResource.put(name, jarFile);
} }

View File

@ -37,7 +37,6 @@ public class JarMapping {
public final Map<String, String> classes = new HashMap<String, String>(); public final Map<String, String> classes = new HashMap<String, String>();
public final Map<String, String> fields = new HashMap<String, String>(); public final Map<String, String> fields = new HashMap<String, String>();
public final Map<String, String> methods = new HashMap<String, String>(); public final Map<String, String> methods = new HashMap<String, String>();
private InheritanceMap inheritanceMap = new InheritanceMap(); private InheritanceMap inheritanceMap = new InheritanceMap();
private IInheritanceProvider fallbackInheritanceProvider = null; private IInheritanceProvider fallbackInheritanceProvider = null;
@ -45,16 +44,17 @@ public class JarMapping {
} }
/** /**
* Set the inheritance map used for caching superclass/interfaces. This call be omitted to * Set the inheritance map used for caching superclass/interfaces. This call
* use a local cache, or set to your own global cache. * be omitted to use a local cache, or set to your own global cache.
*/ */
public void setInheritanceMap(InheritanceMap inheritanceMap) { public void setInheritanceMap(InheritanceMap inheritanceMap) {
this.inheritanceMap = inheritanceMap; this.inheritanceMap = inheritanceMap;
} }
/** /**
* Set the inheritance provider to be consulted if the inheritance map has no information on * Set the inheritance provider to be consulted if the inheritance map has
* the requested class (results will be cached in the inheritance map). * no information on the requested class (results will be cached in the
* inheritance map).
*/ */
public void setFallbackInheritanceProvider(IInheritanceProvider fallbackInheritanceProvider) { public void setFallbackInheritanceProvider(IInheritanceProvider fallbackInheritanceProvider) {
this.fallbackInheritanceProvider = fallbackInheritanceProvider; this.fallbackInheritanceProvider = fallbackInheritanceProvider;
@ -92,13 +92,15 @@ public class JarMapping {
* *
* @param dirname MCP directory name, local file or remote URL ending in '/' * @param dirname MCP directory name, local file or remote URL ending in '/'
* @param reverse If true, swap input and output * @param reverse If true, swap input and output
* @param ignoreCsv If true, ignore fields.csv and methods.csv (but not packages.csv) * @param ignoreCsv If true, ignore fields.csv and methods.csv (but not
* @param numericSrgNames If true, load numeric "srg" names (num->mcp instead of obf->mcp) * packages.csv)
* @param numericSrgNames If true, load numeric "srg" names (num->mcp
* instead of obf->mcp)
*/ */
private void loadMappingsDir(String dirname, boolean reverse, boolean ignoreCsv, boolean numericSrgNames) throws IOException { private void loadMappingsDir(String dirname, boolean reverse, boolean ignoreCsv, boolean numericSrgNames) throws IOException {
File dir = new File(dirname); File dir = new File(dirname);
if (!URLDownloader.isHTTPURL(dirname) && !dir.isDirectory()) { if (!URLDownloader.isHTTPURL(dirname) && !dir.isDirectory()) {
throw new IllegalArgumentException("loadMappingsDir("+dir+"): not a directory"); throw new IllegalArgumentException("loadMappingsDir(" + dir + "): not a directory");
} }
String sep = System.getProperty("file.separator"); String sep = System.getProperty("file.separator");
@ -122,7 +124,7 @@ public class JarMapping {
} }
if (srgFiles.size() == 0) { if (srgFiles.size() == 0) {
throw new IOException("loadMappingsDir("+dirname+"): no joined.srg, client.srg, or client.srg found"); throw new IOException("loadMappingsDir(" + dirname + "): no joined.srg, client.srg, or client.srg found");
} }
// Read output names through csv mappings, if available & enabled // Read output names through csv mappings, if available & enabled
@ -152,7 +154,7 @@ public class JarMapping {
outputTransformer = null; outputTransformer = null;
} }
for (File srg : srgFiles) { for (File srg : srgFiles) {
loadMappings(new BufferedReader(new FileReader(srg)), inputTransformer, outputTransformer, reverse); loadMappings(new BufferedReader(new FileReader(srg)), inputTransformer, outputTransformer, reverse);
} }
} }
@ -168,9 +170,11 @@ public class JarMapping {
/** /**
* *
* @param filename A filename of a .srg/.csrg or an MCP directory of .srg+.csv, local or remote * @param filename A filename of a .srg/.csrg or an MCP directory of
* .srg+.csv, local or remote
* @param reverse Swap input and output mappings * @param reverse Swap input and output mappings
* @param numericSrgNames When reading mapping directory, load numeric "srg" instead obfuscated names * @param numericSrgNames When reading mapping directory, load numeric "srg"
* instead obfuscated names
* @param inShadeRelocation Apply relocation on mapping input * @param inShadeRelocation Apply relocation on mapping input
* @param outShadeRelocation Apply relocation on mapping output * @param outShadeRelocation Apply relocation on mapping output
* @throws IOException * @throws IOException
@ -192,7 +196,7 @@ public class JarMapping {
// Existing local dir or dir URL // Existing local dir or dir URL
if (inputTransformer != null || outputTransformer != null) { if (inputTransformer != null || outputTransformer != null) {
throw new IllegalArgumentException("loadMappings("+filename+"): shade relocation not supported on directories"); // yet throw new IllegalArgumentException("loadMappings(" + filename + "): shade relocation not supported on directories"); // yet
} }
loadMappingsDir(filename, reverse, false, numericSrgNames); loadMappingsDir(filename, reverse, false, numericSrgNames);
@ -200,7 +204,7 @@ public class JarMapping {
// File // File
if (numericSrgNames) { if (numericSrgNames) {
throw new IllegalArgumentException("loadMappings("+filename+"): numeric only supported on directories, not files"); throw new IllegalArgumentException("loadMappings(" + filename + "): numeric only supported on directories, not files");
} }
loadMappings(new BufferedReader(new FileReader(URLDownloader.getLocalFile(filename))), inputTransformer, outputTransformer, reverse); loadMappings(new BufferedReader(new FileReader(URLDownloader.getLocalFile(filename))), inputTransformer, outputTransformer, reverse);
@ -213,7 +217,8 @@ public class JarMapping {
* @param reader Mapping file reader * @param reader Mapping file reader
* @param inputTransformer Transformation to apply on input * @param inputTransformer Transformation to apply on input
* @param outputTransformer Transformation to apply on output * @param outputTransformer Transformation to apply on output
* @param reverse Swap input and output mappings (after applying any input/output transformations) * @param reverse Swap input and output mappings (after applying any
* input/output transformations)
* @throws IOException * @throws IOException
*/ */
public void loadMappings(BufferedReader reader, JarMappingLoadTransformer inputTransformer, JarMappingLoadTransformer outputTransformer, boolean reverse) throws IOException { public void loadMappings(BufferedReader reader, JarMappingLoadTransformer inputTransformer, JarMappingLoadTransformer outputTransformer, boolean reverse) throws IOException {
@ -226,7 +231,7 @@ public class JarMapping {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.startsWith("#") || line.isEmpty()){ if (line.startsWith("#") || line.isEmpty()) {
continue; continue;
} }
@ -272,12 +277,13 @@ public class JarMapping {
String newMethodName = outputTransformer.transformMethodName(tokens[0], tokens[3], tokens[2]); String newMethodName = outputTransformer.transformMethodName(tokens[0], tokens[3], tokens[2]);
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName); methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName);
} else { } else {
throw new IOException("Invalid csrg file line, token count " + tokens.length + " unexpected in "+line); throw new IOException("Invalid csrg file line, token count " + tokens.length + " unexpected in " + line);
} }
} }
/** /**
* Parse a standard 'srg' mapping format line and populate the data structures * Parse a standard 'srg' mapping format line and populate the data
* structures
*/ */
private void parseSrgLine(String line, JarMappingLoadTransformer inputTransformer, JarMappingLoadTransformer outputTransformer, boolean reverse) throws IOException { private void parseSrgLine(String line, JarMappingLoadTransformer inputTransformer, JarMappingLoadTransformer outputTransformer, boolean reverse) throws IOException {
String[] tokens = line.split(" "); String[] tokens = line.split(" ");
@ -294,29 +300,29 @@ public class JarMapping {
} }
if (classes.containsKey(oldClassName) && !newClassName.equals(classes.get(oldClassName))) { if (classes.containsKey(oldClassName) && !newClassName.equals(classes.get(oldClassName))) {
throw new IllegalArgumentException("Duplicate class mapping: " + oldClassName + " -> " + newClassName + throw new IllegalArgumentException("Duplicate class mapping: " + oldClassName + " -> " + newClassName
" but already mapped to "+classes.get(oldClassName)+" in line="+line); + " but already mapped to " + classes.get(oldClassName) + " in line=" + line);
} }
classes.put(oldClassName, newClassName); classes.put(oldClassName, newClassName);
} else if (kind.equals("PK:")) { } else if (kind.equals("PK:")) {
/* TODO: support .srg's package maps /* TODO: support .srg's package maps
String oldPackageName = inputTransformer.transformClassName(tokens[1]); String oldPackageName = inputTransformer.transformClassName(tokens[1]);
String newPackageName = outputTransformer.transformClassName(tokens[2]); String newPackageName = outputTransformer.transformClassName(tokens[2]);
if (reverse) { if (reverse) {
String temp = newPackageName; String temp = newPackageName;
newPackageName = oldPackageName; newPackageName = oldPackageName;
oldPackageName = temp; oldPackageName = temp;
} }
if (packages.containsKey(oldPackageName) && !newPackageName.equals(packages.get(oldPackageName))) { if (packages.containsKey(oldPackageName) && !newPackageName.equals(packages.get(oldPackageName))) {
throw new IllegalArgumentException("Duplicate package mapping: " + oldPackageName + " ->" + newPackageName + throw new IllegalArgumentException("Duplicate package mapping: " + oldPackageName + " ->" + newPackageName +
" but already mapped to "+packages.get(oldPackageName)+" in line="+line); " but already mapped to "+packages.get(oldPackageName)+" in line="+line);
} }
packages.put(oldPackageName, newPackageName); packages.put(oldPackageName, newPackageName);
*/ */
} else if (kind.equals("FD:")) { } else if (kind.equals("FD:")) {
String oldFull = tokens[1]; String oldFull = tokens[1];
String newFull = tokens[2]; String newFull = tokens[2];
@ -325,8 +331,8 @@ public class JarMapping {
int splitOld = oldFull.lastIndexOf('/'); int splitOld = oldFull.lastIndexOf('/');
int splitNew = newFull.lastIndexOf('/'); int splitNew = newFull.lastIndexOf('/');
if (splitOld == -1 || splitNew == -1) { if (splitOld == -1 || splitNew == -1) {
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull + throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull
" -> " + newFull + " in line="+line); + " -> " + newFull + " in line=" + line);
} }
String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld)); String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld));
@ -351,8 +357,8 @@ public class JarMapping {
int splitOld = oldFull.lastIndexOf('/'); int splitOld = oldFull.lastIndexOf('/');
int splitNew = newFull.lastIndexOf('/'); int splitNew = newFull.lastIndexOf('/');
if (splitOld == -1 || splitNew == -1) { if (splitOld == -1 || splitNew == -1) {
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull + throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull
" -> " + newFull + " in line="+line); + " -> " + newFull + " in line=" + line);
} }
String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld)); String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld));
@ -373,7 +379,7 @@ public class JarMapping {
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName); methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName);
} else { } else {
throw new IllegalArgumentException("Unable to parse srg file, unrecognized mapping type in line="+line); throw new IllegalArgumentException("Unable to parse srg file, unrecognized mapping type in line=" + line);
} }
} }

View File

@ -50,5 +50,4 @@ public abstract class JarMappingLoadTransformer {
public String transformMethodDescriptor(String oldDescriptor) { public String transformMethodDescriptor(String oldDescriptor) {
return oldDescriptor; return oldDescriptor;
} }
} }

View File

@ -44,7 +44,6 @@ import org.objectweb.asm.commons.RemappingClassAdapter;
public class JarRemapper extends Remapper { public class JarRemapper extends Remapper {
private static final int CLASS_LEN = ".class".length(); private static final int CLASS_LEN = ".class".length();
public final JarMapping jarMapping; public final JarMapping jarMapping;
public RemapperPreprocessor remapperPreprocessor; public RemapperPreprocessor remapperPreprocessor;
@ -95,7 +94,6 @@ public class JarRemapper extends Remapper {
return mapped == null ? name : mapped; return mapped == null ? name : mapped;
} }
@Override @Override
public String mapMethodName(String owner, String name, String desc) { public String mapMethodName(String owner, String name, String desc) {
String mapped = jarMapping.tryClimb(jarMapping.methods, NodeType.METHOD, owner, name + " " + desc); String mapped = jarMapping.tryClimb(jarMapping.methods, NodeType.METHOD, owner, name + " " + desc);

View File

@ -32,6 +32,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class MethodDescriptorTransformer { public class MethodDescriptorTransformer {
private LinkedHashMap<String, String> packageMap; private LinkedHashMap<String, String> packageMap;
private Map<String, String> classMap; private Map<String, String> classMap;

View File

@ -33,9 +33,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* Lookup class inheritance from classes at runtime, remapped through a JarMapping * Lookup class inheritance from classes at runtime, remapped through a
* JarMapping
*/ */
public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvider { public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvider {
private final JarMapping jarMapping; private final JarMapping jarMapping;
private final JarMapping inverseJarMapping; private final JarMapping inverseJarMapping;
@ -63,13 +65,13 @@ public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvid
String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes, null); String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes, null);
if (after == null) { if (after == null) {
if (verbose) { if (verbose) {
System.out.println("RemappedRuntimeInheritanceProvider doesn't know about "+before); System.out.println("RemappedRuntimeInheritanceProvider doesn't know about " + before);
} }
return null; return null;
} }
if (verbose) { if (verbose) {
System.out.println("RemappedRuntimeInheritanceProvider getParents "+before+" -> "+after); System.out.println("RemappedRuntimeInheritanceProvider getParents " + before + " -> " + after);
} }
List<String> beforeParents = super.getParents(after); List<String> beforeParents = super.getParents(after);

View File

@ -40,24 +40,24 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* "Pre-process" a class file, intended to be used before remapping with JarRemapper. * "Pre-process" a class file, intended to be used before remapping with
* JarRemapper.
* *
* Currently includes: * Currently includes: - Extracting inheritance
* - Extracting inheritance
*/ */
public class RemapperPreprocessor { public class RemapperPreprocessor {
public boolean debug = false; public boolean debug = false;
private InheritanceMap inheritanceMap; private InheritanceMap inheritanceMap;
private JarMapping jarMapping; private JarMapping jarMapping;
private AccessMap accessMap; private AccessMap accessMap;
/** /**
* *
* @param inheritanceMap Map to add extracted inheritance information too, or null to not extract inheritance * @param inheritanceMap Map to add extracted inheritance information too,
* @param jarMapping Mapping for reflection remapping, or null to not remap reflection * or null to not extract inheritance
* @param jarMapping Mapping for reflection remapping, or null to not remap
* reflection
* @throws IOException * @throws IOException
*/ */
public RemapperPreprocessor(InheritanceMap inheritanceMap, JarMapping jarMapping, AccessMap accessMap) { public RemapperPreprocessor(InheritanceMap inheritanceMap, JarMapping jarMapping, AccessMap accessMap) {
@ -95,7 +95,7 @@ public class RemapperPreprocessor {
// Inheritance extraction // Inheritance extraction
if (inheritanceMap != null) { if (inheritanceMap != null) {
logI("Loading plugin class inheritance for "+className); logI("Loading plugin class inheritance for " + className);
// Get inheritance // Get inheritance
ArrayList<String> parents = new ArrayList<String>(); ArrayList<String> parents = new ArrayList<String>();
@ -107,7 +107,7 @@ public class RemapperPreprocessor {
inheritanceMap.setParents(className.replace('.', '/'), parents); inheritanceMap.setParents(className.replace('.', '/'), parents);
logI("Inheritance added "+className+" parents "+parents.size()); logI("Inheritance added " + className + " parents " + parents.size());
} }
if (isRewritingNeeded()) { if (isRewritingNeeded()) {
@ -157,6 +157,7 @@ public class RemapperPreprocessor {
/** /**
* Replace class.getDeclaredField("string") with a remapped field string * Replace class.getDeclaredField("string") with a remapped field string
*
* @param insn Method call instruction * @param insn Method call instruction
*/ */
private void remapGetDeclaredField(AbstractInsnNode insn) { private void remapGetDeclaredField(AbstractInsnNode insn) {
@ -191,7 +192,7 @@ public class RemapperPreprocessor {
String className = ((Type) ldcClass.cst).getInternalName(); String className = ((Type) ldcClass.cst).getInternalName();
String newName = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, className, fieldName); String newName = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, className, fieldName);
logR("Remapping "+className+"/"+fieldName + " -> " + newName); logR("Remapping " + className + "/" + fieldName + " -> " + newName);
if (newName != null) { if (newName != null) {
// Change the string literal to the correct name // Change the string literal to the correct name

View File

@ -35,6 +35,7 @@ import java.util.ArrayList;
* Lookup class inheritance from classes loaded at runtime. * Lookup class inheritance from classes loaded at runtime.
*/ */
public class RuntimeInheritanceProvider implements IInheritanceProvider { public class RuntimeInheritanceProvider implements IInheritanceProvider {
protected final ClassLoader classLoader; protected final ClassLoader classLoader;
protected final boolean verbose; protected final boolean verbose;

View File

@ -184,7 +184,7 @@ public class SpecialSource {
BiMap<String, String> inverseClassMap = HashBiMap.create(jarMapping.classes).inverse(); BiMap<String, String> inverseClassMap = HashBiMap.create(jarMapping.classes).inverse();
inheritanceMap.load(reader, inverseClassMap); inheritanceMap.load(reader, inverseClassMap);
log("Loaded inheritance map for "+inheritanceMap.size()+" classes"); log("Loaded inheritance map for " + inheritanceMap.size() + " classes");
inheritanceProviders.add(inheritanceMap); inheritanceProviders.add(inheritanceMap);
} }
@ -253,13 +253,13 @@ public class SpecialSource {
public static void validate(JarComparer visitor1, JarComparer visitor2) { public static void validate(JarComparer visitor1, JarComparer visitor2) {
if (visitor1.classes.size() != visitor2.classes.size()) { if (visitor1.classes.size() != visitor2.classes.size()) {
throw new IllegalStateException("classes "+visitor1.classes.size()+" != "+visitor2.classes.size()); throw new IllegalStateException("classes " + visitor1.classes.size() + " != " + visitor2.classes.size());
} }
if (visitor1.fields.size() != visitor2.fields.size()) { if (visitor1.fields.size() != visitor2.fields.size()) {
throw new IllegalStateException("fields "+visitor1.fields.size()+" != "+visitor2.fields.size()); throw new IllegalStateException("fields " + visitor1.fields.size() + " != " + visitor2.fields.size());
} }
if (visitor1.methods.size() != visitor2.methods.size()) { if (visitor1.methods.size() != visitor2.methods.size()) {
throw new IllegalStateException("methods "+visitor1.methods.size()+" != "+visitor2.methods.size()); throw new IllegalStateException("methods " + visitor1.methods.size() + " != " + visitor2.methods.size());
} }
} }
} }

View File

@ -42,6 +42,7 @@ import java.util.List;
* Lookup inheritance from a class in a given URLClassLoader. * Lookup inheritance from a class in a given URLClassLoader.
*/ */
public class URLClassLoaderInheritanceProvider implements IInheritanceProvider { public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
private final URLClassLoader classLoader; private final URLClassLoader classLoader;
private final boolean verbose; private final boolean verbose;
@ -56,7 +57,7 @@ public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
try { try {
String ownerInternalName = owner.replace('.', '/').concat(".class"); String ownerInternalName = owner.replace('.', '/').concat(".class");
if (verbose) { if (verbose) {
System.out.println("URLClassLoaderInheritanceProvider looking up "+ownerInternalName); System.out.println("URLClassLoaderInheritanceProvider looking up " + ownerInternalName);
} }
URL url = classLoader.findResource(ownerInternalName); URL url = classLoader.findResource(ownerInternalName);
if (url == null) { if (url == null) {
@ -77,18 +78,18 @@ public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
for (String iface : (List<String>) node.interfaces) { for (String iface : (List<String>) node.interfaces) {
parents.add(iface); parents.add(iface);
if (verbose) { if (verbose) {
System.out.println(" - "+iface); System.out.println(" - " + iface);
} }
} }
parents.add(node.superName); parents.add(node.superName);
if (verbose) { if (verbose) {
System.out.println(" + "+node.superName); System.out.println(" + " + node.superName);
} }
return parents; return parents;
} catch (IOException ex) { } catch (IOException ex) {
if (verbose) { if (verbose) {
System.out.println("URLClassLoaderInheritanceProvider "+owner+" exception: "+ex); System.out.println("URLClassLoaderInheritanceProvider " + owner + " exception: " + ex);
ex.printStackTrace(); ex.printStackTrace();
} }
return null; return null;

View File

@ -38,7 +38,6 @@ import java.net.URL;
public class URLDownloader { public class URLDownloader {
private static String CACHE_FOLDER = "SpecialSource.cache"; private static String CACHE_FOLDER = "SpecialSource.cache";
private URL url; private URL url;
public static boolean verbose = true; public static boolean verbose = true;
public static boolean useCache = true; public static boolean useCache = true;
@ -57,7 +56,7 @@ public class URLDownloader {
if (file.exists() && useCache) { if (file.exists() && useCache) {
if (verbose) { if (verbose) {
System.out.println("Using cached file "+file.getPath()+" for "+url); System.out.println("Using cached file " + file.getPath() + " for " + url);
} }
return file; return file;
@ -66,7 +65,7 @@ public class URLDownloader {
// Download // Download
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
if (verbose) { if (verbose) {
System.out.println("Downloading "+url); System.out.println("Downloading " + url);
} }
url.openConnection(); url.openConnection();
@ -107,11 +106,13 @@ public class URLDownloader {
// Borrowed from Guava 13 (since we're on Guava 12) - TODO: remove and use Guava after https://github.com/MinecraftForge/FML/commit/937e9a016936195e4dc51f33ab9e8dde52621684 // Borrowed from Guava 13 (since we're on Guava 12) - TODO: remove and use Guava after https://github.com/MinecraftForge/FML/commit/937e9a016936195e4dc51f33ab9e8dde52621684
/** /**
* Returns the file name without its * Returns the file name without its
* <a href="http://en.wikipedia.org/wiki/Filename_extension">file extension</a> or path. This is * <a href="http://en.wikipedia.org/wiki/Filename_extension">file
* similar to the {@code basename} unix command. The result does not include the '{@code .}'. * extension</a> or path. This is similar to the {@code basename} unix
* command. The result does not include the '{@code .}'.
* *
* @param file The name of the file to trim the extension from. This can be either a fully * @param file The name of the file to trim the extension from. This can be
* qualified file name (including a path) or just a file name. * either a fully qualified file name (including a path) or just a file
* name.
* @return The file name without its path or extension. * @return The file name without its path or extension.
* @since 14.0 * @since 14.0
*/ */