diff options
| author | 2019-05-12 11:56:22 +0200 | |
|---|---|---|
| committer | 2019-05-12 11:56:22 +0200 | |
| commit | 8e8609cd032d299f79307cfdd41998d331a876a7 (patch) | |
| tree | 256d31b457e0d4673eae2a582eceb916163d1d25 /src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | |
| parent | Resolve root when navigating to declaration (diff) | |
| download | enigma-fork-8e8609cd032d299f79307cfdd41998d331a876a7.tar.gz enigma-fork-8e8609cd032d299f79307cfdd41998d331a876a7.tar.xz enigma-fork-8e8609cd032d299f79307cfdd41998d331a876a7.zip | |
Simplify Plugin API and support all entry types
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java index 93643ab..1e96a06 100644 --- a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java +++ b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | |||
| @@ -4,18 +4,17 @@ import cuchaz.enigma.Deobfuscator; | |||
| 4 | import cuchaz.enigma.analysis.EntryReference; | 4 | import cuchaz.enigma.analysis.EntryReference; |
| 5 | import cuchaz.enigma.analysis.SourceIndex; | 5 | import cuchaz.enigma.analysis.SourceIndex; |
| 6 | import cuchaz.enigma.analysis.Token; | 6 | import cuchaz.enigma.analysis.Token; |
| 7 | import cuchaz.enigma.api.EnigmaPlugin; | ||
| 8 | import cuchaz.enigma.gui.highlight.TokenHighlightType; | 7 | import cuchaz.enigma.gui.highlight.TokenHighlightType; |
| 9 | import cuchaz.enigma.translation.LocalNameGenerator; | 8 | import cuchaz.enigma.translation.LocalNameGenerator; |
| 10 | import cuchaz.enigma.translation.Translator; | 9 | import cuchaz.enigma.translation.Translator; |
| 11 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 10 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 12 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 11 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 13 | import cuchaz.enigma.translation.representation.entry.Entry; | 12 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 14 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 15 | import cuchaz.enigma.translation.representation.entry.LocalVariableDefEntry; | 13 | import cuchaz.enigma.translation.representation.entry.LocalVariableDefEntry; |
| 16 | 14 | ||
| 17 | import javax.annotation.Nullable; | 15 | import javax.annotation.Nullable; |
| 18 | import java.util.*; | 16 | import java.util.*; |
| 17 | import java.util.stream.Stream; | ||
| 19 | 18 | ||
| 20 | public class DecompiledClassSource { | 19 | public class DecompiledClassSource { |
| 21 | private final ClassEntry classEntry; | 20 | private final ClassEntry classEntry; |
| @@ -55,10 +54,10 @@ public class DecompiledClassSource { | |||
| 55 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); | 54 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); |
| 56 | return translatedEntry.getSourceRemapName(); | 55 | return translatedEntry.getSourceRemapName(); |
| 57 | } else { | 56 | } else { |
| 58 | String proposedName = proposeName(deobfuscator, entry); | 57 | Optional<String> proposedName = proposeName(deobfuscator, entry); |
| 59 | if (proposedName != null) { | 58 | if (proposedName.isPresent()) { |
| 60 | highlightToken(movedToken, TokenHighlightType.PROPOSED); | 59 | highlightToken(movedToken, TokenHighlightType.PROPOSED); |
| 61 | return proposedName; | 60 | return proposedName.get(); |
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | highlightToken(movedToken, TokenHighlightType.OBFUSCATED); | 63 | highlightToken(movedToken, TokenHighlightType.OBFUSCATED); |
| @@ -73,18 +72,13 @@ public class DecompiledClassSource { | |||
| 73 | return null; | 72 | return null; |
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | @Nullable | 75 | private Optional<String> proposeName(Deobfuscator deobfuscator, Entry<?> entry) { |
| 77 | private String proposeName(Deobfuscator deobfuscator, Entry<?> entry) { | 76 | Stream<String> proposals = deobfuscator.getPlugins() |
| 78 | if (entry instanceof FieldEntry) { | 77 | .map(plugin -> plugin.proposeName(entry, deobfuscator.getMapper())) |
| 79 | for (EnigmaPlugin plugin : deobfuscator.getPlugins()) { | 78 | .filter(Optional::isPresent) |
| 80 | String owner = entry.getContainingClass().getFullName(); | 79 | .map(Optional::get); |
| 81 | String proposal = plugin.proposeFieldName(owner, entry.getName(), ((FieldEntry) entry).getDesc().toString()); | 80 | |
| 82 | if (proposal != null) { | 81 | return proposals.findFirst(); |
| 83 | return proposal; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | return null; | ||
| 88 | } | 82 | } |
| 89 | 83 | ||
| 90 | @Nullable | 84 | @Nullable |