自动化测试工具 求助:python 怎么解析出嵌套的 if 代码结构?

tongyuruo · 2017年02月14日 · 最后由 tongyuruo 回复于 2017年02月22日 · 1031 次阅读

本人在做个工具,目前需要解析 java 写的一部分代码,找到其他的 if 块和对应的 else 代码块?比如下面代码,需要解析出 if 包含的代码块,对应的 else 代码块.
我现在用队列,可以解析出不嵌套的 if 和 else 代码块,但是如果是嵌套的话,需要标记 if 对应的是哪个 else,这个不太好实现?不知道大家有没有好的建议?
public void testA(int a,int b) {
//ClassA classA = new ClassA(a,b);
int max = 3;
int c = 0;
if (max > 2){
c = 3;
if (a == 2)
System.out.println(2);
else
System.out.println(3);
}
else
System.out.println(max);
}

共收到 3 条回复 时间 点赞

建议你可以参考下开源的代码扫描工具

—— 来自 TesterHome 官方 安卓客户端

CC 回复

好的,多谢

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册