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:
*
* - visibility upgrade (required)
* -- public, protected, private ('*', no change), or default (package-private)
* -- additional optional flag(s), preceded by '+' to set, '-' to clear
* - visibility upgrade (required) -- public, protected, private ('*', no
* change), or default (package-private) -- additional optional flag(s),
* 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
*/
@ -56,7 +57,6 @@ public class AccessChange {
private int clear; // bits to clear to 0
private int set; // bits to set to 1 (overrides clear)
private int vis; // desired visibility increase
private final static Map<String, Integer> accessCodes = new HashMap<String, Integer>();
static {
@ -85,16 +85,14 @@ public class AccessChange {
accessCodes.put("enum", Opcodes.ACC_ENUM);
accessCodes.put("deprecated", Opcodes.ACC_DEPRECATED);
}
private final static BiMap<Integer, Integer> visibilityOrder = HashBiMap.create();
static {
visibilityOrder.put(Opcodes.ACC_PRIVATE, 100);
visibilityOrder.put(0, 200); // default package-private
visibilityOrder.put(Opcodes.ACC_PROTECTED, 300);
visibilityOrder.put(Opcodes.ACC_PUBLIC, 400);
visibilityOrder.put(Opcodes.ACC_PRIVATE, 100);
visibilityOrder.put(0, 200); // default package-private
visibilityOrder.put(Opcodes.ACC_PROTECTED, 300);
visibilityOrder.put(Opcodes.ACC_PUBLIC, 400);
}
private final static int MASK_ALL_VISIBILITY = Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED;
public AccessChange(String s) {
@ -116,7 +114,7 @@ public class AccessChange {
// Modifiers
for (int i = 1; i < parts.length; ++i) {
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
@ -125,15 +123,20 @@ public class AccessChange {
int modifier;
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);
// Toggle
switch (actionChar) {
case '+': set |= modifier; break;
case '-': clear |= modifier; break;
default: throw new IllegalArgumentException("Invalid action "+actionChar+" in access string: " + s);
case '+':
set |= modifier;
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
*/
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);
}
@ -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 visibility
* @return

View File

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

View File

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

View File

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

View File

@ -36,7 +36,8 @@ public interface IInheritanceProvider {
* Get the superclass and implemented interfaces of a class
*
* @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);
}

View File

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

View File

@ -47,9 +47,10 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
/**
* This class wraps one or more {@link JarFile}s enabling quick access to the jar's main
* class, as well as the ability to get the {@link InputStream} of a class file,
* and speedy lookups to see if the jar contains the specified class.
* This class wraps one or more {@link JarFile}s enabling quick access to the
* jar's main class, as well as the ability to get the {@link InputStream} of a
* class file, and speedy lookups to see if the jar contains the specified
* class.
*/
@ToString
@EqualsAndHashCode
@ -138,10 +139,10 @@ public class Jar {
String name = entry.getName();
/*
if (jarForResource.containsKey(name)) {
System.out.println("INFO: overwriting "+entry.getName()+" from "+jarForResource.get(name).getName()+" with "+jarFile.getName());
}
*/
if (jarForResource.containsKey(name)) {
System.out.println("INFO: overwriting "+entry.getName()+" from "+jarForResource.get(name).getName()+" with "+jarFile.getName());
}
*/
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> fields = new HashMap<String, String>();
public final Map<String, String> methods = new HashMap<String, String>();
private InheritanceMap inheritanceMap = new InheritanceMap();
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
* use a local cache, or set to your own global cache.
* Set the inheritance map used for caching superclass/interfaces. This call
* be omitted to use a local cache, or set to your own global cache.
*/
public void setInheritanceMap(InheritanceMap inheritanceMap) {
this.inheritanceMap = inheritanceMap;
}
/**
* Set the inheritance provider to be consulted if the inheritance map has no information on
* the requested class (results will be cached in the inheritance map).
* Set the inheritance provider to be consulted if the inheritance map has
* no information on the requested class (results will be cached in the
* inheritance map).
*/
public void setFallbackInheritanceProvider(IInheritanceProvider fallbackInheritanceProvider) {
this.fallbackInheritanceProvider = fallbackInheritanceProvider;
@ -92,13 +92,15 @@ public class JarMapping {
*
* @param dirname MCP directory name, local file or remote URL ending in '/'
* @param reverse If true, swap input and output
* @param ignoreCsv If true, ignore fields.csv and methods.csv (but not packages.csv)
* @param numericSrgNames If true, load numeric "srg" names (num->mcp instead of obf->mcp)
* @param ignoreCsv If true, ignore fields.csv and methods.csv (but not
* 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 {
File dir = new File(dirname);
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");
@ -122,7 +124,7 @@ public class JarMapping {
}
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
@ -152,7 +154,7 @@ public class JarMapping {
outputTransformer = null;
}
for (File srg : srgFiles) {
for (File srg : srgFiles) {
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 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 outShadeRelocation Apply relocation on mapping output
* @throws IOException
@ -192,7 +196,7 @@ public class JarMapping {
// Existing local dir or dir URL
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);
@ -200,7 +204,7 @@ public class JarMapping {
// File
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);
@ -213,7 +217,8 @@ public class JarMapping {
* @param reader Mapping file reader
* @param inputTransformer Transformation to apply on input
* @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
*/
public void loadMappings(BufferedReader reader, JarMappingLoadTransformer inputTransformer, JarMappingLoadTransformer outputTransformer, boolean reverse) throws IOException {
@ -226,7 +231,7 @@ public class JarMapping {
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith("#") || line.isEmpty()){
if (line.startsWith("#") || line.isEmpty()) {
continue;
}
@ -272,12 +277,13 @@ public class JarMapping {
String newMethodName = outputTransformer.transformMethodName(tokens[0], tokens[3], tokens[2]);
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName);
} 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 {
String[] tokens = line.split(" ");
@ -294,29 +300,29 @@ public class JarMapping {
}
if (classes.containsKey(oldClassName) && !newClassName.equals(classes.get(oldClassName))) {
throw new IllegalArgumentException("Duplicate class mapping: " + oldClassName + " -> " + newClassName +
" but already mapped to "+classes.get(oldClassName)+" in line="+line);
throw new IllegalArgumentException("Duplicate class mapping: " + oldClassName + " -> " + newClassName
+ " but already mapped to " + classes.get(oldClassName) + " in line=" + line);
}
classes.put(oldClassName, newClassName);
} else if (kind.equals("PK:")) {
/* TODO: support .srg's package maps
String oldPackageName = inputTransformer.transformClassName(tokens[1]);
String newPackageName = outputTransformer.transformClassName(tokens[2]);
String oldPackageName = inputTransformer.transformClassName(tokens[1]);
String newPackageName = outputTransformer.transformClassName(tokens[2]);
if (reverse) {
String temp = newPackageName;
newPackageName = oldPackageName;
oldPackageName = temp;
}
if (reverse) {
String temp = newPackageName;
newPackageName = oldPackageName;
oldPackageName = temp;
}
if (packages.containsKey(oldPackageName) && !newPackageName.equals(packages.get(oldPackageName))) {
throw new IllegalArgumentException("Duplicate package mapping: " + oldPackageName + " ->" + newPackageName +
" but already mapped to "+packages.get(oldPackageName)+" in line="+line);
}
if (packages.containsKey(oldPackageName) && !newPackageName.equals(packages.get(oldPackageName))) {
throw new IllegalArgumentException("Duplicate package mapping: " + oldPackageName + " ->" + newPackageName +
" but already mapped to "+packages.get(oldPackageName)+" in line="+line);
}
packages.put(oldPackageName, newPackageName);
*/
packages.put(oldPackageName, newPackageName);
*/
} else if (kind.equals("FD:")) {
String oldFull = tokens[1];
String newFull = tokens[2];
@ -325,8 +331,8 @@ public class JarMapping {
int splitOld = oldFull.lastIndexOf('/');
int splitNew = newFull.lastIndexOf('/');
if (splitOld == -1 || splitNew == -1) {
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull +
" -> " + newFull + " in line="+line);
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull
+ " -> " + newFull + " in line=" + line);
}
String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld));
@ -351,8 +357,8 @@ public class JarMapping {
int splitOld = oldFull.lastIndexOf('/');
int splitNew = newFull.lastIndexOf('/');
if (splitOld == -1 || splitNew == -1) {
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull +
" -> " + newFull + " in line="+line);
throw new IllegalArgumentException("Field name is invalid, not fully-qualified: " + oldFull
+ " -> " + newFull + " in line=" + line);
}
String oldClassName = inputTransformer.transformClassName(oldFull.substring(0, splitOld));
@ -373,7 +379,7 @@ public class JarMapping {
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName);
} 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) {
return oldDescriptor;
}
}

View File

@ -44,7 +44,6 @@ import org.objectweb.asm.commons.RemappingClassAdapter;
public class JarRemapper extends Remapper {
private static final int CLASS_LEN = ".class".length();
public final JarMapping jarMapping;
public RemapperPreprocessor remapperPreprocessor;
@ -95,7 +94,6 @@ public class JarRemapper extends Remapper {
return mapped == null ? name : mapped;
}
@Override
public String mapMethodName(String owner, String name, String 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;
public class MethodDescriptorTransformer {
private LinkedHashMap<String, String> packageMap;
private Map<String, String> classMap;

View File

@ -33,9 +33,11 @@ import java.util.List;
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 {
private final JarMapping jarMapping;
private final JarMapping inverseJarMapping;
@ -63,13 +65,13 @@ public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvid
String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes, null);
if (after == null) {
if (verbose) {
System.out.println("RemappedRuntimeInheritanceProvider doesn't know about "+before);
System.out.println("RemappedRuntimeInheritanceProvider doesn't know about " + before);
}
return null;
}
if (verbose) {
System.out.println("RemappedRuntimeInheritanceProvider getParents "+before+" -> "+after);
System.out.println("RemappedRuntimeInheritanceProvider getParents " + before + " -> " + after);
}
List<String> beforeParents = super.getParents(after);

View File

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

View File

@ -184,7 +184,7 @@ public class SpecialSource {
BiMap<String, String> inverseClassMap = HashBiMap.create(jarMapping.classes).inverse();
inheritanceMap.load(reader, inverseClassMap);
log("Loaded inheritance map for "+inheritanceMap.size()+" classes");
log("Loaded inheritance map for " + inheritanceMap.size() + " classes");
inheritanceProviders.add(inheritanceMap);
}
@ -253,13 +253,13 @@ public class SpecialSource {
public static void validate(JarComparer visitor1, JarComparer visitor2) {
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()) {
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()) {
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.
*/
public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
private final URLClassLoader classLoader;
private final boolean verbose;
@ -56,7 +57,7 @@ public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
try {
String ownerInternalName = owner.replace('.', '/').concat(".class");
if (verbose) {
System.out.println("URLClassLoaderInheritanceProvider looking up "+ownerInternalName);
System.out.println("URLClassLoaderInheritanceProvider looking up " + ownerInternalName);
}
URL url = classLoader.findResource(ownerInternalName);
if (url == null) {
@ -77,18 +78,18 @@ public class URLClassLoaderInheritanceProvider implements IInheritanceProvider {
for (String iface : (List<String>) node.interfaces) {
parents.add(iface);
if (verbose) {
System.out.println(" - "+iface);
System.out.println(" - " + iface);
}
}
parents.add(node.superName);
if (verbose) {
System.out.println(" + "+node.superName);
System.out.println(" + " + node.superName);
}
return parents;
} catch (IOException ex) {
if (verbose) {
System.out.println("URLClassLoaderInheritanceProvider "+owner+" exception: "+ex);
System.out.println("URLClassLoaderInheritanceProvider " + owner + " exception: " + ex);
ex.printStackTrace();
}
return null;

View File

@ -38,7 +38,6 @@ import java.net.URL;
public class URLDownloader {
private static String CACHE_FOLDER = "SpecialSource.cache";
private URL url;
public static boolean verbose = true;
public static boolean useCache = true;
@ -57,7 +56,7 @@ public class URLDownloader {
if (file.exists() && useCache) {
if (verbose) {
System.out.println("Using cached file "+file.getPath()+" for "+url);
System.out.println("Using cached file " + file.getPath() + " for " + url);
}
return file;
@ -66,7 +65,7 @@ public class URLDownloader {
// Download
file.getParentFile().mkdirs();
if (verbose) {
System.out.println("Downloading "+url);
System.out.println("Downloading " + url);
}
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
/**
* Returns the file name without its
* <a href="http://en.wikipedia.org/wiki/Filename_extension">file extension</a> or path. This is
* similar to the {@code basename} unix command. The result does not include the '{@code .}'.
* <a href="http://en.wikipedia.org/wiki/Filename_extension">file
* 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
* qualified file name (including a path) or just a file name.
* @param file The name of the file to trim the extension from. This can be
* either a fully qualified file name (including a path) or just a file
* name.
* @return The file name without its path or extension.
* @since 14.0
*/