Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support defaulted/deleted methods API documentation #584

Merged
merged 1 commit into from
Jul 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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