-
- The Prototype
-
-
- Research
Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
The german version of this tutorial is available here.
After this tutorial you will be able to write and use a simple Detector of Cultivate. For this purpose we are going to write a Detector which finds the occurrence of “;” without previous Statements. This Detector is already included in Cultivate as the NopSmell-Detector.
public class A { public void x() { ;; } }
:- multifile detector_description/4.
:- consult('externalFile.pl'). :- consult('inDirectory/anotherExternalFile.pl').
Now we are ready to write our first Detector! Add to the 'conventions.pl' file
detector_description(myFirstDetector,'a short description',statement,unrated). detector_(myFirstDetector,occurrence,[(statement,CallID)],[]) :- fail.
The predicates used in this two lines are
After saving the 'conventions.pl' we need to refresh all detector definitions. Right Click the Project for the context menu and choose 'Refresh Detector Definitions'.
For viewing the Detector-Results goto Window/Show View/Other… and Cultivate/ Metrics and Detector Results. In the right top corner of this view clicking on the triangle will show a list of all available Detectors, including our new written one.
Currently our Detector should return no results, because we implemented it with a 'fail'. We will change this in the next section.
Substitute the detector_ predicate in the 'conventions.pl' file with the following code:
detector_(myFirstDetector, occurrence, [(statement, CallID)], []) :- nopT(CallID, _, _).
The nopT-predicate represents a single semicolon, just what we need. After saving the file don't forget to refresh the detector definitions. In the View you should see now two results, one for each single semicolon.