Java code analysis and linting with SQL
Important note: This project is in early stage. It is published for evaluation purpose with your help!
Please give it a try and send us your feedback, we would love to hear your thoughts!
JQL (Java Query Language) makes it possible to query Java source code with SQL. This allows you to answer questions like:
This repository provides a static analysis tool that gives you precious insights on your code base in order to improve its quality.
JQL engine creates a relational database from a Java code base. Once you have created the relational database, you can
query it with standard SQL. The relational model has been designed to be intuitive, natural and easy to understand and query.
Here are the core entities and relations:
You can find a complete description of the database schema here.
SELECT i.NAME as name, COUNT(m.ID) as nbMethods
FROM INTERFACE i, METHOD m
WHERE m.TYPE_ID = i.ID GROUP BY i.ID HAVING COUNT(m.ID) > 20;
SELECT c.NAME as name, COUNT(c.ID) as nbConstructors
FROM CLASS c, CONSTRUCTOR co
WHERE co.TYPE_ID = c.ID GROUP BY c.NAME HAVING COUNT(c.ID) > 5;
SELECT t.NAME as typeName, m.NAME as methodName, COUNT(m.ID) as nbParams
FROM TYPE t, METHOD m, PARAMETER p
WHERE p.METHOD_ID = m.ID and m.TYPE_ID = t.ID
GROUP BY m.ID HAVING COUNT(m.ID) > 5;
SELECT name, LENGTH(name) as length from CLASS ORDER BY length DESC LIMIT 10;
You can find some real world examples on popular open source projects here.
JQL engine is distributed as a single executable jar that creates a self-contained serverless Sqlite relational database from your Java code base:
java -jar jql-core-0.1.jar /path/to/project/to/analyse /path/to/database/directory
This command will index your code and create a file named jql.db
in the specified directory.
For maven based projects, just run the following command in the root directory of the project to analyse:
mvn io.github.benas:jql-maven-plugin:index
The jql.db
file will be created in the target
directory.
Once you are done, you can open the jql.db
file with your favorite SQL client and start writing queries.
You can find all details about how to get started here.
Since the project is still a PoC, we are not yet focused on the quality of the code base.
The main goal for the moment is to see if the relational model is adequate for Java code analysis and linting.
If you want to contribute, please consider the tool as a black box for now.
Any suggestion or improvement of the relational model is very welcome!
You can try to index a code base (or download a pre-indexed database sample) and write some queries.
If there is a question you cannot answer, you have certainly found a way to improve the current model!
So please open an issue with your question and this would be a great contribution!
JQL tools use JavaParser to parse Java code and transform it into a relational model.
JQL tools use Sqlite to store Java code model in a relational database.
JQL tools are released under the MIT license:
The MIT License
Copyright (c) 2016, Mahmoud Ben Hassine ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.