|
|
|
@ -9,6 +9,7 @@ package com.keyware.sonar.cxx; |
|
|
|
|
import com.sonar.cxx.sslr.api.AstNode; |
|
|
|
|
import com.sonar.cxx.sslr.api.AstNodeType; |
|
|
|
|
import com.sonar.cxx.sslr.api.Grammar; |
|
|
|
|
import org.sonar.cxx.squidbridge.SquidAstVisitor; |
|
|
|
|
import org.sonar.cxx.squidbridge.checks.SquidCheck; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
@ -19,13 +20,15 @@ import java.util.List; |
|
|
|
|
* @author GuoXin |
|
|
|
|
* @date 2024/1/13 |
|
|
|
|
*/ |
|
|
|
|
public abstract class SubscriptionAstVisitor extends SquidCheck<Grammar> { |
|
|
|
|
public abstract class SubscriptionAstVisitor extends SquidAstVisitor<Grammar> { |
|
|
|
|
private SquidCheck<Grammar> checker; |
|
|
|
|
/** |
|
|
|
|
* 构造函数需要传入初代访问器 |
|
|
|
|
* |
|
|
|
|
* @param checker 初代规则检查器 |
|
|
|
|
*/ |
|
|
|
|
public SubscriptionAstVisitor(SquidCheck<Grammar> checker) { |
|
|
|
|
this.checker = checker; |
|
|
|
|
setContext(checker.getContext()); |
|
|
|
|
visitNodeTypes().forEach(this::subscribeTo); |
|
|
|
|
} |
|
|
|
@ -95,7 +98,7 @@ public abstract class SubscriptionAstVisitor extends SquidCheck<Grammar> { |
|
|
|
|
* @param messageParameters 可选消息参数(请参阅 java.text.MessageFormat) |
|
|
|
|
*/ |
|
|
|
|
protected void reportIssue(String message, Object... messageParameters) { |
|
|
|
|
getContext().createFileViolation(this, message, messageParameters); |
|
|
|
|
getContext().createFileViolation(checker, message, messageParameters); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -106,7 +109,7 @@ public abstract class SubscriptionAstVisitor extends SquidCheck<Grammar> { |
|
|
|
|
* @param messageParameters 可选消息参数(请参阅 java.text.MessageFormat) |
|
|
|
|
*/ |
|
|
|
|
protected void reportIssue(AstNode node, String message, Object... messageParameters) { |
|
|
|
|
getContext().createLineViolation(this, message, node, messageParameters); |
|
|
|
|
getContext().createLineViolation(checker, message, node, messageParameters); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|