You can integrate CQL Queries directly in your source code using Java annotations. During the analysis these rules are extracted and integrated into the report and the GUI.
There are two different annotations:
- The CQLConstraint annotation allows you to specify a query on a code element.
Sample Java class using @CQLConstraint
@CQLConstraint(name="Testing HasAnnotation on members", query="WARN IF Count < 1 IN SELECT METHODS WHERE HasAnnotation \"org.junit.Test\"") package com.octo.xdepend.provider.loader.samples; import com.xdepend.tools.CQLConstraint; ..........
- The CQLConstraints annotation allows you to group multiple CQLConstraint annotations on the same code element.
Sample Java class using @CQLConstraints
@CQLConstraints({ @CQLConstraint(name="Testing HasAnnotation on members", query="WARN IF Count < 1 IN SELECT METHODS WHERE HasAnnotation \"org.junit.Test\""), @CQLConstraint(name="Testing HasAnnotation on types", query="WARN IF Count < 1 IN SELECT TYPES WHERE HasAnnotation \"com.octo.xdepend.provider.domain.CQLConstraint\"") }) package com.octo.xdepend.provider.loader.samples; import com.xdepend.tools.CQLConstraint; import com.xdepend.tools.CQLConstraints; .......... - Complete definition on CQLConstraint
@CQLConstraint complete definition
package com.xdepend.tools; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.CLASS) public @interface CQLConstraint { //The human readable name of the query (will be displayed in CQL list view in VisualXDepend ) String name() default "Custom Query"; // The CQL query String query(); //Activate or not query in report boolean active() default true; //Display detailed results in report boolean displayListInReport() default true; //Display statistics in report boolean displayStatInReport() default true; //Display.. boolean displaySelectionViewInReport() default true; }
These annotations are available in a jar which you can download here.
Once downloaded you can use this jar as a dependency to your project. In Eclipse for instance, you would right click on the project then Build Path > Add External Archives and select the jar. You can then start adding CQL queries to your code.
