fix: conditions in ternary if (#449) (PR #558)

This commit is contained in:
Ahmed Ashour
2019-04-12 17:11:22 +02:00
committed by skylot
parent ac1d1a5858
commit eb77aa51b2
4 changed files with 217 additions and 2 deletions
@@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import jadx.core.dex.instructions.ArithNode;
import jadx.core.dex.instructions.ArithOp;
@@ -118,7 +119,7 @@ public final class IfCondition {
case COMPARE:
return new IfCondition(cond.getCompare().invert());
case TERNARY:
return ternary(not(cond.first()), cond.third(), cond.second());
return ternary(cond.first(), not(cond.second()), not(cond.third()));
case NOT:
return cond.first();
case AND:
@@ -137,6 +138,9 @@ public final class IfCondition {
if (cond.getMode() == Mode.NOT) {
return cond.first();
}
if (cond.getCompare() != null) {
return new IfCondition(cond.compare.invert());
}
return new IfCondition(Mode.NOT, Collections.singletonList(cond));
}
@@ -281,4 +285,30 @@ public final class IfCondition {
}
return "??";
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof IfCondition)) {
return false;
}
IfCondition other = (IfCondition) obj;
if (mode != other.mode) {
return false;
}
return Objects.equals(other.args, other.args)
&& Objects.equals(compare, other.compare);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + mode.hashCode();
result = 31 * result + args.hashCode();
result = 31 * result + (compare != null ? compare.hashCode() : 0);
return result;
}
}