summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
diff options
context:
space:
mode:
authorGravatar asiekierka2016-08-17 18:35:12 +0200
committerGravatar asiekierka2016-08-17 18:35:12 +0200
commit5540c815de36e316d0749ce2163f12c61895b327 (patch)
tree2b30d5ae98735ee7cba7d1c0087c51d68ed3ebf9 /src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
parentRevert "Removed util" (diff)
downloadenigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.gz
enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.xz
enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.zip
Revert "Removed unused methods"
This reverts commit 1742190f784d0d62e7cc869eebafdfe1927e448f.
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassIdentifier.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassIdentifier.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
new file mode 100644
index 0000000..f545437
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java
@@ -0,0 +1,56 @@
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 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.convert;
12
13import com.google.common.collect.Maps;
14
15import java.util.Map;
16import java.util.jar.JarFile;
17
18import cuchaz.enigma.TranslatingTypeLoader;
19import cuchaz.enigma.analysis.JarIndex;
20import cuchaz.enigma.convert.ClassNamer.SidedClassNamer;
21import cuchaz.enigma.mapping.ClassEntry;
22import cuchaz.enigma.mapping.TranslationDirection;
23import cuchaz.enigma.mapping.Translator;
24import javassist.CtClass;
25
26
27public class ClassIdentifier {
28
29 private JarIndex index;
30 private SidedClassNamer namer;
31 private boolean useReferences;
32 private TranslatingTypeLoader loader;
33 private Map<ClassEntry, ClassIdentity> cache;
34
35 public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) {
36 this.index = index;
37 this.namer = namer;
38 this.useReferences = useReferences;
39 this.loader = new TranslatingTypeLoader(jar, index, new Translator(), new Translator());
40 this.cache = Maps.newHashMap();
41 }
42
43 public ClassIdentity identify(ClassEntry classEntry)
44 throws ClassNotFoundException {
45 ClassIdentity identity = this.cache.get(classEntry);
46 if (identity == null) {
47 CtClass c = this.loader.loadClass(classEntry.getName());
48 if (c == null) {
49 throw new ClassNotFoundException(classEntry.getName());
50 }
51 identity = new ClassIdentity(c, this.namer, this.index, this.useReferences);
52 this.cache.put(classEntry, identity);
53 }
54 return identity;
55 }
56}