summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
diff options
context:
space:
mode:
authorGravatar Thog2017-03-08 08:17:04 +0100
committerGravatar Thog2017-03-08 08:17:04 +0100
commit6e464ea251cab63c776ece0b2a356f1498ffa294 (patch)
tree5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
parentDrop unix case style and implement hashCode when equals is overrided (diff)
downloadenigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassIdentifier.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassIdentifier.java61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
index 557e608..0a72073 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
@@ -8,13 +8,10 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.convert; 12package cuchaz.enigma.convert;
12 13
13import com.google.common.collect.Maps; 14import com.google.common.collect.Maps;
14
15import java.util.Map;
16import java.util.jar.JarFile;
17
18import cuchaz.enigma.TranslatingTypeLoader; 15import cuchaz.enigma.TranslatingTypeLoader;
19import cuchaz.enigma.analysis.JarIndex; 16import cuchaz.enigma.analysis.JarIndex;
20import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; 17import cuchaz.enigma.convert.ClassNamer.SidedClassNamer;
@@ -22,34 +19,36 @@ import cuchaz.enigma.mapping.ClassEntry;
22import cuchaz.enigma.mapping.Translator; 19import cuchaz.enigma.mapping.Translator;
23import javassist.CtClass; 20import javassist.CtClass;
24 21
22import java.util.Map;
23import java.util.jar.JarFile;
25 24
26public class ClassIdentifier { 25public class ClassIdentifier {
27 26
28 private JarIndex index; 27 private JarIndex index;
29 private SidedClassNamer namer; 28 private SidedClassNamer namer;
30 private boolean useReferences; 29 private boolean useReferences;
31 private TranslatingTypeLoader loader; 30 private TranslatingTypeLoader loader;
32 private Map<ClassEntry, ClassIdentity> cache; 31 private Map<ClassEntry, ClassIdentity> cache;
33 32
34 public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { 33 public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) {
35 this.index = index; 34 this.index = index;
36 this.namer = namer; 35 this.namer = namer;
37 this.useReferences = useReferences; 36 this.useReferences = useReferences;
38 this.loader = new TranslatingTypeLoader(jar, index, new Translator(), new Translator()); 37 this.loader = new TranslatingTypeLoader(jar, index, new Translator(), new Translator());
39 this.cache = Maps.newHashMap(); 38 this.cache = Maps.newHashMap();
40 } 39 }
41 40
42 public ClassIdentity identify(ClassEntry classEntry) 41 public ClassIdentity identify(ClassEntry classEntry)
43 throws ClassNotFoundException { 42 throws ClassNotFoundException {
44 ClassIdentity identity = this.cache.get(classEntry); 43 ClassIdentity identity = this.cache.get(classEntry);
45 if (identity == null) { 44 if (identity == null) {
46 CtClass c = this.loader.loadClass(classEntry.getName()); 45 CtClass c = this.loader.loadClass(classEntry.getName());
47 if (c == null) { 46 if (c == null) {
48 throw new ClassNotFoundException(classEntry.getName()); 47 throw new ClassNotFoundException(classEntry.getName());
49 } 48 }
50 identity = new ClassIdentity(c, this.namer, this.index, this.useReferences); 49 identity = new ClassIdentity(c, this.namer, this.index, this.useReferences);
51 this.cache.put(classEntry, identity); 50 this.cache.put(classEntry, identity);
52 } 51 }
53 return identity; 52 return identity;
54 } 53 }
55} 54}