Skip to content

Commit

Permalink
style(gui): reformat code and fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jan 21, 2019
1 parent ffedaea commit bcaca78
Show file tree
Hide file tree
Showing 31 changed files with 256 additions and 289 deletions.
8 changes: 4 additions & 4 deletions jadx-gui/src/main/java/jadx/gui/JadxWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ public void run() {

/**
* Get the complete list of classes
* @return
*/
public List<JavaClass> getClasses() {
return decompiler.getClasses();
}

/**
* Get all classes that are not excluded by the excluded packages settings
* @return
*/
public List<JavaClass> getIncludedClasses() {
List<JavaClass> classList = decompiler.getClasses();
String excludedPackages = settings.getExcludedPackages().trim();
if (excludedPackages.length() == 0)
if (excludedPackages.length() == 0) {
return classList;
}
String[] excluded = excludedPackages.split("[ ]+");

return classList.stream().filter(cls -> {
for (String exclude : excluded) {
if (cls.getFullName().startsWith(exclude))
if (cls.getFullName().startsWith(exclude)) {
return false;
}
}
return true;
}).collect(Collectors.toList());
Expand Down
11 changes: 3 additions & 8 deletions jadx-gui/src/main/java/jadx/gui/jobs/BackgroundWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import javax.swing.*;
import java.util.concurrent.Future;

import jadx.gui.utils.NLS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jadx.gui.ui.ProgressPanel;
import jadx.gui.utils.CacheObject;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;
import jadx.gui.utils.search.TextSearchIndex;

Expand All @@ -27,12 +27,7 @@ public void exec() {
if (isDone()) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
progressPane.setVisible(true);
}
});
SwingUtilities.invokeLater(() -> progressPane.setVisible(true));
addPropertyChangeListener(progressPane);
execute();
}
Expand All @@ -46,7 +41,7 @@ public void stop() {
}

@Override
protected Void doInBackground() throws Exception {
protected Void doInBackground() {
try {
System.gc();
LOG.debug("Memory usage: Before decompile: {}", Utils.memoryInfo());
Expand Down
7 changes: 1 addition & 6 deletions jadx-gui/src/main/java/jadx/gui/jobs/DecompileJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ public DecompileJob(JadxWrapper wrapper, int threadsCount) {

protected void runJob() {
for (final JavaClass cls : wrapper.getIncludedClasses()) {
addTask(new Runnable() {
@Override
public void run() {
cls.decompile();
}
});
addTask(cls::decompile);
}
}

Expand Down
1 change: 0 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public boolean loadWindowPos(Window window) {
return true;
}


public boolean isShowHeapUsageBar() {
return showHeapUsageBar;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class JadxSettingsAdapter {

private static final Preferences PREFS = Preferences.userNodeForPackage(JadxGUI.class);

private static ExclusionStrategy EXCLUDE_FIELDS = new ExclusionStrategy() {
private static final ExclusionStrategy EXCLUDE_FIELDS = new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return JadxSettings.SKIP_FIELDS.contains(f.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package jadx.gui.settings;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
Expand Down Expand Up @@ -245,11 +243,11 @@ private SettingsGroup makeDecompilationGroup() {
});

JButton editExcludedPackages = new JButton(NLS.str("preferences.excludedPackages.button"));
editExcludedPackages.addActionListener( event -> {
editExcludedPackages.addActionListener(event -> {

String result = JOptionPane.showInputDialog(this, NLS.str("preferences.excludedPackages.editDialog"),
settings.getExcludedPackages());
if (result !=null) {
if (result != null) {
settings.setExcludedPackages(result);
}
});
Expand Down
46 changes: 23 additions & 23 deletions jadx-gui/src/main/java/jadx/gui/treemodel/ApkSignature.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
package jadx.gui.treemodel;

import javax.swing.*;
import java.io.File;
import java.security.cert.Certificate;
import java.util.List;
import java.util.stream.Collectors;

import com.android.apksig.ApkVerifier;
import jadx.api.ResourceType;
import jadx.gui.JadxWrapper;
import jadx.gui.utils.CertificateManager;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.io.File;
import java.security.cert.Certificate;
import java.util.List;
import java.util.stream.Collectors;
import jadx.gui.JadxWrapper;
import jadx.gui.utils.CertificateManager;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;

public class ApkSignature extends JNode {
private static final long serialVersionUID = -9121321926113143407L;

private static final Logger LOG = LoggerFactory.getLogger(ApkSignature.class);

private static final Logger log = LoggerFactory.getLogger(ApkSignature.class);
private static final ImageIcon CERTIFICATE_ICON = Utils.openIcon("certificate_obj");

private final transient File openFile;
private String content = null;
private String content;

public static ApkSignature getApkSignature(JadxWrapper wrapper) {
// Only show the ApkSignature node if an AndroidManifest.xml is present.
// Without a manifest the Google ApkVerifier refuses to work.
if (!wrapper.getResources().stream().anyMatch(r -> "AndroidManifest.xml".equals(r.getName()))) {
if (wrapper.getResources().stream().noneMatch(r -> "AndroidManifest.xml".equals(r.getName()))) {
return null;
}
File openFile = wrapper.getOpenFile();
Expand Down Expand Up @@ -56,8 +58,9 @@ public String makeString() {

@Override
public String getContent() {
if (content != null)
if (content != null) {
return this.content;
}
ApkVerifier verifier = new ApkVerifier.Builder(openFile).build();
try {
ApkVerifier.Result result = verifier.verify();
Expand All @@ -80,7 +83,7 @@ public String getContent() {
writeIssues(builder, err, result.getErrors());
writeIssues(builder, warn, result.getWarnings());

if (result.getV1SchemeSigners().size() > 0) {
if (!result.getV1SchemeSigners().isEmpty()) {
builder.append("<h2>");
builder.escape(String.format(result.isVerifiedUsingV1Scheme() ? sigSucc : sigFail, 1));
builder.append("</h2>\n");
Expand All @@ -101,7 +104,7 @@ public String getContent() {
}
builder.append("</blockquote>");
}
if (result.getV2SchemeSigners().size() > 0) {
if (!result.getV2SchemeSigners().isEmpty()) {
builder.append("<h2>");
builder.escape(String.format(result.isVerifiedUsingV2Scheme() ? sigSucc : sigFail, 2));
builder.append("</h2>\n");
Expand All @@ -121,7 +124,7 @@ public String getContent() {
}
this.content = builder.toString();
} catch (Exception e) {
log.error(e.getMessage(), e);
LOG.error(e.getMessage(), e);
StringEscapeUtils.Builder builder = StringEscapeUtils.builder(StringEscapeUtils.ESCAPE_HTML4);
builder.append("<h1>");
builder.escape(NLS.str("apkSignature.exception"));
Expand All @@ -147,15 +150,15 @@ private void writeCertificate(StringEscapeUtils.Builder builder, Certificate cer
}

private void writeIssues(StringEscapeUtils.Builder builder, String issueType, List<ApkVerifier.IssueWithParams> issueList) {
if (issueList.size() > 0) {
if (!issueList.isEmpty()) {
builder.append("<h3>");
builder.escape(issueType);
builder.append("</h3>");
builder.append("<blockquote>");
// Unprotected Zip entry issues are very common, handle them separately
List<ApkVerifier.IssueWithParams> unprotIssues = issueList.stream().filter(i ->
i.getIssue() == ApkVerifier.Issue.JAR_SIG_UNPROTECTED_ZIP_ENTRY).collect(Collectors.toList());
if (unprotIssues.size() > 0) {
if (!unprotIssues.isEmpty()) {
builder.append("<h4>");
builder.escape(NLS.str("apkSignature.unprotectedEntry"));
builder.append("</h4><blockquote>");
Expand All @@ -167,7 +170,7 @@ private void writeIssues(StringEscapeUtils.Builder builder, String issueType, Li
}
List<ApkVerifier.IssueWithParams> remainingIssues = issueList.stream().filter(i ->
i.getIssue() != ApkVerifier.Issue.JAR_SIG_UNPROTECTED_ZIP_ENTRY).collect(Collectors.toList());
if (remainingIssues.size() > 0) {
if (!remainingIssues.isEmpty()) {
builder.append("<pre>\n");
for (ApkVerifier.IssueWithParams issue : remainingIssues) {
builder.escape(issue.toString());
Expand All @@ -177,8 +180,5 @@ private void writeIssues(StringEscapeUtils.Builder builder, String issueType, Li
}
builder.append("</blockquote>");
}

}


}
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ List<JPackage> getHierarchyPackages(List<JavaPackage> packages) {
}
}
// use identity set for collect inner packages
Set<JPackage> innerPackages = Collections.newSetFromMap(new IdentityHashMap<JPackage, Boolean>());
Set<JPackage> innerPackages = Collections.newSetFromMap(new IdentityHashMap<>());
for (JPackage pkg : pkgMap.values()) {
innerPackages.addAll(pkg.getInnerPackages());
}
Expand Down
8 changes: 1 addition & 7 deletions jadx-gui/src/main/java/jadx/gui/ui/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import jadx.api.JadxDecompiler;
import jadx.gui.utils.NLS;
Expand Down Expand Up @@ -42,11 +40,7 @@ public final void initUI() {
textPane.add(Box.createRigidArea(new Dimension(0, 20)));

JButton close = new JButton(NLS.str("tabs.close"));
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
dispose();
}
});
close.addActionListener(event -> dispose());
close.setAlignmentX(0.5f);

Container contentPane = getContentPane();
Expand Down
6 changes: 3 additions & 3 deletions jadx-gui/src/main/java/jadx/gui/ui/CommonSearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import jadx.gui.treemodel.JNode;
import jadx.gui.ui.codearea.CodeArea;
import jadx.gui.utils.CacheObject;
import jadx.gui.utils.NLS;
import jadx.gui.utils.JumpPosition;
import jadx.gui.utils.NLS;
import jadx.gui.utils.search.TextSearchIndex;

public abstract class CommonSearchDialog extends JDialog {
private static final long serialVersionUID = 8939332306115370276L;

private static final Logger LOG = LoggerFactory.getLogger(CommonSearchDialog.class);
private static final long serialVersionUID = 8939332306115370276L;

public static final int RESULTS_PER_PAGE = 100;

Expand Down Expand Up @@ -399,7 +399,7 @@ protected class ResultsTableCellRenderer implements TableCellRenderer {
private final JLabel emptyLabel = new JLabel();
private final Color codeSelectedColor;
private final Color codeBackground;
private Map<Integer, Component> componentCache = new HashMap<>();
private final Map<Integer, Component> componentCache = new HashMap<>();

public ResultsTableCellRenderer() {
RSyntaxTextArea area = CodeArea.getDefaultArea(mainWindow);
Expand Down
33 changes: 14 additions & 19 deletions jadx-gui/src/main/java/jadx/gui/ui/HeapUsageBar.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
package jadx.gui.ui;

import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class HeapUsageBar extends JProgressBar implements ActionListener {

private static final double TWO_TO_20 = 1048576d; // 1024 * 1024

private final Color GREEN = new Color(0, 180, 0);
private final Color RED = new Color(200, 0, 0);
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils;

private final Runtime r;
public class HeapUsageBar extends JProgressBar implements ActionListener {
private static final long serialVersionUID = -8739563124249884967L;

private String maxHeapStr;
private static final double TWO_TO_20 = 1048576d;

private final Timer timer;
private static final Color GREEN = new Color(0, 180, 0);
private static final Color RED = new Color(200, 0, 0);

private final double maxGB;
private final transient Runtime runtime = Runtime.getRuntime();
private final transient Timer timer;

private final String textFormat;
private final double maxGB;

public HeapUsageBar() {
super();
textFormat = NLS.str("heapUsage.text");
r = Runtime.getRuntime();
this.textFormat = NLS.str("heapUsage.text");
setBorderPainted(false);
setStringPainted(true);
setValue(10);
int maxKB = (int) (r.maxMemory() / 1024);
int maxKB = (int) (runtime.maxMemory() / 1024);
setMaximum(maxKB);
maxGB = maxKB / TWO_TO_20;
update();
timer = new Timer(2000, this);
}

public void update() {
long used = r.totalMemory() - r.freeMemory();
long used = runtime.totalMemory() - runtime.freeMemory();
int usedKB = (int) (used / 1024);
setValue(usedKB);
setString(String.format(textFormat, (usedKB / TWO_TO_20), maxGB));

if ((used + Utils.MIN_FREE_MEMORY) > r.maxMemory()) {
if ((used + Utils.MIN_FREE_MEMORY) > runtime.maxMemory()) {
setForeground(RED);
} else {
setForeground(GREEN);
Expand Down
Loading

0 comments on commit bcaca78

Please sign in to comment.