From ad0da498438df04d5e7a21c4baca06049b796352 Mon Sep 17 00:00:00 2001 From: Ivan Galkin Date: Thu, 28 Jun 2018 11:12:56 +0200 Subject: [PATCH] deprecate *PUBLIC*API* metrics * `PUBLIC_API`, `PUBLIC_UNDOCUMENTED_API` and `PUBLIC_DOCUMENTED_API_DENSITY` were depricated since SQ 6.2 (https://jira.sonarsource.com/browse/SONAR-8328) but existed as custom sonar-cxx metrics * the minimal supported SQ version now is 6.7 * moreover, it looks like there is a general problem in displaying custom metrics (see #1509) * that means that nobody a) expects that the SQ plugin implements the deprectad metrics and b) nobody misses them (because they are just not visualized) * the squid check `UndocumentedApiCheck` is not affected (it doesn't rely on the stored metric, but visits the AST by itself) * BTW public API measurements belong to the obligatory AST Visitors and introduce the time overhead of ~6% (measured with #1507, 6% means, that if there is no sensors activated at all the importing of C++ project will still cause a calculation of a bunch of metrics; summary overhead of this calculation considered as 100%) --- .../cxx/sensors/squid/CxxSquidSensor.java | 18 -- .../sonar/cxx/sensors/utils/CxxMetrics.java | 36 --- .../cxx/sensors/utils/CxxMetricsTest.java | 11 - .../java/org/sonar/cxx/CxxAstScanner.java | 4 - .../java/org/sonar/cxx/api/CxxMetric.java | 4 +- .../cxx/visitors/CxxPublicApiVisitor.java | 105 ------- .../java/org/sonar/cxx/api/CxxMetricTest.java | 2 +- .../cxx/visitors/CxxPublicApiVisitorTest.java | 271 ------------------ .../metrics/alias_in_template_func.h | 25 -- .../test/resources/metrics/doxygen_example.h | 61 ---- cxx-squid/src/test/resources/metrics/no_doc.h | 89 ------ .../src/test/resources/metrics/public_api.h | 195 ------------- .../src/test/resources/metrics/template.h | 73 ----- .../test/resources/metrics/unnamed_class.h | 7 - .../src/test/resources/metrics/unnamed_enum.h | 3 - 15 files changed, 2 insertions(+), 902 deletions(-) delete mode 100644 cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxPublicApiVisitor.java delete mode 100644 cxx-squid/src/test/java/org/sonar/cxx/visitors/CxxPublicApiVisitorTest.java delete mode 100644 cxx-squid/src/test/resources/metrics/alias_in_template_func.h delete mode 100644 cxx-squid/src/test/resources/metrics/doxygen_example.h delete mode 100644 cxx-squid/src/test/resources/metrics/no_doc.h delete mode 100644 cxx-squid/src/test/resources/metrics/public_api.h delete mode 100644 cxx-squid/src/test/resources/metrics/template.h delete mode 100644 cxx-squid/src/test/resources/metrics/unnamed_class.h delete mode 100644 cxx-squid/src/test/resources/metrics/unnamed_enum.h diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/squid/CxxSquidSensor.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/squid/CxxSquidSensor.java index fa1f33e51a..6d6ba5d6bd 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/squid/CxxSquidSensor.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/squid/CxxSquidSensor.java @@ -256,24 +256,6 @@ private void saveMeasures(InputFile inputFile, SourceFile squidFile, SensorConte .withValue(squidFile.getInt(CxxMetric.COMPLEXITY)).save(); context.newMeasure().forMetric(CoreMetrics.COMMENT_LINES).on(inputFile) .withValue(squidFile.getInt(CxxMetric.COMMENT_LINES)).save(); - context.newMeasure().forMetric(CoreMetrics.PUBLIC_API).on(inputFile) - .withValue(squidFile.getInt(CxxMetric.PUBLIC_API)).save(); - context.newMeasure().forMetric(CoreMetrics.PUBLIC_UNDOCUMENTED_API).on(inputFile) - .withValue(squidFile.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)).save(); - - // Configuration properties for SQ 6.2++ - // see https://jira.sonarsource.com/browse/SONAR-8328 - if (!language.getMetricsCache().isEmpty()) { - int publicApi = squidFile.getInt(CxxMetric.PUBLIC_API); - int publicUndocumentedApi = squidFile.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API); - double densityOfPublicDocumentedApi = (publicApi > publicUndocumentedApi) ? ((publicApi - publicUndocumentedApi) / (double) publicApi * 100.0) : 0.0; - context.newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_API_KEY)) - .on(inputFile).withValue(publicApi).save(); - context.newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_UNDOCUMENTED_API_KEY)).on(inputFile) - .withValue(publicUndocumentedApi).save(); - context.newMeasure().forMetric(language.getMetric(CxxMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY)) - .on(inputFile).withValue(densityOfPublicDocumentedApi).save(); - } for(SquidSensor sensor: squidSensors) { sensor.publishMeasureForFile(inputFile, squidFile, context); diff --git a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxMetrics.java b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxMetrics.java index 0ee3d48e3a..6c9d637a10 100644 --- a/cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxMetrics.java +++ b/cxx-sensors/src/main/java/org/sonar/cxx/sensors/utils/CxxMetrics.java @@ -45,12 +45,6 @@ public class CxxMetrics implements Metrics { private final CxxLanguage language; private final String domain; - // Introduce own documentation metrics, after they has been removed from SQ core - // see https://jira.sonarsource.com/browse/SONAR-8328 - public static final String PUBLIC_API_KEY = "public_api"; - public static final String PUBLIC_UNDOCUMENTED_API_KEY = "public_undocumented_api"; - public static final String PUBLIC_DOCUMENTED_API_DENSITY_KEY = "public_documented_api_density"; - /** * CxxMetrics * @@ -61,36 +55,6 @@ public CxxMetrics(CxxLanguage language) { this.language = language; this.domain = language.getKey().toUpperCase(Locale.ENGLISH); - Metric metric = new Metric.Builder(getKey(PUBLIC_API_KEY, language), "Public API", Metric.ValueType.INT) - .setDescription("Public API") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(Boolean.FALSE) - .setDomain(this.domain) - .create(); - saveMetric(PUBLIC_API_KEY, metric); - - metric = new Metric.Builder(getKey(PUBLIC_DOCUMENTED_API_DENSITY_KEY, language), "Public Documented API (%)", Metric.ValueType.PERCENT) - .setDescription("Public documented classes and functions balanced by ncloc") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(Boolean.TRUE) - .setDomain(this.domain) - .setWorstValue(0.0) - .setBestValue(100.0) - .setOptimizedBestValue(true) - .create(); - saveMetric(PUBLIC_DOCUMENTED_API_DENSITY_KEY, metric); - - metric = new Metric.Builder(getKey(PUBLIC_UNDOCUMENTED_API_KEY, language), "Public Undocumented API", Metric.ValueType.INT) - .setDescription("Public undocumented classes, functions and variables") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(Boolean.TRUE) - .setDomain(this.domain) - .setBestValue(0.0) - .setDirection(Metric.DIRECTION_WORST) - .setOptimizedBestValue(true) - .create(); - saveMetric(PUBLIC_UNDOCUMENTED_API_KEY, metric); - saveMetric(CxxCompilerSensor.KEY, buildReportMetric(CxxCompilerSensor.KEY, "Compiler issues")); saveMetric(CxxCppCheckSensor.KEY, buildReportMetric(CxxCppCheckSensor.KEY, "CppCheck issues")); saveMetric(CxxOtherSensor.KEY, buildReportMetric(CxxOtherSensor.KEY, "Other tools issues")); diff --git a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/utils/CxxMetricsTest.java b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/utils/CxxMetricsTest.java index 16676e5710..15b3b63d78 100644 --- a/cxx-sensors/src/test/java/org/sonar/cxx/sensors/utils/CxxMetricsTest.java +++ b/cxx-sensors/src/test/java/org/sonar/cxx/sensors/utils/CxxMetricsTest.java @@ -86,15 +86,4 @@ public void getMetricsTest() { assertThat(list.size()).isEqualTo(14); } - @Test - public void getMetricTest() { - Metric metric = language.getMetric(CxxMetrics.PUBLIC_API_KEY); - assertThat(metric).isNotNull(); - - metric = language.getMetric(CxxMetrics.PUBLIC_UNDOCUMENTED_API_KEY); - assertThat(metric).isNotNull(); - - metric = language.getMetric(CxxMetrics.PUBLIC_DOCUMENTED_API_DENSITY_KEY); - assertThat(metric).isNotNull(); - } } diff --git a/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java b/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java index c646924df7..2ab46f72a8 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java @@ -39,7 +39,6 @@ import org.sonar.cxx.visitors.CxxLinesOfCodeInFunctionBodyVisitor; import org.sonar.cxx.visitors.CxxLinesOfCodeVisitor; import org.sonar.cxx.visitors.CxxParseErrorLoggerVisitor; -import org.sonar.cxx.visitors.CxxPublicApiVisitor; import org.sonar.squidbridge.AstScanner; import org.sonar.squidbridge.CommentAnalyser; import org.sonar.squidbridge.SourceCodeBuilderCallback; @@ -201,9 +200,6 @@ public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) builder.withSquidAstVisitor(new LinesVisitor<>(CxxMetric.LINES)); builder.withSquidAstVisitor(new CxxLinesOfCodeVisitor<>(CxxMetric.LINES_OF_CODE)); builder.withSquidAstVisitor(new CxxLinesOfCodeInFunctionBodyVisitor<>()); - builder.withSquidAstVisitor(new CxxPublicApiVisitor<>(CxxMetric.PUBLIC_API, - CxxMetric.PUBLIC_UNDOCUMENTED_API) - .withHeaderFileSuffixes(conf.getHeaderFileSuffixes())); builder.withSquidAstVisitor(CommentsVisitor.builder().withCommentMetric(CxxMetric.COMMENT_LINES) .withNoSonar(true) diff --git a/cxx-squid/src/main/java/org/sonar/cxx/api/CxxMetric.java b/cxx-squid/src/main/java/org/sonar/cxx/api/CxxMetric.java index 2cd2d0e7b9..9f02496f1c 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/api/CxxMetric.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/api/CxxMetric.java @@ -33,9 +33,7 @@ public enum CxxMetric implements MetricDef { CLASSES, COMPLEXITY, COGNITIVE_COMPLEXITY, - COMMENT_LINES, - PUBLIC_API, - PUBLIC_UNDOCUMENTED_API; + COMMENT_LINES; @Override public String getName() { diff --git a/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxPublicApiVisitor.java b/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxPublicApiVisitor.java deleted file mode 100644 index 633cd0c72d..0000000000 --- a/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxPublicApiVisitor.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Sonar C++ Plugin (Community) - * Copyright (C) 2010-2018 SonarOpenCommunity - * http://github.com/SonarOpenCommunity/sonar-cxx - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.cxx.visitors; - -import com.sonar.sslr.api.AstNode; -import com.sonar.sslr.api.Grammar; -import com.sonar.sslr.api.Token; -import java.util.List; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.squidbridge.measures.MetricDef; - -/** - * Visitor that counts documented and undocumented API items.
- * Following items are counted as public API: - *
    - *
  • classes/structures
  • - *
  • class members (public and protected)
  • - *
  • structure members
  • - *
  • enumerations
  • - *
  • enumeration values
  • - *
  • typedefs
  • - *
  • functions
  • - *
  • variables
  • - *
- *

- * Public API items are considered documented if they have Doxygen comments.
- * Function arguments are not counted since they can be documented in function documentation and this visitor does not - * parse Doxygen comments.
- * This visitor should be applied only on header files.
- * Currently, no filtering is applied using preprocessing directive.
- *

- * Limitation: only "in front of the declaration" comments and inline comments (for members) are considered. Documenting - * public API by name (\struct Foo for instance) in other files is not supported. - * - * @see - * Doxygen Manual: Documenting the code - * - * @author Ludovic Cintrat - * - * @param - */ -// @Rule(key = "UndocumentedApi", description = -// "All public APIs should be documented", priority = Priority.MINOR) -public class CxxPublicApiVisitor extends - AbstractCxxPublicApiVisitor { - - private static final Logger LOG = Loggers.get(CxxPublicApiVisitor.class); - - private final MetricDef undocumented; - private final MetricDef api; - - public interface PublicApiHandler { - - void onPublicApi(AstNode node, String id, List comments); - } - - private PublicApiHandler handler; - - public CxxPublicApiVisitor(MetricDef publicDocumentedApi, - MetricDef publicUndocumentedApi) { - super(); - api = publicDocumentedApi; - undocumented = publicUndocumentedApi; - } - - @Override - protected void onPublicApi(AstNode node, String id, List comments) { - boolean commented = !comments.isEmpty(); - - LOG.debug("node: {} line: {} id: '{}' documented: {}", - node.getType(), node.getTokenLine(), id, commented); - - if (handler != null) { - handler.onPublicApi(node, id, comments); - } - - if (!commented) { - getContext().peekSourceCode().add(undocumented, 1); - } - - getContext().peekSourceCode().add(api, 1); - } - - public void setHandler(PublicApiHandler handler) { - this.handler = handler; - } -} diff --git a/cxx-squid/src/test/java/org/sonar/cxx/api/CxxMetricTest.java b/cxx-squid/src/test/java/org/sonar/cxx/api/CxxMetricTest.java index 2728fa0934..7a72de6517 100644 --- a/cxx-squid/src/test/java/org/sonar/cxx/api/CxxMetricTest.java +++ b/cxx-squid/src/test/java/org/sonar/cxx/api/CxxMetricTest.java @@ -27,7 +27,7 @@ public class CxxMetricTest { @Test public void test() { SoftAssertions softly = new SoftAssertions(); - softly.assertThat(CxxMetric.values()).hasSize(12); + softly.assertThat(CxxMetric.values()).hasSize(10); for (CxxMetric metric : CxxMetric.values()) { softly.assertThat(metric.getName()).isEqualTo(metric.name()); diff --git a/cxx-squid/src/test/java/org/sonar/cxx/visitors/CxxPublicApiVisitorTest.java b/cxx-squid/src/test/java/org/sonar/cxx/visitors/CxxPublicApiVisitorTest.java deleted file mode 100644 index 7ba50e037f..0000000000 --- a/cxx-squid/src/test/java/org/sonar/cxx/visitors/CxxPublicApiVisitorTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Sonar C++ Plugin (Community) - * Copyright (C) 2010-2018 SonarOpenCommunity - * http://github.com/SonarOpenCommunity/sonar-cxx - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.cxx.visitors; - -import com.sonar.sslr.api.AstNode; -import com.sonar.sslr.api.Grammar; -import com.sonar.sslr.api.Token; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static org.assertj.core.api.Assertions.assertThat; -import org.assertj.core.groups.Tuple; -import static org.assertj.core.groups.Tuple.tuple; -import org.fest.assertions.Fail; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.cxx.CxxAstScanner; -import org.sonar.cxx.CxxFileTester; -import org.sonar.cxx.CxxFileTesterHelper; -import org.sonar.cxx.api.CxxMetric; -import org.sonar.cxx.visitors.CxxPublicApiVisitor.PublicApiHandler; -import org.sonar.squidbridge.api.SourceFile; - -public class CxxPublicApiVisitorTest { - - private static final Logger LOG = LoggerFactory - .getLogger("CxxPublicApiVisitorTest"); - - private static String getFileExtension(String fileName) { - int lastIndexOf = fileName.lastIndexOf("."); - if (lastIndexOf == -1) { - return ""; - } - return fileName.substring(lastIndexOf); - } - - /** - * Check that CxxPublicApiVisitor correctly counts API for given file. - * - * @param fileName the file to use for test - * @param expectedApi expected number of API - * @param expectedUndoc expected number of undocumented API - * @param checkDouble if true, fails the test if two items with the same id are counted.. - */ - private Tuple testFile(String fileName, boolean checkDouble) - throws UnsupportedEncodingException, IOException { - - CxxPublicApiVisitor visitor = new CxxPublicApiVisitor<>( - CxxMetric.PUBLIC_API, CxxMetric.PUBLIC_UNDOCUMENTED_API); - - if (checkDouble) { - final Map> idCommentMap = new HashMap<>(); - - visitor.setHandler(new PublicApiHandler() { - @Override - public void onPublicApi(AstNode node, String id, - List comments) { - if (idCommentMap.containsKey(id)) { - Fail.fail("DOUBLE ID: " + id); - } - - // store and compare later in order to not break the parsing - idCommentMap.put(id, comments); - } - }); - } - - visitor.withHeaderFileSuffixes(Arrays - .asList(getFileExtension(fileName))); - - CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester(fileName, ".", ""); - SourceFile file = CxxAstScanner.scanSingleFile( - tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), visitor); - - if (LOG.isDebugEnabled()) { - LOG.debug("#API: {} UNDOC: {}", - file.getInt(CxxMetric.PUBLIC_API), file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)); - } - - return (new Tuple(file.getInt(CxxMetric.PUBLIC_API), file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API))); - } - - @Test - public void test_no_matching_suffix() throws IOException { - CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/metrics/doxygen_example.h", ".", ""); - SourceFile file = CxxAstScanner.scanSingleFile(tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), - new CxxPublicApiVisitor<>(CxxMetric.PUBLIC_API, - CxxMetric.PUBLIC_UNDOCUMENTED_API) - .withHeaderFileSuffixes(Arrays.asList(".hpp"))); - - assertThat(file.getInt(CxxMetric.PUBLIC_API)).isEqualTo(0); - assertThat(file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)).isEqualTo(0); - } - - @Test - public void doxygen_example() throws IOException { - assertThat(testFile("src/test/resources/metrics/doxygen_example.h", false)).isEqualTo(tuple(13, 0)); - } - - @Test - public void to_delete() throws IOException { - assertThat(testFile("src/test/resources/metrics/public_api.h", true)).isEqualTo(tuple(43, 0)); - - } - - @Test - public void no_doc() throws IOException { - assertThat(testFile("src/test/resources/metrics/no_doc.h", true)).isEqualTo(tuple(22, 22)); - } - - @Test - public void template() throws IOException { - assertThat(testFile("src/test/resources/metrics/template.h", false)).isEqualTo(tuple(14, 4)); - } - - @Test - public void alias_function_template() throws IOException { - assertThat(testFile("src/test/resources/metrics/alias_in_template_func.h", false)).isEqualTo(tuple(4, 3)); - } - - @Test - public void unnamed_class() throws IOException { - assertThat(testFile("src/test/resources/metrics/unnamed_class.h", false)).isEqualTo(tuple(3, 1)); - } - - @Test - public void unnamed_enum() throws IOException { - assertThat(testFile("src/test/resources/metrics/unnamed_enum.h", false)).isEqualTo(tuple(1, 1)); - } - - @Test - public void public_api() throws UnsupportedEncodingException, IOException { - CxxPublicApiVisitor visitor = new CxxPublicApiVisitor<>( - CxxMetric.PUBLIC_API, CxxMetric.PUBLIC_UNDOCUMENTED_API); - - final Map> idCommentMap = new HashMap<>(); - - visitor.setHandler(new PublicApiHandler() { - @Override - public void onPublicApi(AstNode node, String id, - List comments) { - if (idCommentMap.containsKey(id)) { - Fail.fail("DOUBLE ID: " + id); - } - - // store and compare later in order to not break the parsing - idCommentMap.put(id, comments); - } - }); - - visitor.withHeaderFileSuffixes(Arrays.asList(".h")); - - CxxFileTester tester = CxxFileTesterHelper.CreateCxxFileTester("src/test/resources/metrics/public_api.h", ".", ""); - SourceFile file = CxxAstScanner.scanSingleFile(tester.cxxFile, tester.sensorContext, CxxFileTesterHelper.mockCxxLanguage(), visitor); // - - if (LOG.isDebugEnabled()) { - LOG.debug("DOC: {} UNDOC: {}", - file.getInt(CxxMetric.PUBLIC_API), file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)); - } - - final Map expectedIdCommentMap = new HashMap<>(); - - expectedIdCommentMap.put("publicDefinedMethod", "publicDefinedMethod"); - expectedIdCommentMap.put("aliasDeclaration", "aliasDeclaration"); - expectedIdCommentMap.put("publicMethod", "publicMethod"); - expectedIdCommentMap.put("testStruct", "testStruct"); - expectedIdCommentMap.put("testUnion", "testUnion"); - expectedIdCommentMap.put("inlineCommentedAttr", "inlineCommentedAttr"); - expectedIdCommentMap.put("inlineCommentedLastAttr", - "inlineCommentedLastAttr"); - expectedIdCommentMap.put("enumVar", "classEnum"); // only one - // declarator, then - // doc should precede - // decl - expectedIdCommentMap.put("classEnum", "classEnum"); - expectedIdCommentMap.put("classEnumValue", "classEnumValue"); - expectedIdCommentMap.put("protectedMethod", "protectedMethod"); - expectedIdCommentMap.put("testTypeDef", "testTypeDef"); - expectedIdCommentMap.put("testField", "testField"); - expectedIdCommentMap.put("inlinePublicMethod", "inlinePublicMethod"); - expectedIdCommentMap.put("publicAttribute", "publicAttribute"); - expectedIdCommentMap.put("testEnum", "testEnum"); - expectedIdCommentMap.put("testClass", "testClass"); - expectedIdCommentMap.put("enum_val", "enum_val"); - expectedIdCommentMap.put("testFunction", "testFunction"); - expectedIdCommentMap.put("testFunction2", "testFunction2"); - expectedIdCommentMap.put("globalVar", "globalVar"); - expectedIdCommentMap.put("globalVarInline", "globalVarInline"); - expectedIdCommentMap.put("globalVar1", "globalVar1"); - expectedIdCommentMap.put("globalVar2", "globalVar2"); - expectedIdCommentMap.put("globalVar3", "globalVar3"); - expectedIdCommentMap.put("globalAliasDeclaration", "globalAliasDeclaration"); - expectedIdCommentMap.put("testType", "testType"); - expectedIdCommentMap.put("enumVar1", "enumVar1"); - expectedIdCommentMap.put("enumVar2", "enumVar2"); - expectedIdCommentMap.put("attr1", "attr1"); - expectedIdCommentMap.put("attr2", "attr2"); - expectedIdCommentMap.put("lastVar", "lastVar"); - expectedIdCommentMap.put("protectedStruct", "protectedStruct"); - expectedIdCommentMap - .put("protectedStructField", "protectedStructField"); - expectedIdCommentMap.put("protectedStructField2", - "protectedStructField2"); - expectedIdCommentMap.put("protectedClass", "protectedClass"); - expectedIdCommentMap.put("operator[]", "operator"); - expectedIdCommentMap.put("bitfield", "bitfield"); - expectedIdCommentMap.put("", ""); - expectedIdCommentMap.put("testField2", "testField2"); -// expectedIdCommentMap.put("operator=", "operator="); - expectedIdCommentMap.put("testUnnamedStructVar", "testUnnamedStructVar"); - expectedIdCommentMap.put("globalFuncDef", "globalFuncDef"); - expectedIdCommentMap.put("linkageSpecification", "linkageSpecification"); - - // check completeness - for (final String id : expectedIdCommentMap.keySet()) { - LOG.debug("id: {}", id); - - List comments = idCommentMap.get(id); - - assertThat(idCommentMap.keySet()) - .overridingErrorMessage("No public API for " + id) - .contains(id); - assertThat(comments) - .overridingErrorMessage("No documentation for " + id) - .isNotEmpty(); - assertThat(comments.get(0).getValue()) - .overridingErrorMessage("Unexpected documentation for " + id) - .contains(expectedIdCommentMap.get(id)); - } - - // check correction - for (final String id : idCommentMap.keySet()) { - LOG.debug("id: {}", id); - - List comments = idCommentMap.get(id); - - assertThat(comments) - .overridingErrorMessage("No documentation for " + id) - .isNotEmpty(); - assertThat(expectedIdCommentMap.keySet()) - .overridingErrorMessage("Should not be part of public API: " + id) - .contains(id); - } - - assertThat(file.getInt(CxxMetric.PUBLIC_API)).isEqualTo( - expectedIdCommentMap.keySet().size()); - assertThat(file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)).isEqualTo(0); - } - -} diff --git a/cxx-squid/src/test/resources/metrics/alias_in_template_func.h b/cxx-squid/src/test/resources/metrics/alias_in_template_func.h deleted file mode 100644 index 3f1ac736f9..0000000000 --- a/cxx-squid/src/test/resources/metrics/alias_in_template_func.h +++ /dev/null @@ -1,25 +0,0 @@ -template -struct A { - template - void foo(){ - using type = void; - } -}; - -template -void bar(){ - using type = void; -} - -/*! - * \brief Commented - */ -template -void foobar(){ - /*! - * \brief Commented (Not a doxygen comment) - */ - using type = void; - - using second_type = double; -} diff --git a/cxx-squid/src/test/resources/metrics/doxygen_example.h b/cxx-squid/src/test/resources/metrics/doxygen_example.h deleted file mode 100644 index d88d830922..0000000000 --- a/cxx-squid/src/test/resources/metrics/doxygen_example.h +++ /dev/null @@ -1,61 +0,0 @@ -//! A test class. -/*! - A more elaborate class description. -*/ -class Test -{ - public: - //! An enum. - /*! More detailed enum description. */ - enum TEnum { - TVal1, /*!< Enum value TVal1. */ - TVal2, /*!< Enum value TVal2. */ - TVal3 /*!< Enum value TVal3. */ - } - //! Enum pointer. - /*! Details. */ - *enumPtr, - //! Enum variable. - /*! Details. */ - enumVar; - - //! A constructor. - /*! - A more elaborate description of the constructor. - */ - Test(); - //! A destructor. - /*! - A more elaborate description of the destructor. - */ - ~Test(); - - //! A normal member taking two arguments and returning an integer value. - /*! - \param a an integer argument. - \param s a constant character pointer. - \return The test results - \sa Test(), ~Test(), testMeToo() and publicVar() - */ - int testMe(int a,const char *s); - - //! A pure virtual member. - /*! - \sa testMe() - \param c1 the first argument. - \param c2 the second argument. - */ - virtual void testMeToo(char c1,char c2) = 0; - - //! A public variable. - /*! - Details. - */ - int publicVar; - - //! A function variable. - /*! - Details. - */ - int (*handler)(int a,int b); -}; diff --git a/cxx-squid/src/test/resources/metrics/no_doc.h b/cxx-squid/src/test/resources/metrics/no_doc.h deleted file mode 100644 index 0e3391f6a6..0000000000 --- a/cxx-squid/src/test/resources/metrics/no_doc.h +++ /dev/null @@ -1,89 +0,0 @@ -#define TEST_MACRO() \ - macro - -#define EXPORT - -class testClass -{ - void defaultMethod(); - -public: - using aliasDeclaration = int; - - void publicMethod(); - - enum classEnum { - classEnumValue - } - - enumVar; - - EXPORT int publicAttribute; - - 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(); - -private: - void privateMethod(); - - enum privateEnum { - privateEnumVal - }; - - struct privateStruct { - int privateStructField; - }; - - class privateClass { - int i; - }; - - union privateUnion { - int u; - }; - -public: - int inlineCommentedLastAttr; -}; - - -struct testStruct { - int testField; -}; - -extern int globalVar; - -void testFunction(); - -enum emptyEnum -{}; - -enum testEnum -{ - enum_val -}; - -union testUnion -{ - -}; - -template -struct tmplStruct -{}; - -void func() { - for (int i = 0; i < 10; i++) {} -} diff --git a/cxx-squid/src/test/resources/metrics/public_api.h b/cxx-squid/src/test/resources/metrics/public_api.h deleted file mode 100644 index 30f4667890..0000000000 --- a/cxx-squid/src/test/resources/metrics/public_api.h +++ /dev/null @@ -1,195 +0,0 @@ -#define TEST_MACRO() \ - macro - -/** - testClass doc - */ -class testClass -{ - void defaultMethod(); - -public: - // comment - - /// aliasDeclaration - using aliasDeclaration = int; - - /** publicMethod doc */ - void publicMethod(); - - /// classEnum doc - enum classEnum { - classEnumValue ///< classEnumValue doc - } - /// block enumVar doc - enumVar; ///< inline enumVar doc, invalid ? - - /** - publicAttribute doc - */ - int publicAttribute; - - int inlineCommentedAttr; //!< inlineCommentedAttr comment - - void inlinePublicMethod(); //!< inlinePublicMethod comment - - int attr1, //!< attr1 doc - attr2; ///< attr2 doc - - // ignore friend declaration - template 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 - */ - virtual void protectedMethod(); - - virtual void overriddenMethod() override; // no doc is OK, it could come from ancestor - - /** - protectedStruct doc - */ - struct protectedStruct { - int protectedStructField; ///< protectedStructField doc - int protectedStructField2; ///< protectedStructField2 doc - }; - - /*! - protectedClass doc - */ - class protectedClass { - }; - - /** - operator doc - */ - value_t& operator[](std::size_t idx); - -private: - void privateMethod(); - - enum privateEnum { - privateEnumVal - }; - - struct privateStruct { - int privateStructField; - }; - - class privateClass { - int i; - }; - - union privateUnion { - int u; - }; - - using privateAliasDeclaration = int; - -public: - int inlineCommentedLastAttr; //!< inlineCommentedLastAttr comment -}; - -/// testStruct doc -struct testStruct { - int testField; /**< inline testField comment */ - - /// testTypeDef - /// - typedef toto testTypeDef; - - /** - * bitfield doc - */ - unsigned int bitfield:1; - -private: - void private_def(){} -}; - -/** - globalVar doc -*/ -extern int globalVar; - -int globalVarInline; //!< globalVarInline doc - -int -/** -globalVar1 doc -*/ -globalVar1, -globalVar2, ///< globalVar2 doc -globalVar3; /*!< globalVar3 doc */ - -/// testFunction doc -void testFunction(); - -void testFunction2(); //!< testFunction2 doc - -using globalAliasDeclaration = int; ///< inline globalAliasDeclaration - -typedef int testType; ///< testType doc - -/** - testEnum doc -*/ -enum testEnum -{ - /** - enum_val doc - */ - enum_val -}; - -enum testEnum enumVar1, ///< enumVar1 doc -/** - enumVar2 doc -*/ -enumVar2; - -/*! - testUnion doc -*/ -union testUnion -{ - -}; - -/** - * doc - */ -struct { - int testField2; /**< inline testField2 comment */ -} testUnnamedStructVar; ///< testUnnamedStructVar doc - -int lastVar; ///< lastVar doc - -/** - * globalFuncDef doc - */ -void globalFuncDef() {} - -#define EXTERN_C extern "C" -#define EXPORT -#define CALLCONV -#define sint32 unsigned int -#define bool char -/** - * linkageSpecification doc. - * @return value doc - */ -EXTERN_C EXPORT sint32 CALLCONV linkageSpecification(byte* params); diff --git a/cxx-squid/src/test/resources/metrics/template.h b/cxx-squid/src/test/resources/metrics/template.h deleted file mode 100644 index b5b3663b05..0000000000 --- a/cxx-squid/src/test/resources/metrics/template.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - testClass -*/ -template -class testClass -{ -public: - void publicMethod(); - - int publicAttr; - - // Issue #928 (should be marked undocumented) - using type = void; -}; - -template -struct second_struct { - /*! - * \brief Issue #928 (should be marked documented) - */ - using alpha = float; - - /*! - * \brief Issue #928 (should be marked documented) - */ - using beta = double; -}; - -/*! - * \brief issue #736 - */ -template -using intrinsic_type = typename intrinsic_traits::intrinsic_type; - -template -using inline_intrinsic_type = typename intrinsic_traits::intrinsic_type; ///< issue #736 - -/** - * @brief cascaded templateDeclaration doc (issue #1000) - */ -template -template -void TestClass::functionTest(); - -/** - * @brief issue #1025 - */ -template -class TestClass2 { -public: - - /** - * @brief DOCUMENTATION FUNCTION - */ - template - void functionTest2(); -}; - -/** - * @brief DOCUMENTATION - */ -template -template -void TestClass2::functionTest2() -{ -} - -/** - * @brief issue #1067 - */ -struct A { - template class B; -}; diff --git a/cxx-squid/src/test/resources/metrics/unnamed_class.h b/cxx-squid/src/test/resources/metrics/unnamed_class.h deleted file mode 100644 index e89629186f..0000000000 --- a/cxx-squid/src/test/resources/metrics/unnamed_class.h +++ /dev/null @@ -1,7 +0,0 @@ -class { -public: - /** - * a doc - */ - int a; -} b; ///< b doc diff --git a/cxx-squid/src/test/resources/metrics/unnamed_enum.h b/cxx-squid/src/test/resources/metrics/unnamed_enum.h deleted file mode 100644 index 1ea71e7254..0000000000 --- a/cxx-squid/src/test/resources/metrics/unnamed_enum.h +++ /dev/null @@ -1,3 +0,0 @@ -enum /*anonymous enum*/ { -}; -