SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
research:cultivate:tutorial_my_first_detector [2009/03/11 23:44]
127.0.0.1 external edit
research:cultivate:tutorial_my_first_detector [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== Tutorial - Writing a first Detector ======
 +The german version of this tutorial is available [[tutorialeigenedetektorenschreiben|here]].
 +
 +===== Goal of the Tutorial =====
 +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.
 +
 +===== Step 0: Setup =====
 +
 +   - Eclipse and Cultivate should be installed and runable. The complete installation guide can be found on [[..:​..:​teaching:​labs:​xp:​2009a:​development_environment| Development Environment]].
 +   - Create a new project and include the following class
 +<​note> ​
 +  package a;
 +  public class A {
 +  ​
 +    public void x() {
 +       ;; ​   ​
 +    }
 +  }
 + </​note>​
 +   - Assign JTransformer and Prolog-Nature to this project. ​
 +   - Goto the project properties and assign the Cultivate-Nature ​ (Cultivate->​ [x] Cultivate Nature), this is only available after you assigned JTransformer-Nature.
 +===== Step 1: Creating Conventions.pl ​ =====
 +   - Create a file named '​conventions.pl'​ in the main folder of the project with the following content:
 +<​note> ​
 +     :- multifile detector_/​4.
 +     :- multifile detector_description/​4.
 +</​note> ​
 +   - Project specific Detectors, in external files, can be included in this file with
 +<​note>​
 +     :- consult('​externalFile.pl'​).
 +     :- consult('​inDirectory/​anotherExternalFile.pl'​).
 +</​note>​
 +===== Step 2: Creating a empty Detector ​ =====
 +Now we are ready to write our first Detector! Add to the '​conventions.pl'​ file
 +<​note>​
 +        detector_description(myFirstDetector,'​a short description',​statement,​unrated).
 +        detector_(myFirstDetector,​occurrence,​[(statement,​CallID)],​[]) :- 
 +                 fail.    ​
 +</​note>​
 +
 +The predicates used in this two lines are
 +== detector_description/​4 ​ ==
 +     - The name of the Detector, this must be equal in both predicates.
 +     - A short description of the Detector
 +     - Name of the Role. A Detector returns references to code-elements (IDs)  and relations between them.  To each ID a role is assigned.
 +     - A RatingType, for simple Detectors '​unrated'​ is sufficient.
 +== detector_/​4 ​ (Don't forget the '​_'​)==
 +     - The name of the Detector, this must be equal in both predicates.
 +     - We are using the unrated RatingType, so all Ratings must be '​occurrence'​
 +     - A list of IDs and their Roles. Here we are using only one Role '​statement'​ assigned to the ID '​CallID'​.
 +     - The Relation between code-elements,​ can be empty ('​[]'​).
 +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**'​.
 +{{:​teaching:​labs:​xp:​2009a:​newdetectortutorial_refresh.png|}}
 +
 +
 +===== Step 3: Viewing the Detector-Results ​ =====
 +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.
 +
 +
 +{{:​teaching:​labs:​xp:​2009a:​newdetectortutorial_1_1.png|}}
 +
 +Currently our Detector should return no results, because we implemented it with a '​fail'​. We will change this in the next section.
 +===== Step 4: Implementing the Detector ​ =====
 +Substitute the **detector_** predicate in the '​conventions.pl'​ file with the following code:
 +<​note>​
 +     ​detector_(myFirstDetector,​ occurrence, [(statement,​ CallID)], []) :- 
 +         ​nopT(CallID,​ _, _).
 +</​note>​
 +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.
 +
 +===== Appendix A: Hints & Tips  =====
 +==== Possible Errors ====
 +     - After saving the conventions.pl file no refresh of the detector definitions was done.
 +     - When using '​unrated'​ RatingType ​ the Rating '​occurrence'​ must be used
 +     - Prolog errors in the code
 +==== Finding Errors ====
 +     - If the Detector is not working, look into the output log of Eclipse and browse through the output. If this doesn'​t help look at the StackTrace and change the logging level.
 +
  
research/cultivate/tutorial_my_first_detector.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019