summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar gegy10002019-06-18 20:20:40 +0200
committerGravatar gegy10002019-06-18 20:20:40 +0200
commit42243fa65e1d87f6a0498f6e2d83505605409411 (patch)
treec4127d7928c752360639b42b221c96678cdc5807
parentPlugin rework along with API rework: Enigma split from EnigmaProject; plugins... (diff)
parentfix unwanted declaration navigation during Quick Find (diff)
downloadenigma-42243fa65e1d87f6a0498f6e2d83505605409411.tar.gz
enigma-42243fa65e1d87f6a0498f6e2d83505605409411.tar.xz
enigma-42243fa65e1d87f6a0498f6e2d83505605409411.zip
Mostly resolve test failures
-rw-r--r--build.gradle4
-rw-r--r--src/main/java/cuchaz/enigma/EnigmaProject.java1
-rw-r--r--src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java4
-rw-r--r--src/main/java/cuchaz/enigma/gui/EnigmaQuickFindDialog.java7
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java8
-rw-r--r--src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java19
-rw-r--r--src/test/java/cuchaz/enigma/TestDeobfed.java7
-rw-r--r--src/test/java/cuchaz/enigma/TestDeobfuscator.java36
-rw-r--r--src/test/java/cuchaz/enigma/TestInnerClasses.java11
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java12
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java9
-rw-r--r--src/test/java/cuchaz/enigma/TestSourceIndex.java32
-rw-r--r--src/test/java/cuchaz/enigma/TestTokensConstructors.java4
-rw-r--r--src/test/java/cuchaz/enigma/TokenChecker.java15
14 files changed, 90 insertions, 79 deletions
diff --git a/build.gradle b/build.gradle
index 63c221da..e7ceb932 100644
--- a/build.gradle
+++ b/build.gradle
@@ -83,8 +83,8 @@ configurations {
83} 83}
84 84
85dependencies { 85dependencies {
86 compile 'com.google.guava:guava:27.1-jre' 86 compile 'com.google.guava:guava:28.0-jre'
87 compile 'net.fabricmc:procyon-fabric-compilertools:0.5.33.+' 87 compile 'net.fabricmc:procyon-fabric-compilertools:0.5.35.+'
88 compile 'com.google.code.gson:gson:2.8.5' 88 compile 'com.google.code.gson:gson:2.8.5'
89 compile 'org.ow2.asm:asm:7.1' 89 compile 'org.ow2.asm:asm:7.1'
90 compile 'org.ow2.asm:asm-commons:7.1' 90 compile 'org.ow2.asm:asm-commons:7.1'
diff --git a/src/main/java/cuchaz/enigma/EnigmaProject.java b/src/main/java/cuchaz/enigma/EnigmaProject.java
index 82fc0bdf..dd1f9fa4 100644
--- a/src/main/java/cuchaz/enigma/EnigmaProject.java
+++ b/src/main/java/cuchaz/enigma/EnigmaProject.java
@@ -273,6 +273,7 @@ public class EnigmaProject {
273 } 273 }
274 274
275 void writeTo(Path path) throws IOException { 275 void writeTo(Path path) throws IOException {
276 Files.createDirectories(path.getParent());
276 try (BufferedWriter writer = Files.newBufferedWriter(path)) { 277 try (BufferedWriter writer = Files.newBufferedWriter(path)) {
277 writer.write(source); 278 writer.write(source);
278 } 279 }
diff --git a/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java b/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java
index c24e6613..b0d2a7d0 100644
--- a/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java
+++ b/src/main/java/cuchaz/enigma/command/DeobfuscateCommand.java
@@ -32,8 +32,6 @@ public class DeobfuscateCommand extends Command {
32 ProgressListener progress = new ConsoleProgressListener(); 32 ProgressListener progress = new ConsoleProgressListener();
33 33
34 EnigmaProject.JarExport jar = project.exportRemappedJar(progress); 34 EnigmaProject.JarExport jar = project.exportRemappedJar(progress);
35 EnigmaProject.SourceExport source = jar.decompile(progress); 35 jar.write(fileJarOut, progress);
36
37 source.write(fileJarOut, progress);
38 } 36 }
39} 37}
diff --git a/src/main/java/cuchaz/enigma/gui/EnigmaQuickFindDialog.java b/src/main/java/cuchaz/enigma/gui/EnigmaQuickFindDialog.java
index 0c1d4cd6..c912be3a 100644
--- a/src/main/java/cuchaz/enigma/gui/EnigmaQuickFindDialog.java
+++ b/src/main/java/cuchaz/enigma/gui/EnigmaQuickFindDialog.java
@@ -36,7 +36,12 @@ public class EnigmaQuickFindDialog extends QuickFindDialog {
36 public void showFor(JTextComponent target) { 36 public void showFor(JTextComponent target) {
37 String selectedText = target.getSelectedText(); 37 String selectedText = target.getSelectedText();
38 38
39 super.showFor(target); 39 try {
40 super.showFor(target);
41 } catch (Exception e) {
42 e.printStackTrace();
43 return;
44 }
40 45
41 Container view = target.getParent(); 46 Container view = target.getParent();
42 Point loc = new Point(0, view.getHeight() - getSize().height); 47 Point loc = new Point(0, view.getHeight() - getSize().height);
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index f5dd8a04..6fc9fcf7 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -529,16 +529,15 @@ public class Gui {
529 return combo; 529 return combo;
530 } 530 }
531 531
532 public void onCaretMove(int pos) { 532 public void onCaretMove(int pos, boolean fromClick) {
533 EntryRemapper mapper = controller.project.getMapper(); 533 EntryRemapper mapper = controller.project.getMapper();
534
535 Token token = this.controller.getToken(pos); 534 Token token = this.controller.getToken(pos);
536 boolean isToken = token != null; 535 boolean isToken = token != null;
537 536
538 cursorReference = this.controller.getReference(token); 537 cursorReference = this.controller.getReference(token);
539 Entry<?> referenceEntry = cursorReference != null ? cursorReference.entry : null; 538 Entry<?> referenceEntry = cursorReference != null ? cursorReference.entry : null;
540 539
541 if (referenceEntry != null && shouldNavigateOnClick) { 540 if (referenceEntry != null && shouldNavigateOnClick && fromClick) {
542 shouldNavigateOnClick = false; 541 shouldNavigateOnClick = false;
543 Entry<?> navigationEntry = referenceEntry; 542 Entry<?> navigationEntry = referenceEntry;
544 if (cursorReference.context == null) { 543 if (cursorReference.context == null) {
@@ -773,8 +772,9 @@ public class Gui {
773 if (response == JOptionPane.YES_OPTION) { 772 if (response == JOptionPane.YES_OPTION) {
774 this.saveMapping(); 773 this.saveMapping();
775 this.frame.dispose(); 774 this.frame.dispose();
776 } else if (response == JOptionPane.NO_OPTION) 775 } else if (response == JOptionPane.NO_OPTION) {
777 this.frame.dispose(); 776 this.frame.dispose();
777 }
778 778
779 return null; 779 return null;
780 }, "Save and exit", "Discard changes", "Cancel"); 780 }, "Save and exit", "Discard changes", "Cancel");
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java
index e8a9cadc..123238fe 100644
--- a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java
+++ b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java
@@ -16,14 +16,21 @@ import java.awt.event.MouseAdapter;
16import java.awt.event.MouseEvent; 16import java.awt.event.MouseEvent;
17 17
18public class PanelEditor extends JEditorPane { 18public class PanelEditor extends JEditorPane {
19 private boolean mouseIsPressed = false;
20
19 public PanelEditor(Gui gui) { 21 public PanelEditor(Gui gui) {
20 this.setEditable(false); 22 this.setEditable(false);
21 this.setSelectionColor(new Color(31, 46, 90)); 23 this.setSelectionColor(new Color(31, 46, 90));
22 this.setCaret(new BrowserCaret()); 24 this.setCaret(new BrowserCaret());
23 this.addCaretListener(event -> gui.onCaretMove(event.getDot())); 25 this.addCaretListener(event -> gui.onCaretMove(event.getDot(), mouseIsPressed));
24 final PanelEditor self = this; 26 final PanelEditor self = this;
25 this.addMouseListener(new MouseAdapter() { 27 this.addMouseListener(new MouseAdapter() {
26 @Override 28 @Override
29 public void mousePressed(MouseEvent mouseEvent) {
30 mouseIsPressed = true;
31 }
32
33 @Override
27 public void mouseReleased(MouseEvent e) { 34 public void mouseReleased(MouseEvent e) {
28 switch (e.getButton()) { 35 switch (e.getButton()) {
29 case MouseEvent.BUTTON3: // Right click 36 case MouseEvent.BUTTON3: // Right click
@@ -38,12 +45,15 @@ public class PanelEditor extends JEditorPane {
38 gui.getController().openNextReference(); 45 gui.getController().openNextReference();
39 break; 46 break;
40 } 47 }
48 mouseIsPressed = false;
41 } 49 }
42 }); 50 });
43 this.addKeyListener(new KeyAdapter() { 51 this.addKeyListener(new KeyAdapter() {
44 @Override 52 @Override
45 public void keyPressed(KeyEvent event) { 53 public void keyPressed(KeyEvent event) {
46 if (event.isControlDown()) { 54 if (event.isControlDown()) {
55 gui.setShouldNavigateOnClick(false);
56
47 switch (event.getKeyCode()) { 57 switch (event.getKeyCode()) {
48 case KeyEvent.VK_I: 58 case KeyEvent.VK_I:
49 gui.popupMenu.showInheritanceMenu.doClick(); 59 gui.popupMenu.showInheritanceMenu.doClick();
@@ -81,12 +91,15 @@ public class PanelEditor extends JEditorPane {
81 gui.getController().refreshCurrentClass(); 91 gui.getController().refreshCurrentClass();
82 break; 92 break;
83 93
94 case KeyEvent.VK_F:
95 // prevent navigating on click when quick find activated
96 break;
97
84 default: 98 default:
99 gui.setShouldNavigateOnClick(true); // CTRL
85 break; 100 break;
86 } 101 }
87 } 102 }
88
89 gui.setShouldNavigateOnClick(event.isControlDown());
90 } 103 }
91 104
92 @Override 105 @Override
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java
index 3d875dfe..3ee86cb7 100644
--- a/src/test/java/cuchaz/enigma/TestDeobfed.java
+++ b/src/test/java/cuchaz/enigma/TestDeobfed.java
@@ -66,11 +66,12 @@ public class TestDeobfed {
66 } 66 }
67 67
68 @Test 68 @Test
69 public void decompile() 69 public void decompile() {
70 throws Exception {
71 EnigmaProject project = new EnigmaProject(enigma, classCache, index); 70 EnigmaProject project = new EnigmaProject(enigma, classCache, index);
72 71
73 SourceProvider sourceProvider = project.getObfSourceProvider(); 72 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache());
73 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
74
74 sourceProvider.getSources("a"); 75 sourceProvider.getSources("a");
75 sourceProvider.getSources("b"); 76 sourceProvider.getSources("b");
76 sourceProvider.getSources("c"); 77 sourceProvider.getSources("c");
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java
index 5b9611cc..2a6fec49 100644
--- a/src/test/java/cuchaz/enigma/TestDeobfuscator.java
+++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java
@@ -11,47 +11,31 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import com.google.common.collect.Lists;
15import cuchaz.enigma.translation.representation.entry.ClassEntry;
16import org.junit.Test; 14import org.junit.Test;
17 15
18import java.io.IOException; 16import java.io.IOException;
19import java.util.List; 17import java.nio.file.Paths;
20import java.util.jar.JarFile;
21
22import static org.junit.Assert.assertEquals;
23 18
24public class TestDeobfuscator { 19public class TestDeobfuscator {
25 20
26 private Enigma getDeobfuscator() 21 private EnigmaProject openProject() throws IOException {
27 throws IOException { 22 Enigma enigma = Enigma.create();
28 return new Enigma(new JarFile("build/test-obf/loneClass.jar")); 23 return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none());
29 } 24 }
30 25
31 @Test 26 @Test
32 public void loadJar() 27 public void loadJar()
33 throws Exception { 28 throws Exception {
34 getDeobfuscator(); 29 openProject();
35 } 30 }
36 31
37 @Test 32 @Test
38 public void getClasses() 33 public void decompileClass() throws Exception {
39 throws Exception { 34 EnigmaProject project = openProject();
40 Enigma enigma = getDeobfuscator(); 35
41 List<ClassEntry> obfClasses = Lists.newArrayList(); 36 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache());
42 List<ClassEntry> deobfClasses = Lists.newArrayList(); 37 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
43 enigma.getSeparatedClasses(obfClasses, deobfClasses);
44 assertEquals(1, obfClasses.size());
45 assertEquals("a", obfClasses.get(0).getName());
46 assertEquals(1, deobfClasses.size());
47 assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName());
48 }
49 38
50 @Test
51 public void decompileClass()
52 throws Exception {
53 Enigma enigma = getDeobfuscator();
54 SourceProvider sourceProvider = enigma.getObfSourceProvider();
55 sourceProvider.writeSourceToString(sourceProvider.getSources("a")); 39 sourceProvider.writeSourceToString(sourceProvider.getSources("a"));
56 } 40 }
57} 41}
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java
index b6e4e2d4..18e49369 100644
--- a/src/test/java/cuchaz/enigma/TestInnerClasses.java
+++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java
@@ -17,7 +17,6 @@ import cuchaz.enigma.translation.representation.entry.ClassEntry;
17import org.junit.Test; 17import org.junit.Test;
18 18
19import java.nio.file.Paths; 19import java.nio.file.Paths;
20import java.util.jar.JarFile;
21 20
22import static cuchaz.enigma.TestEntryFactory.newClass; 21import static cuchaz.enigma.TestEntryFactory.newClass;
23import static org.hamcrest.MatcherAssert.assertThat; 22import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,14 +33,14 @@ public class TestInnerClasses {
34 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); 33 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a");
35 private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); 34 private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a");
36 private JarIndex index; 35 private JarIndex index;
37 private Enigma enigma; 36 private SourceProvider sourceProvider;
38 37
39 public TestInnerClasses() 38 public TestInnerClasses() throws Exception {
40 throws Exception {
41 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); 39 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar"));
42 index = classCache.index(ProgressListener.none()); 40 index = classCache.index(ProgressListener.none());
43 41
44 enigma = new Enigma(jar); 42 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
43 sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
45 } 44 }
46 45
47 @Test 46 @Test
@@ -80,6 +79,6 @@ public class TestInnerClasses {
80 } 79 }
81 80
82 private void decompile(ClassEntry classEntry) { 81 private void decompile(ClassEntry classEntry) {
83 enigma.getObfSourceProvider().getSources(classEntry.getName()); 82 sourceProvider.getSources(classEntry.getName());
84 } 83 }
85} 84}
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
index 0712ccf5..48975c82 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
@@ -11,6 +11,7 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.ClassCache;
14import cuchaz.enigma.analysis.EntryReference; 15import cuchaz.enigma.analysis.EntryReference;
15import cuchaz.enigma.analysis.index.JarIndex; 16import cuchaz.enigma.analysis.index.JarIndex;
16import cuchaz.enigma.translation.representation.entry.ClassEntry; 17import cuchaz.enigma.translation.representation.entry.ClassEntry;
@@ -18,9 +19,8 @@ import cuchaz.enigma.translation.representation.entry.MethodDefEntry;
18import cuchaz.enigma.translation.representation.entry.MethodEntry; 19import cuchaz.enigma.translation.representation.entry.MethodEntry;
19import org.junit.Test; 20import org.junit.Test;
20 21
21import java.io.File; 22import java.nio.file.Paths;
22import java.util.Collection; 23import java.util.Collection;
23import java.util.jar.JarFile;
24 24
25import static cuchaz.enigma.TestEntryFactory.*; 25import static cuchaz.enigma.TestEntryFactory.*;
26import static org.hamcrest.MatcherAssert.assertThat; 26import static org.hamcrest.MatcherAssert.assertThat;
@@ -36,11 +36,9 @@ public class TestJarIndexConstructorReferences {
36 private ClassEntry defaultClass = newClass("c"); 36 private ClassEntry defaultClass = newClass("c");
37 private ClassEntry callerClass = newClass("b"); 37 private ClassEntry callerClass = newClass("b");
38 38
39 public TestJarIndexConstructorReferences() 39 public TestJarIndexConstructorReferences() throws Exception {
40 throws Exception { 40 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/constructors.jar"));
41 File jarFile = new File("build/test-obf/constructors.jar"); 41 index = classCache.index(ProgressListener.none());
42 index = JarIndex.empty();
43 index.indexJar(new ParsedJar(new JarFile(jarFile)), s -> {});
44 } 42 }
45 43
46 @Test 44 @Test
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
index 1299bccc..103c366b 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
@@ -23,9 +23,9 @@ import cuchaz.enigma.translation.representation.entry.MethodDefEntry;
23import cuchaz.enigma.translation.representation.entry.MethodEntry; 23import cuchaz.enigma.translation.representation.entry.MethodEntry;
24import org.junit.Test; 24import org.junit.Test;
25 25
26import java.nio.file.Paths;
26import java.util.Collection; 27import java.util.Collection;
27import java.util.List; 28import java.util.List;
28import java.util.jar.JarFile;
29 29
30import static cuchaz.enigma.TestEntryFactory.*; 30import static cuchaz.enigma.TestEntryFactory.*;
31import static org.hamcrest.MatcherAssert.assertThat; 31import static org.hamcrest.MatcherAssert.assertThat;
@@ -35,10 +35,9 @@ public class TestJarIndexLoneClass {
35 35
36 private JarIndex index; 36 private JarIndex index;
37 37
38 public TestJarIndexLoneClass() 38 public TestJarIndexLoneClass() throws Exception {
39 throws Exception { 39 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/loneClass.jar"));
40 index = JarIndex.empty(); 40 index = classCache.index(ProgressListener.none());
41 index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), s -> {});
42 } 41 }
43 42
44 @Test 43 @Test
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java
index 8a604f80..b1d11822 100644
--- a/src/test/java/cuchaz/enigma/TestSourceIndex.java
+++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java
@@ -13,13 +13,15 @@ package cuchaz.enigma;
13 13
14import com.google.common.collect.Sets; 14import com.google.common.collect.Sets;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.index.JarIndex;
17import cuchaz.enigma.translation.representation.entry.ClassEntry; 19import cuchaz.enigma.translation.representation.entry.ClassEntry;
18import org.junit.Test; 20import org.junit.Test;
19 21
20import java.io.File; 22import java.nio.file.Path;
23import java.nio.file.Paths;
21import java.util.Set; 24import java.util.Set;
22import java.util.jar.JarFile;
23 25
24public class TestSourceIndex { 26public class TestSourceIndex {
25 @Test 27 @Test
@@ -27,31 +29,41 @@ public class TestSourceIndex {
27 throws Exception { 29 throws Exception {
28 // Figure out where Minecraft is... 30 // Figure out where Minecraft is...
29 final String mcDir = System.getProperty("enigma.test.minecraftdir"); 31 final String mcDir = System.getProperty("enigma.test.minecraftdir");
30 File mcJar = null; 32 Path mcJar = null;
31 if (mcDir == null) { 33 if (mcDir == null) {
32 String osname = System.getProperty("os.name").toLowerCase(); 34 String osname = System.getProperty("os.name").toLowerCase();
33 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { 35 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) {
34 mcJar = new File(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); 36 mcJar = Paths.get(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar");
35 } else if (osname.contains("mac") || osname.contains("darwin")) { 37 } else if (osname.contains("mac") || osname.contains("darwin")) {
36 mcJar = new File(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); 38 mcJar = Paths.get(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar");
37 } else if (osname.contains("win")) { 39 } else if (osname.contains("win")) {
38 mcJar = new File(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); 40 mcJar = Paths.get(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar");
39 } 41 }
40 } else { 42 } else {
41 mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); 43 mcJar = Paths.get(mcDir, "versions/1.8.3/1.8.3.jar");
42 } 44 }
43 45
44 Enigma enigma = new Enigma(new JarFile(mcJar)); 46 if (mcJar == null) {
47 throw new NullPointerException("Couldn't find jar");
48 }
49
50 Enigma enigma = Enigma.create();
51 EnigmaProject project = enigma.openJar(mcJar, ProgressListener.none());
52
53 ClassCache classCache = project.getClassCache();
54 JarIndex index = project.getJarIndex();
55
56 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
57 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
45 58
46 // get all classes that aren't inner classes 59 // get all classes that aren't inner classes
47 Set<ClassEntry> classEntries = Sets.newHashSet(); 60 Set<ClassEntry> classEntries = Sets.newHashSet();
48 for (ClassEntry obfClassEntry : enigma.getJarIndex().getEntryIndex().getClasses()) { 61 for (ClassEntry obfClassEntry : index.getEntryIndex().getClasses()) {
49 if (!obfClassEntry.isInnerClass()) { 62 if (!obfClassEntry.isInnerClass()) {
50 classEntries.add(obfClassEntry); 63 classEntries.add(obfClassEntry);
51 } 64 }
52 } 65 }
53 66
54 SourceProvider sourceProvider = enigma.getObfSourceProvider();
55 for (ClassEntry obfClassEntry : classEntries) { 67 for (ClassEntry obfClassEntry : classEntries) {
56 try { 68 try {
57 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); 69 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName());
diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
index 1ee0bde1..0398de4f 100644
--- a/src/test/java/cuchaz/enigma/TestTokensConstructors.java
+++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
@@ -14,7 +14,7 @@ package cuchaz.enigma;
14import cuchaz.enigma.translation.representation.entry.MethodEntry; 14import cuchaz.enigma.translation.representation.entry.MethodEntry;
15import org.junit.Test; 15import org.junit.Test;
16 16
17import java.util.jar.JarFile; 17import java.nio.file.Paths;
18 18
19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; 19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod;
20import static cuchaz.enigma.TestEntryFactory.newMethod; 20import static cuchaz.enigma.TestEntryFactory.newMethod;
@@ -25,7 +25,7 @@ public class TestTokensConstructors extends TokenChecker {
25 25
26 public TestTokensConstructors() 26 public TestTokensConstructors()
27 throws Exception { 27 throws Exception {
28 super(new JarFile("build/test-obf/constructors.jar")); 28 super(Paths.get("build/test-obf/constructors.jar"));
29 } 29 }
30 30
31 @Test 31 @Test
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java
index 9e0c696c..1dde0349 100644
--- a/src/test/java/cuchaz/enigma/TokenChecker.java
+++ b/src/test/java/cuchaz/enigma/TokenChecker.java
@@ -13,28 +13,30 @@ package cuchaz.enigma;
13 13
14import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.EntryReference; 17import cuchaz.enigma.analysis.EntryReference;
17import cuchaz.enigma.analysis.SourceIndex; 18import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.Token; 19import cuchaz.enigma.analysis.Token;
19import cuchaz.enigma.translation.representation.entry.Entry; 20import cuchaz.enigma.translation.representation.entry.Entry;
20 21
21import java.io.IOException; 22import java.io.IOException;
23import java.nio.file.Path;
22import java.util.Collection; 24import java.util.Collection;
23import java.util.List; 25import java.util.List;
24import java.util.jar.JarFile;
25 26
26public class TokenChecker { 27public class TokenChecker {
27 28
28 private Enigma enigma; 29 private SourceProvider sourceProvider;
29 30
30 protected TokenChecker(JarFile jarFile) 31 protected TokenChecker(Path path) throws IOException {
31 throws IOException { 32 ClassCache classCache = ClassCache.of(path);
32 enigma = new Enigma(jarFile); 33
34 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
35 sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
33 } 36 }
34 37
35 protected String getDeclarationToken(Entry<?> entry) { 38 protected String getDeclarationToken(Entry<?> entry) {
36 // decompile the class 39 // decompile the class
37 SourceProvider sourceProvider = enigma.getObfSourceProvider();
38 CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); 40 CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName());
39 // DEBUG 41 // DEBUG
40 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); 42 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null );
@@ -52,7 +54,6 @@ public class TokenChecker {
52 @SuppressWarnings("unchecked") 54 @SuppressWarnings("unchecked")
53 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { 55 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) {
54 // decompile the class 56 // decompile the class
55 SourceProvider sourceProvider = enigma.getObfSourceProvider();
56 CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); 57 CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName());
57 String source = sourceProvider.writeSourceToString(tree); 58 String source = sourceProvider.writeSourceToString(tree);
58 SourceIndex index = SourceIndex.buildIndex(source, tree, true); 59 SourceIndex index = SourceIndex.buildIndex(source, tree, true);