diff options
| author | 2025-08-20 17:15:23 +0100 | |
|---|---|---|
| committer | 2025-09-13 09:14:23 +0100 | |
| commit | d0a52bb6de19c81705094b26132931a57dc40866 (patch) | |
| tree | 1ed5009b5c84acef7f1d67e564899a77c327eded | |
| parent | Add I18n service (diff) | |
| download | enigma-d0a52bb6de19c81705094b26132931a57dc40866.tar.gz enigma-d0a52bb6de19c81705094b26132931a57dc40866.tar.xz enigma-d0a52bb6de19c81705094b26132931a57dc40866.zip | |
Add GuiService for plugins to make additions to the GUI. Also add enough context to do something useful.
26 files changed, 305 insertions, 79 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index 5881900c..12877fed 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -45,6 +45,7 @@ import org.jetbrains.annotations.Nullable; | |||
| 45 | 45 | ||
| 46 | import cuchaz.enigma.Enigma; | 46 | import cuchaz.enigma.Enigma; |
| 47 | import cuchaz.enigma.analysis.EntryReference; | 47 | import cuchaz.enigma.analysis.EntryReference; |
| 48 | import cuchaz.enigma.api.service.GuiService; | ||
| 48 | import cuchaz.enigma.gui.config.Themes; | 49 | import cuchaz.enigma.gui.config.Themes; |
| 49 | import cuchaz.enigma.gui.config.UiConfig; | 50 | import cuchaz.enigma.gui.config.UiConfig; |
| 50 | import cuchaz.enigma.gui.dialog.JavadocDialog; | 51 | import cuchaz.enigma.gui.dialog.JavadocDialog; |
| @@ -142,6 +143,10 @@ public class Gui { | |||
| 142 | LanguageUtil.addListener(this::retranslateUi); | 143 | LanguageUtil.addListener(this::retranslateUi); |
| 143 | Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); | 144 | Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); |
| 144 | 145 | ||
| 146 | for (GuiService guiService : enigma.getServices().get(GuiService.TYPE)) { | ||
| 147 | guiService.onStart(controller); | ||
| 148 | } | ||
| 149 | |||
| 145 | this.mainWindow.setVisible(true); | 150 | this.mainWindow.setVisible(true); |
| 146 | } | 151 | } |
| 147 | 152 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index e1e8521a..3609427d 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -31,6 +31,7 @@ import javax.swing.JOptionPane; | |||
| 31 | import javax.swing.SwingUtilities; | 31 | import javax.swing.SwingUtilities; |
| 32 | 32 | ||
| 33 | import org.jetbrains.annotations.ApiStatus; | 33 | import org.jetbrains.annotations.ApiStatus; |
| 34 | import org.jetbrains.annotations.Nullable; | ||
| 34 | 35 | ||
| 35 | import cuchaz.enigma.Enigma; | 36 | import cuchaz.enigma.Enigma; |
| 36 | import cuchaz.enigma.EnigmaProject; | 37 | import cuchaz.enigma.EnigmaProject; |
| @@ -46,6 +47,8 @@ import cuchaz.enigma.analysis.MethodReferenceTreeNode; | |||
| 46 | import cuchaz.enigma.analysis.StructureTreeNode; | 47 | import cuchaz.enigma.analysis.StructureTreeNode; |
| 47 | import cuchaz.enigma.analysis.StructureTreeOptions; | 48 | import cuchaz.enigma.analysis.StructureTreeOptions; |
| 48 | import cuchaz.enigma.api.service.ObfuscationTestService; | 49 | import cuchaz.enigma.api.service.ObfuscationTestService; |
| 50 | import cuchaz.enigma.api.view.GuiView; | ||
| 51 | import cuchaz.enigma.api.view.entry.EntryReferenceView; | ||
| 49 | import cuchaz.enigma.classhandle.ClassHandle; | 52 | import cuchaz.enigma.classhandle.ClassHandle; |
| 50 | import cuchaz.enigma.classhandle.ClassHandleProvider; | 53 | import cuchaz.enigma.classhandle.ClassHandleProvider; |
| 51 | import cuchaz.enigma.classprovider.ClasspathClassProvider; | 54 | import cuchaz.enigma.classprovider.ClasspathClassProvider; |
| @@ -91,7 +94,7 @@ import cuchaz.enigma.utils.Utils; | |||
| 91 | import cuchaz.enigma.utils.validation.PrintValidatable; | 94 | import cuchaz.enigma.utils.validation.PrintValidatable; |
| 92 | import cuchaz.enigma.utils.validation.ValidationContext; | 95 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 93 | 96 | ||
| 94 | public class GuiController implements ClientPacketHandler { | 97 | public class GuiController implements ClientPacketHandler, GuiView { |
| 95 | private final Gui gui; | 98 | private final Gui gui; |
| 96 | public final Enigma enigma; | 99 | public final Enigma enigma; |
| 97 | 100 | ||
| @@ -115,6 +118,11 @@ public class GuiController implements ClientPacketHandler { | |||
| 115 | this.enigma = enigma; | 118 | this.enigma = enigma; |
| 116 | } | 119 | } |
| 117 | 120 | ||
| 121 | @Override | ||
| 122 | public EnigmaProject getProject() { | ||
| 123 | return project; | ||
| 124 | } | ||
| 125 | |||
| 118 | public boolean isDirty() { | 126 | public boolean isDirty() { |
| 119 | return project != null && project.getMapper().isDirty(); | 127 | return project != null && project.getMapper().isDirty(); |
| 120 | } | 128 | } |
| @@ -330,6 +338,12 @@ public class GuiController implements ClientPacketHandler { | |||
| 330 | } | 338 | } |
| 331 | } | 339 | } |
| 332 | 340 | ||
| 341 | @Override | ||
| 342 | @Nullable | ||
| 343 | public EntryReferenceView getCursorReference() { | ||
| 344 | return gui.getCursorReference(); | ||
| 345 | } | ||
| 346 | |||
| 333 | /** | 347 | /** |
| 334 | * Navigates to the declaration with respect to navigation history. | 348 | * Navigates to the declaration with respect to navigation history. |
| 335 | * | 349 | * |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/CustomMenuItem.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/CustomMenuItem.java new file mode 100644 index 00000000..055a00f7 --- /dev/null +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/CustomMenuItem.java | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | package cuchaz.enigma.gui.elements; | ||
| 2 | |||
| 3 | import java.util.function.BooleanSupplier; | ||
| 4 | import java.util.function.Supplier; | ||
| 5 | |||
| 6 | import javax.swing.JMenuItem; | ||
| 7 | import javax.swing.KeyStroke; | ||
| 8 | |||
| 9 | import cuchaz.enigma.api.service.GuiService; | ||
| 10 | import cuchaz.enigma.utils.I18n; | ||
| 11 | |||
| 12 | public class CustomMenuItem implements GuiService.MenuItemBuilder { | ||
| 13 | private final JMenuItem menuItem; | ||
| 14 | private final Supplier<String> translationKey; | ||
| 15 | private BooleanSupplier enabledCondition = () -> true; | ||
| 16 | |||
| 17 | public CustomMenuItem(JMenuItem menuItem, Supplier<String> translationKey) { | ||
| 18 | this.menuItem = menuItem; | ||
| 19 | this.translationKey = translationKey; | ||
| 20 | menuItem.setText(translationKey.get()); | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public GuiService.MenuItemBuilder setAccelerator(KeyStroke accelerator) { | ||
| 25 | menuItem.setAccelerator(accelerator); | ||
| 26 | return this; | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public GuiService.MenuItemBuilder setEnabledWhen(BooleanSupplier condition) { | ||
| 31 | this.enabledCondition = condition; | ||
| 32 | return this; | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public GuiService.MenuItemBuilder setAction(Runnable action) { | ||
| 37 | menuItem.addActionListener(e -> action.run()); | ||
| 38 | return this; | ||
| 39 | } | ||
| 40 | |||
| 41 | public void updateUiState() { | ||
| 42 | menuItem.setEnabled(enabledCondition.getAsBoolean()); | ||
| 43 | menuItem.setText(I18n.translate(translationKey.get())); | ||
| 44 | } | ||
| 45 | |||
| 46 | public void retranslateUi() { | ||
| 47 | menuItem.setText(I18n.translate(translationKey.get())); | ||
| 48 | } | ||
| 49 | } | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java index dd37798a..8f968f38 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/EditorPopupMenu.java | |||
| @@ -1,13 +1,18 @@ | |||
| 1 | package cuchaz.enigma.gui.elements; | 1 | package cuchaz.enigma.gui.elements; |
| 2 | 2 | ||
| 3 | import java.awt.Component; | ||
| 3 | import java.awt.event.InputEvent; | 4 | import java.awt.event.InputEvent; |
| 4 | import java.awt.event.KeyEvent; | 5 | import java.awt.event.KeyEvent; |
| 6 | import java.util.ArrayList; | ||
| 7 | import java.util.List; | ||
| 8 | import java.util.function.Supplier; | ||
| 5 | 9 | ||
| 6 | import javax.swing.JMenuItem; | 10 | import javax.swing.JMenuItem; |
| 7 | import javax.swing.JPopupMenu; | 11 | import javax.swing.JPopupMenu; |
| 8 | import javax.swing.KeyStroke; | 12 | import javax.swing.KeyStroke; |
| 9 | 13 | ||
| 10 | import cuchaz.enigma.analysis.EntryReference; | 14 | import cuchaz.enigma.analysis.EntryReference; |
| 15 | import cuchaz.enigma.api.service.GuiService; | ||
| 11 | import cuchaz.enigma.gui.EditableType; | 16 | import cuchaz.enigma.gui.EditableType; |
| 12 | import cuchaz.enigma.gui.Gui; | 17 | import cuchaz.enigma.gui.Gui; |
| 13 | import cuchaz.enigma.gui.GuiController; | 18 | import cuchaz.enigma.gui.GuiController; |
| @@ -36,6 +41,7 @@ public class EditorPopupMenu { | |||
| 36 | private final JMenuItem zoomInItem = new JMenuItem(); | 41 | private final JMenuItem zoomInItem = new JMenuItem(); |
| 37 | private final JMenuItem zoomOutMenu = new JMenuItem(); | 42 | private final JMenuItem zoomOutMenu = new JMenuItem(); |
| 38 | private final JMenuItem resetZoomItem = new JMenuItem(); | 43 | private final JMenuItem resetZoomItem = new JMenuItem(); |
| 44 | private final List<CustomMenuItem> customItems = new ArrayList<>(); | ||
| 39 | 45 | ||
| 40 | private final EditorPanel editor; | 46 | private final EditorPanel editor; |
| 41 | private final Gui gui; | 47 | private final Gui gui; |
| @@ -102,48 +108,35 @@ public class EditorPopupMenu { | |||
| 102 | this.zoomInItem.addActionListener(event -> editor.offsetEditorZoom(2)); | 108 | this.zoomInItem.addActionListener(event -> editor.offsetEditorZoom(2)); |
| 103 | this.zoomOutMenu.addActionListener(event -> editor.offsetEditorZoom(-2)); | 109 | this.zoomOutMenu.addActionListener(event -> editor.offsetEditorZoom(-2)); |
| 104 | this.resetZoomItem.addActionListener(event -> editor.resetEditorZoom()); | 110 | this.resetZoomItem.addActionListener(event -> editor.resetEditorZoom()); |
| 111 | |||
| 112 | for (GuiService guiService : gui.getController().enigma.getServices().get(GuiService.TYPE)) { | ||
| 113 | guiService.addToEditorContextMenu(gui.getController(), new GuiService.MenuRegistrar() { | ||
| 114 | @Override | ||
| 115 | public void addSeparator() { | ||
| 116 | ui.addSeparator(); | ||
| 117 | } | ||
| 118 | |||
| 119 | @Override | ||
| 120 | public GuiService.MenuItemBuilder add(Supplier<String> translationKey) { | ||
| 121 | JMenuItem menuItem = new JMenuItem(); | ||
| 122 | ui.add(menuItem); | ||
| 123 | CustomMenuItem item = new CustomMenuItem(menuItem, translationKey); | ||
| 124 | customItems.add(item); | ||
| 125 | return item; | ||
| 126 | } | ||
| 127 | }); | ||
| 128 | } | ||
| 105 | } | 129 | } |
| 106 | 130 | ||
| 107 | // TODO have editor redirect key event to menu so that the actions get | 131 | // TODO have editor redirect key event to menu so that the actions get |
| 108 | // triggered without having to hardcode them here, because this | 132 | // triggered without having to hardcode them here, because this |
| 109 | // is a hack | 133 | // is a hack |
| 110 | public boolean handleKeyEvent(KeyEvent event) { | 134 | public boolean handleKeyEvent(KeyEvent event) { |
| 111 | if (event.isControlDown()) { | 135 | KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(event); |
| 112 | switch (event.getKeyCode()) { | ||
| 113 | case KeyEvent.VK_I: | ||
| 114 | this.showInheritanceItem.doClick(); | ||
| 115 | return true; | ||
| 116 | case KeyEvent.VK_M: | ||
| 117 | this.showImplementationsItem.doClick(); | ||
| 118 | return true; | ||
| 119 | case KeyEvent.VK_N: | ||
| 120 | this.openEntryItem.doClick(); | ||
| 121 | return true; | ||
| 122 | case KeyEvent.VK_P: | ||
| 123 | this.openPreviousItem.doClick(); | ||
| 124 | return true; | ||
| 125 | case KeyEvent.VK_E: | ||
| 126 | this.openNextItem.doClick(); | ||
| 127 | return true; | ||
| 128 | case KeyEvent.VK_C: | ||
| 129 | if (event.isShiftDown()) { | ||
| 130 | this.showCallsSpecificItem.doClick(); | ||
| 131 | } else { | ||
| 132 | this.showCallsItem.doClick(); | ||
| 133 | } | ||
| 134 | 136 | ||
| 135 | return true; | 137 | for (Component component : ui.getComponents()) { |
| 136 | case KeyEvent.VK_O: | 138 | if (component instanceof JMenuItem menuItem && keyStroke.equals(menuItem.getAccelerator())) { |
| 137 | this.toggleMappingItem.doClick(); | 139 | menuItem.doClick(); |
| 138 | return true; | ||
| 139 | case KeyEvent.VK_R: | ||
| 140 | this.renameItem.doClick(); | ||
| 141 | return true; | ||
| 142 | case KeyEvent.VK_D: | ||
| 143 | this.editJavadocItem.doClick(); | ||
| 144 | return true; | ||
| 145 | case KeyEvent.VK_V: | ||
| 146 | this.pasteItem.doClick(); | ||
| 147 | return true; | 140 | return true; |
| 148 | } | 141 | } |
| 149 | } | 142 | } |
| @@ -184,6 +177,10 @@ public class EditorPopupMenu { | |||
| 184 | } | 177 | } |
| 185 | 178 | ||
| 186 | this.toggleMappingItem.setText(I18n.translate("popup_menu." + (isDeobfuscated ? "reset_obfuscated" : "mark_deobfuscated"))); | 179 | this.toggleMappingItem.setText(I18n.translate("popup_menu." + (isDeobfuscated ? "reset_obfuscated" : "mark_deobfuscated"))); |
| 180 | |||
| 181 | for (CustomMenuItem customItem : customItems) { | ||
| 182 | customItem.updateUiState(); | ||
| 183 | } | ||
| 187 | } | 184 | } |
| 188 | 185 | ||
| 189 | public void retranslateUi() { | 186 | public void retranslateUi() { |
| @@ -201,6 +198,10 @@ public class EditorPopupMenu { | |||
| 201 | this.zoomInItem.setText(I18n.translate("popup_menu.zoom.in")); | 198 | this.zoomInItem.setText(I18n.translate("popup_menu.zoom.in")); |
| 202 | this.zoomOutMenu.setText(I18n.translate("popup_menu.zoom.out")); | 199 | this.zoomOutMenu.setText(I18n.translate("popup_menu.zoom.out")); |
| 203 | this.resetZoomItem.setText(I18n.translate("popup_menu.zoom.reset")); | 200 | this.resetZoomItem.setText(I18n.translate("popup_menu.zoom.reset")); |
| 201 | |||
| 202 | for (CustomMenuItem customItem : customItems) { | ||
| 203 | customItem.retranslateUi(); | ||
| 204 | } | ||
| 204 | } | 205 | } |
| 205 | 206 | ||
| 206 | public JPopupMenu getUi() { | 207 | public JPopupMenu getUi() { |
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index 79df2fb7..96ad433b 100644 --- a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java +++ b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java | |||
| @@ -24,6 +24,8 @@ import cuchaz.enigma.analysis.EntryReference; | |||
| 24 | import cuchaz.enigma.analysis.index.JarIndex; | 24 | import cuchaz.enigma.analysis.index.JarIndex; |
| 25 | import cuchaz.enigma.api.service.NameProposalService; | 25 | import cuchaz.enigma.api.service.NameProposalService; |
| 26 | import cuchaz.enigma.api.service.ObfuscationTestService; | 26 | import cuchaz.enigma.api.service.ObfuscationTestService; |
| 27 | import cuchaz.enigma.api.view.ProjectView; | ||
| 28 | import cuchaz.enigma.api.view.entry.EntryView; | ||
| 27 | import cuchaz.enigma.bytecode.translators.TranslationClassVisitor; | 29 | import cuchaz.enigma.bytecode.translators.TranslationClassVisitor; |
| 28 | import cuchaz.enigma.classprovider.ClassProvider; | 30 | import cuchaz.enigma.classprovider.ClassProvider; |
| 29 | import cuchaz.enigma.classprovider.ObfuscationFixClassProvider; | 31 | import cuchaz.enigma.classprovider.ObfuscationFixClassProvider; |
| @@ -31,6 +33,7 @@ import cuchaz.enigma.source.Decompiler; | |||
| 31 | import cuchaz.enigma.source.DecompilerService; | 33 | import cuchaz.enigma.source.DecompilerService; |
| 32 | import cuchaz.enigma.source.SourceSettings; | 34 | import cuchaz.enigma.source.SourceSettings; |
| 33 | import cuchaz.enigma.translation.ProposingTranslator; | 35 | import cuchaz.enigma.translation.ProposingTranslator; |
| 36 | import cuchaz.enigma.translation.Translatable; | ||
| 34 | import cuchaz.enigma.translation.Translator; | 37 | import cuchaz.enigma.translation.Translator; |
| 35 | import cuchaz.enigma.translation.mapping.EntryMapping; | 38 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 36 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 39 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| @@ -44,7 +47,7 @@ import cuchaz.enigma.translation.representation.entry.LocalVariableEntry; | |||
| 44 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 47 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 45 | import cuchaz.enigma.utils.I18n; | 48 | import cuchaz.enigma.utils.I18n; |
| 46 | 49 | ||
| 47 | public class EnigmaProject { | 50 | public class EnigmaProject implements ProjectView { |
| 48 | private final Enigma enigma; | 51 | private final Enigma enigma; |
| 49 | 52 | ||
| 50 | private final List<Path> jarPaths; | 53 | private final List<Path> jarPaths; |
| @@ -325,6 +328,12 @@ public class EnigmaProject { | |||
| 325 | } | 328 | } |
| 326 | } | 329 | } |
| 327 | 330 | ||
| 331 | @Override | ||
| 332 | @SuppressWarnings("unchecked") | ||
| 333 | public <T extends EntryView> T deobfuscate(T entry) { | ||
| 334 | return (T) mapper.extendedDeobfuscate((Translatable) entry).getValue(); | ||
| 335 | } | ||
| 336 | |||
| 328 | public static final class SourceExport { | 337 | public static final class SourceExport { |
| 329 | public final Collection<ClassSource> decompiled; | 338 | public final Collection<ClassSource> decompiled; |
| 330 | 339 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java index 9c542814..ec9b3750 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java | |||
| @@ -15,6 +15,7 @@ import java.util.Arrays; | |||
| 15 | import java.util.List; | 15 | import java.util.List; |
| 16 | import java.util.Objects; | 16 | import java.util.Objects; |
| 17 | 17 | ||
| 18 | import cuchaz.enigma.api.view.entry.EntryReferenceView; | ||
| 18 | import cuchaz.enigma.translation.Translatable; | 19 | import cuchaz.enigma.translation.Translatable; |
| 19 | import cuchaz.enigma.translation.TranslateResult; | 20 | import cuchaz.enigma.translation.TranslateResult; |
| 20 | import cuchaz.enigma.translation.Translator; | 21 | import cuchaz.enigma.translation.Translator; |
| @@ -25,7 +26,7 @@ import cuchaz.enigma.translation.representation.entry.ClassEntry; | |||
| 25 | import cuchaz.enigma.translation.representation.entry.Entry; | 26 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 26 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 27 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 27 | 28 | ||
| 28 | public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable { | 29 | public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements Translatable, EntryReferenceView { |
| 29 | private static final List<String> CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); | 30 | private static final List<String> CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); |
| 30 | public final E entry; | 31 | public final E entry; |
| 31 | public final C context; | 32 | public final C context; |
| @@ -89,6 +90,11 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 89 | return this.declaration; | 90 | return this.declaration; |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 93 | @Override | ||
| 94 | public E getEntry() { | ||
| 95 | return entry; | ||
| 96 | } | ||
| 97 | |||
| 92 | public Entry<?> getNameableEntry() { | 98 | public Entry<?> getNameableEntry() { |
| 93 | if (entry instanceof MethodEntry method && method.isConstructor()) { | 99 | if (entry instanceof MethodEntry method && method.isConstructor()) { |
| 94 | // renaming a constructor really means renaming the class | 100 | // renaming a constructor really means renaming the class |
diff --git a/enigma/src/main/java/cuchaz/enigma/api/service/GuiService.java b/enigma/src/main/java/cuchaz/enigma/api/service/GuiService.java new file mode 100644 index 00000000..b00b94db --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/service/GuiService.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | package cuchaz.enigma.api.service; | ||
| 2 | |||
| 3 | import java.util.function.BooleanSupplier; | ||
| 4 | import java.util.function.Supplier; | ||
| 5 | |||
| 6 | import javax.swing.KeyStroke; | ||
| 7 | |||
| 8 | import cuchaz.enigma.api.view.GuiView; | ||
| 9 | |||
| 10 | public interface GuiService extends EnigmaService { | ||
| 11 | EnigmaServiceType<GuiService> TYPE = EnigmaServiceType.create("gui"); | ||
| 12 | |||
| 13 | default void onStart(GuiView gui) { | ||
| 14 | } | ||
| 15 | |||
| 16 | default void addToEditorContextMenu(GuiView gui, MenuRegistrar registrar) { | ||
| 17 | } | ||
| 18 | |||
| 19 | interface MenuRegistrar { | ||
| 20 | void addSeparator(); | ||
| 21 | |||
| 22 | default MenuItemBuilder add(String translationKey) { | ||
| 23 | return add(() -> translationKey); | ||
| 24 | } | ||
| 25 | |||
| 26 | MenuItemBuilder add(Supplier<String> translationKey); | ||
| 27 | } | ||
| 28 | |||
| 29 | interface MenuItemBuilder { | ||
| 30 | MenuItemBuilder setAccelerator(KeyStroke accelerator); | ||
| 31 | MenuItemBuilder setEnabledWhen(BooleanSupplier condition); | ||
| 32 | MenuItemBuilder setAction(Runnable action); | ||
| 33 | } | ||
| 34 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java b/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java new file mode 100644 index 00000000..15c2dc64 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package cuchaz.enigma.api.view; | ||
| 2 | |||
| 3 | import org.jetbrains.annotations.Nullable; | ||
| 4 | |||
| 5 | import cuchaz.enigma.api.view.entry.EntryReferenceView; | ||
| 6 | |||
| 7 | public interface GuiView { | ||
| 8 | @Nullable | ||
| 9 | ProjectView getProject(); | ||
| 10 | |||
| 11 | @Nullable | ||
| 12 | EntryReferenceView getCursorReference(); | ||
| 13 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java new file mode 100644 index 00000000..e07645a7 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | package cuchaz.enigma.api.view; | ||
| 2 | |||
| 3 | import cuchaz.enigma.api.view.entry.EntryView; | ||
| 4 | |||
| 5 | public interface ProjectView { | ||
| 6 | <T extends EntryView> T deobfuscate(T entry); | ||
| 7 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassDefEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassDefEntryView.java new file mode 100644 index 00000000..7cb18291 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassDefEntryView.java | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | import org.jetbrains.annotations.Nullable; | ||
| 4 | |||
| 5 | public interface ClassDefEntryView extends ClassEntryView, DefEntryView { | ||
| 6 | @Nullable | ||
| 7 | ClassEntryView getSuperClass(); | ||
| 8 | |||
| 9 | ClassEntryView[] getInterfaces(); | ||
| 10 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassEntryView.java new file mode 100644 index 00000000..40c0bcba --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassEntryView.java | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface ClassEntryView extends EntryView { | ||
| 4 | ClassEntryView getParent(); | ||
| 5 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/DefEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/DefEntryView.java new file mode 100644 index 00000000..bf246fb9 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/DefEntryView.java | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface DefEntryView { | ||
| 4 | int getAccessFlags(); | ||
| 5 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryReferenceView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryReferenceView.java new file mode 100644 index 00000000..d49aa1ee --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryReferenceView.java | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface EntryReferenceView { | ||
| 4 | EntryView getEntry(); | ||
| 5 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryView.java new file mode 100644 index 00000000..2dad5629 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryView.java | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | import org.jetbrains.annotations.Nullable; | ||
| 4 | |||
| 5 | public interface EntryView { | ||
| 6 | /** | ||
| 7 | * Returns the default name of this entry. | ||
| 8 | * | ||
| 9 | * <br><p>Examples:</p> | ||
| 10 | * <ul> | ||
| 11 | * <li>Outer class: "domain.name.ClassA"</li> | ||
| 12 | * <li>Inner class: "ClassB"</li> | ||
| 13 | * <li>Method: "methodC"</li> | ||
| 14 | * </ul> | ||
| 15 | */ | ||
| 16 | String getName(); | ||
| 17 | |||
| 18 | /** | ||
| 19 | * Returns the full name of this entry. | ||
| 20 | * | ||
| 21 | * <p>For methods, fields and inner classes, it's their name prefixed with the full name | ||
| 22 | * of their parent entry.</p> | ||
| 23 | * <p>For other classes, it's their name prefixed with their package name.</p> | ||
| 24 | * | ||
| 25 | * <br><p>Examples:</p> | ||
| 26 | * <ul> | ||
| 27 | * <li>Outer class: "domain.name.ClassA"</li> | ||
| 28 | * <li>Inner class: "domain.name.ClassA$ClassB"</li> | ||
| 29 | * <li>Method: "domain.name.ClassA.methodC"</li> | ||
| 30 | * </ul> | ||
| 31 | */ | ||
| 32 | String getFullName(); | ||
| 33 | |||
| 34 | @Nullable | ||
| 35 | String getJavadocs(); | ||
| 36 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/FieldEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/FieldEntryView.java new file mode 100644 index 00000000..a7967daf --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/FieldEntryView.java | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface FieldEntryView extends EntryView { | ||
| 4 | String getDescriptor(); | ||
| 5 | |||
| 6 | ClassEntryView getParent(); | ||
| 7 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableDefEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableDefEntryView.java new file mode 100644 index 00000000..d0915602 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableDefEntryView.java | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface LocalVariableDefEntryView extends LocalVariableEntryView { | ||
| 4 | String getDescriptor(); | ||
| 5 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableEntryView.java new file mode 100644 index 00000000..391bc0f0 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableEntryView.java | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface LocalVariableEntryView extends EntryView { | ||
| 4 | int getIndex(); | ||
| 5 | |||
| 6 | boolean isArgument(); | ||
| 7 | |||
| 8 | MethodEntryView getParent(); | ||
| 9 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/entry/MethodEntryView.java b/enigma/src/main/java/cuchaz/enigma/api/view/entry/MethodEntryView.java new file mode 100644 index 00000000..7db192b4 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/view/entry/MethodEntryView.java | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | package cuchaz.enigma.api.view.entry; | ||
| 2 | |||
| 3 | public interface MethodEntryView extends EntryView { | ||
| 4 | String getDescriptor(); | ||
| 5 | |||
| 6 | ClassEntryView getParent(); | ||
| 7 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java index 3cbd0c9a..2f8b2500 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassDefEntry.java | |||
| @@ -17,6 +17,7 @@ import java.util.Objects; | |||
| 17 | import org.jetbrains.annotations.NotNull; | 17 | import org.jetbrains.annotations.NotNull; |
| 18 | import org.jetbrains.annotations.Nullable; | 18 | import org.jetbrains.annotations.Nullable; |
| 19 | 19 | ||
| 20 | import cuchaz.enigma.api.view.entry.ClassDefEntryView; | ||
| 20 | import cuchaz.enigma.source.RenamableTokenType; | 21 | import cuchaz.enigma.source.RenamableTokenType; |
| 21 | import cuchaz.enigma.translation.TranslateResult; | 22 | import cuchaz.enigma.translation.TranslateResult; |
| 22 | import cuchaz.enigma.translation.Translator; | 23 | import cuchaz.enigma.translation.Translator; |
| @@ -24,7 +25,7 @@ import cuchaz.enigma.translation.mapping.EntryMapping; | |||
| 24 | import cuchaz.enigma.translation.representation.AccessFlags; | 25 | import cuchaz.enigma.translation.representation.AccessFlags; |
| 25 | import cuchaz.enigma.translation.representation.Signature; | 26 | import cuchaz.enigma.translation.representation.Signature; |
| 26 | 27 | ||
| 27 | public class ClassDefEntry extends ClassEntry implements DefEntry<ClassEntry> { | 28 | public class ClassDefEntry extends ClassEntry implements DefEntry<ClassEntry>, ClassDefEntryView { |
| 28 | private final AccessFlags access; | 29 | private final AccessFlags access; |
| 29 | private final Signature signature; | 30 | private final Signature signature; |
| 30 | private final @Nullable ClassEntry superClass; | 31 | private final @Nullable ClassEntry superClass; |
| @@ -62,11 +63,13 @@ public class ClassDefEntry extends ClassEntry implements DefEntry<ClassEntry> { | |||
| 62 | return access; | 63 | return access; |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 66 | @Override | ||
| 65 | @Nullable | 67 | @Nullable |
| 66 | public ClassEntry getSuperClass() { | 68 | public ClassEntry getSuperClass() { |
| 67 | return superClass; | 69 | return superClass; |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 72 | @Override | ||
| 70 | public ClassEntry[] getInterfaces() { | 73 | public ClassEntry[] getInterfaces() { |
| 71 | return interfaces; | 74 | return interfaces; |
| 72 | } | 75 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java index 23c4f4f9..2662b3c1 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java | |||
| @@ -17,6 +17,7 @@ import java.util.Objects; | |||
| 17 | import org.jetbrains.annotations.NotNull; | 17 | import org.jetbrains.annotations.NotNull; |
| 18 | import org.jetbrains.annotations.Nullable; | 18 | import org.jetbrains.annotations.Nullable; |
| 19 | 19 | ||
| 20 | import cuchaz.enigma.api.view.entry.ClassEntryView; | ||
| 20 | import cuchaz.enigma.source.RenamableTokenType; | 21 | import cuchaz.enigma.source.RenamableTokenType; |
| 21 | import cuchaz.enigma.translation.TranslateResult; | 22 | import cuchaz.enigma.translation.TranslateResult; |
| 22 | import cuchaz.enigma.translation.Translator; | 23 | import cuchaz.enigma.translation.Translator; |
| @@ -25,7 +26,7 @@ import cuchaz.enigma.translation.mapping.IdentifierValidation; | |||
| 25 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 26 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 26 | import cuchaz.enigma.utils.validation.ValidationContext; | 27 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 27 | 28 | ||
| 28 | public class ClassEntry extends ParentedEntry<ClassEntry> implements Comparable<ClassEntry> { | 29 | public class ClassEntry extends ParentedEntry<ClassEntry> implements Comparable<ClassEntry>, ClassEntryView { |
| 29 | private final String fullName; | 30 | private final String fullName; |
| 30 | 31 | ||
| 31 | public ClassEntry(String className) { | 32 | public ClassEntry(String className) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java index 82536c73..d6e77291 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/DefEntry.java | |||
| @@ -1,7 +1,13 @@ | |||
| 1 | package cuchaz.enigma.translation.representation.entry; | 1 | package cuchaz.enigma.translation.representation.entry; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.api.view.entry.DefEntryView; | ||
| 3 | import cuchaz.enigma.translation.representation.AccessFlags; | 4 | import cuchaz.enigma.translation.representation.AccessFlags; |
| 4 | 5 | ||
| 5 | public interface DefEntry<P extends Entry<?>> extends Entry<P> { | 6 | public interface DefEntry<P extends Entry<?>> extends Entry<P>, DefEntryView { |
| 6 | AccessFlags getAccess(); | 7 | AccessFlags getAccess(); |
| 8 | |||
| 9 | @Override | ||
| 10 | default int getAccessFlags() { | ||
| 11 | return getAccess().getFlags(); | ||
| 12 | } | ||
| 7 | } | 13 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java index 568d01c9..6f73948e 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java | |||
| @@ -17,26 +17,12 @@ import java.util.Objects; | |||
| 17 | 17 | ||
| 18 | import org.jetbrains.annotations.Nullable; | 18 | import org.jetbrains.annotations.Nullable; |
| 19 | 19 | ||
| 20 | import cuchaz.enigma.api.view.entry.EntryView; | ||
| 20 | import cuchaz.enigma.translation.Translatable; | 21 | import cuchaz.enigma.translation.Translatable; |
| 21 | import cuchaz.enigma.translation.mapping.IdentifierValidation; | 22 | import cuchaz.enigma.translation.mapping.IdentifierValidation; |
| 22 | import cuchaz.enigma.utils.validation.ValidationContext; | 23 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 23 | 24 | ||
| 24 | public interface Entry<P extends Entry<?>> extends Translatable { | 25 | public interface Entry<P extends Entry<?>> extends Translatable, EntryView { |
| 25 | /** | ||
| 26 | * Returns the default name of this entry. | ||
| 27 | * | ||
| 28 | * <p>For methods, fields and inner classes, it's the same as {@link #getSimpleName()}.</p> | ||
| 29 | * <p>For other classes, it's the same as {@link #getFullName()}.</p> | ||
| 30 | * | ||
| 31 | * <br><p>Examples:</p> | ||
| 32 | * <ul> | ||
| 33 | * <li>Outer class: "domain.name.ClassA"</li> | ||
| 34 | * <li>Inner class: "ClassB"</li> | ||
| 35 | * <li>Method: "methodC"</li> | ||
| 36 | * </ul> | ||
| 37 | */ | ||
| 38 | String getName(); | ||
| 39 | |||
| 40 | /** | 26 | /** |
| 41 | * Returns the simple name of this entry. | 27 | * Returns the simple name of this entry. |
| 42 | * | 28 | * |
| @@ -53,22 +39,6 @@ public interface Entry<P extends Entry<?>> extends Translatable { | |||
| 53 | String getSimpleName(); | 39 | String getSimpleName(); |
| 54 | 40 | ||
| 55 | /** | 41 | /** |
| 56 | * Returns the full name of this entry. | ||
| 57 | * | ||
| 58 | * <p>For methods, fields and inner classes, it's their name prefixed with the full name | ||
| 59 | * of their parent entry.</p> | ||
| 60 | * <p>For other classes, it's their name prefixed with their package name.</p> | ||
| 61 | * | ||
| 62 | * <br><p>Examples:</p> | ||
| 63 | * <ul> | ||
| 64 | * <li>Outer class: "domain.name.ClassA"</li> | ||
| 65 | * <li>Inner class: "domain.name.ClassA$ClassB"</li> | ||
| 66 | * <li>Method: "domain.name.ClassA.methodC"</li> | ||
| 67 | * </ul> | ||
| 68 | */ | ||
| 69 | String getFullName(); | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Returns the contextual name of this entry. | 42 | * Returns the contextual name of this entry. |
| 73 | * | 43 | * |
| 74 | * <p>For methods, fields and inner classes, it's their name prefixed with the contextual | 44 | * <p>For methods, fields and inner classes, it's their name prefixed with the contextual |
| @@ -84,8 +54,6 @@ public interface Entry<P extends Entry<?>> extends Translatable { | |||
| 84 | */ | 54 | */ |
| 85 | String getContextualName(); | 55 | String getContextualName(); |
| 86 | 56 | ||
| 87 | String getJavadocs(); | ||
| 88 | |||
| 89 | default String getSourceRemapName() { | 57 | default String getSourceRemapName() { |
| 90 | return getName(); | 58 | return getName(); |
| 91 | } | 59 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java index 745485f0..dba86448 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/FieldEntry.java | |||
| @@ -15,13 +15,14 @@ import java.util.Objects; | |||
| 15 | 15 | ||
| 16 | import org.jetbrains.annotations.NotNull; | 16 | import org.jetbrains.annotations.NotNull; |
| 17 | 17 | ||
| 18 | import cuchaz.enigma.api.view.entry.FieldEntryView; | ||
| 18 | import cuchaz.enigma.source.RenamableTokenType; | 19 | import cuchaz.enigma.source.RenamableTokenType; |
| 19 | import cuchaz.enigma.translation.TranslateResult; | 20 | import cuchaz.enigma.translation.TranslateResult; |
| 20 | import cuchaz.enigma.translation.Translator; | 21 | import cuchaz.enigma.translation.Translator; |
| 21 | import cuchaz.enigma.translation.mapping.EntryMapping; | 22 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 22 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 23 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 23 | 24 | ||
| 24 | public class FieldEntry extends ParentedEntry<ClassEntry> implements Comparable<FieldEntry> { | 25 | public class FieldEntry extends ParentedEntry<ClassEntry> implements Comparable<FieldEntry>, FieldEntryView { |
| 25 | protected final TypeDescriptor desc; | 26 | protected final TypeDescriptor desc; |
| 26 | 27 | ||
| 27 | public FieldEntry(ClassEntry parent, String name, TypeDescriptor desc) { | 28 | public FieldEntry(ClassEntry parent, String name, TypeDescriptor desc) { |
| @@ -48,6 +49,11 @@ public class FieldEntry extends ParentedEntry<ClassEntry> implements Comparable< | |||
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | @Override | 51 | @Override |
| 52 | public String getDescriptor() { | ||
| 53 | return this.desc.toString(); | ||
| 54 | } | ||
| 55 | |||
| 56 | @Override | ||
| 51 | public FieldEntry withName(String name) { | 57 | public FieldEntry withName(String name) { |
| 52 | return new FieldEntry(parent, name, desc, null); | 58 | return new FieldEntry(parent, name, desc, null); |
| 53 | } | 59 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java index 9eda3a9e..eca8c5d2 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableDefEntry.java | |||
| @@ -4,6 +4,7 @@ import java.util.Objects; | |||
| 4 | 4 | ||
| 5 | import org.jetbrains.annotations.NotNull; | 5 | import org.jetbrains.annotations.NotNull; |
| 6 | 6 | ||
| 7 | import cuchaz.enigma.api.view.entry.LocalVariableDefEntryView; | ||
| 7 | import cuchaz.enigma.source.RenamableTokenType; | 8 | import cuchaz.enigma.source.RenamableTokenType; |
| 8 | import cuchaz.enigma.translation.TranslateResult; | 9 | import cuchaz.enigma.translation.TranslateResult; |
| 9 | import cuchaz.enigma.translation.Translator; | 10 | import cuchaz.enigma.translation.Translator; |
| @@ -15,7 +16,7 @@ import cuchaz.enigma.translation.representation.TypeDescriptor; | |||
| 15 | * Created by Thog | 16 | * Created by Thog |
| 16 | * 19/10/2016 | 17 | * 19/10/2016 |
| 17 | */ | 18 | */ |
| 18 | public class LocalVariableDefEntry extends LocalVariableEntry { | 19 | public class LocalVariableDefEntry extends LocalVariableEntry implements LocalVariableDefEntryView { |
| 19 | protected final TypeDescriptor desc; | 20 | protected final TypeDescriptor desc; |
| 20 | 21 | ||
| 21 | public LocalVariableDefEntry(MethodEntry ownerEntry, int index, String name, boolean parameter, TypeDescriptor desc, String javadoc) { | 22 | public LocalVariableDefEntry(MethodEntry ownerEntry, int index, String name, boolean parameter, TypeDescriptor desc, String javadoc) { |
| @@ -29,6 +30,11 @@ public class LocalVariableDefEntry extends LocalVariableEntry { | |||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | @Override | 32 | @Override |
| 33 | public String getDescriptor() { | ||
| 34 | return desc.toString(); | ||
| 35 | } | ||
| 36 | |||
| 37 | @Override | ||
| 32 | protected TranslateResult<LocalVariableEntry> extendedTranslate(Translator translator, @NotNull EntryMapping mapping) { | 38 | protected TranslateResult<LocalVariableEntry> extendedTranslate(Translator translator, @NotNull EntryMapping mapping) { |
| 33 | TypeDescriptor translatedDesc = translator.translate(desc); | 39 | TypeDescriptor translatedDesc = translator.translate(desc); |
| 34 | String translatedName = mapping.targetName() != null ? mapping.targetName() : name; | 40 | String translatedName = mapping.targetName() != null ? mapping.targetName() : name; |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java index b188fb5b..4213ff9d 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java | |||
| @@ -4,6 +4,7 @@ import java.util.Objects; | |||
| 4 | 4 | ||
| 5 | import org.jetbrains.annotations.NotNull; | 5 | import org.jetbrains.annotations.NotNull; |
| 6 | 6 | ||
| 7 | import cuchaz.enigma.api.view.entry.LocalVariableEntryView; | ||
| 7 | import cuchaz.enigma.source.RenamableTokenType; | 8 | import cuchaz.enigma.source.RenamableTokenType; |
| 8 | import cuchaz.enigma.translation.TranslateResult; | 9 | import cuchaz.enigma.translation.TranslateResult; |
| 9 | import cuchaz.enigma.translation.Translator; | 10 | import cuchaz.enigma.translation.Translator; |
| @@ -14,7 +15,7 @@ import cuchaz.enigma.translation.mapping.EntryMapping; | |||
| 14 | * Created by Thog | 15 | * Created by Thog |
| 15 | * 19/10/2016 | 16 | * 19/10/2016 |
| 16 | */ | 17 | */ |
| 17 | public class LocalVariableEntry extends ParentedEntry<MethodEntry> implements Comparable<LocalVariableEntry> { | 18 | public class LocalVariableEntry extends ParentedEntry<MethodEntry> implements Comparable<LocalVariableEntry>, LocalVariableEntryView { |
| 18 | protected final int index; | 19 | protected final int index; |
| 19 | protected final boolean parameter; | 20 | protected final boolean parameter; |
| 20 | 21 | ||
| @@ -34,10 +35,12 @@ public class LocalVariableEntry extends ParentedEntry<MethodEntry> implements Co | |||
| 34 | return MethodEntry.class; | 35 | return MethodEntry.class; |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 38 | @Override | ||
| 37 | public boolean isArgument() { | 39 | public boolean isArgument() { |
| 38 | return this.parameter; | 40 | return this.parameter; |
| 39 | } | 41 | } |
| 40 | 42 | ||
| 43 | @Override | ||
| 41 | public int getIndex() { | 44 | public int getIndex() { |
| 42 | return index; | 45 | return index; |
| 43 | } | 46 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java index 3390bc57..d86f1564 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/entry/MethodEntry.java | |||
| @@ -15,13 +15,14 @@ import java.util.Objects; | |||
| 15 | 15 | ||
| 16 | import org.jetbrains.annotations.NotNull; | 16 | import org.jetbrains.annotations.NotNull; |
| 17 | 17 | ||
| 18 | import cuchaz.enigma.api.view.entry.MethodEntryView; | ||
| 18 | import cuchaz.enigma.source.RenamableTokenType; | 19 | import cuchaz.enigma.source.RenamableTokenType; |
| 19 | import cuchaz.enigma.translation.TranslateResult; | 20 | import cuchaz.enigma.translation.TranslateResult; |
| 20 | import cuchaz.enigma.translation.Translator; | 21 | import cuchaz.enigma.translation.Translator; |
| 21 | import cuchaz.enigma.translation.mapping.EntryMapping; | 22 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 22 | import cuchaz.enigma.translation.representation.MethodDescriptor; | 23 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| 23 | 24 | ||
| 24 | public class MethodEntry extends ParentedEntry<ClassEntry> implements Comparable<MethodEntry> { | 25 | public class MethodEntry extends ParentedEntry<ClassEntry> implements Comparable<MethodEntry>, MethodEntryView { |
| 25 | protected final MethodDescriptor descriptor; | 26 | protected final MethodDescriptor descriptor; |
| 26 | 27 | ||
| 27 | public MethodEntry(ClassEntry parent, String name, MethodDescriptor descriptor) { | 28 | public MethodEntry(ClassEntry parent, String name, MethodDescriptor descriptor) { |
| @@ -47,6 +48,11 @@ public class MethodEntry extends ParentedEntry<ClassEntry> implements Comparable | |||
| 47 | return this.descriptor; | 48 | return this.descriptor; |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 51 | @Override | ||
| 52 | public String getDescriptor() { | ||
| 53 | return descriptor.toString(); | ||
| 54 | } | ||
| 55 | |||
| 50 | public boolean isConstructor() { | 56 | public boolean isConstructor() { |
| 51 | return name.equals("<init>") || name.equals("<clinit>"); | 57 | return name.equals("<init>") || name.equals("<clinit>"); |
| 52 | } | 58 | } |