Skip to content

Commit

Permalink
Merge pull request #810 from lcintrat/fix-761
Browse files Browse the repository at this point in the history
Remove methods marked with "override" from public API
  • Loading branch information
guwirth committed Mar 13, 2016
2 parents 773b307 + bb94a88 commit 41221fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ abstract protected void onPublicApi(AstNode node, String id,
private static final String UNNAMED_CLASSIFIER_ID = "<unnamed class>";
private static final String UNNAMED_ENUM_ID = "<unnamed enumeration>";

private static final String TOKEN_OVERRIDE = "override";

public interface PublicApiHandler {

void onPublicApi(AstNode node, String id, List<Token> comments);
Expand Down Expand Up @@ -418,6 +420,20 @@ private boolean isDefaultOrDeleteFunctionBody(AstNode functionBodyNode) {
return defaultOrDelete;
}

private boolean isOverriddenMethod(AstNode memberDeclarator) {
List<AstNode> modifiers = memberDeclarator.getDescendants(CxxGrammarImpl.cliFunctionModifier);

for (AstNode modifier : modifiers) {
AstNode modifierId = modifier.getFirstChild();

if (TOKEN_OVERRIDE.equals(modifierId.getTokenValue())) {
return true;
}
}

return false;
}

/**
* Find documentation node, associated documentation, identifier of a
* <em>public</em> member declarator and visit it as a public API.
Expand All @@ -430,6 +446,12 @@ private void visitMemberDeclarator(AstNode node) {
CxxGrammarImpl.templateDeclaration,
CxxGrammarImpl.classSpecifier);

if (isOverriddenMethod(node)) {
// assume that ancestor method is documented
// and do not count as public API
return;
}

AstNode docNode;

if (container == null
Expand Down
4 changes: 3 additions & 1 deletion cxx-squid/src/test/resources/metrics/public_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class testClass
protectedMethod doc
*/
virtual void protectedMethod();


virtual void overriddenMethod() override; // no doc is OK, it could come from ancestor

/**
protectedStruct doc
*/
Expand Down

0 comments on commit 41221fe

Please sign in to comment.