Code Query Language (CQL)

REFLECTK comes with a build-in, powerful but intuitive DSL that makes it possible to formulate all kinds of searches on the classpath with a minimum of programming effort. This language is called CQL. The syntax has similarities to the SQL. While SQL inspects database tables to find rows that match a certain condition, CQL does the same with an application's classpath to find Java language entities (packages, classes, fields, methods,...).

It is seamlessly integrated into the JDK's Scripting API. So it is possible to realize new queries or rules very fast with minimal effort.

First (simple) Example

Let's assume you've developed an application that is packaged in the two jar files base.jar and ui.jar. Unfortunately all test-cases you've written are included in these jars as well. But in production environment you don't want to deploy tests. So you need to list all test classes (each test class is named .*Test) to remove them.

Corresponding CQL statement:

Second Example

Now you experienced problems with garbage collection. You had debugged the application and found out that the error was raised by a incorrectly overridden method of java.lang.Object#finalize(). To minimize risks you'd like to search all classes that override finalizers to review them.

Corresponding CQL statement:

Third (complex) Example

By the way you found several code blocks that print debug messaged to stdout. You realized that those messages would not be included in your application's logfile. So you have to fix this issue, too.

Corresponding CQL statement:

Check it out

To get familiar with the basic REFLECTK architecture and the important concepts, please visit the Framework section. An overall documentation of the CQL syntax and language elements can be found in the CQL specification

To get a taste of CQL please take a look at the CQL Console.