Skip to content

Commit

Permalink
Support defaulted/deleted methods API documentation
Browse files Browse the repository at this point in the history
Remove public API documentation violation generation for defaulted and
deleted methods.

Fix SonarOpenCommunity#558
  • Loading branch information
lcintrat committed Jul 11, 2015
1 parent 96ee202 commit 27d4ff0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,41 @@ private void visitMemberDeclaration(AstNode memberDeclaration) {

private void visitFunctionDefinition(AstNode functionDef) {
if (isPublicApiMember(functionDef)) {
// filter out deleted and defaulted methods
AstNode functionBodyNode = functionDef
.getFirstChild(CxxGrammarImpl.functionBody);

if (functionBodyNode != null) {
if (isDefaultOrDeleteFunctionBody(functionBodyNode)) {
return;
}
}

visitMemberDeclarator(functionDef);
}
}

private boolean isDefaultOrDeleteFunctionBody(AstNode functionBodyNode) {
boolean defaultOrDelete = false;
List<AstNode> functionBody = functionBodyNode.getChildren();

// look for exact sub AST
if (functionBody.size() == 3) {
if (functionBody.get(0).is(CxxPunctuator.ASSIGN)
&& functionBody.get(2).is(CxxPunctuator.SEMICOLON)) {

AstNode bodyType = functionBody.get(1);

if (bodyType.is(CxxKeyword.DELETE)
|| bodyType.is(CxxKeyword.DEFAULT)) {
defaultOrDelete = true;
}
}
}

return defaultOrDelete;
}

/**
* Find documentation node, associated documentation,
* identifier of a <em>public</em> member declarator and visit it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public void doxygen_example() {

@Test
public void to_delete() {
testFile("src/test/resources/metrics/public_api.h", 40, 0, true);
testFile("src/test/resources/metrics/public_api.h", 41, 0, true);
}

@Test
public void no_doc() {
testFile("src/test/resources/metrics/no_doc.h", 21, 21, true);
testFile("src/test/resources/metrics/no_doc.h", 22, 22, true);
}

@Test
Expand Down Expand Up @@ -175,6 +175,7 @@ public void onPublicApi(AstNode node, String id,

final Map<String, String> expectedIdCommentMap = new HashMap<String, String>();

expectedIdCommentMap.put("publicDefinedMethod", "publicDefinedMethod");
expectedIdCommentMap.put("aliasDeclaration", "aliasDeclaration");
expectedIdCommentMap.put("publicMethod", "publicMethod");
expectedIdCommentMap.put("testStruct", "testStruct");
Expand Down
8 changes: 8 additions & 0 deletions cxx-squid/src/test/resources/metrics/no_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class testClass
int inlineCommentedAttr;

void inlinePublicMethod();

// ignore deleted methods
A(A const&) = delete;

// ignore defaulted methods
A& operator=(A const&) = default;

void publicDefinedMethod() { }

protected:
virtual void protectedMethod();
Expand Down
11 changes: 11 additions & 0 deletions cxx-squid/src/test/resources/metrics/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ class testClass
template<typename S> friend S& operator<<(S&, A const&);

friend class friendClass;

// ignore deleted methods
A(A const&) = delete;

// ignore defaulted methods
A& operator=(A const&) = default;

/**
* publicDefinedMethod comment
*/
void publicDefinedMethod() { }
protected:
/**
protectedMethod doc
Expand Down

0 comments on commit 27d4ff0

Please sign in to comment.