Commit 50d31444 authored by Skylot's avatar Skylot

core: fix code style

parent f8d57d92
......@@ -77,15 +77,15 @@ public class ClspGraph {
return clsName;
}
NClass cls = nameMap.get(implClsName);
if (cls != null) {
if (isImplements(clsName, implClsName)) {
return implClsName;
}
Set<String> anc = getAncestors(clsName);
return searchCommonParent(anc, cls);
if (cls == null) {
LOG.debug("Missing class: {}", implClsName);
return null;
}
LOG.debug("Missing class: {}", implClsName);
return null;
if (isImplements(clsName, implClsName)) {
return implClsName;
}
Set<String> anc = getAncestors(clsName);
return searchCommonParent(anc, cls);
}
private String searchCommonParent(Set<String> anc, NClass cls) {
......@@ -93,11 +93,10 @@ public class ClspGraph {
String name = p.getName();
if (anc.contains(name)) {
return name;
} else {
String r = searchCommonParent(anc, p);
if (r != null) {
return r;
}
}
String r = searchCommonParent(anc, p);
if (r != null) {
return r;
}
}
return null;
......@@ -109,17 +108,17 @@ public class ClspGraph {
return result;
}
NClass cls = nameMap.get(clsName);
if (cls != null) {
result = new HashSet<String>();
addAncestorsNames(cls, result);
if (result.isEmpty()) {
result = Collections.emptySet();
}
ancestorCache.put(clsName, result);
return result;
if (cls == null) {
LOG.debug("Missing class: {}", clsName);
return Collections.emptySet();
}
result = new HashSet<String>();
addAncestorsNames(cls, result);
if (result.isEmpty()) {
result = Collections.emptySet();
}
LOG.debug("Missing class: {}", clsName);
return Collections.emptySet();
ancestorCache.put(clsName, result);
return result;
}
private void addAncestorsNames(NClass cls, Set<String> result) {
......
......@@ -10,6 +10,7 @@ import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.regions.Compare;
import jadx.core.dex.regions.IfCondition;
import jadx.core.dex.regions.IfCondition.Mode;
import jadx.core.utils.ErrorsCounter;
import jadx.core.utils.exceptions.CodegenException;
import jadx.core.utils.exceptions.JadxRuntimeException;
......@@ -99,7 +100,7 @@ public class ConditionGen extends InsnGen {
}
private void addAndOr(CodeWriter code, IfCondition condition) throws CodegenException {
String mode = condition.getMode() == IfCondition.Mode.AND ? " && " : " || ";
String mode = condition.getMode() == Mode.AND ? " && " : " || ";
Iterator<IfCondition> it = condition.getArgs().iterator();
while (it.hasNext()) {
wrap(code, it.next());
......@@ -110,7 +111,7 @@ public class ConditionGen extends InsnGen {
}
private boolean isWrapNeeded(IfCondition condition) {
return !condition.isCompare() && condition.getMode() != IfCondition.Mode.NOT;
return !condition.isCompare() && condition.getMode() != Mode.NOT;
}
private static boolean isArgWrapNeeded(InsnArg arg) {
......
......@@ -58,7 +58,7 @@ public class InsnGen {
protected final RootNode root;
protected final boolean fallback;
private static enum Flags {
private enum Flags {
BODY_ONLY,
BODY_ONLY_NOWRAP,
}
......
......@@ -132,7 +132,7 @@ public class MethodGen {
if (type.isArray()) {
ArgType elType = type.getArrayElement();
classGen.useType(argsCode, elType);
argsCode.add(" ...");
argsCode.add("...");
} else {
LOG.warn(ErrorsCounter.formatErrorMsg(mth, "Last argument in varargs method not array"));
classGen.useType(argsCode, arg.getType());
......
......@@ -9,7 +9,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
public class TypeGen {
public static String signature(ArgType type) {
final PrimitiveType stype = type.getPrimitiveType();
PrimitiveType stype = type.getPrimitiveType();
if (stype == PrimitiveType.OBJECT) {
return Utils.makeQualifiedObjectName(type.getObject());
}
......
......@@ -6,7 +6,7 @@ import java.util.Map;
public class Annotation {
public static enum Visibility {
public enum Visibility {
BUILD, RUNTIME, SYSTEM
}
......
......@@ -53,7 +53,7 @@ public class EnumClassAttr implements IAttribute {
private MethodNode staticMethod;
public EnumClassAttr(int fieldsCount) {
this.fields = new ArrayList<EnumClassAttr.EnumField>(fieldsCount);
this.fields = new ArrayList<EnumField>(fieldsCount);
}
public List<EnumField> getFields() {
......
......@@ -8,7 +8,7 @@ public class AccessInfo {
private final int accFlags;
public static enum AFType {
public enum AFType {
CLASS, FIELD, METHOD
}
......
......@@ -17,7 +17,7 @@ public enum ArithOp {
private final String symbol;
private ArithOp(String symbol) {
ArithOp(String symbol) {
this.symbol = symbol;
}
......
......@@ -12,7 +12,7 @@ public enum IfOp {
private final String symbol;
private IfOp(String symbol) {
IfOp(String symbol) {
this.symbol = symbol;
}
......@@ -23,19 +23,19 @@ public enum IfOp {
public IfOp invert() {
switch (this) {
case EQ:
return IfOp.NE;
return NE;
case NE:
return IfOp.EQ;
return EQ;
case LT:
return IfOp.GE;
return GE;
case LE:
return IfOp.GT;
return GT;
case GT:
return IfOp.LE;
return LE;
case GE:
return IfOp.LT;
return LT;
default:
throw new JadxRuntimeException("Unknown if operations type: " + this);
......
......@@ -48,6 +48,10 @@ public abstract class ArgType {
ArgType.clsp = clsp;
}
public static boolean isClspSet() {
return ArgType.clsp != null;
}
private static ArgType primitive(PrimitiveType stype) {
return new PrimitiveArg(stype);
}
......@@ -174,7 +178,7 @@ public abstract class ArgType {
private final int bounds;
public WildcardType(ArgType obj, int bound) {
super(ArgType.OBJECT.getObject());
super(OBJECT.getObject());
this.type = obj;
this.bounds = bound;
}
......@@ -214,7 +218,7 @@ public abstract class ArgType {
if (bounds == 0) {
return "?";
}
return "? " + (bounds == -1 ? "super" : "extends") + " " + type.toString();
return "? " + (bounds == -1 ? "super" : "extends") + " " + type;
}
}
......@@ -398,7 +402,7 @@ public abstract class ArgType {
}
/**
* @see jadx.core.dex.instructions.args.ArgType.WildcardType#getWildcardBounds()
* @see WildcardType#getWildcardBounds()
*/
public int getWildcardBounds() {
return 0;
......@@ -513,7 +517,7 @@ public abstract class ArgType {
return OBJECT;
} else {
ArgType res = merge(ea, eb);
return res == null ? null : ArgType.array(res);
return res == null ? null : array(res);
}
} else if (b.equals(OBJECT)) {
return OBJECT;
......
......@@ -2,7 +2,7 @@ package jadx.core.dex.instructions.args;
public class MthParameterArg extends RegisterArg {
private boolean isThis = false;
private boolean isThis;
public MthParameterArg(int rn, ArgType type) {
super(rn, type);
......
......@@ -16,7 +16,7 @@ public enum PrimitiveType {
private final String shortName;
private final String longName;
private PrimitiveType(String shortName, String longName) {
PrimitiveType(String shortName, String longName) {
this.shortName = shortName;
this.longName = longName;
}
......
......@@ -14,7 +14,7 @@ public class ConstructorInsn extends InsnNode {
private final CallType callType;
private final RegisterArg instanceArg;
private static enum CallType {
private enum CallType {
CONSTRUCTOR, // just new instance
SUPER, // super call
THIS, // call constructor from other constructor
......
......@@ -48,11 +48,13 @@ public class RootNode {
}
private static void initClassPath(List<ClassNode> classes) throws IOException, DecodeException {
ClspGraph clsp = new ClspGraph();
clsp.load();
clsp.addApp(classes);
if (!ArgType.isClspSet()) {
ClspGraph clsp = new ClspGraph();
clsp.load();
clsp.addApp(classes);
ArgType.setClsp(clsp);
ArgType.setClsp(clsp);
}
}
private void initInnerClasses(List<ClassNode> classes) {
......
......@@ -20,7 +20,7 @@ import com.android.dex.Dex.Section;
public class AnnotationsParser {
private static final Annotation.Visibility[] VISIBILITIES = {
private static final Visibility[] VISIBILITIES = {
Visibility.BUILD,
Visibility.RUNTIME,
Visibility.SYSTEM
......
......@@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory;
final class LocalVar {
private static final Logger LOG = LoggerFactory.getLogger(LocalVar.class);
private int regNum;
private final int regNum;
private String name;
private ArgType type;
......
......@@ -20,7 +20,7 @@ import java.util.List;
public final class IfCondition {
public static enum Mode {
public enum Mode {
COMPARE,
NOT,
AND,
......
......@@ -7,6 +7,7 @@ import jadx.core.dex.nodes.IContainer;
import jadx.core.dex.nodes.IRegion;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.regions.IfCondition;
import jadx.core.dex.regions.IfCondition.Mode;
import jadx.core.dex.regions.IfRegion;
import jadx.core.dex.regions.Region;
import jadx.core.dex.visitors.AbstractVisitor;
......@@ -58,7 +59,7 @@ public class IfRegionVisitor extends AbstractVisitor implements IRegionVisitor,
private static void simplifyIfCondition(IfRegion ifRegion) {
if (ifRegion.simplifyCondition()) {
IfCondition condition = ifRegion.getCondition();
if (condition.getMode() == IfCondition.Mode.NOT) {
if (condition.getMode() == Mode.NOT) {
invertIfRegion(ifRegion);
}
}
......
......@@ -403,12 +403,12 @@ public class RegionMaker {
// select 'then', 'else' and 'exit' blocks
if (bElse.getPredecessors().size() != 1
&& BlockUtils.isPathExists(bThen, bElse)) {
&& isPathExists(bThen, bElse)) {
thenBlock = bThen;
elseBlock = null;
out = bElse;
} else if (bThen.getPredecessors().size() != 1
&& BlockUtils.isPathExists(bElse, bThen)) {
&& isPathExists(bElse, bThen)) {
ifnode.invertCondition();
thenBlock = ifnode.getThenBlock();
elseBlock = null;
......@@ -511,7 +511,7 @@ public class RegionMaker {
for (BlockNode maybeOut : block.getSuccessors()) {
boolean allReached = true;
for (BlockNode s : block.getSuccessors()) {
if (!BlockUtils.isPathExists(s, maybeOut)) {
if (!isPathExists(s, maybeOut)) {
allReached = false;
break;
}
......
......@@ -51,6 +51,11 @@ public abstract class InternalJadxTest extends TestUtils {
}
// don't unload class
checkCode(cls);
return cls;
}
private static void checkCode(ClassNode cls) {
assertTrue("Inconsistent cls: " + cls,
!cls.contains(AFlag.INCONSISTENT_CODE) && !cls.contains(AType.JADX_ERROR));
for (MethodNode mthNode : cls.getMethods()) {
......@@ -58,7 +63,6 @@ public abstract class InternalJadxTest extends TestUtils {
!mthNode.contains(AFlag.INCONSISTENT_CODE) && !mthNode.contains(AType.JADX_ERROR));
}
assertThat(cls.getCode().toString(), not(containsString("inconsistent")));
return cls;
}
protected List<IDexTreeVisitor> getPasses() {
......
......@@ -5,6 +5,9 @@ import jadx.core.codegen.CodeWriter;
public class TestUtils {
public static String indent(int indent) {
if (indent == 1) {
return CodeWriter.INDENT;
}
StringBuilder sb = new StringBuilder(indent * CodeWriter.INDENT.length());
for (int i = 0; i < indent; i++) {
sb.append(CodeWriter.INDENT);
......
......@@ -5,6 +5,7 @@ import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
......@@ -52,13 +53,14 @@ public class TestAnnotations extends InternalJadxTest {
System.out.println(code);
assertThat(code, not(containsString("@A(a = 255)")));
assertThat(code, containsString("@A(a = -1)"));
assertThat(code, containsString("@A(a = -253)"));
assertThat(code, containsString("@A(a = -11253)"));
assertThat(code, containsString("@V(false)"));
assertThat(code, containsOne("@A(a = -1)"));
assertThat(code, containsOne("@A(a = -253)"));
assertThat(code, containsOne("@A(a = -11253)"));
assertThat(code, containsOne("@V(false)"));
assertThat(code, not(containsString("@D()")));
assertThat(code, containsOne("@D"));
assertThat(code, containsString("int a();"));
assertThat(code, containsString("float value() default 1.1f;"));
assertThat(code, containsOne("int a();"));
assertThat(code, containsOne("float value() default 1.1f;"));
}
}
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