diff options
| author | 2020-12-15 21:22:55 +0100 | |
|---|---|---|
| committer | 2020-12-15 21:22:55 +0100 | |
| commit | 12f270c80570b136add40dc259c25383ac36bf81 (patch) | |
| tree | ce73c02ba96dcc39c550f900988afed629c5256c /enigma-swing/src/main/java/cuchaz | |
| parent | minor bump (diff) | |
| download | enigma-fork-12f270c80570b136add40dc259c25383ac36bf81.tar.gz enigma-fork-12f270c80570b136add40dc259c25383ac36bf81.tar.xz enigma-fork-12f270c80570b136add40dc259c25383ac36bf81.zip | |
avoid duplicate logic
Diffstat (limited to 'enigma-swing/src/main/java/cuchaz')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java | 43 |
1 files changed, 6 insertions, 37 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java index b898eac..20d6a0e 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java | |||
| @@ -3,8 +3,6 @@ package cuchaz.enigma.gui.stats; | |||
| 3 | import cuchaz.enigma.EnigmaProject; | 3 | import cuchaz.enigma.EnigmaProject; |
| 4 | import cuchaz.enigma.ProgressListener; | 4 | import cuchaz.enigma.ProgressListener; |
| 5 | import cuchaz.enigma.analysis.index.EntryIndex; | 5 | import cuchaz.enigma.analysis.index.EntryIndex; |
| 6 | import cuchaz.enigma.api.service.NameProposalService; | ||
| 7 | import cuchaz.enigma.api.service.ObfuscationTestService; | ||
| 8 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 9 | import cuchaz.enigma.translation.mapping.EntryResolver; | 7 | import cuchaz.enigma.translation.mapping.EntryResolver; |
| 10 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | 8 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; |
| @@ -15,18 +13,16 @@ import cuchaz.enigma.utils.I18n; | |||
| 15 | import java.util.*; | 13 | import java.util.*; |
| 16 | 14 | ||
| 17 | public class StatsGenerator { | 15 | public class StatsGenerator { |
| 16 | private final EnigmaProject project; | ||
| 18 | private final EntryIndex entryIndex; | 17 | private final EntryIndex entryIndex; |
| 19 | private final EntryRemapper mapper; | 18 | private final EntryRemapper mapper; |
| 20 | private final EntryResolver entryResolver; | 19 | private final EntryResolver entryResolver; |
| 21 | private final List<ObfuscationTestService> obfuscationTestServices; | ||
| 22 | private final List<NameProposalService> nameProposalServices; | ||
| 23 | 20 | ||
| 24 | public StatsGenerator(EnigmaProject project) { | 21 | public StatsGenerator(EnigmaProject project) { |
| 25 | entryIndex = project.getJarIndex().getEntryIndex(); | 22 | this.project = project; |
| 26 | mapper = project.getMapper(); | 23 | this.entryIndex = project.getJarIndex().getEntryIndex(); |
| 27 | entryResolver = project.getJarIndex().getEntryResolver(); | 24 | this.mapper = project.getMapper(); |
| 28 | obfuscationTestServices = project.getEnigma().getServices().get(ObfuscationTestService.TYPE); | 25 | this.entryResolver = project.getJarIndex().getEntryResolver(); |
| 29 | nameProposalServices = project.getEnigma().getServices().get(NameProposalService.TYPE); | ||
| 30 | } | 26 | } |
| 31 | 27 | ||
| 32 | public StatsResult generate(ProgressListener progress, Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { | 28 | public StatsResult generate(ProgressListener progress, Set<StatsMember> includedMembers, String topLevelPackage, boolean includeSynthetic) { |
| @@ -111,36 +107,9 @@ public class StatsGenerator { | |||
| 111 | } | 107 | } |
| 112 | 108 | ||
| 113 | private void update(Map<String, Integer> counts, Entry<?> entry) { | 109 | private void update(Map<String, Integer> counts, Entry<?> entry) { |
| 114 | if (isObfuscated(entry)) { | 110 | if (project.isObfuscated(entry)) { |
| 115 | String parent = mapper.deobfuscate(entry.getAncestry().get(0)).getName().replace('/', '.'); | 111 | String parent = mapper.deobfuscate(entry.getAncestry().get(0)).getName().replace('/', '.'); |
| 116 | counts.put(parent, counts.getOrDefault(parent, 0) + 1); | 112 | counts.put(parent, counts.getOrDefault(parent, 0) + 1); |
| 117 | } | 113 | } |
| 118 | } | 114 | } |
| 119 | |||
| 120 | private boolean isObfuscated(Entry<?> entry) { | ||
| 121 | String name = entry.getName(); | ||
| 122 | |||
| 123 | if (!obfuscationTestServices.isEmpty()) { | ||
| 124 | for (ObfuscationTestService service : obfuscationTestServices) { | ||
| 125 | if (service.testDeobfuscated(entry)) { | ||
| 126 | return false; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!nameProposalServices.isEmpty()) { | ||
| 132 | for (NameProposalService service : nameProposalServices) { | ||
| 133 | if (service.proposeName(entry, mapper).isPresent()) { | ||
| 134 | return false; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | String mappedName = mapper.deobfuscate(entry).getName(); | ||
| 140 | if (mappedName != null && !mappedName.isEmpty() && !mappedName.equals(name)) { | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | |||
| 144 | return true; | ||
| 145 | } | ||
| 146 | } | 115 | } |