|
JStyle5 vastly improves upon the reporting capabilities of the earlier release. At the core of the new reporting functionality is List & Label reporting engine from Combit Software. What this means to you is that you can now define custom report formats and populate them with project data through scripts. There is a Report Manager that allows you to define reports and associate them with the menu.
To invoke the Report Manager dialog, click the
speedbar icon or select Reports > Report Manager from the main menu. This brings up the following dialog.
Fig. 6.1
Reports are grouped into folders. These folders are listed in the "Reports:" list box. The root folder is labeled
Reports. If you define additional report categories, they will be displayed as sub folders under the root. When you expand a category folder, it will display all the reports under that category. There cannot be nested categories, so a category folder (other than the root) will not have sub folders.
You can select one of several output formats for the report - Preview, HTML, PDF, and JPEG are just a few of the possibilities.
As an example of what is possible, here is a script to generate package metrics on a sample project:
PrepareReport(report){
// flag indicating whether packages selected for Comment Generation (all
// the packages in the project) or those selected for Report Generation
// should be used. If enabled, Report Generation Settings are used.
// If disabled, Comment Generation Settings are used.
useRptGenSettings = true;
// flag used to calculate Package Metrics. If enabled, metrics of all files
// in the package are used to calculate the package metrics. If disabled,
// metrics of only the files selected in the package are used.
includeMetricsOfAllFiles = false;
project = getProject();
met = project.generateMetrics();
report.createVariable("Project", project.name);
populateTable(report, met, includeMetricsOfAllFiles, useRptGenSettings);
}
populateTable(report, metrics, includeMetricsOfAllFiles, useRptGenSettings) {
table = report.createTable("PackageMetrics");
table.defineFields("PackageName", "Files", reportVarNumeric, "Classes",
reportVarNumeric, "TotalLines", reportVarNumeric, "FileChart",
reportVarChart);
application = getApplication();
application.WriteToStatusBar ("Preparing package metrics ...");
application.createProgress(0, getProject().packages.Count);
foreach(pack in getProject().packages){
if(packageEnabled(pack, useRptGenSettings)) {
packMet = getPackageMetrics(pack, metrics, includeMetricsOfAllFiles,
useRptGenSettings);
createTableRecord(table, pack, packMet);
}
application.IncrementProgress(1);
}
table.sort("PackageName", sortCaseInSensitive);
application.RemoveProgress();
application.WriteToStatusBar ("");
}
createTableRecord(table, pack, packMetrics) {
[totalLines, sourceLines, blankLines, commentLines, nFiles, nClasses] =
packMetrics;
// Create the table for the chart column and populate chart table's records
fileChart = table.CreateChartTable("FileChart");
fileChart.defineFields("Name", "Lines", reportVarNumeric);
rec = fileChart.createRecord("Comment", commentLines);
rec = fileChart.createRecord("Source", sourceLines);
rec = fileChart.createRecord("Blank", blankLines);
// Populate the main table's records
rec = table.createRecord(pack.Name, nFiles, nClasses, totalLines, fileChart);
}
getFileCount(pack, includeMetricsOfAllFiles, useRptGenSettings) {
if(includeMetricsOfAllFiles || (!useRptGenSettings)) {
return pack.files.count;
}
// To calculate the no.of files enabled for report generation.
fileCnt = 0;
foreach(file in pack.files) {
if(FileMetrics.fileEnabled(file, useRptGenSettings)) {
fileCnt++;
}
}
return fileCnt;
}
getClassCount(pack, includeMetricsOfAllFiles, useRptGenSettings) {
if(includeMetricsOfAllFiles || (!useRptGenSettings)) {
return pack.classes.count;
}
// To calculate the no.of classes enabled for report generation.
clsCnt = 0;
foreach(cls in pack.classes) {
if(ClassMetrics.classEnabled(cls, useRptGenSettings)) {
clsCnt++;
}
}
return clsCnt;
}
getPackageMetrics(pack, metrics, includeMetricsOfAllFiles, useRptGenSettings) {
packTotLines = 0;
packSrcLines = 0;
packBlkLines = 0;
packCmtLines = 0;
foreach(file in pack.files){
// if only files selected for Report/Comment Generation should
// be used and the file is not enabled in the Settings (indicated
// by the flag 'useRptGenSettings'), do not add the file's metrics to
// the package metrics. Just move on to the next file.
if(!includeMetricsOfAllFiles) {
if(!FileMetrics.fileEnabled(file, useRptGenSettings)){
continue;
}
}
fileMet= metrics.fileMetrics(file);
packTotLines += fileMet.totalLines;
packSrcLines += fileMet.sourceLines;
packBlkLines += fileMet.blankLines;
packCmtLines += fileMet.commentLines;
}
nfiles = getFileCount(pack, includeMetricsOfAllFiles, useRptGenSettings);
nclasses= getClassCount(pack, includeMetricsOfAllFiles, useRptGenSettings);
pckmet = {packTotLines, packSrcLines, packBlkLines, packCmtLines, nfiles,
nclasses};
return pckmet;
}
boolean packageEnabled(pack, useRptGenSettings) {
return useRptGenSettings ?
getApplication().JSXProject.isPackageSelectedForReport(pack.name) :
true;
} |
The generated report looks as follows:
Fig. 6.2
|
|