コード例 #1
0
void CyclomaticComplexityRule::apply(CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet) {
    Decl *decl = CursorHelper::getDecl(node);
    if (decl && (isa<ObjCMethodDecl>(decl) || isa<FunctionDecl>(decl))) {
        int ccn = CyclomaticComplexityMeasurement::getCCNOfCursor(node);
        if (ccn > maxAllowedCCN()) {
            Violation violation(node, this);
            violationSet.addViolation(violation);
        }
    }
}
コード例 #2
0
ファイル: RawResultsTest.cpp プロジェクト: Abioy/oclint
TEST(ResultsTest, NumberOfViolations)
{
    ResultsTest_ResultsStub collector;
    RawResults results(collector);
    ViolationSet *violationSetWithOneViolation = new ViolationSet();
    Violation violation1(new MockRuleBaseOne(), "", 1, 2, 3, 4);
    violationSetWithOneViolation->addViolation(violation1);
    collector.add(violationSetWithOneViolation);
    EXPECT_THAT(results.numberOfViolations(), Eq(1));
    collector.add(new ViolationSet());
    EXPECT_THAT(results.numberOfViolations(), Eq(1));
    ViolationSet *violationSetWithTwoViolations = new ViolationSet();
    Violation violation2(new MockRuleBaseOne(), "", 1, 2, 3, 4);
    Violation violation3(new MockRuleBaseTwo(), "", 1, 2, 3, 4);
    violationSetWithTwoViolations->addViolation(violation2);
    violationSetWithTwoViolations->addViolation(violation3);
    collector.add(violationSetWithTwoViolations);
    EXPECT_THAT(results.numberOfViolations(), Eq(3));
}
コード例 #3
0
TEST(ResultCollectorTest, ViolationSetsInCollection)
{
    ResultCollector *results = new ResultCollectorTest_ResultCollectorStub();
    ViolationSet *violationSetWithOneViolation = new ViolationSet();
    Violation violation1(new MockRuleBaseOne(), "", 1, 2, 3, 4);
    violationSetWithOneViolation->addViolation(violation1);
    results->add(violationSetWithOneViolation);
    EXPECT_EQ(1, results->getCollection().size());
    EXPECT_EQ(*violationSetWithOneViolation, *results->getCollection()[0]);
    results->add(new ViolationSet());
    EXPECT_EQ(2, results->getCollection().size());
    EXPECT_EQ(ViolationSet(), *results->getCollection()[1]);
    ViolationSet *violationSetWithTwoViolations = new ViolationSet();
    Violation violation2(new MockRuleBaseOne(), "", 1, 2, 3, 4);
    Violation violation3(new MockRuleBaseTwo(), "", 1, 2, 3, 4);
    violationSetWithTwoViolations->addViolation(violation2);
    violationSetWithTwoViolations->addViolation(violation3);
    results->add(violationSetWithTwoViolations);
    EXPECT_EQ(3, results->getCollection().size());
    EXPECT_EQ(*violationSetWithTwoViolations, *results->getCollection()[2]);
}
コード例 #4
0
void RedundantLocalVariableRule::apply(CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet) {
  Stmt *stmt = CursorHelper::getStmt(node);
  Stmt *parentStmt = CursorHelper::getStmt(parentNode);
  if (stmt && parentStmt) {
    NamedDecl *returnDeclRef = extractFromReturnStmt(stmt);
    NamedDecl *namedDecl = extractFromDeclStmt(parentStmt);
    if (returnDeclRef && namedDecl && returnDeclRef->getName().equals(namedDecl->getName())) {
      Violation violation(node, this);
      violationSet.addViolation(violation);
    }
  }
}
コード例 #5
0
ファイル: NPathComplexityRule.cpp プロジェクト: BlackMac/mo
void NPathComplexityRule::apply(
  CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet)
{
  Decl *decl = CursorHelper::getDecl(node);
  if (decl && isMethodDefination(decl) && isMethodNPathHigh(node))
  {
    string description = "NPath Complexity Number "
      + StringHelper::convertIntToString(getNPathOfCursor(node))
      + " exceeds limit of "
      + StringHelper::convertIntToString(maxAllowedNPath()) + ".";
    violationSet.addViolation(node, this, description);
  }
}
コード例 #6
0
ファイル: EmptyIfStatementRule.cpp プロジェクト: BlackMac/mo
void EmptyIfStatementRule::apply(
  CXCursor& node, CXCursor& parentNode, ViolationSet& violationSet)
{
  Stmt *stmt = CursorHelper::getStmt(node);
  if (stmt)
  {
    IfStmt *ifStmt = dyn_cast<IfStmt>(stmt);
    if (ifStmt && (isLexicalEmpty(ifStmt->getThen())
      || isLexicalEmpty(ifStmt->getElse())))
    {
      Violation violation(node, this);
      violationSet.addViolation(violation);
    }
  }
}