|
|
|
@ -7,11 +7,11 @@ |
|
|
|
|
package com.keyware.sonar.java.rules.checkers; |
|
|
|
|
|
|
|
|
|
import org.sonar.check.Rule; |
|
|
|
|
import org.sonar.java.model.expression.IdentifierTreeImpl; |
|
|
|
|
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; |
|
|
|
|
import org.sonar.plugins.java.api.tree.*; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 上传文件检查规则 |
|
|
|
@ -99,35 +99,35 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
public void visitMethodInvocation(MethodInvocationTree tree) { |
|
|
|
|
//获取到方法调用的参数
|
|
|
|
|
ExpressionTree expressionTree = tree.methodSelect(); |
|
|
|
|
if (expressionTree instanceof MemberSelectExpressionTree) { |
|
|
|
|
if (expressionTree != null && expressionTree instanceof MemberSelectExpressionTree) { |
|
|
|
|
MemberSelectExpressionTree expressionTree1 = (MemberSelectExpressionTree) expressionTree; |
|
|
|
|
//对调用方法进行判断
|
|
|
|
|
if ("getOriginalFilename".equals(expressionTree1.identifier().toString())) { |
|
|
|
|
Tree parent = expressionTree1.parent(); |
|
|
|
|
if (parent instanceof MethodInvocationTree) { |
|
|
|
|
if (parent != null && parent instanceof MethodInvocationTree) { |
|
|
|
|
MethodInvocationTree memberSelectExpressionTree = (MethodInvocationTree) parent; |
|
|
|
|
Tree parent1 = memberSelectExpressionTree.parent(); |
|
|
|
|
if (parent1 instanceof VariableTree) { |
|
|
|
|
if (parent1 != null && parent1 instanceof VariableTree) { |
|
|
|
|
VariableTree variableTree = (VariableTree) parent1; |
|
|
|
|
fileName = variableTree.simpleName().toString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if ("extName".equals(expressionTree1.identifier().toString())) { |
|
|
|
|
Tree parent = expressionTree1.parent(); |
|
|
|
|
if (parent instanceof MethodInvocationTree) { |
|
|
|
|
if (parent != null && parent instanceof MethodInvocationTree) { |
|
|
|
|
MethodInvocationTree memberSelectExpressionTree = (MethodInvocationTree) parent; |
|
|
|
|
Tree parent1 = memberSelectExpressionTree.parent(); |
|
|
|
|
if (parent1 instanceof VariableTree) { |
|
|
|
|
if (parent1 != null && parent1 instanceof VariableTree) { |
|
|
|
|
VariableTree variableTree = (VariableTree) parent1; |
|
|
|
|
fileType = variableTree.simpleName().toString(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if ("getSize".equals(expressionTree1.identifier().toString())) { |
|
|
|
|
Tree parent = expressionTree1.parent(); |
|
|
|
|
if (parent instanceof MethodInvocationTree) { |
|
|
|
|
if (parent != null && parent instanceof MethodInvocationTree) { |
|
|
|
|
MethodInvocationTree memberSelectExpressionTree = (MethodInvocationTree) parent; |
|
|
|
|
Tree parent1 = memberSelectExpressionTree.parent(); |
|
|
|
|
if (parent1 instanceof VariableTree) { |
|
|
|
|
if (parent1 != null && parent1 instanceof VariableTree) { |
|
|
|
|
VariableTree variableTree = (VariableTree) parent1; |
|
|
|
|
sizeName = variableTree.simpleName().toString(); |
|
|
|
|
} |
|
|
|
@ -153,7 +153,7 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
public void visitIfStatement(IfStatementTree tree) { |
|
|
|
|
//获取到if表达式
|
|
|
|
|
ExpressionTree condition = tree.condition(); |
|
|
|
|
if (condition instanceof BinaryExpressionTree) { |
|
|
|
|
if (condition != null && condition instanceof BinaryExpressionTree) { |
|
|
|
|
BinaryExpressionTree binaryExpressionTree = (BinaryExpressionTree) condition; |
|
|
|
|
//判断是否进行if判断
|
|
|
|
|
if (name.equals(binaryExpressionTree.leftOperand().toString())) { |
|
|
|
@ -162,12 +162,12 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
boo = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (condition instanceof IdentifierTreeImpl) { |
|
|
|
|
IdentifierTreeImpl identifierTreeImpl = (IdentifierTreeImpl) condition; |
|
|
|
|
if (condition != null && condition instanceof IdentifierTree) { |
|
|
|
|
IdentifierTree identifierTree = (IdentifierTree) condition; |
|
|
|
|
//判断是否进行if判断
|
|
|
|
|
if (name.equals(identifierTreeImpl.name())) { |
|
|
|
|
if (name.equals(identifierTree.name())) { |
|
|
|
|
boo = false; |
|
|
|
|
} else if (name.equals(identifierTreeImpl.name())) { |
|
|
|
|
} else if (name.equals(identifierTree.name())) { |
|
|
|
|
boo = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -188,8 +188,8 @@ public class UploadFileVerifyChecker extends IssuableSubscriptionVisitor { |
|
|
|
|
public void visitVariable(VariableTree tree) { |
|
|
|
|
IdentifierTree identifierTree = tree.simpleName(); |
|
|
|
|
TypeTree type = tree.type(); |
|
|
|
|
if(type instanceof IdentifierTreeImpl){ |
|
|
|
|
IdentifierTreeImpl fierTree = (IdentifierTreeImpl) type; |
|
|
|
|
if(type != null && type instanceof IdentifierTree){ |
|
|
|
|
IdentifierTree fierTree = (IdentifierTree) type; |
|
|
|
|
if("Fileltem".equals(fierTree.name())){ |
|
|
|
|
NodeIf nodeIf = new NodeIf(identifierTree.name()); |
|
|
|
|
node.block().accept(nodeIf); |
|
|
|
|