Search in sources :

Example 1 with CodeSmellType

use of org.eclipse.titanium.markers.types.CodeSmellType in project titan.EclipsePlug-ins by eclipse.

the class RepairTimePage method createContents.

@Override
protected Control createContents(final Composite parent) {
    final Composite ret = new Composite(parent, 0);
    ret.setLayout(new GridLayout(4, false));
    new Label(ret, SWT.NONE).setText("");
    new Label(ret, SWT.NONE).setText("Minimal");
    new Label(ret, SWT.NONE).setText("Average");
    new Label(ret, SWT.NONE).setText("Maximal");
    for (final TaskType actSmell : TaskType.values()) {
        makeNewRow(ret, actSmell);
    }
    for (final CodeSmellType actSmell : CodeSmellType.values()) {
        makeNewRow(ret, actSmell);
    }
    return ret;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) Composite(org.eclipse.swt.widgets.Composite) TaskType(org.eclipse.titanium.markers.types.TaskType) Label(org.eclipse.swt.widgets.Label)

Example 2 with CodeSmellType

use of org.eclipse.titanium.markers.types.CodeSmellType in project titan.EclipsePlug-ins by eclipse.

the class CsvProblemExporter method exportMarkers.

/**
 * Export the code smells of a project to CSV files.
 * <p>
 * There is always a CSV with the name summary, which contains the names of
 * all code smells, and their occurrence in the actual project. And for each
 * code smell, where at least 1 occurrence was present a separate CSV is
 * created too. In this CSV the reported error messages, the path of the
 * resources and the line number in which the smell was found is listed.
 *
 * Note: All code smell types are used in the analysis and are written in
 * the output. Some code smells use external settings, which can be fine
 * tuned on the preference page.
 *
 * @param filenamePrefix
 *            the filename prefix to be used in creating the CSV files.
 * @param date
 *            the time stamp to be used (currently unused)
 *
 * @throws IOException
 *             when writing the file fails
 */
@Override
public void exportMarkers(final IProgressMonitor monitor, final String filenamePrefix, final Date date) throws IOException {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    final PrintWriter summaryFile = new PrintWriter(new FileWriter(filenamePrefix + "_summary.csv"));
    final PrintWriter timesFile = new PrintWriter(new FileWriter(filenamePrefix + "_times.csv"));
    try {
        summaryFile.println("Smell name" + SEPARATOR + "Amount");
        timesFile.println("Smell name" + SEPARATOR + "Minimal repair time" + SEPARATOR + "Average repair time" + SEPARATOR + "Maximal repair time");
        PrintWriter actualSmellFile = null;
        final Map<TaskType, List<IMarker>> markers = collectMarkers();
        for (final TaskType actSmell : TaskType.values()) {
            int row = 0;
            if (!markers.get(actSmell).isEmpty()) {
                actualSmellFile = new PrintWriter(new FileWriter(filenamePrefix + "_" + actSmell.getHumanReadableName() + ".csv"));
                actualSmellFile.println("Message" + SEPARATOR + "Smell name" + SEPARATOR + "Line number");
                for (final IMarker m : markers.get(actSmell)) {
                    actualSmellFile.println(m.getAttribute(IMarker.MESSAGE).toString() + SEPARATOR + m.getResource().getName() + SEPARATOR + m.getAttribute(IMarker.LINE_NUMBER));
                    ++row;
                }
                actualSmellFile.close();
                actualSmellFile = null;
            }
            summaryFile.println(actSmell.getHumanReadableName() + SEPARATOR + row);
            timesFile.println(actSmell.getHumanReadableName() + SEPARATOR + row * actSmell.getMinRepairTime() + SEPARATOR + row * actSmell.getAvgRepairTime() + SEPARATOR + row * actSmell.getMaxRepairTime());
        }
        progress.worked(20);
        final MarkerHandler mh = AnalyzerCache.withAll().analyzeProject(progress.newChild(30), project);
        progress.setWorkRemaining(CodeSmellType.values().length);
        for (final CodeSmellType actSmell : CodeSmellType.values()) {
            int row = 0;
            if (!mh.get(actSmell).isEmpty()) {
                actualSmellFile = new PrintWriter(new FileWriter(filenamePrefix + "_" + actSmell.name() + ".csv"));
                actualSmellFile.println("Description; Resurce; Location");
                for (final Marker m : mh.get(actSmell)) {
                    if (m.getLine() == -1 || m.getResource() == null) {
                        continue;
                    }
                    actualSmellFile.println(m.getMessage() + SEPARATOR + m.getResource().getName() + SEPARATOR + m.getLine());
                    ++row;
                }
                actualSmellFile.close();
                actualSmellFile = null;
            }
            summaryFile.println(actSmell.getHumanReadableName() + SEPARATOR + row + SEPARATOR + row * actSmell.getMinRepairTime() + SEPARATOR + row * actSmell.getAvgRepairTime() + SEPARATOR + row * actSmell.getMaxRepairTime());
            timesFile.println(actSmell.getHumanReadableName() + SEPARATOR + row * actSmell.getMinRepairTime() + SEPARATOR + row * actSmell.getAvgRepairTime() + SEPARATOR + row * actSmell.getMaxRepairTime());
            progress.worked(1);
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace("Error while exporting to csv", e);
    } finally {
        summaryFile.close();
        timesFile.close();
    }
}
Also used : CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) CoreException(org.eclipse.core.runtime.CoreException) FileWriter(java.io.FileWriter) TaskType(org.eclipse.titanium.markers.types.TaskType) SubMonitor(org.eclipse.core.runtime.SubMonitor) List(java.util.List) IMarker(org.eclipse.core.resources.IMarker) Marker(org.eclipse.titanium.markers.handler.Marker) IMarker(org.eclipse.core.resources.IMarker) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) PrintWriter(java.io.PrintWriter)

Example 3 with CodeSmellType

use of org.eclipse.titanium.markers.types.CodeSmellType in project titan.EclipsePlug-ins by eclipse.

the class XlsProblemExporter method createTimeSheet.

/**
 * Create the summary sheet in the exported document.
 *
 * @param workbook the workbook to work in.
 */
private void createTimeSheet(final HSSFWorkbook workbook) {
    final HSSFSheet timeSheet = workbook.createSheet("Repair times");
    workbook.setSheetOrder("Repair times", 1);
    final Row headerRow = timeSheet.createRow(0);
    headerRow.createCell(1).setCellValue("Minimal repair time");
    headerRow.createCell(2).setCellValue("Average repair time");
    headerRow.createCell(3).setCellValue("Maximal repair time");
    int summaryRow = 4;
    Cell label;
    for (final TaskType t : TaskType.values()) {
        final Row row2 = timeSheet.createRow(summaryRow);
        label = row2.createCell(0);
        label.setCellValue(t.getHumanReadableName());
        final Cell minTimeCell = row2.createCell(1);
        minTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        minTimeCell.setCellFormula(t.getMinRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell avgTimeCell = row2.createCell(2);
        avgTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        avgTimeCell.setCellFormula(t.getAvgRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell maxTimeCell = row2.createCell(3);
        maxTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        maxTimeCell.setCellFormula(t.getMaxRepairTime() + "*Summary!$B" + (++summaryRow));
    }
    for (final CodeSmellType t : CodeSmellType.values()) {
        final Row row2 = timeSheet.createRow(summaryRow);
        label = row2.createCell(0);
        label.setCellValue(t.getHumanReadableName());
        final Cell minTimeCell = row2.createCell(1);
        minTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        minTimeCell.setCellFormula(t.getMinRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell avgTimeCell = row2.createCell(2);
        avgTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        avgTimeCell.setCellFormula(t.getAvgRepairTime() + "*Summary!$B" + (summaryRow + 1));
        final Cell maxTimeCell = row2.createCell(3);
        maxTimeCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
        maxTimeCell.setCellFormula(t.getMaxRepairTime() + "*Summary!$B" + (++summaryRow));
    }
    final Row totalRow = timeSheet.createRow(1);
    totalRow.createCell(0).setCellValue("Total");
    final Cell cell1 = totalRow.createCell(1);
    cell1.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell1.setCellFormula("SUM($B4:$B" + summaryRow + ")");
    final Cell cell2 = totalRow.createCell(2);
    cell2.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell2.setCellFormula("SUM($C4:$C" + summaryRow + ")");
    final Cell cell3 = totalRow.createCell(3);
    cell3.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    cell3.setCellFormula("SUM($D4:$D" + summaryRow + ")");
    timeSheet.autoSizeColumn(0);
    timeSheet.autoSizeColumn(1);
    timeSheet.autoSizeColumn(2);
    timeSheet.autoSizeColumn(3);
}
Also used : CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) TaskType(org.eclipse.titanium.markers.types.TaskType) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell)

Example 4 with CodeSmellType

use of org.eclipse.titanium.markers.types.CodeSmellType in project titan.EclipsePlug-ins by eclipse.

the class XlsProblemExporter method exportMarkers.

/**
 * Export the code smells of a project to an excel workbook.
 * <p>
 * The first sheet of the workbook is a summary page, showing the number of
 * hits for each code smell, and an expressive bar chart of these data. The
 * further sheets enumerate the specific code smells of each kind, including
 * the message of the code smell, and the file name and line where it
 * occurred.
 * <p>
 * Note: All code smell types are used in the analysis and are written in
 * the output. Some code smells use external settings, which can be fine
 * tuned on the preference page.
 *
 * @param filename
 *            the file to save the xls
 * @param date
 *            the time stamp to write on the summary page
 *
 * @throws IOException
 *             when writing the file fails
 */
@Override
public // guaranteed to be initialized first.
void exportMarkers(final IProgressMonitor monitor, final String filename, final Date date) throws IOException {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    final File file = new File(filename);
    POIFSFileSystem fs = null;
    HSSFWorkbook workbook = null;
    try {
        fs = new POIFSFileSystem(XlsProblemExporter.class.getResourceAsStream("ProblemMarkers.xlt"));
        workbook = new HSSFWorkbook(fs, true);
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
        // one (without the chart).
        if (reportDebugInformation) {
            TITANDebugConsole.println("Error on opening ProblemMarkers.xlt. Chartless xls will be generated");
        }
        workbook = new HSSFWorkbook(new FileInputStream(file));
        workbook.createSheet("Summary");
        workbook.setSheetOrder("Summary", 0);
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
        return;
    }
    progress.worked(10);
    final List<IProject> projects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
    projects.remove(project);
    try {
        final HSSFSheet summarySheet = workbook.getSheetAt(0);
        createTimeSheet(workbook);
        final Map<String, Integer> smellCount = new HashMap<String, Integer>();
        int summaryRow = 4;
        Cell label = null;
        Cell numberCell = null;
        final Map<TaskType, List<IMarker>> markers = collectMarkers();
        // export the task markers:
        for (final TaskType t : TaskType.values()) {
            createTaskSheet(workbook, t, markers.get(t), projects.size() > 0);
            final Row row1 = summarySheet.createRow(summaryRow++);
            label = row1.createCell(0);
            label.setCellValue(t.getHumanReadableName());
            final int nofMarkers = markers.get(t).size();
            numberCell = row1.createCell(1);
            numberCell.setCellValue(nofMarkers);
            // row-1 is the number of found markers
            smellCount.put(t.name(), nofMarkers);
        }
        progress.worked(20);
        final MarkerHandler mh = AnalyzerCache.withAll().analyzeProject(progress.newChild(30), project);
        progress.setWorkRemaining(CodeSmellType.values().length + 1);
        // export the semantic problem markers:
        for (final CodeSmellType t : CodeSmellType.values()) {
            createCodeSmellSheet(workbook, mh, t, projects.size() > 0);
            final Row row1 = summarySheet.createRow(summaryRow++);
            label = row1.createCell(0);
            label.setCellValue(t.getHumanReadableName());
            smellCount.put(t.name(), mh.numberOfOccurrences(t));
            numberCell = row1.createCell(1);
            numberCell.setCellValue(mh.numberOfOccurrences(t));
            progress.worked(1);
        }
        final StringBuilder nameBuilder = new StringBuilder("Project: ");
        nameBuilder.append(project.getName());
        if (projects.size() > 0) {
            nameBuilder.append(" including ( ");
            for (int i = 0; i < projects.size(); i++) {
                if (i > 0) {
                    nameBuilder.append(", ");
                }
                nameBuilder.append(projects.get(i).getName());
            }
            nameBuilder.append(" )");
        }
        final Row row0 = summarySheet.createRow(0);
        row0.createCell(0).setCellValue(nameBuilder.toString());
        final Row row1 = summarySheet.createRow(1);
        row1.createCell(0).setCellValue("Code smell \\ date");
        final CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("yyyy.mm.dd"));
        label = row1.createCell(1);
        label.setCellValue(date);
        label.setCellStyle(cellStyle);
        final Row row2 = summarySheet.createRow(2);
        row2.createCell(0).setCellValue("Commulative Project Risk Factor");
        final int riskFactor = new RiskFactorCalculator().measure(project, smellCount);
        row2.createCell(1).setCellValue(riskFactor);
        summarySheet.autoSizeColumn(0);
        summarySheet.autoSizeColumn(1);
        progress.worked(1);
    } catch (Exception e) {
        ErrorReporter.logExceptionStackTrace("Error while exporting to excel", e);
    } finally {
        FileOutputStream fileOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(file);
            workbook.write(fileOutputStream);
        } catch (Exception e) {
            ErrorReporter.logExceptionStackTrace("Error while closing the generated excel", e);
        } finally {
            IOUtils.closeQuietly(fileOutputStream);
        }
    }
}
Also used : HashMap(java.util.HashMap) TaskType(org.eclipse.titanium.markers.types.TaskType) List(java.util.List) MarkerHandler(org.eclipse.titanium.markers.handler.MarkerHandler) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileOutputStream(java.io.FileOutputStream) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) File(java.io.File) RiskFactorCalculator(org.eclipse.titanium.markers.utils.RiskFactorCalculator)

Example 5 with CodeSmellType

use of org.eclipse.titanium.markers.types.CodeSmellType in project titan.EclipsePlug-ins by eclipse.

the class RepairTimePage method performOk.

@Override
public boolean performOk() {
    for (final TaskType actSmell : TaskType.values()) {
        final TimeDataEntry value = storedValues.get(actSmell);
        if (value != null) {
            setAvgValue(actSmell, value.avgTime);
            setMinValue(actSmell, value.minTime);
            setMaxValue(actSmell, value.maxTime);
        }
    }
    for (final CodeSmellType actSmell : CodeSmellType.values()) {
        final TimeDataEntry value = storedValues.get(actSmell);
        if (value != null) {
            setAvgValue(actSmell, value.avgTime);
            setMinValue(actSmell, value.minTime);
            setMaxValue(actSmell, value.maxTime);
        }
    }
    return super.performOk();
}
Also used : CodeSmellType(org.eclipse.titanium.markers.types.CodeSmellType) TaskType(org.eclipse.titanium.markers.types.TaskType)

Aggregations

CodeSmellType (org.eclipse.titanium.markers.types.CodeSmellType)6 TaskType (org.eclipse.titanium.markers.types.TaskType)6 List (java.util.List)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 CoreException (org.eclipse.core.runtime.CoreException)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 MarkerHandler (org.eclipse.titanium.markers.handler.MarkerHandler)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1