diff options
| author | 2019-02-19 19:16:55 +0200 | |
|---|---|---|
| committer | 2019-02-19 19:16:55 +0200 | |
| commit | d23e4d934c9b020adcbde411a64bbef7549f3020 (patch) | |
| tree | bbd61d5fb08d589ede58d0949e33255b95f62bcc /src/main/java/cuchaz/enigma/gui/GuiController.java | |
| parent | Match token navigation reference resolution to match source index (diff) | |
| download | enigma-fork-d23e4d934c9b020adcbde411a64bbef7549f3020.tar.gz enigma-fork-d23e4d934c9b020adcbde411a64bbef7549f3020.tar.xz enigma-fork-d23e4d934c9b020adcbde411a64bbef7549f3020.zip | |
Write stacktrace to editor when decompilation throws an exception
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/GuiController.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 357d812..a8ff0d0 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -35,6 +35,8 @@ import javax.annotation.Nullable; | |||
| 35 | import java.awt.event.ItemEvent; | 35 | import java.awt.event.ItemEvent; |
| 36 | import java.io.File; | 36 | import java.io.File; |
| 37 | import java.io.IOException; | 37 | import java.io.IOException; |
| 38 | import java.io.PrintWriter; | ||
| 39 | import java.io.StringWriter; | ||
| 38 | import java.nio.file.Path; | 40 | import java.nio.file.Path; |
| 39 | import java.util.Collection; | 41 | import java.util.Collection; |
| 40 | import java.util.Deque; | 42 | import java.util.Deque; |
| @@ -320,7 +322,7 @@ public class GuiController { | |||
| 320 | DECOMPILER_SERVICE.submit(() -> { | 322 | DECOMPILER_SERVICE.submit(() -> { |
| 321 | try { | 323 | try { |
| 322 | if (requiresDecompile) { | 324 | if (requiresDecompile) { |
| 323 | decompileSource(targetClass, deobfuscator.getObfSourceProvider()); | 325 | currentSource = decompileSource(targetClass, deobfuscator.getObfSourceProvider()); |
| 324 | } | 326 | } |
| 325 | 327 | ||
| 326 | remapSource(deobfuscator.getMapper().getDeobfuscator()); | 328 | remapSource(deobfuscator.getMapper().getDeobfuscator()); |
| @@ -332,21 +334,28 @@ public class GuiController { | |||
| 332 | }); | 334 | }); |
| 333 | } | 335 | } |
| 334 | 336 | ||
| 335 | private void decompileSource(ClassEntry targetClass, SourceProvider sourceProvider) { | 337 | private DecompiledClassSource decompileSource(ClassEntry targetClass, SourceProvider sourceProvider) { |
| 336 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); | 338 | try { |
| 337 | if (sourceTree == null) { | 339 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); |
| 338 | gui.setEditorText("Unable to find class: " + targetClass); | 340 | if (sourceTree == null) { |
| 339 | return; | 341 | gui.setEditorText("Unable to find class: " + targetClass); |
| 340 | } | 342 | return DecompiledClassSource.text(targetClass, "Unable to find class"); |
| 343 | } | ||
| 341 | 344 | ||
| 342 | DropImportAstTransform.INSTANCE.run(sourceTree); | 345 | DropImportAstTransform.INSTANCE.run(sourceTree); |
| 343 | 346 | ||
| 344 | String sourceString = sourceProvider.writeSourceToString(sourceTree); | 347 | String sourceString = sourceProvider.writeSourceToString(sourceTree); |
| 345 | 348 | ||
| 346 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); | 349 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); |
| 347 | index.resolveReferences(deobfuscator.getMapper().getObfResolver()); | 350 | index.resolveReferences(deobfuscator.getMapper().getObfResolver()); |
| 348 | 351 | ||
| 349 | currentSource = new DecompiledClassSource(targetClass, deobfuscator, index); | 352 | return new DecompiledClassSource(targetClass, index); |
| 353 | } catch (Exception e) { | ||
| 354 | StringWriter traceWriter = new StringWriter(); | ||
| 355 | e.printStackTrace(new PrintWriter(traceWriter)); | ||
| 356 | |||
| 357 | return DecompiledClassSource.text(targetClass, traceWriter.toString()); | ||
| 358 | } | ||
| 350 | } | 359 | } |
| 351 | 360 | ||
| 352 | private void remapSource(Translator translator) { | 361 | private void remapSource(Translator translator) { |
| @@ -354,7 +363,7 @@ public class GuiController { | |||
| 354 | return; | 363 | return; |
| 355 | } | 364 | } |
| 356 | 365 | ||
| 357 | currentSource.remapSource(translator); | 366 | currentSource.remapSource(deobfuscator, translator); |
| 358 | 367 | ||
| 359 | gui.setEditorTheme(Config.getInstance().lookAndFeel); | 368 | gui.setEditorTheme(Config.getInstance().lookAndFeel); |
| 360 | gui.setSource(currentSource); | 369 | gui.setSource(currentSource); |