Rule catalog

In this page you find all rules currently supported in Dicto.

Each rule can be expressed in 5 modes:
  • X must have property A
  • X must have be related to some A
  • X cannot have property A
  • X can only have property A
  • only X can have property A
Rules can have multiple subjects and multiple predicate arguments:
  • X, Y must have property A, B
  • X, Y must have property A / B
Variables can be described through a combination of various selection attributes.

Dependencies

ō Class / Package cannot depend on Class / Package
ō Class / Method cannot invoke Method
ō Method must be invoked
ō Set <Package> must be layered
ō Package / System cannot contain dead methods
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
Tests = Class with name:"*test_*"
Application = Package with name:"org.myapp.application"
Contrib = Package with name:"org.myapp.contrib.*"

Tests can only depend on Application
Contrib cannot depend on Application
ControllerMethods = Method with name:"org.myapp.controller.*Controller.*"
CheckErr = Method with name:"org.springframework.validation.BindingResult.hasErrors()"

ControllerMethods must invoke CheckErr
ServiceMethods = Method with name:"org.myapp.*.service.Service.*"
TestMethods = Method with name:"*.test*"
DeprecatedMethods = Method with annotation:"@Deprecated"

ServiceMethods must be invoked
TestMethods cannot be invoked
DeprecatedMethods cannot be invoked
Controller = Package with name:"org.myapp.controller"
Model = Package with name:"org.myapp.model"
Dao = Package with name:"org.myapp.dao"

Controller, Model, Dao must be layered
Util = Package with name:"org.myapp.util"
Test = Package with name:"org.myapp.test"

Util cannot contain dead methods
only Test can contain dead methods

Structural properties

ō Class must have method Method / "String"
ō Method must be named "String"
ō Class / Method / Field must have annotation "@String(..)"
ō Class / Method / Field must have annotation name "String"
ō Class / Method / Field must have annotation type "String"
ō Class must implement interface "String"
ō Method must have method parameter Class
ō Any type must exist
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
Tests = Class with name:"*test_*"
JunitSetup = Method with annotation:"@Before", name:"setUp"
JunitTeardown = Method with annotation:"@After", name:"tearDown"

Tests must have method JunitSetup, JunitTeardown
Tests must have method "test*"
PojoMethods = Method with containingClass:"org.myapp.controller.pojos.*"

PojoMethods can only be named "get*", "set*"
ServiceMethods = Method with containingClass:"org.myapp.controller.service.*ServiceImpl"
ControllerMethods = Method with containingClass:"org.myapp.controller.*", annotation:"@Controller"

ServiceMethods must have annotation "@javax.transaction.Transactional"
ControllerMethods can only have annotation "@org.springframework.*.RequestMapping(*,*.RequestMethod.GET)", "@*RequestMapping(*,*.RequestMethod.POST)"
only ControllerMethods can have annotation "@org.springframework.*.RequestMapping"
ServiceMethods = Method with containingClass:"org.myapp.controller.service.*ServiceImpl"

ServiceMethods must have annotation name "Transactional"
ServiceMethods = Method with containingClass:"org.myapp.controller.service.*ServiceImpl"

ServiceMethods must have annotation type "javax.transaction.Transactional"
ModelClasses = Class with name:"**.*Model", type!:"interface"
ImplClasses = Class with name:"(**).impl.(*)Impl"

ModelClasses must implement interface "java.io.Serializable"
ImplClasses must implement interface "$1.$2"
ControllerHandlers = Method with annotation:"@RequestMapping"
Entities = Class with annotation:"@Entity"

ControllerHandlers cannot have method parameter Entities
POM = File with file:"*/pom.xml"

POM must exist

Exceptions

ō Class / Method must throw Class
ō Class / Method must catch Class
ō Class must be caught
ō Class cannot have empty catch block
ō Class must be thrown
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
Controllers = Class with name:"org.sample.controller.*Controller"
ValidationExceptions = Class with name:"org.sample.*.*ValidationException"

Controllers must throw ValidationExceptions
ProjectClasses = Class with name:"*"
Controllers = Class with name:"org.sample.controller.*Controller"
ProjectExceptions = Class with name:"org.sample.controller.exceptions.*"
ValidationExceptions = Class with name:"org.sample.*.*ValidationException"

ProjectClasses can only catch ProjectExceptions
only Controllers can catch ValidationExceptions
ProjectExceptions = Class with name:"org.sample.controller.exceptions.*"

ProjectExceptions must be caught
ControllerMethods = Method with name:"**.controller.**"

ControllerMethods cannot have empty catch block
ProjectExceptions = Class with name:"org.sample.controller.exceptions.*"

ProjectExceptions must be thrown

Anti-patterns

ō System / Package cannot contain code clones
ō System / Package cannot contain cycles
ō Class cannot lead to deadlock
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
Util = Package with name:"org.myapp.util"

SYSTEM cannot contain code clones
Util cannot contain code clones
Model = Package with name:"org.myapp.model"

SYSTEM cannot contain cycles
Model cannot contain cycles
ModelClasses = Class with name:"org.myapp.model.*"

ModelClasses cannot lead to deadlock

Web applications

ō WebResource must have latency < "Integer ms"
ō WebResource must handle load from "Integer users"
ō WebResource must have content "String"
ō WebResource must have content type "String"
ō WebResource must have content length > "Integer"
ō WebResource must have status code "Integer"
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
Example = WebResource with url:"http://www.example.com"

Example must have latency < "1000 ms"
Example = WebResource with url:"http://www.example.com"

Example must handle load from "10 users"
GetUser = WebResource with url:"http://www.example.com/api/user?id=1"

GetUser must have content "*'John Doe'*"
SaveUser = WebResource with url:"http://www.example.com/api/createUsers", method:"post", content:"{\"name\":\"John\", \"surname\":\"Doe\"}" contentType:"application/json"

SaveUser must have content type "application/json"
SaveUser = WebResource with url:"http://www.example.com/api/listUsers"

SaveUser must have content length > "100"
SaveUser = WebResource with url:"http://www.example.com/api/error"

SaveUser must have status code "500"

Text/XML Files

ō File / Method must contain text "String"
ō File must exist
ō XMLTag must have text "String"
ō XMLTag must have child "String" / XMLTag
ō XMLTag must have attribute "String" / XMLTagAttribute
ō XMLTagAttribute must have value "String"
ō XMLTagAttribute must have name "String"
Concrete Examples:
Click on the ō symbol next to the rule template to display examples.
POM = File with file:"*/pom.xml"

POM must contain text "spring-core", "spring-web", "spring-data-jpa"
POM = File with file:"*/pom.xml"

POM must exist
WebServletClass = XMLTag with file:"*/web.xml", name: "servlet-class"
WebServletParam = XMLTag with file:"*/web.xml", xpath: "//servlet/*/param-value"

ServletClass must have text "org.springframework.web.servlet.DispatcherServlet"
WebContextParam must have text "/WEB-INF/config/*.xml"
WebRoot = XMLTag with file:"*/web.xml", name: "web-app"

WebRoot must have child "servlet", "servlet-mapping", "listener"
DataBean = XMLTag with file:"*/springData.xml", name: "bean", attribute:"mainDataSource"

DataBean must have attribute "destroy-method"
WebRootVersion = XMLTagAttribute with file:"*/web.xml", name: "version"

DataBean must have value "2.5"
XMLUrls = XMLTagAttribute with file:"*/*.xml", value: "http://*"

XMLUrls must have name "*-url"