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/java/cuchaz | |
| 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/java/cuchaz')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | 54 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeOptions.java | 59 |
2 files changed, 98 insertions, 15 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 | } | ||