gui: fix some sonar warnings
This commit is contained in:
@@ -24,6 +24,10 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
jar {
|
||||
version = jadxVersion
|
||||
manifest {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package jadx.core.codegen;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jadx.core.dex.instructions.ArithNode;
|
||||
import jadx.core.dex.instructions.IfOp;
|
||||
import jadx.core.dex.instructions.InsnType;
|
||||
@@ -15,13 +22,6 @@ import jadx.core.utils.ErrorsCounter;
|
||||
import jadx.core.utils.exceptions.CodegenException;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConditionGen extends InsnGen {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConditionGen.class);
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ConditionGen extends InsnGen {
|
||||
wrap(code, firstArg);
|
||||
return;
|
||||
}
|
||||
LOG.warn(ErrorsCounter.formatErrorMsg(mth, "Unsupported boolean condition " + op.getSymbol()));
|
||||
ErrorsCounter.methodError(mth, "Unsupported boolean condition " + op.getSymbol());
|
||||
}
|
||||
|
||||
addArg(code, firstArg, isArgWrapNeeded(firstArg));
|
||||
@@ -179,6 +179,9 @@ public class ConditionGen extends InsnGen {
|
||||
case DIV:
|
||||
case REM:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
switch (insnType) {
|
||||
@@ -189,10 +192,10 @@ public class ConditionGen extends InsnGen {
|
||||
case CONST:
|
||||
case ARRAY_LENGTH:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class NameMapper {
|
||||
"(" + VALID_JAVA_IDENTIFIER + "\\.)*" + VALID_JAVA_IDENTIFIER);
|
||||
|
||||
private static final Set<String> RESERVED_NAMES = new HashSet<>(
|
||||
Arrays.asList(new String[]{
|
||||
Arrays.asList(
|
||||
"abstract",
|
||||
"assert",
|
||||
"boolean",
|
||||
@@ -67,8 +67,8 @@ public class NameMapper {
|
||||
"try",
|
||||
"void",
|
||||
"volatile",
|
||||
"while",
|
||||
})
|
||||
"while"
|
||||
)
|
||||
);
|
||||
|
||||
public static boolean isReserved(String str) {
|
||||
@@ -96,4 +96,7 @@ public class NameMapper {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private NameMapper() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
package jadx.core.dex.nodes;
|
||||
|
||||
import jadx.core.dex.info.ClassInfo;
|
||||
import jadx.core.dex.info.FieldInfo;
|
||||
import jadx.core.dex.info.MethodInfo;
|
||||
import jadx.core.dex.instructions.args.ArgType;
|
||||
import jadx.core.utils.exceptions.DecodeException;
|
||||
import jadx.core.utils.files.DexFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.android.dex.ClassData;
|
||||
import com.android.dex.ClassData.Method;
|
||||
import com.android.dex.ClassDef;
|
||||
@@ -26,6 +16,14 @@ import com.android.dex.FieldId;
|
||||
import com.android.dex.MethodId;
|
||||
import com.android.dex.ProtoId;
|
||||
import com.android.dex.TypeList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.core.dex.info.ClassInfo;
|
||||
import jadx.core.dex.info.FieldInfo;
|
||||
import jadx.core.dex.info.MethodInfo;
|
||||
import jadx.core.dex.instructions.args.ArgType;
|
||||
import jadx.core.utils.files.DexFile;
|
||||
|
||||
public class DexNode implements IDexNode {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DepthTraversal {
|
||||
visit(visitor, mth);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
ErrorsCounter.classError(cls,
|
||||
e.getClass().getSimpleName() + " in pass: " + visitor.getClass().getSimpleName(), e);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class DepthTraversal {
|
||||
}
|
||||
try {
|
||||
visitor.visit(mth);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
ErrorsCounter.methodError(mth,
|
||||
e.getClass().getSimpleName() + " in pass: " + visitor.getClass().getSimpleName(), e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -26,12 +27,12 @@ public class ErrorsCounter {
|
||||
return errorsCount;
|
||||
}
|
||||
|
||||
private void addError(IAttributeNode node, String msg, Throwable e) {
|
||||
private synchronized void addError(IAttributeNode node, String msg, @Nullable Throwable e) {
|
||||
errorNodes.add(node);
|
||||
errorsCount++;
|
||||
|
||||
if (e != null) {
|
||||
if (e.getClass() == JadxOverflowException.class) {
|
||||
if (e instanceof JadxOverflowException) {
|
||||
// don't print full stack trace
|
||||
e = new JadxOverflowException(e.getMessage());
|
||||
LOG.error("{}, message: {}", msg, e.getMessage());
|
||||
|
||||
@@ -195,8 +195,8 @@ public class FileUtils {
|
||||
makeDirs(testDir);
|
||||
if (caseCheckUpper.createNewFile()) {
|
||||
boolean caseSensitive = !caseCheckLow.exists();
|
||||
LOG.debug("Filesystem at {} is {} case-sensitive", testDir.getAbsolutePath(),
|
||||
(caseSensitive ? "" : "NOT"));
|
||||
LOG.debug("Filesystem at {} is {}case-sensitive", testDir.getAbsolutePath(),
|
||||
(caseSensitive ? "" : "NOT "));
|
||||
return caseSensitive;
|
||||
} else {
|
||||
LOG.debug("Failed to create file: {}", caseCheckUpper.getAbsolutePath());
|
||||
|
||||
@@ -10,11 +10,17 @@ import jadx.core.dex.instructions.args.LiteralArg;
|
||||
import jadx.core.dex.regions.conditions.Compare;
|
||||
import jadx.core.dex.regions.conditions.IfCondition;
|
||||
|
||||
import static jadx.core.dex.instructions.args.LiteralArg.TRUE;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.Mode;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.Mode.AND;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.Mode.COMPARE;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.Mode.NOT;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.Mode.OR;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.merge;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.not;
|
||||
import static jadx.core.dex.regions.conditions.IfCondition.simplify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestIfCondition {
|
||||
|
||||
@@ -41,10 +47,10 @@ public class TestIfCondition {
|
||||
IfCondition c = makeCondition(IfOp.NE, a, LiteralArg.FALSE);
|
||||
IfCondition simp = simplify(c);
|
||||
|
||||
assertEquals(simp.getMode(), Mode.COMPARE);
|
||||
assertThat(simp.getMode(), is(COMPARE));
|
||||
Compare compare = simp.getCompare();
|
||||
assertEquals(compare.getA(), a);
|
||||
assertEquals(compare.getB(), LiteralArg.TRUE);
|
||||
assertThat(compare.getA(), is(a));
|
||||
assertThat(compare.getB(), is(TRUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,23 +59,23 @@ public class TestIfCondition {
|
||||
IfCondition b = makeSimpleCondition();
|
||||
IfCondition c = merge(Mode.OR, a, b);
|
||||
|
||||
assertEquals(c.getMode(), Mode.OR);
|
||||
assertEquals(c.first(), a);
|
||||
assertEquals(c.second(), b);
|
||||
assertThat(c.getMode(), is(OR));
|
||||
assertThat(c.first(), is(a));
|
||||
assertThat(c.second(), is(b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplifyNot() {
|
||||
// !(!a) => a
|
||||
IfCondition a = not(not(makeSimpleCondition()));
|
||||
assertEquals(simplify(a), a);
|
||||
assertThat(simplify(a), is(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplifyNot2() {
|
||||
// !(!a) => a
|
||||
IfCondition a = not(makeNegCondition());
|
||||
assertEquals(simplify(a), a);
|
||||
assertThat(simplify(a), is(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,9 +86,9 @@ public class TestIfCondition {
|
||||
IfCondition c = not(merge(Mode.OR, not(a), not(b)));
|
||||
IfCondition simp = simplify(c);
|
||||
|
||||
assertEquals(simp.getMode(), Mode.AND);
|
||||
assertEquals(simp.first(), a);
|
||||
assertEquals(simp.second(), b);
|
||||
assertThat(simp.getMode(), is(AND));
|
||||
assertThat(simp.first(), is(a));
|
||||
assertThat(simp.second(), is(b));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,12 +100,12 @@ public class TestIfCondition {
|
||||
IfCondition cond = merge(Mode.AND, merge(Mode.OR, not(a), not(b)), not(c));
|
||||
IfCondition simp = simplify(cond);
|
||||
|
||||
assertEquals(simp.getMode(), Mode.NOT);
|
||||
assertThat(simp.getMode(), is(NOT));
|
||||
IfCondition f = simp.first();
|
||||
assertEquals(f.getMode(), Mode.OR);
|
||||
assertEquals(f.first().getMode(), Mode.AND);
|
||||
assertEquals(f.first().first(), a);
|
||||
assertEquals(f.first().second(), b);
|
||||
assertEquals(f.second(), c);
|
||||
assertThat(f.getMode(), is(OR));
|
||||
assertThat(f.first().getMode(), is(AND));
|
||||
assertThat(f.first().first(), is(a));
|
||||
assertThat(f.first().second(), is(b));
|
||||
assertThat(f.second(), is(c));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ import jadx.core.dex.nodes.MethodNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -39,12 +40,12 @@ public class TestDuplicateCast extends IntegrationTest {
|
||||
assertThat(code, containsString("return (int[]) o;"));
|
||||
|
||||
List<InsnNode> insns = mth.getBasicBlocks().get(1).getInstructions();
|
||||
assertEquals(insns.size(), 1);
|
||||
assertThat(insns, hasSize(1));
|
||||
InsnNode insnNode = insns.get(0);
|
||||
assertEquals(InsnType.RETURN, insnNode.getType());
|
||||
assertThat(insnNode.getType(), is(InsnType.RETURN));
|
||||
assertTrue(insnNode.getArg(0).isInsnWrap());
|
||||
InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn();
|
||||
assertEquals(InsnType.CHECK_CAST, wrapInsn.getType());
|
||||
assertThat(wrapInsn.getType(), is(InsnType.CHECK_CAST));
|
||||
assertFalse(wrapInsn.getArg(0).isInsnWrap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package jadx.gui.jobs;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -39,13 +38,10 @@ public abstract class BackgroundJob {
|
||||
|
||||
private class ShutdownTask extends FutureTask<Boolean> {
|
||||
public ShutdownTask() {
|
||||
super(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
runJob();
|
||||
executor.shutdown();
|
||||
return executor.awaitTermination(5, TimeUnit.MINUTES);
|
||||
}
|
||||
super(() -> {
|
||||
runJob();
|
||||
executor.shutdown();
|
||||
return executor.awaitTermination(1, TimeUnit.HOURS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
@@ -143,7 +145,7 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
protected JPanel initResultsTable() {
|
||||
ResultsTableCellRenderer renderer = new ResultsTableCellRenderer();
|
||||
resultsModel = new ResultsModel(renderer);
|
||||
resultsModel.addTableModelListener((e) -> updateProgressLabel());
|
||||
resultsModel.addTableModelListener(e -> updateProgressLabel());
|
||||
resultsTable = new ResultsTable(resultsModel);
|
||||
resultsTable.setShowHorizontalLines(false);
|
||||
resultsTable.setDragEnabled(false);
|
||||
@@ -183,24 +185,24 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
|
||||
|
||||
JPanel paginationPanel = new JPanel();
|
||||
paginationPanel.setAlignmentX( Component.LEFT_ALIGNMENT );
|
||||
paginationPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
paginationPanel.setLayout(new BoxLayout(paginationPanel, BoxLayout.X_AXIS));
|
||||
resultsInfoLabel = new JLabel("");
|
||||
|
||||
JButton nextPageButton = new JButton("->");
|
||||
nextPageButton.setToolTipText(NLS.str("search_dialog.next_page"));
|
||||
nextPageButton.addActionListener((e) -> {
|
||||
nextPageButton.addActionListener(e -> {
|
||||
resultsModel.nextPage();
|
||||
resultsTable.updateTable();
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0,0,1,1));
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
|
||||
});
|
||||
|
||||
JButton prevPageButton = new JButton("<-");
|
||||
prevPageButton.setToolTipText(NLS.str("search_dialog.prev_page"));
|
||||
prevPageButton.addActionListener((e) -> {
|
||||
prevPageButton.addActionListener(e -> {
|
||||
resultsModel.prevPage();
|
||||
resultsTable.updateTable();
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0,0,1,1));
|
||||
resultsTable.scrollRectToVisible(new Rectangle(0, 0, 1, 1));
|
||||
});
|
||||
|
||||
paginationPanel.add(prevPageButton);
|
||||
@@ -309,8 +311,9 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
}
|
||||
|
||||
public int getDisplayedResultsStart() {
|
||||
if (rows.size() == 0)
|
||||
if (rows.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return start + 1;
|
||||
}
|
||||
|
||||
@@ -373,7 +376,7 @@ public abstract class CommonSearchDialog extends JDialog {
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected,
|
||||
boolean hasFocus, int row, int column) {
|
||||
boolean hasFocus, int row, int column) {
|
||||
int id = row << 2 | column;
|
||||
Component comp = componentCache.get(id);
|
||||
if (comp == null) {
|
||||
|
||||
@@ -27,8 +27,6 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -501,12 +499,7 @@ public class MainWindow extends JFrame {
|
||||
|
||||
flatPkgButton = new JToggleButton(ICON_FLAT_PKG);
|
||||
flatPkgButton.setSelected(isFlattenPackage);
|
||||
ActionListener flatPkgAction = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleFlattenPackage();
|
||||
}
|
||||
};
|
||||
ActionListener flatPkgAction = e -> toggleFlattenPackage();
|
||||
flatPkgMenuItem.addActionListener(flatPkgAction);
|
||||
flatPkgButton.addActionListener(flatPkgAction);
|
||||
flatPkgButton.setToolTipText(NLS.str("menu.flatten"));
|
||||
@@ -568,8 +561,8 @@ public class MainWindow extends JFrame {
|
||||
tree.setCellRenderer(new DefaultTreeCellRenderer() {
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree,
|
||||
Object value, boolean selected, boolean expanded,
|
||||
boolean isLeaf, int row, boolean focused) {
|
||||
Object value, boolean selected, boolean expanded,
|
||||
boolean isLeaf, int row, boolean focused) {
|
||||
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
|
||||
if (value instanceof JNode) {
|
||||
setIcon(((JNode) value).getIcon());
|
||||
@@ -660,7 +653,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void menuSelected(MenuEvent e) {
|
||||
public void menuSelected(MenuEvent menuEvent) {
|
||||
recentFiles.removeAll();
|
||||
File openFile = wrapper.getOpenFile();
|
||||
String currentFile = openFile == null ? "" : openFile.getAbsolutePath();
|
||||
@@ -670,12 +663,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
JMenuItem menuItem = new JMenuItem(file);
|
||||
recentFiles.add(menuItem);
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
openFile(new File(file));
|
||||
}
|
||||
});
|
||||
menuItem.addActionListener(e -> openFile(new File(file)));
|
||||
}
|
||||
if (recentFiles.getItemCount() == 0) {
|
||||
recentFiles.add(new JMenuItem(NLS.str("menu.no_recent_files")));
|
||||
|
||||
@@ -6,11 +6,8 @@ import javax.swing.event.DocumentListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jadx.gui.utils.NLS;
|
||||
@@ -28,7 +25,7 @@ public class SearchDialog extends CommonSearchDialog {
|
||||
CODE
|
||||
}
|
||||
|
||||
private Set<SearchOptions> options = EnumSet.allOf(SearchOptions.class);
|
||||
private Set<SearchOptions> options;
|
||||
|
||||
private JTextField searchField;
|
||||
private JCheckBox caseChBox;
|
||||
@@ -87,7 +84,6 @@ public class SearchDialog extends CommonSearchDialog {
|
||||
}
|
||||
|
||||
private class SearchFieldListener implements DocumentListener, ActionListener {
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private synchronized void change() {
|
||||
@@ -126,11 +122,7 @@ public class SearchDialog extends CommonSearchDialog {
|
||||
new TextStandardActions(searchField);
|
||||
|
||||
caseChBox = new JCheckBox(NLS.str("search_dialog.ignorecase"));
|
||||
caseChBox.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
performSearch();
|
||||
}
|
||||
});
|
||||
caseChBox.addItemListener(e -> performSearch());
|
||||
|
||||
JCheckBox clsChBox = makeOptionsCheckBox(NLS.str("search_dialog.class"), SearchOptions.CLASS);
|
||||
JCheckBox mthChBox = makeOptionsCheckBox(NLS.str("search_dialog.method"), SearchOptions.METHOD);
|
||||
@@ -196,15 +188,13 @@ public class SearchDialog extends CommonSearchDialog {
|
||||
final JCheckBox chBox = new JCheckBox(name);
|
||||
chBox.setAlignmentX(LEFT_ALIGNMENT);
|
||||
chBox.setSelected(options.contains(opt));
|
||||
chBox.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (chBox.isSelected()) {
|
||||
options.add(opt);
|
||||
} else {
|
||||
options.remove(opt);
|
||||
}
|
||||
performSearch();
|
||||
chBox.addItemListener(e -> {
|
||||
if (chBox.isSelected()) {
|
||||
options.add(opt);
|
||||
} else {
|
||||
options.remove(opt);
|
||||
}
|
||||
performSearch();
|
||||
});
|
||||
return chBox;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
public class CodeIndex<T> implements SearchIndex<T> {
|
||||
|
||||
private final List<StringRef> keys = new ArrayList<>();
|
||||
private final List<T> values = new ArrayList<T>();
|
||||
private final List<T> values = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void put(String str, T value) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
public class SimpleIndex<T> implements SearchIndex<T> {
|
||||
|
||||
private final List<String> keys = new ArrayList<>();
|
||||
private final List<T> values = new ArrayList<T>();
|
||||
private final List<T> values = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void put(String str, T value) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package jadx.gui.utils.search;
|
||||
|
||||
import static jadx.gui.utils.Utils.caseChar;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static jadx.gui.utils.Utils.caseChar;
|
||||
|
||||
public class StringRef implements CharSequence {
|
||||
|
||||
private final String refStr;
|
||||
@@ -82,8 +83,8 @@ public class StringRef implements CharSequence {
|
||||
}
|
||||
|
||||
private static int indexOf(String source, int sourceOffset, int sourceCount,
|
||||
String target, int targetOffset, int targetCount,
|
||||
int fromIndex, boolean caseInsensitive) {
|
||||
String target, int targetOffset, int targetCount,
|
||||
int fromIndex, boolean caseInsensitive) {
|
||||
if (fromIndex >= sourceCount) {
|
||||
return (targetCount == 0 ? sourceCount : -1);
|
||||
}
|
||||
@@ -187,5 +188,4 @@ public class StringRef implements CharSequence {
|
||||
int offset = this.offset;
|
||||
return refStr.substring(offset, offset + len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -12,10 +12,12 @@ import jadx.api.JadxDecompiler;
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
import jadx.gui.JadxWrapper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -25,7 +27,7 @@ public class JSourcesTest {
|
||||
private JadxDecompiler decompiler;
|
||||
|
||||
@Before
|
||||
public void init() throws JadxException {
|
||||
public void init() {
|
||||
JRoot root = mock(JRoot.class);
|
||||
when(root.isFlatPackages()).thenReturn(false);
|
||||
JadxWrapper wrapper = mock(JadxWrapper.class);
|
||||
@@ -37,50 +39,50 @@ public class JSourcesTest {
|
||||
public void testHierarchyPackages() {
|
||||
String pkgName = "a.b.c.d.e";
|
||||
|
||||
List<JavaPackage> packages = Arrays.asList(newPkg(pkgName));
|
||||
List<JavaPackage> packages = Collections.singletonList(newPkg(pkgName));
|
||||
List<JPackage> out = sources.getHierarchyPackages(packages);
|
||||
|
||||
assertEquals(out.size(), 1);
|
||||
JPackage jpkg = out.get(0);
|
||||
assertEquals(jpkg.getName(), pkgName);
|
||||
assertEquals(jpkg.getClasses().size(), 1);
|
||||
assertThat(out, hasSize(1));
|
||||
JPackage jPkg = out.get(0);
|
||||
assertThat(jPkg.getName(), is(pkgName));
|
||||
assertThat(jPkg.getClasses(), hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchyPackages2() {
|
||||
List<JavaPackage> packages = Arrays.asList(
|
||||
List<JavaPackage> packages = asList(
|
||||
newPkg("a.b"),
|
||||
newPkg("a.c"),
|
||||
newPkg("a.d")
|
||||
);
|
||||
List<JPackage> out = sources.getHierarchyPackages(packages);
|
||||
|
||||
assertEquals(out.size(), 1);
|
||||
JPackage jpkg = out.get(0);
|
||||
assertEquals(jpkg.getName(), "a");
|
||||
assertEquals(jpkg.getClasses().size(), 0);
|
||||
assertEquals(jpkg.getInnerPackages().size(), 3);
|
||||
assertThat(out, hasSize(1));
|
||||
JPackage jPkg = out.get(0);
|
||||
assertThat(jPkg.getName(), is("a"));
|
||||
assertThat(jPkg.getClasses(), hasSize(0));
|
||||
assertThat(jPkg.getInnerPackages(), hasSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchyPackages3() {
|
||||
List<JavaPackage> packages = Arrays.asList(
|
||||
List<JavaPackage> packages = asList(
|
||||
newPkg("a.b.p1"),
|
||||
newPkg("a.b.p2"),
|
||||
newPkg("a.b.p3")
|
||||
);
|
||||
List<JPackage> out = sources.getHierarchyPackages(packages);
|
||||
|
||||
assertEquals(out.size(), 1);
|
||||
JPackage jpkg = out.get(0);
|
||||
assertEquals(jpkg.getName(), "a.b");
|
||||
assertEquals(jpkg.getClasses().size(), 0);
|
||||
assertEquals(jpkg.getInnerPackages().size(), 3);
|
||||
assertThat(out, hasSize(1));
|
||||
JPackage jPkg = out.get(0);
|
||||
assertThat(jPkg.getName(), is("a.b"));
|
||||
assertThat(jPkg.getClasses(), hasSize(0));
|
||||
assertThat(jPkg.getInnerPackages(), hasSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchyPackages4() {
|
||||
List<JavaPackage> packages = Arrays.asList(
|
||||
List<JavaPackage> packages = asList(
|
||||
newPkg("a.p1"),
|
||||
newPkg("a.b.c.p2"),
|
||||
newPkg("a.b.c.p3"),
|
||||
@@ -89,19 +91,18 @@ public class JSourcesTest {
|
||||
);
|
||||
List<JPackage> out = sources.getHierarchyPackages(packages);
|
||||
|
||||
assertEquals(out.size(), 2);
|
||||
assertEquals(out.get(0).getName(), "a");
|
||||
assertEquals(out.get(0).getInnerPackages().size(), 2);
|
||||
assertEquals(out.get(1).getName(), "d");
|
||||
assertEquals(out.get(1).getInnerPackages().size(), 2);
|
||||
assertThat(out, hasSize(2));
|
||||
assertThat(out.get(0).getName(), is("a"));
|
||||
assertThat(out.get(0).getInnerPackages(), hasSize(2));
|
||||
assertThat(out.get(1).getName(), is("d"));
|
||||
assertThat(out.get(1).getInnerPackages(), hasSize(2));
|
||||
}
|
||||
|
||||
private JavaPackage newPkg(String name) {
|
||||
return Factory.newPackage(name, Arrays.asList(newClass()));
|
||||
return Factory.newPackage(name, Collections.singletonList(newClass()));
|
||||
}
|
||||
|
||||
private JavaClass newClass() {
|
||||
return Factory.newClass(decompiler, mock(ClassNode.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user