|
|
|
@ -10,17 +10,15 @@ import com.sonar.cxx.sslr.api.AstNode; |
|
|
|
|
import com.sonar.cxx.sslr.api.Grammar; |
|
|
|
|
import org.sonar.check.Priority; |
|
|
|
|
import org.sonar.check.Rule; |
|
|
|
|
import org.sonar.check.RuleProperty; |
|
|
|
|
import org.sonar.cxx.parser.CxxGrammarImpl; |
|
|
|
|
import org.sonar.cxx.squidbridge.annotations.ActivatedByDefault; |
|
|
|
|
import org.sonar.cxx.squidbridge.annotations.SqaleConstantRemediation; |
|
|
|
|
import org.sonar.cxx.squidbridge.checks.SquidCheck; |
|
|
|
|
|
|
|
|
|
import static com.sonar.cxx.sslr.api.GenericTokenType.IDENTIFIER; |
|
|
|
|
import static javax.swing.Action.DEFAULT; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* TODO ABCVarNameChecker |
|
|
|
|
* C++规则检查器的实现示例 |
|
|
|
|
* |
|
|
|
|
* @author GuoXin |
|
|
|
|
* @date 2024/1/6 |
|
|
|
@ -29,20 +27,23 @@ import static javax.swing.Action.DEFAULT; |
|
|
|
|
@ActivatedByDefault |
|
|
|
|
@SqaleConstantRemediation("5min") |
|
|
|
|
public class ABCVarNameChecker extends SquidCheck<Grammar> { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* format |
|
|
|
|
* 初始化规则检查器 |
|
|
|
|
*/ |
|
|
|
|
@RuleProperty( |
|
|
|
|
key = "format", |
|
|
|
|
defaultValue = "" + DEFAULT) |
|
|
|
|
public String format = DEFAULT; |
|
|
|
|
@Override |
|
|
|
|
public void init() { |
|
|
|
|
// 订阅要检查AST节点类型,用于在visitNode方法中检查该类型节点
|
|
|
|
|
this.subscribeTo( |
|
|
|
|
CxxGrammarImpl.declaratorId |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 检查AST节点 |
|
|
|
|
* |
|
|
|
|
* @param astNode 要处理的AST节点,该节点类型为通过subscribeTo方法订阅的类型 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void visitNode(AstNode astNode) { |
|
|
|
|
var idNode = astNode.getLastChild(IDENTIFIER); |
|
|
|
|