OOPSLA '07: SemmleCode Demo
SeemleCode by Semmle is a tool for for Java and XML code querying. It features its own query language, unsurprisingly called, QL for Query Language and a set of UI options for displaying the results of the queries. Currently, the results could be displayed in a table or in graph form (pie chart, bar chart, etc).
The above code snipper has been taken from their example page. This query finds all classes in the package org.jhotdraw and its subpackages. So the language is like SQL except that it structured as
from Class c
where c.getPackage().getName().matches("org.jhotdraw%")
select c.getPackage(), c
from... where... select...
instead of the more ubiquitous select... from... where...
. According to the developers, this ordering makes it easier to enable context-sensitive content assist as the user is typing.
What I like about this system is the fact that the query language can be used to do a lot of useful things. The example script that comes preloaded with SemmleCode has some example metrics that you could run on you system. Here is an example that measures the Depth of Inheritance Tree.
The code snippet above reports reference types whose maximum distance to Object is greater than 6, in decreasing order of distance.
from MetricRefType t, int d
where t.fromSource() and d = t.getInheritanceDepth() and d > 6
select t, d order by d desc
Moreover, given a complex enough query you could even use it as a form of code lint to check for inconsistencies in the code. So this system is extensible and could be used as a tool to query and inspect the source code in a non-invasive manner by the programmer.
SemmleCode comes with an in-memory database to store all the meta-information for querying. However, using this in-memory database for larger projects is really not recommended. Instead you should either install PostgreSQL or Microsoft SQL Server. Since I was on a Mac, I installed PostgreSQL and got it to work. The installation took only an hour or so (mostly because the internet connection was flaky) and PostgreSQL was easily installed on the Mac following the instructions that came with the download.
One caveat though and I discovered this after showing my installation to one of the developers present at the demo: SemmleCode operates on working sets in Eclipse. Unfortunately, those working sets need to be defined as Java Working Sets and not Resource Working Sets. SemmleCode will not recognize the Java files in a Resource Working Set since it is looking for the Java nature. After fixing this, SemmleCode works just fine. I ran it on the Photran source code and it was able to complete the analysis rather quickly.
So far SemmleCode is free to download and use. I suspect that a paid version would include a prepackaged library that has more sophisticated queries that developers might find useful.
Tweetcomments powered by Disqus