diff options
| author | 2025-08-20 17:15:23 +0100 | |
|---|---|---|
| committer | 2025-09-13 09:14:23 +0100 | |
| commit | d0a52bb6de19c81705094b26132931a57dc40866 (patch) | |
| tree | 1ed5009b5c84acef7f1d67e564899a77c327eded /enigma/src/main/java/cuchaz | |
| parent | Add I18n service (diff) | |
| download | enigma-fork-d0a52bb6de19c81705094b26132931a57dc40866.tar.gz enigma-fork-d0a52bb6de19c81705094b26132931a57dc40866.tar.xz enigma-fork-d0a52bb6de19c81705094b26132931a57dc40866.zip | |
Add GuiService for plugins to make additions to the GUI. Also add enough context to do something useful.
Diffstat (limited to 'enigma/src/main/java/cuchaz')
22 files changed, 200 insertions, 43 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index 79df2fb..96ad433 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 9c54281..ec9b375 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 0000000..b00b94d --- /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 0000000..15c2dc6 --- /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 0000000..e07645a --- /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 0000000..7cb1829 --- /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 0000000..40c0bcb --- /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 0000000..bf246fb --- /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 0000000..d49aa1e --- /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 0000000..2dad562 --- /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 0000000..a7967da --- /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 0000000..d091560 --- /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 0000000..391bc0f --- /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 0000000..7db192b --- /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 3cbd0c9..2f8b250 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 23c4f4f..2662b3c 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 82536c7..d6e7729 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 568d01c..6f73948 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 745485f..dba8644 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 9eda3a9..eca8c5d 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 b188fb5..4213ff9 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 3390bc5..d86f156 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 | } |