diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/ClassIdentifier.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/ClassIdentifier.java | 54 |
1 files changed, 54 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..ee5e903 --- /dev/null +++ b/src/cuchaz/enigma/convert/ClassIdentifier.java | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import java.util.Map; | ||
| 14 | import java.util.jar.JarFile; | ||
| 15 | |||
| 16 | import com.google.common.collect.Maps; | ||
| 17 | |||
| 18 | import javassist.CtClass; | ||
| 19 | import cuchaz.enigma.TranslatingTypeLoader; | ||
| 20 | import cuchaz.enigma.analysis.JarIndex; | ||
| 21 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; | ||
| 22 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 23 | |||
| 24 | |||
| 25 | public class ClassIdentifier { | ||
| 26 | |||
| 27 | private JarIndex m_index; | ||
| 28 | private SidedClassNamer m_namer; | ||
| 29 | private boolean m_useReferences; | ||
| 30 | private TranslatingTypeLoader m_loader; | ||
| 31 | private Map<ClassEntry,ClassIdentity> m_cache; | ||
| 32 | |||
| 33 | public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { | ||
| 34 | m_index = index; | ||
| 35 | m_namer = namer; | ||
| 36 | m_useReferences = useReferences; | ||
| 37 | m_loader = new TranslatingTypeLoader(jar, index); | ||
| 38 | m_cache = Maps.newHashMap(); | ||
| 39 | } | ||
| 40 | |||
| 41 | public ClassIdentity identify(ClassEntry classEntry) | ||
| 42 | throws ClassNotFoundException { | ||
| 43 | ClassIdentity identity = m_cache.get(classEntry); | ||
| 44 | if (identity == null) { | ||
| 45 | CtClass c = m_loader.loadClass(classEntry.getName()); | ||
| 46 | if (c == null) { | ||
| 47 | throw new ClassNotFoundException(classEntry.getName()); | ||
| 48 | } | ||
| 49 | identity = new ClassIdentity(c, m_namer, m_index, m_useReferences); | ||
| 50 | m_cache.put(classEntry, identity); | ||
| 51 | } | ||
| 52 | return identity; | ||
| 53 | } | ||
| 54 | } | ||