From d0a52bb6de19c81705094b26132931a57dc40866 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 20 Aug 2025 17:15:23 +0100 Subject: Add GuiService for plugins to make additions to the GUI. Also add enough context to do something useful. --- .../src/main/java/cuchaz/enigma/gui/Gui.java | 5 ++ .../main/java/cuchaz/enigma/gui/GuiController.java | 16 ++++- .../cuchaz/enigma/gui/elements/CustomMenuItem.java | 49 +++++++++++++++ .../enigma/gui/elements/EditorPopupMenu.java | 71 +++++++++++----------- .../src/main/java/cuchaz/enigma/EnigmaProject.java | 11 +++- .../cuchaz/enigma/analysis/EntryReference.java | 8 ++- .../java/cuchaz/enigma/api/service/GuiService.java | 34 +++++++++++ .../main/java/cuchaz/enigma/api/view/GuiView.java | 13 ++++ .../java/cuchaz/enigma/api/view/ProjectView.java | 7 +++ .../enigma/api/view/entry/ClassDefEntryView.java | 10 +++ .../enigma/api/view/entry/ClassEntryView.java | 5 ++ .../cuchaz/enigma/api/view/entry/DefEntryView.java | 5 ++ .../enigma/api/view/entry/EntryReferenceView.java | 5 ++ .../cuchaz/enigma/api/view/entry/EntryView.java | 36 +++++++++++ .../enigma/api/view/entry/FieldEntryView.java | 7 +++ .../api/view/entry/LocalVariableDefEntryView.java | 5 ++ .../api/view/entry/LocalVariableEntryView.java | 9 +++ .../enigma/api/view/entry/MethodEntryView.java | 7 +++ .../representation/entry/ClassDefEntry.java | 5 +- .../representation/entry/ClassEntry.java | 3 +- .../translation/representation/entry/DefEntry.java | 8 ++- .../translation/representation/entry/Entry.java | 36 +---------- .../representation/entry/FieldEntry.java | 8 ++- .../entry/LocalVariableDefEntry.java | 8 ++- .../representation/entry/LocalVariableEntry.java | 5 +- .../representation/entry/MethodEntry.java | 8 ++- 26 files changed, 305 insertions(+), 79 deletions(-) create mode 100644 enigma-swing/src/main/java/cuchaz/enigma/gui/elements/CustomMenuItem.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/service/GuiService.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/GuiView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassDefEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/ClassEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/DefEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryReferenceView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/EntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/FieldEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableDefEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/LocalVariableEntryView.java create mode 100644 enigma/src/main/java/cuchaz/enigma/api/view/entry/MethodEntryView.java 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; import cuchaz.enigma.Enigma; import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.api.service.GuiService; import cuchaz.enigma.gui.config.Themes; import cuchaz.enigma.gui.config.UiConfig; import cuchaz.enigma.gui.dialog.JavadocDialog; @@ -142,6 +143,10 @@ public class Gui { LanguageUtil.addListener(this::retranslateUi); Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); + for (GuiService guiService : enigma.getServices().get(GuiService.TYPE)) { + guiService.onStart(controller); + } + this.mainWindow.setVisible(true); } 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; import javax.swing.SwingUtilities; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import cuchaz.enigma.Enigma; import cuchaz.enigma.EnigmaProject; @@ -46,6 +47,8 @@ import cuchaz.enigma.analysis.MethodReferenceTreeNode; import cuchaz.enigma.analysis.StructureTreeNode; import cuchaz.enigma.analysis.StructureTreeOptions; import cuchaz.enigma.api.service.ObfuscationTestService; +import cuchaz.enigma.api.view.GuiView; +import cuchaz.enigma.api.view.entry.EntryReferenceView; import cuchaz.enigma.classhandle.ClassHandle; import cuchaz.enigma.classhandle.ClassHandleProvider; import cuchaz.enigma.classprovider.ClasspathClassProvider; @@ -91,7 +94,7 @@ import cuchaz.enigma.utils.Utils; import cuchaz.enigma.utils.validation.PrintValidatable; import cuchaz.enigma.utils.validation.ValidationContext; -public class GuiController implements ClientPacketHandler { +public class GuiController implements ClientPacketHandler, GuiView { private final Gui gui; public final Enigma enigma; @@ -115,6 +118,11 @@ public class GuiController implements ClientPacketHandler { this.enigma = enigma; } + @Override + public EnigmaProject getProject() { + return project; + } + public boolean isDirty() { return project != null && project.getMapper().isDirty(); } @@ -330,6 +338,12 @@ public class GuiController implements ClientPacketHandler { } } + @Override + @Nullable + public EntryReferenceView getCursorReference() { + return gui.getCursorReference(); + } + /** * Navigates to the declaration with respect to navigation history. * 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 @@ +package cuchaz.enigma.gui.elements; + +import java.util.function.BooleanSupplier; +import java.util.function.Supplier; + +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; + +import cuchaz.enigma.api.service.GuiService; +import cuchaz.enigma.utils.I18n; + +public class CustomMenuItem implements GuiService.MenuItemBuilder { + private final JMenuItem menuItem; + private final Supplier translationKey; + private BooleanSupplier enabledCondition = () -> true; + + public CustomMenuItem(JMenuItem menuItem, Supplier translationKey) { + this.menuItem = menuItem; + this.translationKey = translationKey; + menuItem.setText(translationKey.get()); + } + + @Override + public GuiService.MenuItemBuilder setAccelerator(KeyStroke accelerator) { + menuItem.setAccelerator(accelerator); + return this; + } + + @Override + public GuiService.MenuItemBuilder setEnabledWhen(BooleanSupplier condition) { + this.enabledCondition = condition; + return this; + } + + @Override + public GuiService.MenuItemBuilder setAction(Runnable action) { + menuItem.addActionListener(e -> action.run()); + return this; + } + + public void updateUiState() { + menuItem.setEnabled(enabledCondition.getAsBoolean()); + menuItem.setText(I18n.translate(translationKey.get())); + } + + public void retranslateUi() { + menuItem.setText(I18n.translate(translationKey.get())); + } +} 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 @@ package cuchaz.enigma.gui.elements; +import java.awt.Component; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.KeyStroke; import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.api.service.GuiService; import cuchaz.enigma.gui.EditableType; import cuchaz.enigma.gui.Gui; import cuchaz.enigma.gui.GuiController; @@ -36,6 +41,7 @@ public class EditorPopupMenu { private final JMenuItem zoomInItem = new JMenuItem(); private final JMenuItem zoomOutMenu = new JMenuItem(); private final JMenuItem resetZoomItem = new JMenuItem(); + private final List customItems = new ArrayList<>(); private final EditorPanel editor; private final Gui gui; @@ -102,48 +108,35 @@ public class EditorPopupMenu { this.zoomInItem.addActionListener(event -> editor.offsetEditorZoom(2)); this.zoomOutMenu.addActionListener(event -> editor.offsetEditorZoom(-2)); this.resetZoomItem.addActionListener(event -> editor.resetEditorZoom()); + + for (GuiService guiService : gui.getController().enigma.getServices().get(GuiService.TYPE)) { + guiService.addToEditorContextMenu(gui.getController(), new GuiService.MenuRegistrar() { + @Override + public void addSeparator() { + ui.addSeparator(); + } + + @Override + public GuiService.MenuItemBuilder add(Supplier translationKey) { + JMenuItem menuItem = new JMenuItem(); + ui.add(menuItem); + CustomMenuItem item = new CustomMenuItem(menuItem, translationKey); + customItems.add(item); + return item; + } + }); + } } // TODO have editor redirect key event to menu so that the actions get // triggered without having to hardcode them here, because this // is a hack public boolean handleKeyEvent(KeyEvent event) { - if (event.isControlDown()) { - switch (event.getKeyCode()) { - case KeyEvent.VK_I: - this.showInheritanceItem.doClick(); - return true; - case KeyEvent.VK_M: - this.showImplementationsItem.doClick(); - return true; - case KeyEvent.VK_N: - this.openEntryItem.doClick(); - return true; - case KeyEvent.VK_P: - this.openPreviousItem.doClick(); - return true; - case KeyEvent.VK_E: - this.openNextItem.doClick(); - return true; - case KeyEvent.VK_C: - if (event.isShiftDown()) { - this.showCallsSpecificItem.doClick(); - } else { - this.showCallsItem.doClick(); - } + KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(event); - return true; - case KeyEvent.VK_O: - this.toggleMappingItem.doClick(); - return true; - case KeyEvent.VK_R: - this.renameItem.doClick(); - return true; - case KeyEvent.VK_D: - this.editJavadocItem.doClick(); - return true; - case KeyEvent.VK_V: - this.pasteItem.doClick(); + for (Component component : ui.getComponents()) { + if (component instanceof JMenuItem menuItem && keyStroke.equals(menuItem.getAccelerator())) { + menuItem.doClick(); return true; } } @@ -184,6 +177,10 @@ public class EditorPopupMenu { } this.toggleMappingItem.setText(I18n.translate("popup_menu." + (isDeobfuscated ? "reset_obfuscated" : "mark_deobfuscated"))); + + for (CustomMenuItem customItem : customItems) { + customItem.updateUiState(); + } } public void retranslateUi() { @@ -201,6 +198,10 @@ public class EditorPopupMenu { this.zoomInItem.setText(I18n.translate("popup_menu.zoom.in")); this.zoomOutMenu.setText(I18n.translate("popup_menu.zoom.out")); this.resetZoomItem.setText(I18n.translate("popup_menu.zoom.reset")); + + for (CustomMenuItem customItem : customItems) { + customItem.retranslateUi(); + } } 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; import cuchaz.enigma.analysis.index.JarIndex; import cuchaz.enigma.api.service.NameProposalService; import cuchaz.enigma.api.service.ObfuscationTestService; +import cuchaz.enigma.api.view.ProjectView; +import cuchaz.enigma.api.view.entry.EntryView; import cuchaz.enigma.bytecode.translators.TranslationClassVisitor; import cuchaz.enigma.classprovider.ClassProvider; import cuchaz.enigma.classprovider.ObfuscationFixClassProvider; @@ -31,6 +33,7 @@ import cuchaz.enigma.source.Decompiler; import cuchaz.enigma.source.DecompilerService; import cuchaz.enigma.source.SourceSettings; import cuchaz.enigma.translation.ProposingTranslator; +import cuchaz.enigma.translation.Translatable; import cuchaz.enigma.translation.Translator; import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.mapping.EntryRemapper; @@ -44,7 +47,7 @@ import cuchaz.enigma.translation.representation.entry.LocalVariableEntry; import cuchaz.enigma.translation.representation.entry.MethodEntry; import cuchaz.enigma.utils.I18n; -public class EnigmaProject { +public class EnigmaProject implements ProjectView { private final Enigma enigma; private final List jarPaths; @@ -325,6 +328,12 @@ public class EnigmaProject { } } + @Override + @SuppressWarnings("unchecked") + public T deobfuscate(T entry) { + return (T) mapper.extendedDeobfuscate((Translatable) entry).getValue(); + } + public static final class SourceExport { public final Collection decompiled; 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; import java.util.List; import java.util.Objects; +import cuchaz.enigma.api.view.entry.EntryReferenceView; import cuchaz.enigma.translation.Translatable; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; @@ -25,7 +26,7 @@ import cuchaz.enigma.translation.representation.entry.ClassEntry; import cuchaz.enigma.translation.representation.entry.Entry; import cuchaz.enigma.translation.representation.entry.MethodEntry; -public class EntryReference, C extends Entry> implements Translatable { +public class EntryReference, C extends Entry> implements Translatable, EntryReferenceView { private static final List CONSTRUCTOR_NON_NAMES = Arrays.asList("this", "super", "static"); public final E entry; public final C context; @@ -89,6 +90,11 @@ public class EntryReference, C extends Entry> implements T return this.declaration; } + @Override + public E getEntry() { + return entry; + } + public Entry getNameableEntry() { if (entry instanceof MethodEntry method && method.isConstructor()) { // 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 @@ +package cuchaz.enigma.api.service; + +import java.util.function.BooleanSupplier; +import java.util.function.Supplier; + +import javax.swing.KeyStroke; + +import cuchaz.enigma.api.view.GuiView; + +public interface GuiService extends EnigmaService { + EnigmaServiceType TYPE = EnigmaServiceType.create("gui"); + + default void onStart(GuiView gui) { + } + + default void addToEditorContextMenu(GuiView gui, MenuRegistrar registrar) { + } + + interface MenuRegistrar { + void addSeparator(); + + default MenuItemBuilder add(String translationKey) { + return add(() -> translationKey); + } + + MenuItemBuilder add(Supplier translationKey); + } + + interface MenuItemBuilder { + MenuItemBuilder setAccelerator(KeyStroke accelerator); + MenuItemBuilder setEnabledWhen(BooleanSupplier condition); + MenuItemBuilder setAction(Runnable action); + } +} 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 @@ +package cuchaz.enigma.api.view; + +import org.jetbrains.annotations.Nullable; + +import cuchaz.enigma.api.view.entry.EntryReferenceView; + +public interface GuiView { + @Nullable + ProjectView getProject(); + + @Nullable + EntryReferenceView getCursorReference(); +} 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 @@ +package cuchaz.enigma.api.view; + +import cuchaz.enigma.api.view.entry.EntryView; + +public interface ProjectView { + T deobfuscate(T entry); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +import org.jetbrains.annotations.Nullable; + +public interface ClassDefEntryView extends ClassEntryView, DefEntryView { + @Nullable + ClassEntryView getSuperClass(); + + ClassEntryView[] getInterfaces(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface ClassEntryView extends EntryView { + ClassEntryView getParent(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface DefEntryView { + int getAccessFlags(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface EntryReferenceView { + EntryView getEntry(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +import org.jetbrains.annotations.Nullable; + +public interface EntryView { + /** + * Returns the default name of this entry. + * + *

Examples:

+ *
    + *
  • Outer class: "domain.name.ClassA"
  • + *
  • Inner class: "ClassB"
  • + *
  • Method: "methodC"
  • + *
+ */ + String getName(); + + /** + * Returns the full name of this entry. + * + *

For methods, fields and inner classes, it's their name prefixed with the full name + * of their parent entry.

+ *

For other classes, it's their name prefixed with their package name.

+ * + *

Examples:

+ *
    + *
  • Outer class: "domain.name.ClassA"
  • + *
  • Inner class: "domain.name.ClassA$ClassB"
  • + *
  • Method: "domain.name.ClassA.methodC"
  • + *
+ */ + String getFullName(); + + @Nullable + String getJavadocs(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface FieldEntryView extends EntryView { + String getDescriptor(); + + ClassEntryView getParent(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface LocalVariableDefEntryView extends LocalVariableEntryView { + String getDescriptor(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface LocalVariableEntryView extends EntryView { + int getIndex(); + + boolean isArgument(); + + MethodEntryView getParent(); +} 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 @@ +package cuchaz.enigma.api.view.entry; + +public interface MethodEntryView extends EntryView { + String getDescriptor(); + + ClassEntryView getParent(); +} 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; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import cuchaz.enigma.api.view.entry.ClassDefEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; @@ -24,7 +25,7 @@ import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.representation.AccessFlags; import cuchaz.enigma.translation.representation.Signature; -public class ClassDefEntry extends ClassEntry implements DefEntry { +public class ClassDefEntry extends ClassEntry implements DefEntry, ClassDefEntryView { private final AccessFlags access; private final Signature signature; private final @Nullable ClassEntry superClass; @@ -62,11 +63,13 @@ public class ClassDefEntry extends ClassEntry implements DefEntry { return access; } + @Override @Nullable public ClassEntry getSuperClass() { return superClass; } + @Override public ClassEntry[] getInterfaces() { return interfaces; } 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; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import cuchaz.enigma.api.view.entry.ClassEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; @@ -25,7 +26,7 @@ import cuchaz.enigma.translation.mapping.IdentifierValidation; import cuchaz.enigma.translation.representation.TypeDescriptor; import cuchaz.enigma.utils.validation.ValidationContext; -public class ClassEntry extends ParentedEntry implements Comparable { +public class ClassEntry extends ParentedEntry implements Comparable, ClassEntryView { private final String fullName; 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 @@ package cuchaz.enigma.translation.representation.entry; +import cuchaz.enigma.api.view.entry.DefEntryView; import cuchaz.enigma.translation.representation.AccessFlags; -public interface DefEntry

> extends Entry

{ +public interface DefEntry

> extends Entry

, DefEntryView { AccessFlags getAccess(); + + @Override + default int getAccessFlags() { + return getAccess().getFlags(); + } } 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; import org.jetbrains.annotations.Nullable; +import cuchaz.enigma.api.view.entry.EntryView; import cuchaz.enigma.translation.Translatable; import cuchaz.enigma.translation.mapping.IdentifierValidation; import cuchaz.enigma.utils.validation.ValidationContext; -public interface Entry

> extends Translatable { - /** - * Returns the default name of this entry. - * - *

For methods, fields and inner classes, it's the same as {@link #getSimpleName()}.

- *

For other classes, it's the same as {@link #getFullName()}.

- * - *

Examples:

- *
    - *
  • Outer class: "domain.name.ClassA"
  • - *
  • Inner class: "ClassB"
  • - *
  • Method: "methodC"
  • - *
- */ - String getName(); - +public interface Entry

> extends Translatable, EntryView { /** * Returns the simple name of this entry. * @@ -52,22 +38,6 @@ public interface Entry

> extends Translatable { */ String getSimpleName(); - /** - * Returns the full name of this entry. - * - *

For methods, fields and inner classes, it's their name prefixed with the full name - * of their parent entry.

- *

For other classes, it's their name prefixed with their package name.

- * - *

Examples:

- *
    - *
  • Outer class: "domain.name.ClassA"
  • - *
  • Inner class: "domain.name.ClassA$ClassB"
  • - *
  • Method: "domain.name.ClassA.methodC"
  • - *
- */ - String getFullName(); - /** * Returns the contextual name of this entry. * @@ -84,8 +54,6 @@ public interface Entry

> extends Translatable { */ String getContextualName(); - String getJavadocs(); - default String getSourceRemapName() { return getName(); } 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; import org.jetbrains.annotations.NotNull; +import cuchaz.enigma.api.view.entry.FieldEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.representation.TypeDescriptor; -public class FieldEntry extends ParentedEntry implements Comparable { +public class FieldEntry extends ParentedEntry implements Comparable, FieldEntryView { protected final TypeDescriptor desc; public FieldEntry(ClassEntry parent, String name, TypeDescriptor desc) { @@ -47,6 +48,11 @@ public class FieldEntry extends ParentedEntry implements Comparable< return this.desc; } + @Override + public String getDescriptor() { + return this.desc.toString(); + } + @Override public FieldEntry withName(String name) { return new FieldEntry(parent, name, desc, null); 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; import org.jetbrains.annotations.NotNull; +import cuchaz.enigma.api.view.entry.LocalVariableDefEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; @@ -15,7 +16,7 @@ import cuchaz.enigma.translation.representation.TypeDescriptor; * Created by Thog * 19/10/2016 */ -public class LocalVariableDefEntry extends LocalVariableEntry { +public class LocalVariableDefEntry extends LocalVariableEntry implements LocalVariableDefEntryView { protected final TypeDescriptor desc; public LocalVariableDefEntry(MethodEntry ownerEntry, int index, String name, boolean parameter, TypeDescriptor desc, String javadoc) { @@ -28,6 +29,11 @@ public class LocalVariableDefEntry extends LocalVariableEntry { return desc; } + @Override + public String getDescriptor() { + return desc.toString(); + } + @Override protected TranslateResult extendedTranslate(Translator translator, @NotNull EntryMapping mapping) { TypeDescriptor translatedDesc = translator.translate(desc); 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; import org.jetbrains.annotations.NotNull; +import cuchaz.enigma.api.view.entry.LocalVariableEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; @@ -14,7 +15,7 @@ import cuchaz.enigma.translation.mapping.EntryMapping; * Created by Thog * 19/10/2016 */ -public class LocalVariableEntry extends ParentedEntry implements Comparable { +public class LocalVariableEntry extends ParentedEntry implements Comparable, LocalVariableEntryView { protected final int index; protected final boolean parameter; @@ -34,10 +35,12 @@ public class LocalVariableEntry extends ParentedEntry implements Co return MethodEntry.class; } + @Override public boolean isArgument() { return this.parameter; } + @Override public int getIndex() { return index; } 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; import org.jetbrains.annotations.NotNull; +import cuchaz.enigma.api.view.entry.MethodEntryView; import cuchaz.enigma.source.RenamableTokenType; import cuchaz.enigma.translation.TranslateResult; import cuchaz.enigma.translation.Translator; import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.representation.MethodDescriptor; -public class MethodEntry extends ParentedEntry implements Comparable { +public class MethodEntry extends ParentedEntry implements Comparable, MethodEntryView { protected final MethodDescriptor descriptor; public MethodEntry(ClassEntry parent, String name, MethodDescriptor descriptor) { @@ -47,6 +48,11 @@ public class MethodEntry extends ParentedEntry implements Comparable return this.descriptor; } + @Override + public String getDescriptor() { + return descriptor.toString(); + } + public boolean isConstructor() { return name.equals("") || name.equals(""); } -- cgit v1.2.3