Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Enigma includes the following open-source libraries:
- [Vineflower](https://github.com/Vineflower/vineflower) (Apache-2.0)
- A [modified version](https://github.com/FabricMC/cfr) of [CFR](https://github.com/leibnitz27/cfr) (MIT)
- A [modified version](https://github.com/FabricMC/procyon) of [Procyon](https://bitbucket.org/mstrobel/procyon) (Apache-2.0)
- [Guava](https://github.com/google/guava) (Apache-2.0)
- [SyntaxPane](https://github.com/Sciss/SyntaxPane) (Apache-2.0)
- [FlatLaf](https://github.com/JFormDesigner/FlatLaf) (Apache-2.0)
- [jopt-simple](https://github.com/jopt-simple/jopt-simple) (MIT)
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ subprojects {
}

dependencies {
implementation 'com.google.guava:guava:32.1.2-jre'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'net.fabricmc:mapping-io:0.7.1'

Expand Down
3 changes: 1 addition & 2 deletions enigma-cli/src/main/java/cuchaz/enigma/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import com.google.common.io.MoreFiles;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.mappingio.tree.VisitableMappingTree;
Expand Down Expand Up @@ -57,7 +56,7 @@ protected static EnigmaProject openProject(Path fileJarIn, Path fileMappings) th

protected static EntryTree<EntryMapping> readMappings(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException {
// Legacy
if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) {
if (path.getFileName().toString().toLowerCase().endsWith(".zip")) {
return MappingFormat.ENIGMA_ZIP.read(path, progress, saveParameters, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import com.google.common.io.MoreFiles;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
Expand Down Expand Up @@ -103,7 +102,7 @@ public static void main(String[] args) {

if (Files.isDirectory(mappingsFile)) {
mappingFormat = MappingFormat.ENIGMA_DIRECTORY;
} else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(mappingsFile))) {
} else if (mappingsFile.getFileName().toString().toLowerCase().endsWith(".zip")) {
mappingFormat = MappingFormat.ENIGMA_ZIP;
} else {
mappingFormat = MappingFormat.ENIGMA_FILE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Objects;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class ServerAddress {
public final String address;
Expand All @@ -23,7 +23,7 @@ public static ServerAddress of(String address, int port) {
return null;
}

if (address.equals("")) {
if (address.isEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cuchaz.enigma.gui;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.translation.representation.entry.ClassEntry;
import cuchaz.enigma.translation.representation.entry.Entry;
Expand Down
3 changes: 2 additions & 1 deletion enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.function.Consumer;
import java.util.function.Function;

import javax.annotation.Nullable;
import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
Expand All @@ -42,6 +41,8 @@
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.Enigma;
import cuchaz.enigma.EnigmaProfile;
import cuchaz.enigma.analysis.EntryReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
Expand All @@ -29,7 +30,6 @@
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import com.google.common.collect.Lists;
import org.jetbrains.annotations.ApiStatus;

import cuchaz.enigma.Enigma;
Expand Down Expand Up @@ -414,8 +414,8 @@ public void refreshClasses() {
return;
}

List<ClassEntry> obfClasses = Lists.newArrayList();
List<ClassEntry> deobfClasses = Lists.newArrayList();
List<ClassEntry> obfClasses = new ArrayList<>();
List<ClassEntry> deobfClasses = new ArrayList<>();
this.addSeparatedClasses(obfClasses, deobfClasses);
this.gui.setObfClasses(obfClasses);
this.gui.setDeobfClasses(deobfClasses);
Expand Down
3 changes: 1 addition & 2 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Set;

import com.google.common.io.MoreFiles;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
Expand Down Expand Up @@ -144,7 +143,7 @@ public static void main(String[] args) throws IOException {

if (Files.isDirectory(mappingsPath)) {
controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath);
} else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(mappingsPath))) {
} else if (mappingsPath.getFileName().toString().toLowerCase().endsWith(".zip")) {
controller.openMappings(MappingFormat.ENIGMA_ZIP, mappingsPath);
} else {
controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cuchaz.enigma.gui.config;

import java.awt.Font;
import java.nio.file.Files;

import cuchaz.enigma.gui.config.legacy.Config;

Expand All @@ -10,7 +11,7 @@ private OldConfigImporter() {

@SuppressWarnings("deprecation")
public static void doImport() {
if (Config.CONFIG_FILE.exists()) {
if (Files.exists(Config.CONFIG_FILE)) {
Config config = new Config();

if (config.editorFont != null) {
Expand Down
13 changes: 8 additions & 5 deletions enigma-swing/src/main/java/cuchaz/enigma/gui/config/Themes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.awt.Font;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.swing.UIManager;

import com.google.common.collect.ImmutableMap;
import de.sciss.syntaxpane.DefaultSyntaxKit;

import cuchaz.enigma.gui.EnigmaSyntaxKit;
Expand All @@ -30,7 +30,7 @@ public static void setupTheme() {
EnigmaSyntaxKit.invalidate();
DefaultSyntaxKit.initKit();
DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName());
ImmutableMap<RenamableTokenType, BoxHighlightPainter> boxHighlightPainters = getBoxHighlightPainters();
Map<RenamableTokenType, BoxHighlightPainter> boxHighlightPainters = getBoxHighlightPainters();
listeners.forEach(l -> l.onThemeChanged(laf, boxHighlightPainters));
ScaleUtil.applyScaling();
UiConfig.save();
Expand Down Expand Up @@ -85,9 +85,12 @@ private static void setFonts() {
}
}

public static ImmutableMap<RenamableTokenType, BoxHighlightPainter> getBoxHighlightPainters() {
return ImmutableMap.of(RenamableTokenType.OBFUSCATED, BoxHighlightPainter.create(UiConfig.getObfuscatedColor(), UiConfig.getObfuscatedOutlineColor()), RenamableTokenType.PROPOSED, BoxHighlightPainter.create(UiConfig.getProposedColor(), UiConfig.getProposedOutlineColor()),
RenamableTokenType.DEOBFUSCATED, BoxHighlightPainter.create(UiConfig.getDeobfuscatedColor(), UiConfig.getDeobfuscatedOutlineColor()));
public static Map<RenamableTokenType, BoxHighlightPainter> getBoxHighlightPainters() {
return Map.of(
RenamableTokenType.OBFUSCATED, BoxHighlightPainter.create(UiConfig.getObfuscatedColor(), UiConfig.getObfuscatedOutlineColor()),
RenamableTokenType.PROPOSED, BoxHighlightPainter.create(UiConfig.getProposedColor(), UiConfig.getProposedOutlineColor()),
RenamableTokenType.DEOBFUSCATED, BoxHighlightPainter.create(UiConfig.getDeobfuscatedColor(), UiConfig.getDeobfuscatedOutlineColor())
);
}

public static void addListener(ThemeChangeListener listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cuchaz.enigma.gui.config.legacy;

import java.awt.Color;
import java.io.File;
import java.io.BufferedReader;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;

import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
Expand Down Expand Up @@ -40,9 +40,9 @@ public Color get() {
}
}

private static final File DIR_HOME = new File(System.getProperty("user.home"));
private static final File ENIGMA_DIR = new File(DIR_HOME, ".enigma");
public static final File CONFIG_FILE = new File(ENIGMA_DIR, "config.json");
private static final Path DIR_HOME = Path.of(System.getProperty("user.home"));
private static final Path ENIGMA_DIR = DIR_HOME.resolve(".enigma");
public static final Path CONFIG_FILE = ENIGMA_DIR.resolve("config.json");

private final transient Gson gson; // transient to exclude it from being exposed

Expand Down Expand Up @@ -86,9 +86,9 @@ public Config() {
}

public void loadConfig() {
if (CONFIG_FILE.exists()) {
try {
gson.fromJson(Files.asCharSource(CONFIG_FILE, Charset.defaultCharset()).read(), Config.class);
if (Files.exists(CONFIG_FILE)) {
try (BufferedReader reader = Files.newBufferedReader(CONFIG_FILE)) {
gson.fromJson(reader, Config.class);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.awt.FlowLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Objects;

import javax.swing.JButton;
import javax.swing.JComboBox;
Expand All @@ -29,8 +30,6 @@
import javax.swing.WindowConstants;
import javax.swing.text.html.HTML;

import com.google.common.base.Strings;

import cuchaz.enigma.analysis.EntryReference;
import cuchaz.enigma.gui.GuiController;
import cuchaz.enigma.gui.config.UiConfig;
Expand Down Expand Up @@ -198,7 +197,7 @@ private EntryChange<?> getEntryChange() {
public static void show(JFrame parent, GuiController controller, EntryReference<Entry<?>, Entry<?>> entry) {
// Get the existing text through the mapping as it works for all entries, including constructors.
EntryMapping mapping = controller.project.getMapper().getDeobfMapping(entry.entry);
String text = Strings.nullToEmpty(mapping.javadoc());
String text = Objects.requireNonNullElse(mapping.javadoc(), "");

// Note: entry.entry is used instead of getNameableEntry() to include constructors,
// which can be documented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;

import javax.annotation.Nullable;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
Expand All @@ -13,6 +12,8 @@
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.analysis.ClassTreeNode;
import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
import cuchaz.enigma.analysis.MethodTreeNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.annotation.Nullable;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;

import com.google.common.collect.HashBiMap;
import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.analysis.EntryReference;
import cuchaz.enigma.classhandle.ClassHandle;
Expand All @@ -24,7 +25,7 @@

public class EditorTabbedPane {
private final JTabbedPane openFiles = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
private final HashBiMap<ClassEntry, EditorPanel> editors = HashBiMap.create();
private final Map<ClassEntry, EditorPanel> editors = new HashMap<>();

private final EditorTabPopupMenu editorTabPopupMenu;
private final Gui gui;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void keyPressed(KeyEvent e) {

public void closeEditor(EditorPanel ed) {
this.openFiles.remove(ed.getUi());
this.editors.inverse().remove(ed);
this.editors.values().remove(ed);
this.gui.showStructure(this.getActiveEditor());
ed.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cuchaz.enigma.gui.elements;

import javax.annotation.Nullable;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.renderer.ImplementationsTreeCellRenderer;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cuchaz.enigma.gui.elements;

import javax.annotation.Nullable;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.renderer.InheritanceTreeCellRenderer;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.gui.util.ScaleUtil;
import cuchaz.enigma.utils.validation.ParameterizedMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.awt.event.MouseEvent;

import javax.accessibility.AccessibleContext;
import javax.annotation.Nullable;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
Expand All @@ -19,6 +18,8 @@
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeListener;

import org.jetbrains.annotations.Nullable;

public class ClosableTabTitlePane {
private final JPanel ui;
private final JButton closeButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Nullable;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
Expand All @@ -36,6 +35,7 @@

import de.sciss.syntaxpane.DefaultSyntaxKit;
import de.sciss.syntaxpane.SyntaxDocument;
import org.jetbrains.annotations.Nullable;

import cuchaz.enigma.EnigmaProject;
import cuchaz.enigma.analysis.EntryReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -36,7 +37,6 @@
import javax.swing.tree.TreePath;

import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.google.common.collect.Lists;

import cuchaz.enigma.analysis.index.EntryIndex;
import cuchaz.enigma.gui.Gui;
Expand Down Expand Up @@ -172,7 +172,7 @@ public static Icon getMethodIcon(MethodEntry entry) {
}

public static TreePath getPathToRoot(TreeNode node) {
List<TreeNode> nodes = Lists.newArrayList();
List<TreeNode> nodes = new ArrayList<>();
TreeNode n = node;

do {
Expand Down
Loading