diff options
| author | 2021-06-15 23:30:03 +0200 | |
|---|---|---|
| committer | 2021-06-15 22:30:03 +0100 | |
| commit | 1ec1ece9efbcc668b9c79de58d79b3176da1b7ca (patch) | |
| tree | 5d34cf25763bde51b40461d5822ff99f33a2867b /enigma/src/main | |
| parent | Fix some exceptions getting silently discarded (e.g. see #398) (diff) | |
| download | enigma-fork-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.tar.gz enigma-fork-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.tar.xz enigma-fork-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.zip | |
Structure panel options (#400)
* Structure panel options
* changes
* always show inner classes in the tree
* workaround for toString() and similar
* show constructor methods depending on the class obfuscation
* use ListCellRenderer instead of toString
* list cell renderer
Diffstat (limited to 'enigma/src/main')
5 files changed, 124 insertions, 18 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java index b4343c1..aea7618 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | |||
| @@ -10,7 +10,9 @@ import cuchaz.enigma.translation.representation.entry.*; | |||
| 10 | 10 | ||
| 11 | import javax.swing.tree.DefaultMutableTreeNode; | 11 | import javax.swing.tree.DefaultMutableTreeNode; |
| 12 | import java.util.ArrayList; | 12 | import java.util.ArrayList; |
| 13 | import java.util.Comparator; | ||
| 13 | import java.util.List; | 14 | import java.util.List; |
| 15 | import java.util.stream.Stream; | ||
| 14 | 16 | ||
| 15 | public class StructureTreeNode extends DefaultMutableTreeNode { | 17 | public class StructureTreeNode extends DefaultMutableTreeNode { |
| 16 | private final List<NameProposalService> nameProposalServices; | 18 | private final List<NameProposalService> nameProposalServices; |
| @@ -32,25 +34,47 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 32 | return this.entry; | 34 | return this.entry; |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | public void load(EnigmaProject project, boolean hideDeobfuscated) { | 37 | public void load(EnigmaProject project, StructureTreeOptions options) { |
| 36 | List<ParentedEntry> children = project.getJarIndex().getChildrenByClass().get(this.parentEntry); | 38 | Stream<ParentedEntry> children = project.getJarIndex().getChildrenByClass().get(this.parentEntry).stream(); |
| 37 | 39 | ||
| 38 | for (ParentedEntry child : children) { | 40 | children = switch (options.obfuscationVisibility()) { |
| 41 | case ALL -> children; | ||
| 42 | case OBFUSCATED -> children | ||
| 43 | // remove deobfuscated members if only obfuscated, unless it's an inner class | ||
| 44 | .filter(e -> (e instanceof ClassEntry) || (project.isObfuscated(e) && project.isRenamable(e))) | ||
| 45 | // keep constructor methods if the class is obfuscated | ||
| 46 | .filter(e -> !(e instanceof MethodEntry m && m.isConstructor()) || project.isObfuscated(e.getParent())); | ||
| 47 | case DEOBFUSCATED -> children.filter(e -> (e instanceof ClassEntry) | ||
| 48 | || (!project.isObfuscated(e) && project.isRenamable(e)) | ||
| 49 | // keep constructor methods if the class is deobfuscated | ||
| 50 | || (e instanceof MethodEntry m && m.isConstructor()) && !project.isObfuscated(e.getParent())); | ||
| 51 | }; | ||
| 52 | |||
| 53 | children = switch (options.documentationVisibility()) { | ||
| 54 | case ALL -> children; | ||
| 55 | // TODO remove EntryRemapper.deobfuscate() calls when javadocs will no longer be tied to deobfuscation | ||
| 56 | case DOCUMENTED -> children.filter(e -> (e instanceof ClassEntry) || (project.getMapper().deobfuscate(e).getJavadocs() != null && !project.getMapper().deobfuscate(e).getJavadocs().isBlank())); | ||
| 57 | case NON_DOCUMENTED -> children.filter(e -> (e instanceof ClassEntry) || (project.getMapper().deobfuscate(e).getJavadocs() == null || project.getMapper().deobfuscate(e).getJavadocs().isBlank())); | ||
| 58 | }; | ||
| 59 | |||
| 60 | children = switch (options.sortingOrder()) { | ||
| 61 | case DEFAULT -> children; | ||
| 62 | case A_Z -> children.sorted(Comparator.comparing(e -> (e instanceof MethodEntry m && m.isConstructor()) | ||
| 63 | // compare the class name when the entry is a constructor | ||
| 64 | ? project.getMapper().deobfuscate(e.getParent()).getSimpleName().toLowerCase() | ||
| 65 | : project.getMapper().deobfuscate(e).getSimpleName().toLowerCase())); | ||
| 66 | case Z_A -> children.sorted(Comparator.comparing(e -> (e instanceof MethodEntry m && m.isConstructor()) | ||
| 67 | ? project.getMapper().deobfuscate(((ParentedEntry<?>) e).getParent()).getSimpleName().toLowerCase() | ||
| 68 | : project.getMapper().deobfuscate((ParentedEntry<?>) e).getSimpleName().toLowerCase()) | ||
| 69 | .reversed()); | ||
| 70 | }; | ||
| 71 | |||
| 72 | for (ParentedEntry<?> child : children.toList()) { | ||
| 39 | StructureTreeNode childNode = new StructureTreeNode(project, this.parentEntry, child); | 73 | StructureTreeNode childNode = new StructureTreeNode(project, this.parentEntry, child); |
| 40 | 74 | ||
| 41 | if (child instanceof ClassEntry) { | 75 | if (child instanceof ClassEntry) { |
| 42 | childNode = new StructureTreeNode(project, (ClassEntry) child, child); | 76 | childNode = new StructureTreeNode(project, (ClassEntry) child, child); |
| 43 | childNode.load(project, hideDeobfuscated); | 77 | childNode.load(project, options); |
| 44 | } | ||
| 45 | |||
| 46 | // don't add deobfuscated members if hideDeobfuscated is true, unless it's an inner class | ||
| 47 | if (hideDeobfuscated && !project.isObfuscated(child) && !(child instanceof ClassEntry)) { | ||
| 48 | continue; | ||
| 49 | } | ||
| 50 | |||
| 51 | // don't add constructor methods if hideDeobfuscated is true | ||
| 52 | if (hideDeobfuscated && (child instanceof MethodEntry method) && method.isConstructor()) { | ||
| 53 | continue; | ||
| 54 | } | 78 | } |
| 55 | 79 | ||
| 56 | this.add(childNode); | 80 | this.add(childNode); |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeOptions.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeOptions.java new file mode 100644 index 0000000..cfc80b4 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeOptions.java | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | package cuchaz.enigma.analysis; | ||
| 2 | |||
| 3 | public record StructureTreeOptions( | ||
| 4 | ObfuscationVisibility obfuscationVisibility, | ||
| 5 | DocumentationVisibility documentationVisibility, | ||
| 6 | SortingOrder sortingOrder) { | ||
| 7 | |||
| 8 | public enum ObfuscationVisibility implements Option { | ||
| 9 | ALL("structure.options.obfuscation.all"), | ||
| 10 | OBFUSCATED("structure.options.obfuscation.obfuscated"), | ||
| 11 | DEOBFUSCATED("structure.options.obfuscation.deobfuscated"); | ||
| 12 | |||
| 13 | private final String translationKey; | ||
| 14 | |||
| 15 | ObfuscationVisibility(String translationKey) { | ||
| 16 | this.translationKey = translationKey; | ||
| 17 | } | ||
| 18 | |||
| 19 | public String getTranslationKey() { | ||
| 20 | return this.translationKey; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | public enum DocumentationVisibility implements Option { | ||
| 25 | ALL("structure.options.documentation.all"), | ||
| 26 | DOCUMENTED("structure.options.documentation.documented"), | ||
| 27 | NON_DOCUMENTED("structure.options.documentation.non_documented"); | ||
| 28 | |||
| 29 | private final String translationKey; | ||
| 30 | |||
| 31 | DocumentationVisibility(String translationKey) { | ||
| 32 | this.translationKey = translationKey; | ||
| 33 | } | ||
| 34 | |||
| 35 | public String getTranslationKey() { | ||
| 36 | return this.translationKey; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | public enum SortingOrder implements Option { | ||
| 41 | DEFAULT("structure.options.sorting.default"), | ||
| 42 | A_Z("structure.options.sorting.a_z"), | ||
| 43 | Z_A("structure.options.sorting.z_a"); | ||
| 44 | |||
| 45 | private final String translationKey; | ||
| 46 | |||
| 47 | SortingOrder(String translationKey) { | ||
| 48 | this.translationKey = translationKey; | ||
| 49 | } | ||
| 50 | |||
| 51 | public String getTranslationKey() { | ||
| 52 | return this.translationKey; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | public interface Option { | ||
| 57 | String getTranslationKey(); | ||
| 58 | } | ||
| 59 | } | ||
diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 57b2ca8..35a4d93 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json | |||
| @@ -106,13 +106,25 @@ | |||
| 106 | "info_panel.editor.class.decompiling": "(decompiling...)", | 106 | "info_panel.editor.class.decompiling": "(decompiling...)", |
| 107 | "info_panel.editor.class.not_found": "Unable to find class:", | 107 | "info_panel.editor.class.not_found": "Unable to find class:", |
| 108 | "info_panel.tree.structure": "Structure", | 108 | "info_panel.tree.structure": "Structure", |
| 109 | "info_panel.tree.structure.hide_deobfuscated": "Hide deobfuscated members", | ||
| 110 | "info_panel.tree.inheritance": "Inheritance", | 109 | "info_panel.tree.inheritance": "Inheritance", |
| 111 | "info_panel.tree.implementations": "Implementations", | 110 | "info_panel.tree.implementations": "Implementations", |
| 112 | "info_panel.tree.calls": "Call Graph", | 111 | "info_panel.tree.calls": "Call Graph", |
| 113 | 112 | ||
| 114 | "popup.copied": "Copied!", | 113 | "popup.copied": "Copied!", |
| 115 | 114 | ||
| 115 | "structure.options.obfuscation": "Obfuscation Visibility", | ||
| 116 | "structure.options.obfuscation.all": "All", | ||
| 117 | "structure.options.obfuscation.obfuscated": "Only obfuscated", | ||
| 118 | "structure.options.obfuscation.deobfuscated": "Only deobfuscated", | ||
| 119 | "structure.options.documentation": "Documentation Visibility", | ||
| 120 | "structure.options.documentation.all": "All", | ||
| 121 | "structure.options.documentation.documented": "Only documented", | ||
| 122 | "structure.options.documentation.non_documented": "Only non documented", | ||
| 123 | "structure.options.sorting": "Sorting Order", | ||
| 124 | "structure.options.sorting.default": "Default", | ||
| 125 | "structure.options.sorting.a_z": "A to Z", | ||
| 126 | "structure.options.sorting.z_a": "Z to A", | ||
| 127 | |||
| 116 | "log_panel.messages": "Messages", | 128 | "log_panel.messages": "Messages", |
| 117 | "log_panel.users": "Users", | 129 | "log_panel.users": "Users", |
| 118 | 130 | ||
diff --git a/enigma/src/main/resources/lang/fr_fr.json b/enigma/src/main/resources/lang/fr_fr.json index 5c46c87..ea1a20f 100644 --- a/enigma/src/main/resources/lang/fr_fr.json +++ b/enigma/src/main/resources/lang/fr_fr.json | |||
| @@ -106,13 +106,25 @@ | |||
| 106 | "info_panel.editor.class.decompiling": "(décompilation...)", | 106 | "info_panel.editor.class.decompiling": "(décompilation...)", |
| 107 | "info_panel.editor.class.not_found": "Impossible de trouver la classe :", | 107 | "info_panel.editor.class.not_found": "Impossible de trouver la classe :", |
| 108 | "info_panel.tree.structure": "Structure", | 108 | "info_panel.tree.structure": "Structure", |
| 109 | "info_panel.tree.structure.hide_deobfuscated": "Masquer les membres déobfusqués", | ||
| 110 | "info_panel.tree.inheritance": "Héritage", | 109 | "info_panel.tree.inheritance": "Héritage", |
| 111 | "info_panel.tree.implementations": "Implémentations", | 110 | "info_panel.tree.implementations": "Implémentations", |
| 112 | "info_panel.tree.calls": "Graphique des appels", | 111 | "info_panel.tree.calls": "Graphique des appels", |
| 113 | 112 | ||
| 114 | "popup.copied": "Copié !", | 113 | "popup.copied": "Copié !", |
| 115 | 114 | ||
| 115 | "structure.options.obfuscation": "Visibilité de l'obfuscation", | ||
| 116 | "structure.options.obfuscation.all": "Tous", | ||
| 117 | "structure.options.obfuscation.obfuscated": "Seulement obfusqués", | ||
| 118 | "structure.options.obfuscation.deobfuscated": "Seulement déobfusqués", | ||
| 119 | "structure.options.documentation": "Visibilité de la documentation", | ||
| 120 | "structure.options.documentation.all": "Tous", | ||
| 121 | "structure.options.documentation.documented": "Seulement documentés", | ||
| 122 | "structure.options.documentation.non_documented": "Seulement non documentés", | ||
| 123 | "structure.options.sorting": "Ordre de tri", | ||
| 124 | "structure.options.sorting.default": "Par défaut", | ||
| 125 | "structure.options.sorting.a_z": "A à Z", | ||
| 126 | "structure.options.sorting.z_a": "Z à A", | ||
| 127 | |||
| 116 | "log_panel.messages": "Messages", | 128 | "log_panel.messages": "Messages", |
| 117 | "log_panel.users": "Utilisateurs", | 129 | "log_panel.users": "Utilisateurs", |
| 118 | 130 | ||
diff --git a/enigma/src/main/resources/lang/ja_jp.json b/enigma/src/main/resources/lang/ja_jp.json index 0ff162a..9399e17 100644 --- a/enigma/src/main/resources/lang/ja_jp.json +++ b/enigma/src/main/resources/lang/ja_jp.json | |||
| @@ -102,7 +102,6 @@ | |||
| 102 | "info_panel.editor.class.decompiling": "(デコンパイル中...)", | 102 | "info_panel.editor.class.decompiling": "(デコンパイル中...)", |
| 103 | "info_panel.editor.class.not_found": "クラスが見つけられません:", | 103 | "info_panel.editor.class.not_found": "クラスが見つけられません:", |
| 104 | "info_panel.tree.structure": "構造", | 104 | "info_panel.tree.structure": "構造", |
| 105 | "info_panel.tree.structure.hide_deobfuscated": "難読化解除されたメンバを隠す", | ||
| 106 | "info_panel.tree.inheritance": "継承", | 105 | "info_panel.tree.inheritance": "継承", |
| 107 | "info_panel.tree.implementations": "実装", | 106 | "info_panel.tree.implementations": "実装", |
| 108 | "info_panel.tree.calls": "呼び出し関係", | 107 | "info_panel.tree.calls": "呼び出し関係", |