Skip to content

Commit e681750

Browse files
mcserepintjftw
andauthored
Endpoints for module-level C++ metric types (#739)
Co-authored-by: Anett Fekete <anett.fekete@ericsson.com>
1 parent 5bfc159 commit e681750

File tree

7 files changed

+267
-25
lines changed

7 files changed

+267
-25
lines changed

model/include/model/file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ struct FileIdView
8787
{
8888
FileId id;
8989
};
90+
91+
#pragma db view object(File)
92+
struct FilePathView
93+
{
94+
#pragma db column(File::id)
95+
FileId id;
96+
97+
#pragma db column(File::path)
98+
std::string path;
99+
};
90100

91101
#pragma db view object(File) query((?) + " GROUP BY " + File::type)
92102
struct FileTypeView

plugins/cpp/model/include/model/cppastnode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ struct AstCountGroupByFiles
230230
std::size_t count;
231231
};
232232

233+
#pragma db view \
234+
object(CppAstNode) \
235+
object(File = LocFile : CppAstNode::location.file)
236+
struct CppAstNodeFilePath
237+
{
238+
#pragma db column(CppAstNode::id)
239+
CppAstNodeId id;
240+
241+
#pragma db column(LocFile::path)
242+
std::string path;
243+
};
244+
233245
#pragma db view object(CppAstNode)
234246
struct CppAstCount
235247
{

plugins/cpp_metrics/model/include/model/cppastnodemetrics.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ struct CppRecordMetricsView
4545
double value;
4646
};
4747

48+
#pragma db view \
49+
object(CppAstNodeMetrics) \
50+
object(CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
51+
object(File = LocFile : CppAstNode::location.file)
52+
struct CppAstNodeMetricsForPathView
53+
{
54+
#pragma db column(CppAstNodeMetrics::astNodeId)
55+
CppAstNodeId astNodeId;
56+
57+
#pragma db column(LocFile::path)
58+
std::string path;
59+
60+
#pragma db column(CppAstNodeMetrics::type)
61+
CppAstNodeMetrics::Type type;
62+
63+
#pragma db column(CppAstNodeMetrics::value)
64+
double value;
65+
};
66+
4867
} //model
4968
} //cc
5069

plugins/cpp_metrics/model/include/model/cppfilemetrics.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ struct CppFileMetrics
2929
unsigned value;
3030
};
3131

32+
#pragma db view \
33+
object(CppFileMetrics) \
34+
object(File : CppFileMetrics::file == File::id)
35+
struct CppModuleMetricsForPathView
36+
{
37+
#pragma db column(CppFileMetrics::file)
38+
FileId fileId;
39+
40+
#pragma db column(File::path)
41+
std::string path;
42+
43+
#pragma db column(CppFileMetrics::type)
44+
CppFileMetrics::Type type;
45+
46+
#pragma db column(CppFileMetrics::value)
47+
unsigned value;
48+
};
49+
3250
} //model
3351
} //cc
3452

plugins/cpp_metrics/service/cxxmetrics.thrift

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,55 @@ include "project/project.thrift"
44
namespace cpp cc.service.cppmetrics
55
namespace java cc.service.cppmetrics
66

7-
enum CppMetricsType
7+
enum CppAstNodeMetricsType
88
{
99
ParameterCount = 1,
1010
McCabe = 2,
1111
LackOfCohesion = 3,
1212
LackOfCohesionHS = 4
1313
}
1414

15-
struct CppMetricsTypeName
15+
enum CppModuleMetricsType
1616
{
17-
1:CppMetricsType type,
17+
Placeholder = 1
18+
}
19+
20+
struct CppAstNodeMetricsTypeName
21+
{
22+
1:CppAstNodeMetricsType type,
23+
2:string name
24+
}
25+
26+
struct CppModuleMetricsTypeName
27+
{
28+
1:CppModuleMetricsType type,
1829
2:string name
1930
}
2031

21-
struct CppMetricsAstNode
32+
struct CppMetricsAstNodeSingle
33+
{
34+
1:string path,
35+
2:CppAstNodeMetricsType type,
36+
3:double value
37+
}
38+
39+
struct CppMetricsAstNodeAll
40+
{
41+
1:common.AstNodeId id,
42+
2:list<CppMetricsAstNodeSingle> metrics
43+
}
44+
45+
struct CppMetricsModuleSingle
46+
{
47+
1:string path,
48+
2:CppModuleMetricsType type,
49+
3:double value
50+
}
51+
52+
struct CppMetricsModuleAll
2253
{
23-
1:CppMetricsType type,
24-
2:double value
54+
1:common.FileId id,
55+
2:list<CppMetricsModuleSingle> metrics
2556
}
2657

2758
service CppMetricsService
@@ -32,17 +63,47 @@ service CppMetricsService
3263
*/
3364
double getSingleCppMetricForAstNode(
3465
1:common.AstNodeId astNodeId,
35-
2:CppMetricsType metric)
66+
2:CppAstNodeMetricsType metric)
3667

3768
/**
3869
* This function returns all available C++ metrics
3970
* for a particular AST node.
4071
*/
41-
list<CppMetricsAstNode> getCppMetricsForAstNode(
72+
list<CppMetricsAstNodeSingle> getCppMetricsForAstNode(
4273
1:common.AstNodeId astNodeId)
4374

4475
/**
45-
* This function returns the names of metrics.
76+
* This function returns all available C++ metrics
77+
* for a particular module (file or directory).
78+
*/
79+
list<CppMetricsModuleSingle> getCppMetricsForModule(
80+
1:common.FileId fileId)
81+
82+
/**
83+
* This function returns all available C++ metrics
84+
* (AST node-level) for a particular path.
85+
*
86+
* The given path is a handled as a prefix.
87+
*/
88+
map<common.AstNodeId, list<CppMetricsAstNodeSingle>> getCppAstNodeMetricsForPath(
89+
1:string path)
90+
91+
/**
92+
* This function returns all available C++ metrics
93+
* (file-level) for a particular path.
94+
*
95+
* The given path is a handled as a prefix.
96+
*/
97+
map<common.FileId, list<CppMetricsModuleSingle>> getCppFileMetricsForPath(
98+
1:string path)
99+
100+
/**
101+
* This function returns the names of the AST node-level C++ metrics.
102+
*/
103+
list<CppAstNodeMetricsTypeName> getCppAstNodeMetricsTypeNames()
104+
105+
/**
106+
* This function returns the names of module-level C++ metrics.
46107
*/
47-
list<CppMetricsTypeName> getCppMetricsTypeNames()
108+
list<CppModuleMetricsTypeName> getCppModuleMetricsTypeNames()
48109
}

plugins/cpp_metrics/service/include/service/cppmetricsservice.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <memory>
55
#include <vector>
6+
#include <map>
67

78
#include <boost/program_options/variables_map.hpp>
89

@@ -12,6 +13,8 @@
1213
#include <model/cppastnodemetrics-odb.hxx>
1314
#include <model/cppastnode.h>
1415
#include <model/cppastnode-odb.hxx>
16+
#include <model/cppfilemetrics.h>
17+
#include <model/cppfilemetrics-odb.hxx>
1518

1619
#include <odb/database.hxx>
1720
#include <util/odbtransaction.h>
@@ -36,14 +39,29 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf
3639

3740
double getSingleCppMetricForAstNode(
3841
const core::AstNodeId& astNodeId_,
39-
CppMetricsType::type metric_) override;
42+
CppAstNodeMetricsType::type metric_) override;
4043

4144
void getCppMetricsForAstNode(
42-
std::vector<CppMetricsAstNode>& _return,
45+
std::vector<CppMetricsAstNodeSingle>& _return,
4346
const core::AstNodeId& astNodeId_) override;
4447

45-
void getCppMetricsTypeNames(
46-
std::vector<CppMetricsTypeName>& _return) override;
48+
void getCppMetricsForModule(
49+
std::vector<CppMetricsModuleSingle>& _return,
50+
const core::FileId& fileId_) override;
51+
52+
void getCppAstNodeMetricsForPath(
53+
std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
54+
const std::string& path_) override;
55+
56+
void getCppFileMetricsForPath(
57+
std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
58+
const std::string& path_) override;
59+
60+
void getCppAstNodeMetricsTypeNames(
61+
std::vector<CppAstNodeMetricsTypeName>& _return) override;
62+
63+
void getCppModuleMetricsTypeNames(
64+
std::vector<CppModuleMetricsTypeName>& _return) override;
4765

4866
private:
4967
std::shared_ptr<odb::database> _db;

0 commit comments

Comments
 (0)