Commit 7cdb0318 authored by Skylot's avatar Skylot

style: resolve some sonar warnings

parent 17d8516d
......@@ -247,29 +247,27 @@ public class JadxArgs {
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("JadxArgs{");
sb.append("inputFiles=").append(inputFiles);
sb.append(", outDir=").append(outDir);
sb.append(", outDirSrc=").append(outDirSrc);
sb.append(", outDirRes=").append(outDirRes);
sb.append(", threadsCount=").append(threadsCount);
sb.append(", cfgOutput=").append(cfgOutput);
sb.append(", rawCFGOutput=").append(rawCFGOutput);
sb.append(", fallbackMode=").append(fallbackMode);
sb.append(", showInconsistentCode=").append(showInconsistentCode);
sb.append(", useImports=").append(useImports);
sb.append(", isSkipResources=").append(isSkipResources);
sb.append(", isSkipSources=").append(isSkipSources);
sb.append(", isDeobfuscationOn=").append(isDeobfuscationOn);
sb.append(", isDeobfuscationForceSave=").append(isDeobfuscationForceSave);
sb.append(", useSourceNameAsClassAlias=").append(useSourceNameAsClassAlias);
sb.append(", deobfuscationMinLength=").append(deobfuscationMinLength);
sb.append(", deobfuscationMaxLength=").append(deobfuscationMaxLength);
sb.append(", escapeUnicode=").append(escapeUnicode);
sb.append(", replaceConsts=").append(replaceConsts);
sb.append(", respectBytecodeAccModifiers=").append(respectBytecodeAccModifiers);
sb.append(", exportAsGradleProject=").append(exportAsGradleProject);
sb.append('}');
return sb.toString();
return "JadxArgs{" + "inputFiles=" + inputFiles +
", outDir=" + outDir +
", outDirSrc=" + outDirSrc +
", outDirRes=" + outDirRes +
", threadsCount=" + threadsCount +
", cfgOutput=" + cfgOutput +
", rawCFGOutput=" + rawCFGOutput +
", fallbackMode=" + fallbackMode +
", showInconsistentCode=" + showInconsistentCode +
", useImports=" + useImports +
", isSkipResources=" + isSkipResources +
", isSkipSources=" + isSkipSources +
", isDeobfuscationOn=" + isDeobfuscationOn +
", isDeobfuscationForceSave=" + isDeobfuscationForceSave +
", useSourceNameAsClassAlias=" + useSourceNameAsClassAlias +
", deobfuscationMinLength=" + deobfuscationMinLength +
", deobfuscationMaxLength=" + deobfuscationMaxLength +
", escapeUnicode=" + escapeUnicode +
", replaceConsts=" + replaceConsts +
", respectBytecodeAccModifiers=" + respectBytecodeAccModifiers +
", exportAsGradleProject=" + exportAsGradleProject +
'}';
}
}
......@@ -97,7 +97,7 @@ public class TypeGen {
if (s == Short.MIN_VALUE) {
return "Short.MIN_VALUE";
}
return "(short) " + Short.toString(s);
return "(short) " + s;
}
public static String formatByte(byte b) {
......@@ -107,7 +107,7 @@ public class TypeGen {
if (b == Byte.MIN_VALUE) {
return "Byte.MIN_VALUE";
}
return "(byte) " + Byte.toString(b);
return "(byte) " + b;
}
public static String formatInteger(int i) {
......
......@@ -4,5 +4,5 @@ import jadx.core.dex.info.MethodInfo;
public interface CallMthInterface {
public MethodInfo getCallMth();
MethodInfo getCallMth();
}
package jadx.core.dex.instructions.args;
import java.util.Objects;
import org.jetbrains.annotations.Nullable;
import jadx.core.dex.info.FieldInfo;
......@@ -68,7 +70,7 @@ public final class FieldArg extends RegisterArg {
if (!field.equals(fieldArg.field)) {
return false;
}
return instArg != null ? instArg.equals(fieldArg.instArg) : fieldArg.instArg == null;
return Objects.equals(instArg, fieldArg.instArg);
}
@Override
......
......@@ -151,9 +151,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
list.add(resultArg);
}
insnNode.getRegisterArgs(list);
int argsCount = list.size();
for (int i = 0; i < argsCount; i++) {
if (list.get(i).getRegNum() >= regsCount) {
for (RegisterArg arg : list) {
if (arg.getRegNum() >= regsCount) {
throw new JadxRuntimeException("Incorrect register number in instruction: " + insnNode
+ ", expected to be less than " + regsCount);
}
......
......@@ -150,7 +150,6 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
if (replace) {
insn.add(AFlag.ARITH_ONEARG);
// insn.getResult().mergeName(arg);
}
}
}
......
......@@ -24,7 +24,6 @@ import jadx.core.dex.instructions.args.FieldArg;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.mods.ConstructorInsn;
import jadx.core.dex.instructions.mods.TernaryInsn;
import jadx.core.dex.nodes.BlockNode;
......
......@@ -29,7 +29,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
public class BlockSplitter extends AbstractVisitor {
// leave these instructions alone in block node
public static final Set<InsnType> SEPARATE_INSNS = EnumSet.of(
private static final Set<InsnType> SEPARATE_INSNS = EnumSet.of(
InsnType.RETURN,
InsnType.IF,
InsnType.SWITCH,
......@@ -38,6 +38,10 @@ public class BlockSplitter extends AbstractVisitor {
InsnType.THROW
);
public static boolean makeSeparate(InsnType insnType) {
return SEPARATE_INSNS.contains(insnType);
}
@Override
public void visit(MethodNode mth) {
if (mth.isNoCode()) {
......@@ -85,7 +89,7 @@ public class BlockSplitter extends AbstractVisitor {
InsnType type = prevInsn.getType();
if (type == InsnType.GOTO
|| type == InsnType.THROW
|| SEPARATE_INSNS.contains(type)) {
|| makeSeparate(type)) {
if (type == InsnType.RETURN || type == InsnType.THROW) {
mth.addExitBlock(curBlock);
......@@ -98,7 +102,7 @@ public class BlockSplitter extends AbstractVisitor {
startNew = true;
} else {
startNew = isSplitByJump(prevInsn, insn)
|| SEPARATE_INSNS.contains(insn.getType())
|| makeSeparate(insn.getType())
|| isDoWhile(blocksMap, curBlock, insn)
|| insn.contains(AType.EXC_HANDLER)
|| prevInsn.contains(AFlag.TRY_LEAVE)
......
......@@ -167,7 +167,7 @@ public class TernaryMod {
}
PhiInsn tPhi = t.getResult().getSVar().getUsedInPhi();
PhiInsn ePhi = e.getResult().getSVar().getUsedInPhi();
if (tPhi == null || ePhi == null || tPhi != ePhi) {
if (ePhi == null || tPhi != ePhi) {
return false;
}
Map<Integer, Integer> map = new HashMap<>(tPhi.getArgsCount());
......
......@@ -321,7 +321,7 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
if (reg.getSVar() == var) {
BlockNode blockNode = entry.getValue();
InsnNode lastInsn = BlockUtils.getLastInsn(blockNode);
if (lastInsn != null && BlockSplitter.SEPARATE_INSNS.contains(lastInsn.getType())) {
if (lastInsn != null && BlockSplitter.makeSeparate(lastInsn.getType())) {
if (Consts.DEBUG) {
LOG.warn("Can't insert move for PHI in block with separate insn: {}", lastInsn);
}
......
......@@ -154,7 +154,6 @@ public class Utils {
}
}
@SuppressWarnings("unchecked")
public static <T> List<T> lockList(List<T> list) {
if (list.isEmpty()) {
return Collections.emptyList();
......
......@@ -18,11 +18,8 @@ import jadx.core.xmlgen.entry.ResourceEntry;
import jadx.core.xmlgen.entry.ValuesParser;
public class ResTableParser extends CommonBinaryParser {
private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class);
private static final int KNOWN_CONFIG_BYTES = 56;
private static final class PackageChunk {
private final int id;
private final String name;
......@@ -150,9 +147,7 @@ public class ResTableParser extends CommonBinaryParser {
}
PackageChunk pkg = new PackageChunk(id, name, typeStrings, keyStrings);
//if (id == 0x7F) {
resStorage.setAppPackage(name);
//}
while (is.getPos() < endPos) {
long chunkStart = is.getPos();
......@@ -198,7 +193,7 @@ public class ResTableParser extends CommonBinaryParser {
if (config.isInvalid) {
String typeName = pkg.getTypeStrings()[id - 1];
LOG.warn("Invalid config flags detected: " + typeName + config.getQualifiers());
LOG.warn("Invalid config flags detected: {}{}", typeName, config.getQualifiers());
}
int[] entryIndexes = new int[entryCount];
......@@ -260,8 +255,6 @@ public class ResTableParser extends CommonBinaryParser {
throw new IOException("Config size < 28");
}
boolean isInvalid = false;
short mcc = (short) is.readInt16();
short mnc = (short) is.readInt16();
......@@ -321,7 +314,7 @@ public class ResTableParser extends CommonBinaryParser {
inputFlags, screenWidth, screenHeight, sdkVersion,
screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp,
screenHeightDp, localeScript, localeVariant, screenLayout2,
colorMode, isInvalid, size);
colorMode, false, size);
}
private char[] unpackLocaleOrRegion(byte in0, byte in1, char base) {
......
......@@ -39,7 +39,7 @@ public class TestRedundantBrackets extends IntegrationTest {
}
}
public void method5(int a[], int n) {
public void method5(int[] a, int n) {
a[1] = n * 2;
a[n - 1] = 1;
}
......
......@@ -13,7 +13,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class TestAnnotations extends IntegrationTest {
public static class TestCls {
private static @interface A {
private @interface A {
int a();
}
......@@ -29,7 +29,7 @@ public class TestAnnotations extends IntegrationTest {
public void methodA3() {
}
private static @interface V {
private @interface V {
boolean value();
}
......@@ -37,7 +37,7 @@ public class TestAnnotations extends IntegrationTest {
public void methodV() {
}
private static @interface D {
private @interface D {
float value() default 1.1f;
}
......
......@@ -41,7 +41,7 @@ public class TestAnnotationsMix extends IntegrationTest {
assertTrue(ma.getAnnotations().length > 0);
MyAnnotation a = (MyAnnotation) ma.getAnnotations()[0];
assertEquals(7, a.num());
assertSame(a.state(), Thread.State.TERMINATED);
assertSame(Thread.State.TERMINATED, a.state());
return true;
}
......
......@@ -8,7 +8,6 @@ import jadx.tests.api.IntegrationTest;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestTernary extends IntegrationTest {
......@@ -18,12 +17,14 @@ public class TestTernary extends IntegrationTest {
}
public void test2(int a) {
assertTrue(a == 3);
checkTrue(a == 3);
}
public int test3(int a) {
return a > 0 ? a : (a + 2) * 3;
}
private static void checkTrue(boolean v) {}
}
@Test
......@@ -33,7 +34,7 @@ public class TestTernary extends IntegrationTest {
assertThat(code, not(containsString("else")));
assertThat(code, containsString("return a != 2;"));
assertThat(code, containsString("assertTrue(a == 3)"));
assertThat(code, containsString("checkTrue(a == 3)"));
assertThat(code, containsString("return a > 0 ? a : (a + 2) * 3;"));
}
}
......@@ -20,7 +20,7 @@ public class TestEnums3 extends IntegrationTest {
private final int num;
private Numbers(int n) {
Numbers(int n) {
this.num = n;
}
......
......@@ -24,7 +24,7 @@ public class TestEnums4 extends IntegrationTest {
private final String[] exts;
private ResType(String... extensions) {
ResType(String... extensions) {
this.exts = extensions;
}
......
......@@ -22,7 +22,7 @@ public class TestEnumsInterface extends IntegrationTest {
public int apply(int x, int y) {
return x - y;
}
};
}
}
public interface IOperation {
......
......@@ -7,7 +7,7 @@ import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestInnerClass5 extends IntegrationTest {
......@@ -83,8 +83,8 @@ public class TestInnerClass5 extends IntegrationTest {
}
public void check() throws Exception {
assertTrue(new I0().i().equals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a"));
assertTrue(i0.equals("i1"));
assertEquals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a", new I0().i());
assertEquals("i1", i0);
}
}
......
......@@ -21,6 +21,7 @@ public class TestSameMethodsNames extends IntegrationTest {
System.out.println("constructor");
}
@SuppressWarnings("MethodNameSameAsClassName")
void Bug() {
System.out.println("Bug");
}
......
......@@ -8,6 +8,7 @@ import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestTryCatchInIf extends IntegrationTest {
......@@ -33,7 +34,7 @@ public class TestTryCatchInIf extends IntegrationTest {
}
public void check() {
assertEquals(null, test("n", null));
assertNull(test("n", null));
assertEquals("n=7", test("n", "7"));
assertEquals("n=77", test("n", "0x" + Integer.toHexString(77)));
assertEquals("Failed to parse number", test("n", "abc"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment