diff options
| author | 2020-12-15 23:28:05 +0200 | |
|---|---|---|
| committer | 2021-01-23 16:27:09 +0200 | |
| commit | 68aaf143193201ecf71ced2ae6cd9eca7a0225a1 (patch) | |
| tree | 933f16082dee32d3bc3fbd4ba02d83d8b8d2cbac /enigma/src/main/java/cuchaz | |
| parent | Attempt fixing rare CME when loading a jar while tabs are open (diff) | |
| download | enigma-fork-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.tar.gz enigma-fork-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.tar.xz enigma-fork-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.zip | |
Add interface/enum/annotation icons and modifier displays
- Adds icons in the sidebar and structure panel for interfaces, enums
and annotations.
- Adds some modifiers (final, default, abstract, static) to the
structure panel.
Diffstat (limited to 'enigma/src/main/java/cuchaz')
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | 33 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java | 8 |
2 files changed, 41 insertions, 0 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java index f310aa7..ac3a381 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | |||
| @@ -4,10 +4,12 @@ import cuchaz.enigma.EnigmaProject; | |||
| 4 | import cuchaz.enigma.api.service.NameProposalService; | 4 | import cuchaz.enigma.api.service.NameProposalService; |
| 5 | import cuchaz.enigma.translation.TranslateResult; | 5 | import cuchaz.enigma.translation.TranslateResult; |
| 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 7 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 7 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 8 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 8 | import cuchaz.enigma.translation.representation.entry.*; | 9 | import cuchaz.enigma.translation.representation.entry.*; |
| 9 | 10 | ||
| 10 | import javax.swing.tree.DefaultMutableTreeNode; | 11 | import javax.swing.tree.DefaultMutableTreeNode; |
| 12 | import java.util.ArrayList; | ||
| 11 | import java.util.List; | 13 | import java.util.List; |
| 12 | 14 | ||
| 13 | public class StructureTreeNode extends DefaultMutableTreeNode { | 15 | public class StructureTreeNode extends DefaultMutableTreeNode { |
| @@ -90,6 +92,37 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 90 | return result; | 92 | return result; |
| 91 | } | 93 | } |
| 92 | 94 | ||
| 95 | public String toHtml() { | ||
| 96 | List<String> modifiers = new ArrayList<>(); | ||
| 97 | |||
| 98 | if (this.entry instanceof DefEntry<?>) { | ||
| 99 | AccessFlags access = ((DefEntry<?>) this.entry).getAccess(); | ||
| 100 | boolean isInterfaceMethod = false; | ||
| 101 | |||
| 102 | if (this.entry instanceof MethodEntry && this.entry.getParent() instanceof ClassDefEntry) { | ||
| 103 | isInterfaceMethod = ((ClassDefEntry) this.entry.getParent()).getAccess().isInterface(); | ||
| 104 | } | ||
| 105 | |||
| 106 | if (access.isStatic() && !access.isEnum()) { | ||
| 107 | // Static member, but not an enum constant | ||
| 108 | modifiers.add("static"); | ||
| 109 | } else if (isInterfaceMethod && !access.isAbstract()) { | ||
| 110 | // Non-static default interface method | ||
| 111 | modifiers.add("default"); | ||
| 112 | } | ||
| 113 | |||
| 114 | if (access.isAbstract() && !access.isInterface() && !isInterfaceMethod) { | ||
| 115 | // Abstract, but not an interface or an interface method (they're always abstract) | ||
| 116 | modifiers.add("abstract"); | ||
| 117 | } else if (access.isFinal() && !access.isEnum()) { | ||
| 118 | // Final, but not an enum or an enum constant (they're always final) | ||
| 119 | modifiers.add("final"); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | return "<i>" + String.join(" ", modifiers) + "</i> " + toString(); | ||
| 124 | } | ||
| 125 | |||
| 93 | private String parseArgs(List<TypeDescriptor> args) { | 126 | private String parseArgs(List<TypeDescriptor> args) { |
| 94 | if (args.size() > 0) { | 127 | if (args.size() > 0) { |
| 95 | String result = "("; | 128 | String result = "("; |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java index b280eef..e8480a2 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java | |||
| @@ -51,6 +51,14 @@ public class AccessFlags { | |||
| 51 | return (flags & Opcodes.ACC_INTERFACE) != 0; | 51 | return (flags & Opcodes.ACC_INTERFACE) != 0; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | public boolean isAbstract() { | ||
| 55 | return (flags & Opcodes.ACC_ABSTRACT) != 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | public boolean isAnnotation() { | ||
| 59 | return (flags & Opcodes.ACC_ANNOTATION) != 0; | ||
| 60 | } | ||
| 61 | |||
| 54 | public AccessFlags setPrivate() { | 62 | public AccessFlags setPrivate() { |
| 55 | this.setVisibility(Opcodes.ACC_PRIVATE); | 63 | this.setVisibility(Opcodes.ACC_PRIVATE); |
| 56 | return this; | 64 | return this; |