diff options
43 files changed, 141 insertions, 233 deletions
diff --git a/enigma-server/src/main/java/cuchaz/enigma/network/packet/ChangeDocsC2SPacket.java b/enigma-server/src/main/java/cuchaz/enigma/network/packet/ChangeDocsC2SPacket.java index 23ffe993..f3e07c2d 100644 --- a/enigma-server/src/main/java/cuchaz/enigma/network/packet/ChangeDocsC2SPacket.java +++ b/enigma-server/src/main/java/cuchaz/enigma/network/packet/ChangeDocsC2SPacket.java | |||
| @@ -9,7 +9,6 @@ import cuchaz.enigma.network.EnigmaServer; | |||
| 9 | import cuchaz.enigma.network.Message; | 9 | import cuchaz.enigma.network.Message; |
| 10 | import cuchaz.enigma.network.ServerPacketHandler; | 10 | import cuchaz.enigma.network.ServerPacketHandler; |
| 11 | import cuchaz.enigma.translation.representation.entry.Entry; | 11 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 12 | import cuchaz.enigma.utils.Utils; | ||
| 13 | import cuchaz.enigma.utils.validation.PrintValidatable; | 12 | import cuchaz.enigma.utils.validation.PrintValidatable; |
| 14 | import cuchaz.enigma.utils.validation.ValidationContext; | 13 | import cuchaz.enigma.utils.validation.ValidationContext; |
| 15 | 14 | ||
| @@ -54,7 +53,7 @@ public class ChangeDocsC2SPacket implements Packet<ServerPacketHandler> { | |||
| 54 | if (mapping == null) { | 53 | if (mapping == null) { |
| 55 | mapping = new EntryMapping(handler.getServer().getMappings().deobfuscate(entry).getName()); | 54 | mapping = new EntryMapping(handler.getServer().getMappings().deobfuscate(entry).getName()); |
| 56 | } | 55 | } |
| 57 | handler.getServer().getMappings().mapFromObf(vc, entry, mapping.withDocs(Utils.isBlank(newDocs) ? null : newDocs)); | 56 | handler.getServer().getMappings().mapFromObf(vc, entry, mapping.withDocs(newDocs.isBlank() ? null : newDocs)); |
| 58 | 57 | ||
| 59 | if (!vc.canProceed()) return; | 58 | if (!vc.canProceed()) return; |
| 60 | 59 | ||
diff --git a/enigma-server/src/main/java/cuchaz/enigma/network/packet/SyncMappingsS2CPacket.java b/enigma-server/src/main/java/cuchaz/enigma/network/packet/SyncMappingsS2CPacket.java index 76ecbc7d..92a78748 100644 --- a/enigma-server/src/main/java/cuchaz/enigma/network/packet/SyncMappingsS2CPacket.java +++ b/enigma-server/src/main/java/cuchaz/enigma/network/packet/SyncMappingsS2CPacket.java | |||
| @@ -13,7 +13,6 @@ import java.io.DataOutput; | |||
| 13 | import java.io.IOException; | 13 | import java.io.IOException; |
| 14 | import java.util.Collection; | 14 | import java.util.Collection; |
| 15 | import java.util.List; | 15 | import java.util.List; |
| 16 | import java.util.stream.Collectors; | ||
| 17 | 16 | ||
| 18 | public class SyncMappingsS2CPacket implements Packet<ClientPacketHandler> { | 17 | public class SyncMappingsS2CPacket implements Packet<ClientPacketHandler> { |
| 19 | private EntryTree<EntryMapping> mappings; | 18 | private EntryTree<EntryMapping> mappings; |
| @@ -55,7 +54,7 @@ public class SyncMappingsS2CPacket implements Packet<ClientPacketHandler> { | |||
| 55 | 54 | ||
| 56 | @Override | 55 | @Override |
| 57 | public void write(DataOutput output) throws IOException { | 56 | public void write(DataOutput output) throws IOException { |
| 58 | List<EntryTreeNode<EntryMapping>> roots = mappings.getRootNodes().collect(Collectors.toList()); | 57 | List<EntryTreeNode<EntryMapping>> roots = mappings.getRootNodes().toList(); |
| 59 | output.writeInt(roots.size()); | 58 | output.writeInt(roots.size()); |
| 60 | for (EntryTreeNode<EntryMapping> node : roots) { | 59 | for (EntryTreeNode<EntryMapping> node : roots) { |
| 61 | writeEntryTreeNode(output, node); | 60 | writeEntryTreeNode(output, node); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java index 91c9705b..7044106b 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java | |||
| @@ -63,8 +63,7 @@ public class ClassSelector extends JTree { | |||
| 63 | if (selectionListener != null && event.getClickCount() == 2) { | 63 | if (selectionListener != null && event.getClickCount() == 2) { |
| 64 | // get the selected node | 64 | // get the selected node |
| 65 | TreePath path = getSelectionPath(); | 65 | TreePath path = getSelectionPath(); |
| 66 | if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { | 66 | if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode node) { |
| 67 | ClassSelectorClassNode node = (ClassSelectorClassNode) path.getLastPathComponent(); | ||
| 68 | selectionListener.onSelectClass(node.getObfEntry()); | 67 | selectionListener.onSelectClass(node.getObfEntry()); |
| 69 | } | 68 | } |
| 70 | } | 69 | } |
| @@ -105,8 +104,7 @@ public class ClassSelector extends JTree { | |||
| 105 | TreePath path = getSelectionPath(); | 104 | TreePath path = getSelectionPath(); |
| 106 | 105 | ||
| 107 | Object realPath = path.getLastPathComponent(); | 106 | Object realPath = path.getLastPathComponent(); |
| 108 | if (realPath != null && realPath instanceof DefaultMutableTreeNode && data != null) { | 107 | if (realPath instanceof DefaultMutableTreeNode node && data != null) { |
| 109 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) realPath; | ||
| 110 | TreeNode parentNode = node.getParent(); | 108 | TreeNode parentNode = node.getParent(); |
| 111 | if (parentNode == null) | 109 | if (parentNode == null) |
| 112 | return; | 110 | return; |
| @@ -251,8 +249,7 @@ public class ClassSelector extends JTree { | |||
| 251 | public ClassEntry getSelectedClass() { | 249 | public ClassEntry getSelectedClass() { |
| 252 | if (!isSelectionEmpty()) { | 250 | if (!isSelectionEmpty()) { |
| 253 | Object selectedNode = getSelectionPath().getLastPathComponent(); | 251 | Object selectedNode = getSelectionPath().getLastPathComponent(); |
| 254 | if (selectedNode instanceof ClassSelectorClassNode) { | 252 | if (selectedNode instanceof ClassSelectorClassNode classNode) { |
| 255 | ClassSelectorClassNode classNode = (ClassSelectorClassNode) selectedNode; | ||
| 256 | return classNode.getClassEntry(); | 253 | return classNode.getClassEntry(); |
| 257 | } | 254 | } |
| 258 | } | 255 | } |
| @@ -262,11 +259,9 @@ public class ClassSelector extends JTree { | |||
| 262 | public String getSelectedPackage() { | 259 | public String getSelectedPackage() { |
| 263 | if (!isSelectionEmpty()) { | 260 | if (!isSelectionEmpty()) { |
| 264 | Object selectedNode = getSelectionPath().getLastPathComponent(); | 261 | Object selectedNode = getSelectionPath().getLastPathComponent(); |
| 265 | if (selectedNode instanceof ClassSelectorPackageNode) { | 262 | if (selectedNode instanceof ClassSelectorPackageNode packageNode) { |
| 266 | ClassSelectorPackageNode packageNode = (ClassSelectorPackageNode) selectedNode; | ||
| 267 | return packageNode.getPackageName(); | 263 | return packageNode.getPackageName(); |
| 268 | } else if (selectedNode instanceof ClassSelectorClassNode) { | 264 | } else if (selectedNode instanceof ClassSelectorClassNode classNode) { |
| 269 | ClassSelectorClassNode classNode = (ClassSelectorClassNode) selectedNode; | ||
| 270 | return classNode.getClassEntry().getPackageName(); | 265 | return classNode.getClassEntry().getPackageName(); |
| 271 | } | 266 | } |
| 272 | } | 267 | } |
| @@ -321,12 +316,8 @@ public class ClassSelector extends JTree { | |||
| 321 | 316 | ||
| 322 | for (StateEntry entry : expansionState) { | 317 | for (StateEntry entry : expansionState) { |
| 323 | switch (entry.state) { | 318 | switch (entry.state) { |
| 324 | case SELECTED: | 319 | case SELECTED -> tree.addSelectionPath(entry.path); |
| 325 | tree.addSelectionPath(entry.path); | 320 | case EXPANDED -> tree.expandPath(entry.path); |
| 326 | break; | ||
| 327 | case EXPANDED: | ||
| 328 | tree.expandPath(entry.path); | ||
| 329 | break; | ||
| 330 | } | 321 | } |
| 331 | } | 322 | } |
| 332 | } | 323 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index aaa04460..8d4fb5be 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -216,11 +216,9 @@ public class Gui implements LanguageChangeListener { | |||
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | Object node = path.getLastPathComponent(); | 218 | Object node = path.getLastPathComponent(); |
| 219 | if (node instanceof ClassImplementationsTreeNode) { | 219 | if (node instanceof ClassImplementationsTreeNode classNode) { |
| 220 | ClassImplementationsTreeNode classNode = (ClassImplementationsTreeNode) node; | ||
| 221 | controller.navigateTo(classNode.getClassEntry()); | 220 | controller.navigateTo(classNode.getClassEntry()); |
| 222 | } else if (node instanceof MethodImplementationsTreeNode) { | 221 | } else if (node instanceof MethodImplementationsTreeNode methodNode) { |
| 223 | MethodImplementationsTreeNode methodNode = (MethodImplementationsTreeNode) node; | ||
| 224 | controller.navigateTo(methodNode.getMethodEntry()); | 222 | controller.navigateTo(methodNode.getMethodEntry()); |
| 225 | } | 223 | } |
| 226 | } | 224 | } |
| @@ -248,8 +246,7 @@ public class Gui implements LanguageChangeListener { | |||
| 248 | } | 246 | } |
| 249 | 247 | ||
| 250 | Object node = path.getLastPathComponent(); | 248 | Object node = path.getLastPathComponent(); |
| 251 | if (node instanceof ReferenceTreeNode) { | 249 | if (node instanceof ReferenceTreeNode referenceNode) { |
| 252 | ReferenceTreeNode<Entry<?>, Entry<?>> referenceNode = ((ReferenceTreeNode<Entry<?>, Entry<?>>) node); | ||
| 253 | if (referenceNode.getReference() != null) { | 250 | if (referenceNode.getReference() != null) { |
| 254 | controller.navigateTo(referenceNode.getReference()); | 251 | controller.navigateTo(referenceNode.getReference()); |
| 255 | } else { | 252 | } else { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index f990f98c..aeee242f 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -21,7 +21,6 @@ import java.util.List; | |||
| 21 | import java.util.Set; | 21 | import java.util.Set; |
| 22 | import java.util.concurrent.CompletableFuture; | 22 | import java.util.concurrent.CompletableFuture; |
| 23 | import java.util.concurrent.ExecutionException; | 23 | import java.util.concurrent.ExecutionException; |
| 24 | import java.util.stream.Collectors; | ||
| 25 | import java.util.stream.Stream; | 24 | import java.util.stream.Stream; |
| 26 | 25 | ||
| 27 | import javax.swing.JOptionPane; | 26 | import javax.swing.JOptionPane; |
| @@ -311,7 +310,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 311 | return mapper.getObfResolver().resolveReference(reference, ResolutionStrategy.RESOLVE_CLOSEST) | 310 | return mapper.getObfResolver().resolveReference(reference, ResolutionStrategy.RESOLVE_CLOSEST) |
| 312 | .stream() | 311 | .stream() |
| 313 | .flatMap(r -> index.getReferenceTokens(r).stream()) | 312 | .flatMap(r -> index.getReferenceTokens(r).stream()) |
| 314 | .collect(Collectors.toList()); | 313 | .toList(); |
| 315 | } | 314 | } |
| 316 | 315 | ||
| 317 | public void openPreviousReference() { | 316 | public void openPreviousReference() { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java index ab9fa2a0..cec3fa1e 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java | |||
| @@ -40,20 +40,11 @@ public enum LookAndFeel { | |||
| 40 | 40 | ||
| 41 | try { | 41 | try { |
| 42 | switch (this) { | 42 | switch (this) { |
| 43 | case NONE: | 43 | case NONE -> UIManager.setLookAndFeel(NONE_LAF); |
| 44 | UIManager.setLookAndFeel(NONE_LAF); | 44 | case DEFAULT -> UIManager.setLookAndFeel(new FlatLightLaf()); |
| 45 | break; | 45 | case METAL -> UIManager.setLookAndFeel(new MetalLookAndFeel()); |
| 46 | case DEFAULT: | 46 | case DARCULA -> UIManager.setLookAndFeel(new FlatDarkLaf()); |
| 47 | UIManager.setLookAndFeel(new FlatLightLaf()); | 47 | case SYSTEM -> UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 48 | break; | ||
| 49 | case METAL: | ||
| 50 | UIManager.setLookAndFeel(new MetalLookAndFeel()); | ||
| 51 | break; | ||
| 52 | case DARCULA: | ||
| 53 | UIManager.setLookAndFeel(new FlatDarkLaf()); | ||
| 54 | break; | ||
| 55 | case SYSTEM: | ||
| 56 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
| 57 | } | 48 | } |
| 58 | } catch (Exception e) { | 49 | } catch (Exception e) { |
| 59 | throw new Error("Failed to set global look and feel", e); | 50 | throw new Error("Failed to set global look and feel", e); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java index 1db8aea2..4e02a666 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | package cuchaz.enigma.gui.dialog; | 1 | package cuchaz.enigma.gui.dialog; |
| 2 | 2 | ||
| 3 | import java.awt.*; | 3 | import java.awt.*; |
| 4 | import java.util.Arrays; | ||
| 5 | import java.util.List; | 4 | import java.util.List; |
| 6 | 5 | ||
| 7 | import javax.swing.JButton; | 6 | import javax.swing.JButton; |
| @@ -18,14 +17,14 @@ import cuchaz.enigma.utils.I18n; | |||
| 18 | 17 | ||
| 19 | public class FontDialog extends JDialog { | 18 | public class FontDialog extends JDialog { |
| 20 | 19 | ||
| 21 | private static final List<String> CATEGORIES = Arrays.asList( | 20 | private static final List<String> CATEGORIES = List.of( |
| 22 | "Default", | 21 | "Default", |
| 23 | "Default 2", | 22 | "Default 2", |
| 24 | "Small", | 23 | "Small", |
| 25 | "Editor" | 24 | "Editor" |
| 26 | ); | 25 | ); |
| 27 | 26 | ||
| 28 | private static final List<String> CATEGORY_TEXTS = Arrays.asList( | 27 | private static final List<String> CATEGORY_TEXTS = List.of( |
| 29 | "fonts.cat.default", | 28 | "fonts.cat.default", |
| 30 | "fonts.cat.default2", | 29 | "fonts.cat.default2", |
| 31 | "fonts.cat.small", | 30 | "fonts.cat.small", |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java index 7110fc86..5f6dbdb5 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/ProgressDialog.java | |||
| @@ -93,13 +93,10 @@ public class ProgressDialog implements ProgressListener, AutoCloseable { | |||
| 93 | 93 | ||
| 94 | return progress; | 94 | return progress; |
| 95 | }, SwingUtilities::invokeLater).thenAcceptAsync(progress -> { | 95 | }, SwingUtilities::invokeLater).thenAcceptAsync(progress -> { |
| 96 | // TODO use "try (progress)" with Java 9 | 96 | try (progress) { |
| 97 | try { | ||
| 98 | runnable.run(progress); | 97 | runnable.run(progress); |
| 99 | } catch (Exception e) { | 98 | } catch (Exception e) { |
| 100 | throw new RuntimeException(e); | 99 | throw new RuntimeException(e); |
| 101 | } finally { | ||
| 102 | progress.close(); | ||
| 103 | } | 100 | } |
| 104 | }); | 101 | }); |
| 105 | } | 102 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java index 9ed7339c..053adad8 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java | |||
| @@ -142,30 +142,23 @@ public class SearchDialog { | |||
| 142 | final EntryIndex entryIndex = parent.getController().project.getJarIndex().getEntryIndex(); | 142 | final EntryIndex entryIndex = parent.getController().project.getJarIndex().getEntryIndex(); |
| 143 | 143 | ||
| 144 | switch (type) { | 144 | switch (type) { |
| 145 | default: | 145 | case CLASS -> entryIndex.getClasses().parallelStream() |
| 146 | case CLASS: | 146 | .filter(e -> !e.isInnerClass()) |
| 147 | entryIndex.getClasses().parallelStream() | 147 | .map(e -> SearchEntryImpl.from(e, parent.getController())) |
| 148 | .filter(e -> !e.isInnerClass()) | 148 | .map(SearchUtil.Entry::from) |
| 149 | .map(e -> SearchEntryImpl.from(e, parent.getController())) | 149 | .sequential() |
| 150 | .map(SearchUtil.Entry::from) | 150 | .forEach(su::add); |
| 151 | .sequential() | 151 | case METHOD -> entryIndex.getMethods().parallelStream() |
| 152 | .forEach(su::add); | 152 | .filter(e -> !e.isConstructor() && !entryIndex.getMethodAccess(e).isSynthetic()) |
| 153 | break; | 153 | .map(e -> SearchEntryImpl.from(e, parent.getController())) |
| 154 | case METHOD: | 154 | .map(SearchUtil.Entry::from) |
| 155 | entryIndex.getMethods().parallelStream() | 155 | .sequential() |
| 156 | .filter(e -> !e.isConstructor() && !entryIndex.getMethodAccess(e).isSynthetic()) | 156 | .forEach(su::add); |
| 157 | .map(e -> SearchEntryImpl.from(e, parent.getController())) | 157 | case FIELD -> entryIndex.getFields().parallelStream() |
| 158 | .map(SearchUtil.Entry::from) | 158 | .map(e -> SearchEntryImpl.from(e, parent.getController())) |
| 159 | .sequential() | 159 | .map(SearchUtil.Entry::from) |
| 160 | .forEach(su::add); | 160 | .sequential() |
| 161 | break; | 161 | .forEach(su::add); |
| 162 | case FIELD: | ||
| 163 | entryIndex.getFields().parallelStream() | ||
| 164 | .map(e -> SearchEntryImpl.from(e, parent.getController())) | ||
| 165 | .map(SearchUtil.Entry::from) | ||
| 166 | .sequential() | ||
| 167 | .forEach(su::add); | ||
| 168 | break; | ||
| 169 | } | 162 | } |
| 170 | 163 | ||
| 171 | updateList(); | 164 | updateList(); |
| @@ -290,10 +283,10 @@ public class SearchDialog { | |||
| 290 | secondaryName.setToolTipText(value.obf.getFullName()); | 283 | secondaryName.setToolTipText(value.obf.getFullName()); |
| 291 | } | 284 | } |
| 292 | 285 | ||
| 293 | if (value.obf instanceof ClassEntry) { | 286 | if (value.obf instanceof ClassEntry classEntry) { |
| 294 | mainName.setIcon(GuiUtil.getClassIcon(gui, (ClassEntry) value.obf)); | 287 | mainName.setIcon(GuiUtil.getClassIcon(gui, classEntry)); |
| 295 | } else if (value.obf instanceof MethodEntry) { | 288 | } else if (value.obf instanceof MethodEntry methodEntry) { |
| 296 | mainName.setIcon(GuiUtil.getMethodIcon((MethodEntry) value.obf)); | 289 | mainName.setIcon(GuiUtil.getMethodIcon(methodEntry)); |
| 297 | } else if (value.obf instanceof FieldEntry) { | 290 | } else if (value.obf instanceof FieldEntry) { |
| 298 | mainName.setIcon(GuiUtil.FIELD_ICON); | 291 | mainName.setIcon(GuiUtil.FIELD_ICON); |
| 299 | } | 292 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java index 8f020b8a..f6564f59 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/EditorPanel.java | |||
| @@ -305,17 +305,10 @@ public class EditorPanel { | |||
| 305 | 305 | ||
| 306 | public void displayError(ClassHandleError t) { | 306 | public void displayError(ClassHandleError t) { |
| 307 | this.setDisplayMode(DisplayMode.ERRORED); | 307 | this.setDisplayMode(DisplayMode.ERRORED); |
| 308 | String str; | 308 | String str = switch (t.type) { |
| 309 | switch (t.type) { | 309 | case DECOMPILE -> "editor.decompile_error"; |
| 310 | case DECOMPILE: | 310 | case REMAP -> "editor.remap_error"; |
| 311 | str = "editor.decompile_error"; | 311 | }; |
| 312 | break; | ||
| 313 | case REMAP: | ||
| 314 | str = "editor.remap_error"; | ||
| 315 | break; | ||
| 316 | default: | ||
| 317 | throw new IllegalStateException("unreachable"); | ||
| 318 | } | ||
| 319 | this.errorLabel.setText(I18n.translate(str)); | 312 | this.errorLabel.setText(I18n.translate(str)); |
| 320 | this.errorTextArea.setText(t.getStackTrace()); | 313 | this.errorTextArea.setText(t.getStackTrace()); |
| 321 | this.errorTextArea.setCaretPosition(0); | 314 | this.errorTextArea.setCaretPosition(0); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java index d8c46614..d6f7e5a7 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java | |||
| @@ -89,10 +89,10 @@ public class StructurePanel extends JPanel { | |||
| 89 | Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); | 89 | Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); |
| 90 | ParentedEntry<?> entry = ((StructureTreeNode) value).getEntry(); | 90 | ParentedEntry<?> entry = ((StructureTreeNode) value).getEntry(); |
| 91 | 91 | ||
| 92 | if (entry instanceof ClassEntry) { | 92 | if (entry instanceof ClassEntry classEntry) { |
| 93 | this.setIcon(GuiUtil.getClassIcon(gui, (ClassEntry) entry)); | 93 | this.setIcon(GuiUtil.getClassIcon(gui, classEntry)); |
| 94 | } else if (entry instanceof MethodEntry) { | 94 | } else if (entry instanceof MethodEntry methodEntry) { |
| 95 | this.setIcon(GuiUtil.getMethodIcon((MethodEntry) entry)); | 95 | this.setIcon(GuiUtil.getMethodIcon(methodEntry)); |
| 96 | } else if (entry instanceof FieldEntry) { | 96 | } else if (entry instanceof FieldEntry) { |
| 97 | this.setIcon(GuiUtil.FIELD_ICON); | 97 | this.setIcon(GuiUtil.FIELD_ICON); |
| 98 | } | 98 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/CallsTreeCellRenderer.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/CallsTreeCellRenderer.java index d5cfdab8..0aa6510c 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/CallsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/CallsTreeCellRenderer.java | |||
| @@ -31,10 +31,10 @@ public class CallsTreeCellRenderer extends DefaultTreeCellRenderer { | |||
| 31 | } | 31 | } |
| 32 | // if the node represents the called entry | 32 | // if the node represents the called entry |
| 33 | } else { | 33 | } else { |
| 34 | if (value instanceof ClassReferenceTreeNode) { | 34 | if (value instanceof ClassReferenceTreeNode node) { |
| 35 | this.setIcon(GuiUtil.getClassIcon(this.gui, ((ClassReferenceTreeNode) value).getEntry())); | 35 | this.setIcon(GuiUtil.getClassIcon(this.gui, node.getEntry())); |
| 36 | } else if (value instanceof MethodReferenceTreeNode) { | 36 | } else if (value instanceof MethodReferenceTreeNode node) { |
| 37 | this.setIcon(GuiUtil.getMethodIcon(((MethodReferenceTreeNode) value).getEntry())); | 37 | this.setIcon(GuiUtil.getMethodIcon(node.getEntry())); |
| 38 | } else if (value instanceof FieldReferenceTreeNode) { | 38 | } else if (value instanceof FieldReferenceTreeNode) { |
| 39 | this.setIcon(GuiUtil.FIELD_ICON); | 39 | this.setIcon(GuiUtil.FIELD_ICON); |
| 40 | } | 40 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java index 2eb7efc4..7bf39005 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java | |||
| @@ -23,10 +23,10 @@ public class ImplementationsTreeCellRenderer extends DefaultTreeCellRenderer { | |||
| 23 | 23 | ||
| 24 | this.setForeground(UiConfig.getTextColor()); | 24 | this.setForeground(UiConfig.getTextColor()); |
| 25 | 25 | ||
| 26 | if (value instanceof ClassImplementationsTreeNode) { | 26 | if (value instanceof ClassImplementationsTreeNode node) { |
| 27 | this.setIcon(GuiUtil.getClassIcon(this.gui, ((ClassImplementationsTreeNode) value).getClassEntry())); | 27 | this.setIcon(GuiUtil.getClassIcon(this.gui, node.getClassEntry())); |
| 28 | } else if (value instanceof MethodImplementationsTreeNode) { | 28 | } else if (value instanceof MethodImplementationsTreeNode node) { |
| 29 | this.setIcon(GuiUtil.getMethodIcon(((MethodImplementationsTreeNode) value).getMethodEntry())); | 29 | this.setIcon(GuiUtil.getMethodIcon(node.getMethodEntry())); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | return c; | 32 | return c; |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/InheritanceTreeCellRenderer.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/InheritanceTreeCellRenderer.java index e377b9a3..a1025531 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/InheritanceTreeCellRenderer.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/InheritanceTreeCellRenderer.java | |||
| @@ -34,7 +34,7 @@ public class InheritanceTreeCellRenderer extends DefaultTreeCellRenderer { | |||
| 34 | public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { | 34 | public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
| 35 | Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); | 35 | Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); |
| 36 | 36 | ||
| 37 | if (!(value instanceof MethodInheritanceTreeNode) || ((MethodInheritanceTreeNode) value).isImplemented()) { | 37 | if (!(value instanceof MethodInheritanceTreeNode node) || node.isImplemented()) { |
| 38 | ret.setForeground(UiConfig.getTextColor()); | 38 | ret.setForeground(UiConfig.getTextColor()); |
| 39 | ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); | 39 | ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); |
| 40 | if (value instanceof ClassInheritanceTreeNode) { | 40 | if (value instanceof ClassInheritanceTreeNode) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index a9e022fa..4f50f2ff 100644 --- a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java +++ b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java | |||
| @@ -120,11 +120,11 @@ public class EnigmaProject { | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | public boolean isRenamable(Entry<?> obfEntry) { | 122 | public boolean isRenamable(Entry<?> obfEntry) { |
| 123 | if (obfEntry instanceof MethodEntry) { | 123 | if (obfEntry instanceof MethodEntry obfMethodEntry) { |
| 124 | // HACKHACK: Object methods are not obfuscated identifiers | 124 | // HACKHACK: Object methods are not obfuscated identifiers |
| 125 | MethodEntry obfMethodEntry = (MethodEntry) obfEntry; | ||
| 126 | String name = obfMethodEntry.getName(); | 125 | String name = obfMethodEntry.getName(); |
| 127 | String sig = obfMethodEntry.getDesc().toString(); | 126 | String sig = obfMethodEntry.getDesc().toString(); |
| 127 | //TODO replace with a map or check if declaring class is java.lang.Object | ||
| 128 | if (name.equals("clone") && sig.equals("()Ljava/lang/Object;")) { | 128 | if (name.equals("clone") && sig.equals("()Ljava/lang/Object;")) { |
| 129 | return false; | 129 | return false; |
| 130 | } else if (name.equals("equals") && sig.equals("(Ljava/lang/Object;)Z")) { | 130 | } else if (name.equals("equals") && sig.equals("(Ljava/lang/Object;)Z")) { |
| @@ -249,14 +249,14 @@ public class EnigmaProject { | |||
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | public SourceExport decompile(ProgressListener progress, DecompilerService decompilerService, DecompileErrorStrategy errorStrategy) { | 251 | public SourceExport decompile(ProgressListener progress, DecompilerService decompilerService, DecompileErrorStrategy errorStrategy) { |
| 252 | List<ClassSource> decompiled = this.decompileStream(progress, decompilerService, errorStrategy).collect(Collectors.toList()); | 252 | List<ClassSource> decompiled = this.decompileStream(progress, decompilerService, errorStrategy).toList(); |
| 253 | return new SourceExport(decompiled); | 253 | return new SourceExport(decompiled); |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | public Stream<ClassSource> decompileStream(ProgressListener progress, DecompilerService decompilerService, DecompileErrorStrategy errorStrategy) { | 256 | public Stream<ClassSource> decompileStream(ProgressListener progress, DecompilerService decompilerService, DecompileErrorStrategy errorStrategy) { |
| 257 | Collection<ClassNode> classes = this.compiled.values().stream() | 257 | Collection<ClassNode> classes = this.compiled.values().stream() |
| 258 | .filter(classNode -> classNode.name.indexOf('$') == -1) | 258 | .filter(classNode -> classNode.name.indexOf('$') == -1) |
| 259 | .collect(Collectors.toList()); | 259 | .toList(); |
| 260 | 260 | ||
| 261 | progress.init(classes.size(), I18n.translate("progress.classes.decompiling")); | 261 | progress.init(classes.size(), I18n.translate("progress.classes.decompiling")); |
| 262 | 262 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/ClassReferenceTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/ClassReferenceTreeNode.java index 90d8a6cf..01424120 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/ClassReferenceTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/ClassReferenceTreeNode.java | |||
| @@ -70,8 +70,7 @@ public class ClassReferenceTreeNode extends DefaultMutableTreeNode | |||
| 70 | 70 | ||
| 71 | if (recurse && this.children != null) { | 71 | if (recurse && this.children != null) { |
| 72 | for (Object child : this.children) { | 72 | for (Object child : this.children) { |
| 73 | if (child instanceof ClassReferenceTreeNode) { | 73 | if (child instanceof ClassReferenceTreeNode node) { |
| 74 | ClassReferenceTreeNode node = (ClassReferenceTreeNode) child; | ||
| 75 | 74 | ||
| 76 | // don't recurse into ancestor | 75 | // don't recurse into ancestor |
| 77 | Set<Entry<?>> ancestors = Sets.newHashSet(); | 76 | Set<Entry<?>> ancestors = Sets.newHashSet(); |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java index 6dd65260..281b05ff 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/EntryReference.java | |||
| @@ -91,7 +91,7 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | public Entry<?> getNameableEntry() { | 93 | public Entry<?> getNameableEntry() { |
| 94 | if (entry instanceof MethodEntry && ((MethodEntry) entry).isConstructor()) { | 94 | if (entry instanceof MethodEntry method && method.isConstructor()) { |
| 95 | // renaming a constructor really means renaming the class | 95 | // renaming a constructor really means renaming the class |
| 96 | return entry.getContainingClass(); | 96 | return entry.getContainingClass(); |
| 97 | } | 97 | } |
| @@ -112,7 +112,7 @@ public class EntryReference<E extends Entry<?>, C extends Entry<?>> implements T | |||
| 112 | 112 | ||
| 113 | @Override | 113 | @Override |
| 114 | public boolean equals(Object other) { | 114 | public boolean equals(Object other) { |
| 115 | return other instanceof EntryReference && equals((EntryReference<?, ?>) other); | 115 | return other instanceof EntryReference reference && equals(reference); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | public boolean equals(EntryReference<?, ?> other) { | 118 | public boolean equals(EntryReference<?, ?> other) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java index 4beab7f8..c93ac53f 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/FieldReferenceTreeNode.java | |||
| @@ -72,10 +72,10 @@ public class FieldReferenceTreeNode extends DefaultMutableTreeNode implements Re | |||
| 72 | 72 | ||
| 73 | if (recurse && children != null) { | 73 | if (recurse && children != null) { |
| 74 | for (Object node : children) { | 74 | for (Object node : children) { |
| 75 | if (node instanceof MethodReferenceTreeNode) { | 75 | if (node instanceof MethodReferenceTreeNode methodNode) { |
| 76 | ((MethodReferenceTreeNode) node).load(index, true, false); | 76 | methodNode.load(index, true, false); |
| 77 | } else if (node instanceof FieldReferenceTreeNode) { | 77 | } else if (node instanceof FieldReferenceTreeNode fieldNode) { |
| 78 | ((FieldReferenceTreeNode) node).load(index, true); | 78 | fieldNode.load(index, true); |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/InterpreterPair.java b/enigma/src/main/java/cuchaz/enigma/analysis/InterpreterPair.java index fad10bf7..a624b7c5 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/InterpreterPair.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/InterpreterPair.java | |||
| @@ -9,7 +9,6 @@ import org.objectweb.asm.tree.analysis.Value; | |||
| 9 | 9 | ||
| 10 | import java.util.List; | 10 | import java.util.List; |
| 11 | import java.util.Objects; | 11 | import java.util.Objects; |
| 12 | import java.util.stream.Collectors; | ||
| 13 | 12 | ||
| 14 | public class InterpreterPair<V extends Value, W extends Value> extends Interpreter<InterpreterPair.PairValue<V, W>> { | 13 | public class InterpreterPair<V extends Value, W extends Value> extends Interpreter<InterpreterPair.PairValue<V, W>> { |
| 15 | private final Interpreter<V> left; | 14 | private final Interpreter<V> left; |
| @@ -72,8 +71,8 @@ public class InterpreterPair<V extends Value, W extends Value> extends Interpret | |||
| 72 | @Override | 71 | @Override |
| 73 | public PairValue<V, W> naryOperation(AbstractInsnNode insn, List<? extends PairValue<V, W>> values) throws AnalyzerException { | 72 | public PairValue<V, W> naryOperation(AbstractInsnNode insn, List<? extends PairValue<V, W>> values) throws AnalyzerException { |
| 74 | return pair( | 73 | return pair( |
| 75 | left.naryOperation(insn, values.stream().map(v -> v.left).collect(Collectors.toList())), | 74 | left.naryOperation(insn, values.stream().map(v -> v.left).toList()), |
| 76 | right.naryOperation(insn, values.stream().map(v -> v.right).collect(Collectors.toList())) | 75 | right.naryOperation(insn, values.stream().map(v -> v.right).toList()) |
| 77 | ); | 76 | ); |
| 78 | } | 77 | } |
| 79 | 78 | ||
| @@ -114,7 +113,7 @@ public class InterpreterPair<V extends Value, W extends Value> extends Interpret | |||
| 114 | 113 | ||
| 115 | @Override | 114 | @Override |
| 116 | public boolean equals(Object o) { | 115 | public boolean equals(Object o) { |
| 117 | return o instanceof InterpreterPair.PairValue && Objects.equals(left, ((PairValue) o).left) && Objects.equals(right, ((PairValue) o).right); | 116 | return o instanceof InterpreterPair.PairValue pairValue && Objects.equals(left, pairValue.left) && Objects.equals(right, pairValue.right); |
| 118 | } | 117 | } |
| 119 | 118 | ||
| 120 | @Override | 119 | @Override |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/MethodReferenceTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/MethodReferenceTreeNode.java index 8995eb5c..68038615 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/MethodReferenceTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/MethodReferenceTreeNode.java | |||
| @@ -72,8 +72,7 @@ public class MethodReferenceTreeNode extends DefaultMutableTreeNode implements R | |||
| 72 | 72 | ||
| 73 | if (recurse && this.children != null) { | 73 | if (recurse && this.children != null) { |
| 74 | for (Object child : this.children) { | 74 | for (Object child : this.children) { |
| 75 | if (child instanceof MethodReferenceTreeNode) { | 75 | if (child instanceof MethodReferenceTreeNode node) { |
| 76 | MethodReferenceTreeNode node = (MethodReferenceTreeNode) child; | ||
| 77 | 76 | ||
| 78 | // don't recurse into ancestor | 77 | // don't recurse into ancestor |
| 79 | Set<Entry<?>> ancestors = Sets.newHashSet(); | 78 | Set<Entry<?>> ancestors = Sets.newHashSet(); |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java index 55d75cf3..b4343c10 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | |||
| @@ -49,7 +49,7 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | // don't add constructor methods if hideDeobfuscated is true | 51 | // don't add constructor methods if hideDeobfuscated is true |
| 52 | if (hideDeobfuscated && (child instanceof MethodEntry) && ((MethodEntry) child).isConstructor()) { | 52 | if (hideDeobfuscated && (child instanceof MethodEntry method) && method.isConstructor()) { |
| 53 | continue; | 53 | continue; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -95,12 +95,12 @@ public class StructureTreeNode extends DefaultMutableTreeNode { | |||
| 95 | public String toHtml() { | 95 | public String toHtml() { |
| 96 | List<String> modifiers = new ArrayList<>(); | 96 | List<String> modifiers = new ArrayList<>(); |
| 97 | 97 | ||
| 98 | if (this.entry instanceof DefEntry<?>) { | 98 | if (this.entry instanceof DefEntry<?> defEntry) { |
| 99 | AccessFlags access = ((DefEntry<?>) this.entry).getAccess(); | 99 | AccessFlags access = defEntry.getAccess(); |
| 100 | boolean isInterfaceMethod = false; | 100 | boolean isInterfaceMethod = false; |
| 101 | 101 | ||
| 102 | if (this.entry instanceof MethodEntry && this.entry.getParent() instanceof ClassDefEntry) { | 102 | if (this.entry instanceof MethodEntry && this.entry.getParent() instanceof ClassDefEntry parent) { |
| 103 | isInterfaceMethod = ((ClassDefEntry) this.entry.getParent()).getAccess().isInterface(); | 103 | isInterfaceMethod = parent.getAccess().isInterface(); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if (access.isStatic() && !access.isEnum()) { | 106 | if (access.isStatic() && !access.isEnum()) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/index/EntryIndex.java b/enigma/src/main/java/cuchaz/enigma/analysis/index/EntryIndex.java index 9a2726e5..bb992b73 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/index/EntryIndex.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/index/EntryIndex.java | |||
| @@ -43,14 +43,14 @@ public class EntryIndex implements JarIndexer { | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public boolean hasEntry(Entry<?> entry) { | 45 | public boolean hasEntry(Entry<?> entry) { |
| 46 | if (entry instanceof ClassEntry) { | 46 | if (entry instanceof ClassEntry classEntry) { |
| 47 | return hasClass((ClassEntry) entry); | 47 | return hasClass(classEntry); |
| 48 | } else if (entry instanceof MethodEntry) { | 48 | } else if (entry instanceof MethodEntry methodEntry) { |
| 49 | return hasMethod((MethodEntry) entry); | 49 | return hasMethod(methodEntry); |
| 50 | } else if (entry instanceof FieldEntry) { | 50 | } else if (entry instanceof FieldEntry fieldEntry) { |
| 51 | return hasField((FieldEntry) entry); | 51 | return hasField(fieldEntry); |
| 52 | } else if (entry instanceof LocalVariableEntry) { | 52 | } else if (entry instanceof LocalVariableEntry localVariableEntry) { |
| 53 | return hasMethod(((LocalVariableEntry) entry).getParent()); | 53 | return hasMethod(localVariableEntry.getParent()); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | return false; | 56 | return false; |
| @@ -73,12 +73,12 @@ public class EntryIndex implements JarIndexer { | |||
| 73 | 73 | ||
| 74 | @Nullable | 74 | @Nullable |
| 75 | public AccessFlags getEntryAccess(Entry<?> entry) { | 75 | public AccessFlags getEntryAccess(Entry<?> entry) { |
| 76 | if (entry instanceof MethodEntry) { | 76 | if (entry instanceof MethodEntry methodEntry) { |
| 77 | return getMethodAccess((MethodEntry) entry); | 77 | return getMethodAccess(methodEntry); |
| 78 | } else if (entry instanceof FieldEntry) { | 78 | } else if (entry instanceof FieldEntry fieldEntry) { |
| 79 | return getFieldAccess((FieldEntry) entry); | 79 | return getFieldAccess(fieldEntry); |
| 80 | } else if (entry instanceof LocalVariableEntry) { | 80 | } else if (entry instanceof LocalVariableEntry localVariableEntry) { |
| 81 | return getMethodAccess(((LocalVariableEntry) entry).getParent()); | 81 | return getMethodAccess(localVariableEntry.getParent()); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | return null; | 84 | return null; |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java b/enigma/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java index f3d419ee..efea83d4 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/index/IndexReferenceVisitor.java | |||
| @@ -17,7 +17,6 @@ import org.objectweb.asm.tree.MethodInsnNode; | |||
| 17 | import org.objectweb.asm.tree.analysis.*; | 17 | import org.objectweb.asm.tree.analysis.*; |
| 18 | 18 | ||
| 19 | import java.util.List; | 19 | import java.util.List; |
| 20 | import java.util.stream.Collectors; | ||
| 21 | 20 | ||
| 22 | public class IndexReferenceVisitor extends ClassVisitor { | 21 | public class IndexReferenceVisitor extends ClassVisitor { |
| 23 | private final JarIndexer indexer; | 22 | private final JarIndexer indexer; |
| @@ -112,7 +111,7 @@ public class IndexReferenceVisitor extends ClassVisitor { | |||
| 112 | 111 | ||
| 113 | if (insn.getOpcode() == Opcodes.INVOKEDYNAMIC) { | 112 | if (insn.getOpcode() == Opcodes.INVOKEDYNAMIC) { |
| 114 | InvokeDynamicInsnNode invokeDynamicInsn = (InvokeDynamicInsnNode) insn; | 113 | InvokeDynamicInsnNode invokeDynamicInsn = (InvokeDynamicInsnNode) insn; |
| 115 | List<AbstractInsnNode> args = values.stream().map(v -> v.right.insns.stream().findFirst().orElseThrow(AssertionError::new)).collect(Collectors.toList()); | 114 | List<AbstractInsnNode> args = values.stream().map(v -> v.right.insns.stream().findFirst().orElseThrow(AssertionError::new)).toList(); |
| 116 | 115 | ||
| 117 | if ("java/lang/invoke/LambdaMetafactory".equals(invokeDynamicInsn.bsm.getOwner()) && "metafactory".equals(invokeDynamicInsn.bsm.getName())) { | 116 | if ("java/lang/invoke/LambdaMetafactory".equals(invokeDynamicInsn.bsm.getOwner()) && "metafactory".equals(invokeDynamicInsn.bsm.getName())) { |
| 118 | Type samMethodType = (Type) invokeDynamicInsn.bsmArgs[0]; | 117 | Type samMethodType = (Type) invokeDynamicInsn.bsmArgs[0]; |
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java b/enigma/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java index aa360cfd..6c26282e 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/index/JarIndex.java | |||
| @@ -44,7 +44,7 @@ public class JarIndex implements JarIndexer { | |||
| 44 | this.referenceIndex = referenceIndex; | 44 | this.referenceIndex = referenceIndex; |
| 45 | this.bridgeMethodIndex = bridgeMethodIndex; | 45 | this.bridgeMethodIndex = bridgeMethodIndex; |
| 46 | this.packageVisibilityIndex = packageVisibilityIndex; | 46 | this.packageVisibilityIndex = packageVisibilityIndex; |
| 47 | this.indexers = Arrays.asList(entryIndex, inheritanceIndex, referenceIndex, bridgeMethodIndex, packageVisibilityIndex); | 47 | this.indexers = List.of(entryIndex, inheritanceIndex, referenceIndex, bridgeMethodIndex, packageVisibilityIndex); |
| 48 | this.entryResolver = new IndexEntryResolver(this); | 48 | this.entryResolver = new IndexEntryResolver(this); |
| 49 | this.childrenByClass = ArrayListMultimap.create(); | 49 | this.childrenByClass = ArrayListMultimap.create(); |
| 50 | } | 50 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/classprovider/ObfuscationFixClassProvider.java b/enigma/src/main/java/cuchaz/enigma/classprovider/ObfuscationFixClassProvider.java index db9e2d04..36236a8d 100644 --- a/enigma/src/main/java/cuchaz/enigma/classprovider/ObfuscationFixClassProvider.java +++ b/enigma/src/main/java/cuchaz/enigma/classprovider/ObfuscationFixClassProvider.java | |||
| @@ -65,8 +65,7 @@ public class ObfuscationFixClassProvider implements ClassProvider { | |||
| 65 | for (MethodNode methodNode : node.methods) { | 65 | for (MethodNode methodNode : node.methods) { |
| 66 | AbstractInsnNode insnNode = methodNode.instructions.getFirst(); | 66 | AbstractInsnNode insnNode = methodNode.instructions.getFirst(); |
| 67 | while (insnNode != null) { | 67 | while (insnNode != null) { |
| 68 | if (insnNode instanceof MethodInsnNode && insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { | 68 | if (insnNode instanceof MethodInsnNode methodInsnNode && insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { |
| 69 | MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; | ||
| 70 | if (methodInsnNode.name.equals("getClass") && methodInsnNode.owner.equals("java/lang/Object") && methodInsnNode.desc.equals("()Ljava/lang/Class;")) { | 69 | if (methodInsnNode.name.equals("getClass") && methodInsnNode.owner.equals("java/lang/Object") && methodInsnNode.desc.equals("()Ljava/lang/Class;")) { |
| 71 | AbstractInsnNode previous = methodInsnNode.getPrevious(); | 70 | AbstractInsnNode previous = methodInsnNode.getPrevious(); |
| 72 | AbstractInsnNode next = methodInsnNode.getNext(); | 71 | AbstractInsnNode next = methodInsnNode.getNext(); |
diff --git a/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java b/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java index ed6cfb94..971252e2 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java +++ b/enigma/src/main/java/cuchaz/enigma/source/SourceIndex.java | |||
| @@ -13,7 +13,6 @@ import java.util.Collection; | |||
| 13 | import java.util.List; | 13 | import java.util.List; |
| 14 | import java.util.Map; | 14 | import java.util.Map; |
| 15 | import java.util.TreeMap; | 15 | import java.util.TreeMap; |
| 16 | import java.util.stream.Collectors; | ||
| 17 | 16 | ||
| 18 | public class SourceIndex { | 17 | public class SourceIndex { |
| 19 | private String source; | 18 | private String source; |
| @@ -159,7 +158,7 @@ public class SourceIndex { | |||
| 159 | Collection<Token> newTokens = oldTokens | 158 | Collection<Token> newTokens = oldTokens |
| 160 | .stream() | 159 | .stream() |
| 161 | .map(result::getRemappedToken) | 160 | .map(result::getRemappedToken) |
| 162 | .collect(Collectors.toList()); | 161 | .toList(); |
| 163 | 162 | ||
| 164 | remapped.referenceToTokens.putAll(reference, newTokens); | 163 | remapped.referenceToTokens.putAll(reference, newTokens); |
| 165 | } | 164 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/Translator.java b/enigma/src/main/java/cuchaz/enigma/translation/Translator.java index d3bc188d..66c2f9ec 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/Translator.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/Translator.java | |||
| @@ -36,7 +36,7 @@ public interface Translator { | |||
| 36 | default <T extends Translatable> Collection<T> translate(Collection<T> translatable) { | 36 | default <T extends Translatable> Collection<T> translate(Collection<T> translatable) { |
| 37 | return translatable.stream() | 37 | return translatable.stream() |
| 38 | .map(this::translate) | 38 | .map(this::translate) |
| 39 | .collect(Collectors.toList()); | 39 | .toList(); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | default <T extends Translatable> Set<T> translate(Set<T> translatable) { | 42 | default <T extends Translatable> Set<T> translate(Set<T> translatable) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/AccessModifier.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/AccessModifier.java index 5b79b794..f57dd900 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/AccessModifier.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/AccessModifier.java | |||
| @@ -10,16 +10,11 @@ public enum AccessModifier { | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | public AccessFlags transform(AccessFlags access) { | 12 | public AccessFlags transform(AccessFlags access) { |
| 13 | switch (this) { | 13 | return switch (this) { |
| 14 | case PUBLIC: | 14 | case PUBLIC -> access.setPublic(); |
| 15 | return access.setPublic(); | 15 | case PROTECTED -> access.setProtected(); |
| 16 | case PROTECTED: | 16 | case PRIVATE -> access.setPrivate(); |
| 17 | return access.setProtected(); | 17 | default -> access; |
| 18 | case PRIVATE: | 18 | }; |
| 19 | return access.setPrivate(); | ||
| 20 | case UNCHANGED: | ||
| 21 | default: | ||
| 22 | return access; | ||
| 23 | } | ||
| 24 | } | 19 | } |
| 25 | } | 20 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryRemapper.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryRemapper.java index ef904d7f..8b5490e1 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryRemapper.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryRemapper.java | |||
| @@ -2,7 +2,6 @@ package cuchaz.enigma.translation.mapping; | |||
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import java.util.Collection; |
| 4 | import java.util.List; | 4 | import java.util.List; |
| 5 | import java.util.stream.Collectors; | ||
| 6 | import java.util.stream.Stream; | 5 | import java.util.stream.Stream; |
| 7 | 6 | ||
| 8 | import javax.annotation.Nullable; | 7 | import javax.annotation.Nullable; |
| @@ -95,7 +94,7 @@ public class EntryRemapper { | |||
| 95 | // Find all the methods in this record class | 94 | // Find all the methods in this record class |
| 96 | List<MethodEntry> classMethods = jarIndex.getEntryIndex().getMethods().stream() | 95 | List<MethodEntry> classMethods = jarIndex.getEntryIndex().getMethods().stream() |
| 97 | .filter(entry -> classEntry.equals(entry.getParent())) | 96 | .filter(entry -> classEntry.equals(entry.getParent())) |
| 98 | .collect(Collectors.toList()); | 97 | .toList(); |
| 99 | 98 | ||
| 100 | MethodEntry methodEntry = null; | 99 | MethodEntry methodEntry = null; |
| 101 | 100 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryResolver.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryResolver.java index 521f72d0..9dd0c3aa 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryResolver.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryResolver.java | |||
| @@ -7,7 +7,6 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 7 | 7 | ||
| 8 | import java.util.Collection; | 8 | import java.util.Collection; |
| 9 | import java.util.Set; | 9 | import java.util.Set; |
| 10 | import java.util.stream.Collectors; | ||
| 11 | 10 | ||
| 12 | public interface EntryResolver { | 11 | public interface EntryResolver { |
| 13 | <E extends Entry<?>> Collection<E> resolveEntry(E entry, ResolutionStrategy strategy); | 12 | <E extends Entry<?>> Collection<E> resolveEntry(E entry, ResolutionStrategy strategy); |
| @@ -21,11 +20,11 @@ public interface EntryResolver { | |||
| 21 | if (reference.context != null) { | 20 | if (reference.context != null) { |
| 22 | Collection<C> context = resolveEntry(reference.context, strategy); | 21 | Collection<C> context = resolveEntry(reference.context, strategy); |
| 23 | return Streams.zip(entry.stream(), context.stream(), (e, c) -> new EntryReference<>(e, c, reference)) | 22 | return Streams.zip(entry.stream(), context.stream(), (e, c) -> new EntryReference<>(e, c, reference)) |
| 24 | .collect(Collectors.toList()); | 23 | .toList(); |
| 25 | } else { | 24 | } else { |
| 26 | return entry.stream() | 25 | return entry.stream() |
| 27 | .map(e -> new EntryReference<>(e, null, reference)) | 26 | .map(e -> new EntryReference<>(e, null, reference)) |
| 28 | .collect(Collectors.toList()); | 27 | .toList(); |
| 29 | } | 28 | } |
| 30 | } | 29 | } |
| 31 | 30 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/IdentifierValidation.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/IdentifierValidation.java index 9595c4e6..e3aeb205 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/IdentifierValidation.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/IdentifierValidation.java | |||
| @@ -11,7 +11,6 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.translation.mapping; | 12 | package cuchaz.enigma.translation.mapping; |
| 13 | 13 | ||
| 14 | import java.util.Arrays; | ||
| 15 | import java.util.List; | 14 | import java.util.List; |
| 16 | 15 | ||
| 17 | import cuchaz.enigma.utils.validation.Message; | 16 | import cuchaz.enigma.utils.validation.Message; |
| @@ -23,12 +22,13 @@ public final class IdentifierValidation { | |||
| 23 | private IdentifierValidation() { | 22 | private IdentifierValidation() { |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | private static final List<String> ILLEGAL_IDENTIFIERS = Arrays.asList( | 25 | private static final List<String> ILLEGAL_IDENTIFIERS = List.of( |
| 27 | "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", "package", "synchronized", | 26 | "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", |
| 28 | "boolean", "do", "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte", | 27 | "continue", "default", "do", "double", "else", "enum", "extends", "false", "final", "finally", |
| 29 | "else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch", | 28 | "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", |
| 30 | "extends", "int", "short", "try", "char", "final", "interface", "static", "void", "class", "finally", | 29 | "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", |
| 31 | "long", "strictfp", "volatile", "const", "float", "native", "super", "while", "true", "false", "null", "_" | 30 | "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", |
| 31 | "void", "volatile", "while", "_" | ||
| 32 | ); | 32 | ); |
| 33 | 33 | ||
| 34 | public static boolean validateClassName(ValidationContext vc, String name, boolean isInner) { | 34 | public static boolean validateClassName(ValidationContext vc, String name, boolean isInner) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/IndexEntryResolver.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/IndexEntryResolver.java index 78231ddd..1a89df7b 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/IndexEntryResolver.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/IndexEntryResolver.java | |||
| @@ -16,7 +16,6 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 16 | 16 | ||
| 17 | import javax.annotation.Nullable; | 17 | import javax.annotation.Nullable; |
| 18 | import java.util.*; | 18 | import java.util.*; |
| 19 | import java.util.stream.Collectors; | ||
| 20 | 19 | ||
| 21 | public class IndexEntryResolver implements EntryResolver { | 20 | public class IndexEntryResolver implements EntryResolver { |
| 22 | private final EntryIndex entryIndex; | 21 | private final EntryIndex entryIndex; |
| @@ -54,7 +53,7 @@ public class IndexEntryResolver implements EntryResolver { | |||
| 54 | if (!resolvedChildren.isEmpty()) { | 53 | if (!resolvedChildren.isEmpty()) { |
| 55 | return resolvedChildren.stream() | 54 | return resolvedChildren.stream() |
| 56 | .map(resolvedChild -> (E) entry.replaceAncestor(classChild, resolvedChild)) | 55 | .map(resolvedChild -> (E) entry.replaceAncestor(classChild, resolvedChild)) |
| 57 | .collect(Collectors.toList()); | 56 | .toList(); |
| 58 | } | 57 | } |
| 59 | } | 58 | } |
| 60 | } | 59 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingValidator.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingValidator.java index f9f3b88e..1615912b 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingValidator.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingValidator.java | |||
| @@ -2,7 +2,7 @@ package cuchaz.enigma.translation.mapping; | |||
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import java.util.Collection; |
| 4 | import java.util.HashSet; | 4 | import java.util.HashSet; |
| 5 | import java.util.stream.Collectors; | 5 | import java.util.List; |
| 6 | 6 | ||
| 7 | import cuchaz.enigma.analysis.index.InheritanceIndex; | 7 | import cuchaz.enigma.analysis.index.InheritanceIndex; |
| 8 | import cuchaz.enigma.analysis.index.JarIndex; | 8 | import cuchaz.enigma.analysis.index.JarIndex; |
| @@ -41,9 +41,9 @@ public class MappingValidator { | |||
| 41 | Entry<?> relatedEntry = entry.replaceAncestor(containingClass, relatedClass); | 41 | Entry<?> relatedEntry = entry.replaceAncestor(containingClass, relatedClass); |
| 42 | Entry<?> translatedEntry = deobfuscator.translate(relatedEntry); | 42 | Entry<?> translatedEntry = deobfuscator.translate(relatedEntry); |
| 43 | 43 | ||
| 44 | Collection<Entry<?>> translatedSiblings = obfToDeobf.getSiblings(relatedEntry).stream() | 44 | List<? extends Entry<?>> translatedSiblings = obfToDeobf.getSiblings(relatedEntry).stream() |
| 45 | .map(deobfuscator::translate) | 45 | .map(deobfuscator::translate) |
| 46 | .collect(Collectors.toList()); | 46 | .toList(); |
| 47 | 47 | ||
| 48 | if (!isUnique(translatedEntry, translatedSiblings, name)) { | 48 | if (!isUnique(translatedEntry, translatedSiblings, name)) { |
| 49 | Entry<?> parent = translatedEntry.getParent(); | 49 | Entry<?> parent = translatedEntry.getParent(); |
| @@ -67,7 +67,7 @@ public class MappingValidator { | |||
| 67 | return relatedClasses; | 67 | return relatedClasses; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | private boolean isUnique(Entry<?> entry, Collection<Entry<?>> siblings, String name) { | 70 | private boolean isUnique(Entry<?> entry, List<? extends Entry<?>> siblings, String name) { |
| 71 | for (Entry<?> sibling : siblings) { | 71 | for (Entry<?> sibling : siblings) { |
| 72 | if (entry.canConflictWith(sibling) && sibling.getName().equals(name)) { | 72 | if (entry.canConflictWith(sibling) && sibling.getName().equals(name)) { |
| 73 | return false; | 73 | return false; |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingsChecker.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingsChecker.java index 5d9794fb..141a07cc 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingsChecker.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/MappingsChecker.java | |||
| @@ -24,7 +24,6 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 24 | import java.util.Collection; | 24 | import java.util.Collection; |
| 25 | import java.util.HashMap; | 25 | import java.util.HashMap; |
| 26 | import java.util.Map; | 26 | import java.util.Map; |
| 27 | import java.util.stream.Collectors; | ||
| 28 | 27 | ||
| 29 | public class MappingsChecker { | 28 | public class MappingsChecker { |
| 30 | private final JarIndex index; | 29 | private final JarIndex index; |
| @@ -40,7 +39,7 @@ public class MappingsChecker { | |||
| 40 | 39 | ||
| 41 | Collection<Entry<?>> obfEntries = mappings.getAllEntries() | 40 | Collection<Entry<?>> obfEntries = mappings.getAllEntries() |
| 42 | .filter(e -> e instanceof ClassEntry || e instanceof MethodEntry || e instanceof FieldEntry || e instanceof LocalVariableEntry) | 41 | .filter(e -> e instanceof ClassEntry || e instanceof MethodEntry || e instanceof FieldEntry || e instanceof LocalVariableEntry) |
| 43 | .collect(Collectors.toList()); | 42 | .toList(); |
| 44 | 43 | ||
| 45 | progress.init(obfEntries.size(), "Checking for dropped mappings"); | 44 | progress.init(obfEntries.size(), "Checking for dropped mappings"); |
| 46 | 45 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsReader.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsReader.java index a1e975c1..27545c03 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsReader.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsReader.java | |||
| @@ -28,7 +28,6 @@ import java.util.Arrays; | |||
| 28 | import java.util.Deque; | 28 | import java.util.Deque; |
| 29 | import java.util.List; | 29 | import java.util.List; |
| 30 | import java.util.Locale; | 30 | import java.util.Locale; |
| 31 | import java.util.stream.Collectors; | ||
| 32 | 31 | ||
| 33 | public enum EnigmaMappingsReader implements MappingsReader { | 32 | public enum EnigmaMappingsReader implements MappingsReader { |
| 34 | FILE { | 33 | FILE { |
| @@ -52,7 +51,7 @@ public enum EnigmaMappingsReader implements MappingsReader { | |||
| 52 | List<Path> files = Files.walk(root) | 51 | List<Path> files = Files.walk(root) |
| 53 | .filter(f -> !Files.isDirectory(f)) | 52 | .filter(f -> !Files.isDirectory(f)) |
| 54 | .filter(f -> f.toString().endsWith(".mapping")) | 53 | .filter(f -> f.toString().endsWith(".mapping")) |
| 55 | .collect(Collectors.toList()); | 54 | .toList(); |
| 56 | 55 | ||
| 57 | progress.init(files.size(), I18n.translate("progress.mappings.enigma_directory.loading")); | 56 | progress.init(files.size(), I18n.translate("progress.mappings.enigma_directory.loading")); |
| 58 | int step = 0; | 57 | int step = 0; |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsWriter.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsWriter.java index 378ed984..d9f1470d 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsWriter.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsWriter.java | |||
| @@ -26,7 +26,6 @@ import java.util.Collection; | |||
| 26 | import java.util.Collections; | 26 | import java.util.Collections; |
| 27 | import java.util.Objects; | 27 | import java.util.Objects; |
| 28 | import java.util.concurrent.atomic.AtomicInteger; | 28 | import java.util.concurrent.atomic.AtomicInteger; |
| 29 | import java.util.stream.Collectors; | ||
| 30 | import java.util.stream.Stream; | 29 | import java.util.stream.Stream; |
| 31 | 30 | ||
| 32 | import cuchaz.enigma.ProgressListener; | 31 | import cuchaz.enigma.ProgressListener; |
| @@ -57,7 +56,7 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 57 | Collection<ClassEntry> classes = mappings.getRootNodes() | 56 | Collection<ClassEntry> classes = mappings.getRootNodes() |
| 58 | .filter(entry -> entry.getEntry() instanceof ClassEntry) | 57 | .filter(entry -> entry.getEntry() instanceof ClassEntry) |
| 59 | .map(entry -> (ClassEntry) entry.getEntry()) | 58 | .map(entry -> (ClassEntry) entry.getEntry()) |
| 60 | .collect(Collectors.toList()); | 59 | .toList(); |
| 61 | 60 | ||
| 62 | progress.init(classes.size(), I18n.translate("progress.mappings.enigma_file.writing")); | 61 | progress.init(classes.size(), I18n.translate("progress.mappings.enigma_file.writing")); |
| 63 | 62 | ||
| @@ -78,7 +77,7 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 78 | Collection<ClassEntry> changedClasses = delta.getChangedRoots() | 77 | Collection<ClassEntry> changedClasses = delta.getChangedRoots() |
| 79 | .filter(entry -> entry instanceof ClassEntry) | 78 | .filter(entry -> entry instanceof ClassEntry) |
| 80 | .map(entry -> (ClassEntry) entry) | 79 | .map(entry -> (ClassEntry) entry) |
| 81 | .collect(Collectors.toList()); | 80 | .toList(); |
| 82 | 81 | ||
| 83 | applyDeletions(path, changedClasses, mappings, delta.getBaseMappings(), saveParameters.getFileNameFormat()); | 82 | applyDeletions(path, changedClasses, mappings, delta.getBaseMappings(), saveParameters.getFileNameFormat()); |
| 84 | 83 | ||
| @@ -120,7 +119,7 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 120 | deletedClassStream = deletedClassStream.map(oldMappingTranslator::translate); | 119 | deletedClassStream = deletedClassStream.map(oldMappingTranslator::translate); |
| 121 | } | 120 | } |
| 122 | 121 | ||
| 123 | Collection<ClassEntry> deletedClasses = deletedClassStream.collect(Collectors.toList()); | 122 | Collection<ClassEntry> deletedClasses = deletedClassStream.toList(); |
| 124 | 123 | ||
| 125 | for (ClassEntry classEntry : deletedClasses) { | 124 | for (ClassEntry classEntry : deletedClasses) { |
| 126 | try { | 125 | try { |
| @@ -309,9 +308,7 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 309 | 308 | ||
| 310 | private String indent(String line, int depth) { | 309 | private String indent(String line, int depth) { |
| 311 | StringBuilder builder = new StringBuilder(); | 310 | StringBuilder builder = new StringBuilder(); |
| 312 | for (int i = 0; i < depth; i++) { | 311 | builder.append("\t".repeat(Math.max(0, depth))); |
| 313 | builder.append("\t"); | ||
| 314 | } | ||
| 315 | builder.append(line.trim()); | 312 | builder.append(line.trim()); |
| 316 | return builder.toString(); | 313 | return builder.toString(); |
| 317 | } | 314 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/srg/SrgMappingsWriter.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/srg/SrgMappingsWriter.java index 9c9f103d..92758475 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/srg/SrgMappingsWriter.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/srg/SrgMappingsWriter.java | |||
| @@ -26,7 +26,6 @@ import java.util.ArrayList; | |||
| 26 | import java.util.Collection; | 26 | import java.util.Collection; |
| 27 | import java.util.Comparator; | 27 | import java.util.Comparator; |
| 28 | import java.util.List; | 28 | import java.util.List; |
| 29 | import java.util.stream.Collectors; | ||
| 30 | 29 | ||
| 31 | public enum SrgMappingsWriter implements MappingsWriter { | 30 | public enum SrgMappingsWriter implements MappingsWriter { |
| 32 | INSTANCE; | 31 | INSTANCE; |
| @@ -44,9 +43,9 @@ public enum SrgMappingsWriter implements MappingsWriter { | |||
| 44 | List<String> fieldLines = new ArrayList<>(); | 43 | List<String> fieldLines = new ArrayList<>(); |
| 45 | List<String> methodLines = new ArrayList<>(); | 44 | List<String> methodLines = new ArrayList<>(); |
| 46 | 45 | ||
| 47 | Collection<Entry<?>> rootEntries = Lists.newArrayList(mappings).stream() | 46 | List<? extends Entry<?>> rootEntries = Lists.newArrayList(mappings).stream() |
| 48 | .map(EntryTreeNode::getEntry) | 47 | .map(EntryTreeNode::getEntry) |
| 49 | .collect(Collectors.toList()); | 48 | .toList(); |
| 50 | progress.init(rootEntries.size(), I18n.translate("progress.mappings.srg_file.generating")); | 49 | progress.init(rootEntries.size(), I18n.translate("progress.mappings.srg_file.generating")); |
| 51 | 50 | ||
| 52 | int steps = 0; | 51 | int steps = 0; |
| @@ -111,7 +110,7 @@ public enum SrgMappingsWriter implements MappingsWriter { | |||
| 111 | return entry.getParent().getFullName() + "/" + entry.getName(); | 110 | return entry.getParent().getFullName() + "/" + entry.getName(); |
| 112 | } | 111 | } |
| 113 | 112 | ||
| 114 | private Collection<Entry<?>> sorted(Iterable<Entry<?>> iterable) { | 113 | private Collection<Entry<?>> sorted(Iterable<? extends Entry<?>> iterable) { |
| 115 | ArrayList<Entry<?>> sorted = Lists.newArrayList(iterable); | 114 | ArrayList<Entry<?>> sorted = Lists.newArrayList(iterable); |
| 116 | sorted.sort(Comparator.comparing(Entry::getName)); | 115 | sorted.sort(Comparator.comparing(Entry::getName)); |
| 117 | return sorted; | 116 | return sorted; |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/tinyv2/TinyV2Writer.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/tinyv2/TinyV2Writer.java index 5546b2fe..5160eda3 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/tinyv2/TinyV2Writer.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/tinyv2/TinyV2Writer.java | |||
| @@ -24,7 +24,6 @@ import java.nio.file.Path; | |||
| 24 | import java.util.Deque; | 24 | import java.util.Deque; |
| 25 | import java.util.LinkedList; | 25 | import java.util.LinkedList; |
| 26 | import java.util.List; | 26 | import java.util.List; |
| 27 | import java.util.stream.Collectors; | ||
| 28 | import java.util.stream.StreamSupport; | 27 | import java.util.stream.StreamSupport; |
| 29 | 28 | ||
| 30 | public final class TinyV2Writer implements MappingsWriter { | 29 | public final class TinyV2Writer implements MappingsWriter { |
| @@ -40,7 +39,7 @@ public final class TinyV2Writer implements MappingsWriter { | |||
| 40 | 39 | ||
| 41 | @Override | 40 | @Override |
| 42 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters parameters) { | 41 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters parameters) { |
| 43 | List<EntryTreeNode<EntryMapping>> classes = StreamSupport.stream(mappings.spliterator(), false).filter(node -> node.getEntry() instanceof ClassEntry).collect(Collectors.toList()); | 42 | List<EntryTreeNode<EntryMapping>> classes = StreamSupport.stream(mappings.spliterator(), false).filter(node -> node.getEntry() instanceof ClassEntry).toList(); |
| 44 | 43 | ||
| 45 | try (PrintWriter writer = new LfPrintWriter(Files.newBufferedWriter(path))) { | 44 | try (PrintWriter writer = new LfPrintWriter(Files.newBufferedWriter(path))) { |
| 46 | writer.println("tiny\t2\t" + MINOR_VERSION + "\t" + obfHeader + "\t" + deobfHeader); | 45 | writer.println("tiny\t2\t" + MINOR_VERSION + "\t" + obfHeader + "\t" + deobfHeader); |
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/mapping/tree/EntryTreeNode.java b/enigma/src/main/java/cuchaz/enigma/translation/mapping/tree/EntryTreeNode.java index affcd504..eb26ea99 100644 --- a/enigma/src/main/java/cuchaz/enigma/translation/mapping/tree/EntryTreeNode.java +++ b/enigma/src/main/java/cuchaz/enigma/translation/mapping/tree/EntryTreeNode.java | |||
| @@ -5,7 +5,7 @@ import cuchaz.enigma.translation.representation.entry.Entry; | |||
| 5 | import javax.annotation.Nullable; | 5 | import javax.annotation.Nullable; |
| 6 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
| 7 | import java.util.Collection; | 7 | import java.util.Collection; |
| 8 | import java.util.stream.Collectors; | 8 | import java.util.List; |
| 9 | 9 | ||
| 10 | public interface EntryTreeNode<T> { | 10 | public interface EntryTreeNode<T> { |
| 11 | @Nullable | 11 | @Nullable |
| @@ -28,10 +28,10 @@ public interface EntryTreeNode<T> { | |||
| 28 | return nodes; | 28 | return nodes; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | default Collection<Entry<?>> getChildrenRecursively() { | 31 | default List<? extends Entry<?>> getChildrenRecursively() { |
| 32 | return getNodesRecursively().stream() | 32 | return getNodesRecursively().stream() |
| 33 | .map(EntryTreeNode::getEntry) | 33 | .map(EntryTreeNode::getEntry) |
| 34 | .collect(Collectors.toList()); | 34 | .toList(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | default boolean hasValue() { | 37 | default boolean hasValue() { |
diff --git a/enigma/src/main/java/cuchaz/enigma/utils/I18n.java b/enigma/src/main/java/cuchaz/enigma/utils/I18n.java index cb498e05..26e5b27a 100644 --- a/enigma/src/main/java/cuchaz/enigma/utils/I18n.java +++ b/enigma/src/main/java/cuchaz/enigma/utils/I18n.java | |||
| @@ -18,15 +18,10 @@ import com.google.gson.Gson; | |||
| 18 | public class I18n { | 18 | public class I18n { |
| 19 | public static final String DEFAULT_LANGUAGE = "en_us"; | 19 | public static final String DEFAULT_LANGUAGE = "en_us"; |
| 20 | private static final Gson GSON = new Gson(); | 20 | private static final Gson GSON = new Gson(); |
| 21 | private static Map<String, String> translations = Maps.newHashMap(); | 21 | private static Map<String, String> defaultTranslations = load(DEFAULT_LANGUAGE); |
| 22 | private static Map<String, String> defaultTranslations = Maps.newHashMap(); | 22 | private static Map<String, String> translations = defaultTranslations; |
| 23 | private static Map<String, String> languageNames = Maps.newHashMap(); | 23 | private static Map<String, String> languageNames = Maps.newHashMap(); |
| 24 | 24 | ||
| 25 | static { | ||
| 26 | defaultTranslations = load(DEFAULT_LANGUAGE); | ||
| 27 | translations = defaultTranslations; | ||
| 28 | } | ||
| 29 | |||
| 30 | @SuppressWarnings("unchecked") | 25 | @SuppressWarnings("unchecked") |
| 31 | public static Map<String, String> load(String language) { | 26 | public static Map<String, String> load(String language) { |
| 32 | try (InputStream inputStream = I18n.class.getResourceAsStream("/lang/" + language + ".json")) { | 27 | try (InputStream inputStream = I18n.class.getResourceAsStream("/lang/" + language + ".json")) { |
diff --git a/enigma/src/main/java/cuchaz/enigma/utils/Utils.java b/enigma/src/main/java/cuchaz/enigma/utils/Utils.java index 8beaaae6..ad4e9368 100644 --- a/enigma/src/main/java/cuchaz/enigma/utils/Utils.java +++ b/enigma/src/main/java/cuchaz/enigma/utils/Utils.java | |||
| @@ -27,7 +27,6 @@ import java.util.List; | |||
| 27 | import java.util.Locale; | 27 | import java.util.Locale; |
| 28 | import java.util.concurrent.locks.Lock; | 28 | import java.util.concurrent.locks.Lock; |
| 29 | import java.util.function.Supplier; | 29 | import java.util.function.Supplier; |
| 30 | import java.util.stream.Collectors; | ||
| 31 | import java.util.zip.ZipEntry; | 30 | import java.util.zip.ZipEntry; |
| 32 | import java.util.zip.ZipFile; | 31 | import java.util.zip.ZipFile; |
| 33 | 32 | ||
| @@ -46,7 +45,7 @@ public class Utils { | |||
| 46 | 45 | ||
| 47 | public static void delete(Path path) throws IOException { | 46 | public static void delete(Path path) throws IOException { |
| 48 | if (Files.exists(path)) { | 47 | if (Files.exists(path)) { |
| 49 | for (Path p : Files.walk(path).sorted(Comparator.reverseOrder()).collect(Collectors.toList())) { | 48 | for (Path p : Files.walk(path).sorted(Comparator.reverseOrder()).toList()) { |
| 50 | Files.delete(p); | 49 | Files.delete(p); |
| 51 | } | 50 | } |
| 52 | } | 51 | } |
| @@ -97,17 +96,4 @@ public class Utils { | |||
| 97 | l.unlock(); | 96 | l.unlock(); |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | |||
| 101 | |||
| 102 | public static boolean isBlank(String input) { | ||
| 103 | if (input == null) { | ||
| 104 | return true; | ||
| 105 | } | ||
| 106 | for (int i = 0; i < input.length(); i++) { | ||
| 107 | if (!Character.isWhitespace(input.charAt(i))) { | ||
| 108 | return false; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | return true; | ||
| 112 | } | ||
| 113 | } | 99 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/utils/validation/ParameterizedMessage.java b/enigma/src/main/java/cuchaz/enigma/utils/validation/ParameterizedMessage.java index 48a5a10f..9ad58679 100644 --- a/enigma/src/main/java/cuchaz/enigma/utils/validation/ParameterizedMessage.java +++ b/enigma/src/main/java/cuchaz/enigma/utils/validation/ParameterizedMessage.java | |||
| @@ -26,8 +26,7 @@ public final class ParameterizedMessage { | |||
| 26 | @Override | 26 | @Override |
| 27 | public boolean equals(Object o) { | 27 | public boolean equals(Object o) { |
| 28 | if (this == o) return true; | 28 | if (this == o) return true; |
| 29 | if (!(o instanceof ParameterizedMessage)) return false; | 29 | if (!(o instanceof ParameterizedMessage that)) return false; |
| 30 | ParameterizedMessage that = (ParameterizedMessage) o; | ||
| 31 | return Objects.equals(message, that.message) && | 30 | return Objects.equals(message, that.message) && |
| 32 | Arrays.equals(params, that.params) && | 31 | Arrays.equals(params, that.params) && |
| 33 | Objects.equals(target, that.target); | 32 | Objects.equals(target, that.target); |
diff --git a/enigma/src/main/java/cuchaz/enigma/utils/validation/PrintValidatable.java b/enigma/src/main/java/cuchaz/enigma/utils/validation/PrintValidatable.java index fe91cc11..81b6c43f 100644 --- a/enigma/src/main/java/cuchaz/enigma/utils/validation/PrintValidatable.java +++ b/enigma/src/main/java/cuchaz/enigma/utils/validation/PrintValidatable.java | |||
| @@ -10,20 +10,11 @@ public class PrintValidatable implements Validatable { | |||
| 10 | public void addMessage(ParameterizedMessage message) { | 10 | public void addMessage(ParameterizedMessage message) { |
| 11 | String text = message.getText(); | 11 | String text = message.getText(); |
| 12 | String longText = message.getLongText(); | 12 | String longText = message.getLongText(); |
| 13 | String type; | 13 | String type = switch (message.message.type) { |
| 14 | switch (message.message.type) { | 14 | case INFO -> "info"; |
| 15 | case INFO: | 15 | case WARNING -> "warning"; |
| 16 | type = "info"; | 16 | case ERROR -> "error"; |
| 17 | break; | 17 | }; |
| 18 | case WARNING: | ||
| 19 | type = "warning"; | ||
| 20 | break; | ||
| 21 | case ERROR: | ||
| 22 | type = "error"; | ||
| 23 | break; | ||
| 24 | default: | ||
| 25 | throw new IllegalStateException("unreachable"); | ||
| 26 | } | ||
| 27 | System.out.printf("%s: %s\n", type, text); | 18 | System.out.printf("%s: %s\n", type, text); |
| 28 | if (!longText.isEmpty()) { | 19 | if (!longText.isEmpty()) { |
| 29 | Arrays.stream(longText.split("\n")).forEach(s -> System.out.printf(" %s\n", s)); | 20 | Arrays.stream(longText.split("\n")).forEach(s -> System.out.printf(" %s\n", s)); |