style: fix some sonar and compiler warnings

This commit is contained in:
Skylot
2019-12-21 07:34:40 +00:00
parent c64ffde11f
commit 7f8d03d192
15 changed files with 84 additions and 39 deletions
@@ -188,7 +188,7 @@ public final class JadxDecompiler {
}
private void appendSourcesSave(ExecutorService executor, File outDir) {
final Predicate<String> classFilter = args.getClassFilter();
Predicate<String> classFilter = args.getClassFilter();
for (JavaClass cls : getClasses()) {
if (cls.getClassNode().contains(AFlag.DONT_GENERATE)) {
continue;
@@ -281,6 +281,9 @@ public final class JadxDecompiler {
root.getErrorsCounter().printReport();
}
/**
* Internal API. Not Stable!
*/
public RootNode getRoot() {
return root;
}
@@ -66,6 +66,9 @@ public final class JavaClass implements JavaNode {
listsLoaded = false;
}
/**
* Internal API. Not Stable!
*/
public ClassNode getClassNode() {
return cls;
}
@@ -174,8 +177,8 @@ public final class JavaClass implements JavaNode {
return cls.getFullName();
}
public String getRealFullName() {
return cls.getRealFullName();
public String getRawName() {
return cls.getRawName();
}
public String getPackage() {
@@ -42,10 +42,14 @@ public final class JavaField implements JavaNode {
return ArgType.tryToResolveClassAlias(field.dex(), field.getType());
}
@Override
public int getDecompiledLine() {
return field.getDecompiledLine();
}
/**
* Internal API. Not Stable!
*/
public FieldNode getFieldNode() {
return field;
}
@@ -70,10 +70,14 @@ public final class JavaMethod implements JavaNode {
return mth.getMethodInfo().isClassInit();
}
@Override
public int getDecompiledLine() {
return mth.getDecompiledLine();
}
/**
* Internal API. Not Stable!
*/
public MethodNode getMethodNode() {
return mth;
}
@@ -163,6 +163,7 @@ public final class ResourcesLoader {
}
}
@SuppressWarnings("CharsetObjectCanBeUsed")
public static ICodeInfo loadToCodeWriter(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(READ_BUFFER_SIZE);
copyStream(is, baos);
@@ -153,6 +153,7 @@ public class CodeWriter {
return this;
}
@SuppressWarnings("StringRepeatCanBeUsed")
private void updateIndent() {
int curIndent = indent;
if (curIndent < INDENT_CACHE.length) {
@@ -527,10 +527,6 @@ public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
return clsInfo.getAliasFullName();
}
public String getRealFullName() {
return clsInfo.getType().getObject();
}
public String getPackage() {
return clsInfo.getAliasPkg();
}
@@ -45,7 +45,7 @@ public class JadxWrapper {
}
}
public void saveAll(final File dir, final ProgressMonitor progressMonitor) {
public void saveAll(File dir, ProgressMonitor progressMonitor) {
Runnable save = () -> {
try {
decompiler.getArgs().setRootDir(dir);
@@ -141,19 +141,21 @@ public class JadxWrapper {
/**
* @param fullName Full name of an outer class. Inner classes are not supported.
* @return
*/
public @Nullable JavaClass searchJavaClassByClassName(String fullName) {
return decompiler.getClasses().stream().filter(cls -> cls.getFullName().equals(fullName))
.findFirst().orElse(null);
return decompiler.getClasses().stream()
.filter(cls -> cls.getFullName().equals(fullName))
.findFirst()
.orElse(null);
}
/**
* @param realName Real name of an outer class. Inner classes are not supported.
* @return
* @param rawName Full raw name of an outer class. Inner classes are not supported.
*/
public @Nullable JavaClass searchJavaClassByRealName(String realName) {
return decompiler.getClasses().stream().filter(cls -> cls.getRealFullName().equals(realName))
.findFirst().orElse(null);
public @Nullable JavaClass searchJavaClassByRawName(String rawName) {
return decompiler.getClasses().stream()
.filter(cls -> cls.getRawName().equals(rawName))
.findFirst()
.orElse(null);
}
}
@@ -71,7 +71,7 @@ public class JResource extends JLoadableNode implements Comparable<JResource> {
} else {
removeAllChildren();
Comparator<JResource> typeComparator = (r1, r2) -> r1.type.ordinal() - r2.type.ordinal();
Comparator<JResource> typeComparator = Comparator.comparingInt(r -> r.type.ordinal());
Comparator<JResource> nameComparator = Comparator.comparing(JResource::getName, String.CASE_INSENSITIVE_ORDER);
files.sort(typeComparator.thenComparing(nameComparator));
@@ -1,6 +1,12 @@
package jadx.gui.ui;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
@@ -26,7 +32,27 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.*;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.event.TreeExpansionEvent;
@@ -186,7 +212,7 @@ public class MainWindow extends JFrame {
}
JadxUpdate.check(new IUpdateCallback() {
@Override
public void onUpdate(final Release r) {
public void onUpdate(Release r) {
SwingUtilities.invokeLater(() -> {
updateLink.setText(NLS.str("menu.update_label", r.getName()));
updateLink.setVisible(true);
@@ -392,7 +418,7 @@ public class MainWindow extends JFrame {
String classRealName = "";
if (javaNode instanceof JavaClass) {
JavaClass javaClass = (JavaClass) javaNode;
classRealName = javaClass.getRealFullName();
classRealName = javaClass.getRawName();
}
@Nullable
JumpPosition position = entry.getValue().getTabbedPane().getCurrentPosition();
@@ -410,7 +436,7 @@ public class MainWindow extends JFrame {
String classRealName = entry.getKey();
int position = entry.getValue();
@Nullable
JavaClass newClass = wrapper.searchJavaClassByRealName(classRealName);
JavaClass newClass = wrapper.searchJavaClassByRawName(classRealName);
if (newClass == null) {
continue;
}
@@ -1047,7 +1073,7 @@ public class MainWindow extends JFrame {
recentProjects.removeAll();
File openFile = wrapper.getOpenFile();
Path currentPath = openFile == null ? null : openFile.toPath();
for (final Path path : settings.getRecentProjects()) {
for (Path path : settings.getRecentProjects()) {
if (!path.equals(currentPath)) {
JMenuItem menuItem = new JMenuItem(path.toAbsolutePath().toString());
recentProjects.add(menuItem);
@@ -24,7 +24,11 @@ import jadx.api.JavaNode;
import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.RootNode;
import jadx.core.utils.files.InputFile;
import jadx.gui.treemodel.*;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JField;
import jadx.gui.treemodel.JMethod;
import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JPackage;
import jadx.gui.ui.codearea.CodeArea;
import jadx.gui.utils.NLS;
import jadx.gui.utils.TextStandardActions;
@@ -91,7 +95,7 @@ public class RenameDialog extends JDialog {
id = javaNode.getFullName();
if (javaNode instanceof JavaClass) {
JavaClass javaClass = (JavaClass) javaNode;
id = javaClass.getRealFullName();
id = javaClass.getRawName();
}
} else if (node instanceof JPackage) {
@@ -104,29 +108,26 @@ public class RenameDialog extends JDialog {
private boolean updateDeobfMap(String renameText, RootNode root) {
Path deobfMapPath = getDeobfMapPath(root);
if (deobfMapPath == null) {
LOG.error("rename(): Failed deofbMapFile is null");
LOG.error("rename(): Failed deofbMapFile is null");
return false;
}
String alias = getNodeAlias(renameText);
LOG.info("rename(): " + alias);
LOG.info("rename(): {}", alias);
try {
List<String> deobfMap = readAndUpdateDeobfMap(deobfMapPath, alias);
File tmpFile = File.createTempFile("deobf_tmp_", ".txt");
FileOutputStream fileOut = new FileOutputStream(tmpFile);
for (String entry : deobfMap) {
fileOut.write(entry.getBytes());
fileOut.write(System.lineSeparator().getBytes());
try (FileOutputStream fileOut = new FileOutputStream(tmpFile)) {
for (String entry : deobfMap) {
fileOut.write(entry.getBytes());
fileOut.write(System.lineSeparator().getBytes());
}
}
fileOut.close();
File oldMap = File.createTempFile("deobf_bak_", ".txt");
Files.copy(deobfMapPath, oldMap.toPath(), StandardCopyOption.REPLACE_EXISTING);
Files.copy(tmpFile.toPath(), deobfMapPath, StandardCopyOption.REPLACE_EXISTING);
Files.delete(oldMap.toPath());
} catch (IOException e) {
LOG.error("rename(): Failed to write deofbMapFile {}", deobfMapPath);
e.printStackTrace();
} catch (Exception e) {
LOG.error("rename(): Failed to write deofbMapFile {}", deobfMapPath, e);
return false;
}
return true;
@@ -135,11 +136,11 @@ public class RenameDialog extends JDialog {
private List<String> readAndUpdateDeobfMap(Path deobfMapPath, String alias) throws IOException {
List<String> deobfMap = Files.readAllLines(deobfMapPath, StandardCharsets.UTF_8);
String id = alias.split("=")[0];
LOG.info("Id = " + id);
LOG.info("Id = {}", id);
int i = 0;
while (i < deobfMap.size()) {
if (deobfMap.get(i).startsWith(id)) {
LOG.info("Removing entry " + deobfMap.get(i));
LOG.info("Removing entry {}", deobfMap.get(i));
deobfMap.remove(i);
} else {
i++;
@@ -91,6 +91,7 @@ public abstract class AbstractCodeArea extends RSyntaxTextArea {
}
}
@SuppressWarnings("deprecation")
public void centerCurrentLine() {
JViewport viewport = (JViewport) SwingUtilities.getAncestorOfClass(JViewport.class, this);
if (viewport == null) {
@@ -11,6 +11,7 @@ import org.fife.ui.rsyntaxtextarea.Token;
import org.jetbrains.annotations.Nullable;
public abstract class JNodeMenuAction<T> extends AbstractAction implements PopupMenuListener {
private static final long serialVersionUID = -2600154727884853550L;
protected final transient CodeArea codeArea;
@Nullable
@@ -182,6 +182,7 @@ public class UiUtils {
public static final int CTRL_BNT_KEY = getCtrlButton();
@SuppressWarnings("deprecation")
@MagicConstant(flagsFromClass = InputEvent.class)
private static int getCtrlButton() {
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
@@ -9,6 +9,7 @@ public class TestTypeResolver2 extends AbstractTest {
private static String result = "";
@SuppressWarnings({ "UnnecessaryBoxing", "CachedNumberConstructorCall", "deprecation" })
public void testOverloadedMethods() {
Object s1 = "The";
Object s2 = "answer";