summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/GuiController.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/GuiController.java35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java
index 69f12e2..0b2fe27 100644
--- a/src/main/java/cuchaz/enigma/gui/GuiController.java
+++ b/src/main/java/cuchaz/enigma/gui/GuiController.java
@@ -368,20 +368,29 @@ public class GuiController {
368 } 368 }
369 369
370 private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference) { 370 private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference) {
371 refreshCurrentClass(reference, false);
372 }
373
374 private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference, boolean forceDecomp) {
371 if (currentSource != null) { 375 if (currentSource != null) {
372 loadClass(currentSource.getEntry(), () -> { 376 loadClass(currentSource.getEntry(), () -> {
373 if (reference != null) { 377 if (reference != null) {
374 showReference(reference); 378 showReference(reference);
375 } 379 }
376 }); 380 }, forceDecomp);
377 } 381 }
378 } 382 }
379 383
380 private void loadClass(ClassEntry classEntry, Runnable callback) { 384 private void loadClass(ClassEntry classEntry, Runnable callback) {
385 loadClass(classEntry, callback, false);
386 }
387
388 private void loadClass(ClassEntry classEntry, Runnable callback, boolean forceDecomp) {
381 ClassEntry targetClass = classEntry.getOutermostClass(); 389 ClassEntry targetClass = classEntry.getOutermostClass();
382 390
383 boolean requiresDecompile = currentSource == null || !currentSource.getEntry().equals(targetClass); 391 boolean requiresDecompile = forceDecomp || currentSource == null || !currentSource.getEntry().equals(targetClass);
384 if (requiresDecompile) { 392 if (requiresDecompile) {
393 currentSource = null; // Or the GUI may try to find a nonexistent token
385 gui.setEditorText("(decompiling...)"); 394 gui.setEditorText("(decompiling...)");
386 } 395 }
387 396
@@ -402,7 +411,7 @@ public class GuiController {
402 411
403 private DecompiledClassSource decompileSource(ClassEntry targetClass) { 412 private DecompiledClassSource decompileSource(ClassEntry targetClass) {
404 try { 413 try {
405 CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); 414 CompilationUnit sourceTree = (CompilationUnit) sourceProvider.getSources(targetClass.getFullName()).clone();
406 if (sourceTree == null) { 415 if (sourceTree == null) {
407 gui.setEditorText("Unable to find class: " + targetClass); 416 gui.setEditorText("Unable to find class: " + targetClass);
408 return DecompiledClassSource.text(targetClass, "Unable to find class"); 417 return DecompiledClassSource.text(targetClass, "Unable to find class");
@@ -410,6 +419,7 @@ public class GuiController {
410 419
411 DropImportAstTransform.INSTANCE.run(sourceTree); 420 DropImportAstTransform.INSTANCE.run(sourceTree);
412 DropVarModifiersAstTransform.INSTANCE.run(sourceTree); 421 DropVarModifiersAstTransform.INSTANCE.run(sourceTree);
422 new AddJavadocsAstTransform(project.getMapper()).run(sourceTree);
413 423
414 String sourceString = sourceProvider.writeSourceToString(sourceTree); 424 String sourceString = sourceProvider.writeSourceToString(sourceTree);
415 425
@@ -521,6 +531,25 @@ public class GuiController {
521 refreshCurrentClass(reference); 531 refreshCurrentClass(reference);
522 } 532 }
523 533
534 public void changeDocs(EntryReference<Entry<?>, Entry<?>> reference, String updatedDocs) {
535 changeDoc(reference.getNameableEntry(), updatedDocs);
536
537 refreshCurrentClass(reference, true);
538 }
539
540 public void changeDoc(Entry<?> obfEntry, String newDoc) {
541 EntryRemapper mapper = project.getMapper();
542 if (mapper.getDeobfMapping(obfEntry) == null) {
543 markAsDeobfuscated(obfEntry,false); // NPE
544 }
545 mapper.mapFromObf(obfEntry, mapper.getDeobfMapping(obfEntry).withDocs(newDoc), false);
546 }
547
548 public void markAsDeobfuscated(Entry<?> obfEntry, boolean renaming) {
549 EntryRemapper mapper = project.getMapper();
550 mapper.mapFromObf(obfEntry, new EntryMapping(mapper.deobfuscate(obfEntry).getName()), renaming);
551 }
552
524 public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) { 553 public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) {
525 EntryRemapper mapper = project.getMapper(); 554 EntryRemapper mapper = project.getMapper();
526 Entry<?> entry = reference.getNameableEntry(); 555 Entry<?> entry = reference.getNameableEntry();