diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassIdentifier.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/ClassIdentifier.java | 61 |
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 | |||
| 11 | package cuchaz.enigma.convert; | 12 | package cuchaz.enigma.convert; |
| 12 | 13 | ||
| 13 | import com.google.common.collect.Maps; | 14 | import com.google.common.collect.Maps; |
| 14 | |||
| 15 | import java.util.Map; | ||
| 16 | import java.util.jar.JarFile; | ||
| 17 | |||
| 18 | import cuchaz.enigma.TranslatingTypeLoader; | 15 | import cuchaz.enigma.TranslatingTypeLoader; |
| 19 | import cuchaz.enigma.analysis.JarIndex; | 16 | import cuchaz.enigma.analysis.JarIndex; |
| 20 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; | 17 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; |
| @@ -22,34 +19,36 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 22 | import cuchaz.enigma.mapping.Translator; | 19 | import cuchaz.enigma.mapping.Translator; |
| 23 | import javassist.CtClass; | 20 | import javassist.CtClass; |
| 24 | 21 | ||
| 22 | import java.util.Map; | ||
| 23 | import java.util.jar.JarFile; | ||
| 25 | 24 | ||
| 26 | public class ClassIdentifier { | 25 | public 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 | } |