diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassIdentifier.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassIdentifier.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/ClassIdentifier.java b/src/cuchaz/enigma/convert/ClassIdentifier.java new file mode 100644 index 0000000..bdbf11b --- /dev/null +++ b/src/cuchaz/enigma/convert/ClassIdentifier.java | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | package cuchaz.enigma.convert; | ||
| 2 | |||
| 3 | import java.util.Map; | ||
| 4 | import java.util.jar.JarFile; | ||
| 5 | |||
| 6 | import javassist.CtClass; | ||
| 7 | |||
| 8 | import com.beust.jcommander.internal.Maps; | ||
| 9 | |||
| 10 | import cuchaz.enigma.TranslatingTypeLoader; | ||
| 11 | import cuchaz.enigma.analysis.JarIndex; | ||
| 12 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; | ||
| 13 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 14 | |||
| 15 | |||
| 16 | public class ClassIdentifier { | ||
| 17 | |||
| 18 | private JarIndex m_index; | ||
| 19 | private SidedClassNamer m_namer; | ||
| 20 | private boolean m_useReferences; | ||
| 21 | private TranslatingTypeLoader m_loader; | ||
| 22 | private Map<ClassEntry,ClassIdentity> m_cache; | ||
| 23 | |||
| 24 | public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { | ||
| 25 | m_index = index; | ||
| 26 | m_namer = namer; | ||
| 27 | m_useReferences = useReferences; | ||
| 28 | m_loader = new TranslatingTypeLoader(jar, index); | ||
| 29 | m_cache = Maps.newHashMap(); | ||
| 30 | } | ||
| 31 | |||
| 32 | public ClassIdentity identify(ClassEntry classEntry) { | ||
| 33 | ClassIdentity identity = m_cache.get(classEntry); | ||
| 34 | if (identity == null) { | ||
| 35 | CtClass c = m_loader.loadClass(classEntry.getName()); | ||
| 36 | identity = new ClassIdentity(c, m_namer, m_index, m_useReferences); | ||
| 37 | m_cache.put(classEntry, identity); | ||
| 38 | } | ||
| 39 | return identity; | ||
| 40 | } | ||
| 41 | } | ||