use of org.eclipse.titanium.markers.handler.Marker in project titan.EclipsePlug-ins by eclipse.
the class Analyzer method analyzeModule.
/**
* Analyze a single module.
* <p>
* Executes the configured code smell spotters on the given module (and if
* the <code>Analyzer</code> uses project-scoped code smell spotters, then
* those are executed, too, on the project of the module). Locking the
* project to prevent modification of the AST is handled internally.
*
* @param monitor
* shows progress and makes it interruptable
* @param module
* the ttcn3 module to analyze
*
* @return the code smells found in the given module
*/
public MarkerHandler analyzeModule(final IProgressMonitor monitor, final Module module) {
final SubMonitor progress = SubMonitor.convert(monitor, 100);
final IResource res = module.getLocation().getFile();
final Map<IResource, List<Marker>> markers = new HashMap<IResource, List<Marker>>();
markers.put(res, internalAnalyzeModule(module));
progress.worked(80);
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
final IProject project = module.getProject();
markers.put(project, internalAnalyzeProject(project));
progress.worked(20);
return new MarkerHandler(markers);
}
use of org.eclipse.titanium.markers.handler.Marker 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();
}
}
use of org.eclipse.titanium.markers.handler.Marker in project titan.EclipsePlug-ins by eclipse.
the class Expectation method runTest.
public void runTest() {
Map<String, List<Integer>> actualMarkers = new HashMap<String, List<Integer>>();
// analyze the modules, and collect the related markers
IProject project = WorkspaceHandlingLibrary.getWorkspace().getRoot().getProject(CustomConfigurable.PROJECT_TO_USE);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
for (String modName : expectedMarkers.keySet()) {
Module mod = parser.getModuleByName(modName);
IResource file = mod.getLocation().getFile();
MarkerHandler mh = Analyzer.builder().addProblem(type).build().analyzeModule(new NullProgressMonitor(), mod);
List<Integer> lines = new ArrayList<Integer>();
for (Marker m : mh.get(file)) {
if (m.getProblemType() == type && m.getLine() != -1) {
lines.add(m.getLine());
}
}
// save the line number of markers that were from our problem type
actualMarkers.put(modName, lines);
}
// check whether the reality complies our expectations
for (String modName : expectedMarkers.keySet()) {
for (Integer ln : expectedMarkers.get(modName)) {
if (!actualMarkers.get(modName).remove(ln)) {
fail("We expected a marker in " + modName + " at line " + ln + ", but have not found it");
}
}
}
// Check whether we managed to consume all markers that showed up during the analysis
for (String modName : actualMarkers.keySet()) {
for (Integer ln : actualMarkers.get(modName)) {
fail("Unexpected marker in " + modName + " at line " + ln);
}
}
}
use of org.eclipse.titanium.markers.handler.Marker in project titan.EclipsePlug-ins by eclipse.
the class Analyzer method internalAnalyzeProject.
private List<Marker> internalAnalyzeProject(final IProject project) {
final List<Marker> markers = new ArrayList<Marker>();
for (final BaseProjectCodeSmellSpotter spotter : projectActions) {
List<Marker> ms;
synchronized (project) {
ms = spotter.checkProject(project);
}
markers.addAll(ms);
}
return markers;
}
use of org.eclipse.titanium.markers.handler.Marker in project titan.EclipsePlug-ins by eclipse.
the class Analyzer method analyzeProject.
/**
* Analyze a whole project.
* <p>
* Executes the configured code smell spotters on the given project. Locking
* the project to prevent modification of the AST is handled internally.
*
* @param monitor
* shows progress and makes it interruptable
* @param module
* the ttcn3 project to analyze
*
* @return the code smells found in the given project
*/
public MarkerHandler analyzeProject(final IProgressMonitor monitor, final IProject project) {
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final SubMonitor progress = SubMonitor.convert(monitor, 1 + knownModuleNames.size());
progress.subTask("Project level analysis");
final Map<IResource, List<Marker>> markers = new HashMap<IResource, List<Marker>>();
markers.put(project, internalAnalyzeProject(project));
progress.worked(1);
for (final String moduleName : knownModuleNames) {
if (progress.isCanceled()) {
throw new OperationCanceledException();
}
final Module mod = projectSourceParser.getModuleByName(moduleName);
progress.subTask("Analyzing module " + mod.getName());
final IResource moduleResource = mod.getLocation().getFile();
markers.put(moduleResource, internalAnalyzeModule(mod));
progress.worked(1);
}
return new MarkerHandler(markers);
}
Aggregations