Skip to content

Commit 2f063fe

Browse files
committed
optimize AST
- skip some nodes to make it more readable and improve performance - improve grammar
1 parent 19be9a5 commit 2f063fe

File tree

3 files changed

+188
-91
lines changed

3 files changed

+188
-91
lines changed

cxx-checks/src/main/java/org/sonar/cxx/checks/BooleanEqualityComparisonCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
public class BooleanEqualityComparisonCheck extends SquidCheck<Grammar> {
4343

4444
private static boolean hasBooleanLiteralOperand(AstNode node) {
45-
return node.hasDirectChildren(CxxGrammarImpl.LITERAL, CxxGrammarImpl.BOOL)
45+
return node.hasDirectChildren(CxxGrammarImpl.BOOL)
4646
&& node.hasDescendant(CxxKeyword.TRUE, CxxKeyword.FALSE);
4747
}
4848

cxx-checks/src/main/java/org/sonar/cxx/checks/UsingNamespaceInHeaderCheck.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static boolean isHeader(String name) {
5757

5858
@Override
5959
public void init() {
60-
subscribeTo(CxxGrammarImpl.blockDeclaration);
60+
subscribeTo(CxxGrammarImpl.usingDirective);
6161
}
6262

6363
@Override
@@ -67,8 +67,8 @@ public void visitFile(AstNode astNode) {
6767

6868
@Override
6969
public void visitNode(AstNode node) {
70-
if (isHeader && CxxKeyword.USING.equals(node.getToken().getType())) {
71-
final boolean containsNamespace = node.getFirstChild().getChildren().stream()
70+
if (isHeader) {
71+
final boolean containsNamespace = node.getChildren().stream()
7272
.anyMatch(childNode -> CxxKeyword.NAMESPACE.equals(childNode.getToken().getType()));
7373
if (containsNamespace) {
7474
getContext().createLineViolation(this, "Using namespace are not allowed in header files.", node);

0 commit comments

Comments
 (0)