|
|
|
@ -38,7 +38,7 @@ public class RedirectUrlChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
// 判断方法的返回节点的类型为RedirectView 或 String 类型
|
|
|
|
|
if ("RedirectView".equals(methodTree.returnType().toString())) { |
|
|
|
|
// 传递上下文,和方法的参数列表
|
|
|
|
|
new RedirectViewCheckVisitor(this, parameters).check(block); |
|
|
|
|
block.accept(new RedirectViewCheckVisitor(this, parameters)); |
|
|
|
|
} else if ("String".equals(methodTree.returnType().toString())) { |
|
|
|
|
checkByStringType(block, parameters); |
|
|
|
|
} |
|
|
|
@ -110,7 +110,7 @@ public class RedirectUrlChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class RedirectViewCheckVisitor extends IssuableSubscriptionVisitor { |
|
|
|
|
static class RedirectViewCheckVisitor extends BaseTreeVisitor { |
|
|
|
|
private final RedirectUrlChecker checker; |
|
|
|
|
// 方法的参数列表
|
|
|
|
|
private final List<? extends VariableTree> methodParameters; |
|
|
|
@ -120,40 +120,28 @@ public class RedirectUrlChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
this.methodParameters = parameters; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void check(Tree block) { |
|
|
|
|
this.scanTree(block); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<Tree.Kind> nodesToVisit() { |
|
|
|
|
// 订阅new class和 函数调用的节点
|
|
|
|
|
var nodeType = new Tree.Kind[]{Tree.Kind.NEW_CLASS, Tree.Kind.METHOD_INVOCATION}; |
|
|
|
|
return Arrays.asList(nodeType); |
|
|
|
|
public void visitNewClass(NewClassTree classTree) { |
|
|
|
|
// 判断是否为RedirectView,如果是,则判断是否有参数,如果有参数,则判断参数的类型是否由方法传递进来的
|
|
|
|
|
String name = classTree.identifier().toString(); |
|
|
|
|
if ("RedirectView".equals(name)) { |
|
|
|
|
if (classTree.arguments().size() > 0) { |
|
|
|
|
// 获取第一个参数语法树节点
|
|
|
|
|
ExpressionTree argNode = classTree.arguments().get(0); |
|
|
|
|
checkArgs(argNode, classTree); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void visitNode(Tree tree) { |
|
|
|
|
if (tree.is(Tree.Kind.NEW_CLASS)) { |
|
|
|
|
NewClassTree classTree = (NewClassTree) tree; |
|
|
|
|
// 判断是否为RedirectView,如果是,则判断是否有参数,如果有参数,则判断参数的类型是否由方法传递进来的
|
|
|
|
|
String name = classTree.identifier().toString(); |
|
|
|
|
if ("RedirectView".equals(name)) { |
|
|
|
|
if (classTree.arguments().size() > 0) { |
|
|
|
|
// 获取第一个参数语法树节点
|
|
|
|
|
ExpressionTree argNode = classTree.arguments().get(0); |
|
|
|
|
checkArgs(argNode, tree); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
MethodInvocationTree invocationTree = (MethodInvocationTree) tree; |
|
|
|
|
ExpressionTree expressionTree = invocationTree.methodSelect(); |
|
|
|
|
if (expressionTree instanceof MemberSelectExpressionTree) { |
|
|
|
|
MemberSelectExpressionTree member = (MemberSelectExpressionTree) expressionTree; |
|
|
|
|
if (member.expression().symbolType().is("RedirectView") |
|
|
|
|
&& "setUrl".equals(member.identifier().name())) { |
|
|
|
|
ExpressionTree argNode = invocationTree.arguments().get(0); |
|
|
|
|
checkArgs(argNode, tree); |
|
|
|
|
} |
|
|
|
|
public void visitMethodInvocation(MethodInvocationTree invocationTree) { |
|
|
|
|
ExpressionTree expressionTree = invocationTree.methodSelect(); |
|
|
|
|
if (expressionTree instanceof MemberSelectExpressionTree) { |
|
|
|
|
MemberSelectExpressionTree member = (MemberSelectExpressionTree) expressionTree; |
|
|
|
|
if (member.expression().symbolType().is("RedirectView") |
|
|
|
|
&& "setUrl".equals(member.identifier().name())) { |
|
|
|
|
ExpressionTree argNode = invocationTree.arguments().get(0); |
|
|
|
|
checkArgs(argNode, invocationTree); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|