Drill Down into Your Java Projects with SemmleCode

Discussions

News: Drill Down into Your Java Projects with SemmleCode

  1. What Java packages are impacted by a proposed change? Do all your enterprise beans comply with the EJB design rules? Are all team members following your in-house coding conventions? What packages and types need refactoring? Find the answers with SemmleCode. Free to download and free to use, SemmleCode is a new Eclipse plugin for drilling down into your codebase. It exposes the relationships between different elements in your code, so that you can search and measure them. SemmleCode takes code queries in development environments to a whole new level. SemmleCode is shipped with a large collection of queries for common tasks, including popular metrics and many checks for bugs and for style violations. Query results can be visualised in a tree view, in the Eclipse problem view, or as charts or graphs, all with direct links to the source code. What it does To understand large software projects, you need to drill down into the relationships between its components. SemmleCode opens up these relationships for you to inspect and query. SemmleCode works by storing Eclipse projects in a relational database. You can then run queries to compute metrics, to find defects, to check style rules, and to navigate. For almost any frequent task, whether it involves a quality audit or a change impact analysis, there is a ready-made query that you can launch via the run menu of Eclipse. In particular there are queries for Robert C. Martin's package metrics, and for checking J2EE coding conventions. Storing a relational representation of code is not new; many tools marketed under the banners of application portfolio management, application mining, application intelligence, business intelligence for software development, and source code analysis do the same. What sets SemmleCode apart is the ease of adapting queries to new situations, and the power of its .QL query language. SemmleCode offers many of the benefits of these other tools, but in an agile way, putting the information at the fingertips of every team member, easily adapted to their expertise and needs. .QL for Checking .QL is a simple object-oriented query language for writing queries over the codebase. It is very intuitive, and tightly integrated in Eclipse with syntax highlighting, auto-completion, and continuous checking. As a first example, let's write a query that is one of the rules for EJBs: every method in a local home interface must not include RemoteException in its throws clause. With .QL we can find violations as follows: from LocalEJBHomeInterface lhi, Method m where m.getDeclaringType()=lhi and m.getAnException().getType().hasQualifiedName("java.rmi", "RemoteException") select m, m.toString() + " must not throw an exception of "+ "type java.rmi.RemoteException" This query will generate warnings in the Eclipse problem view, as well as warning markers in the source code itself. Of course many frameworks have similar restrictions on API usage, and now you can pin those down with code queries in .QL. .QL for Measuring Metrics can also be defined via .QL queries. To illustrate, the afferent coupling of a type is the number of other types that depend on it. Types with high afferent coupling have many responsibilities, and changing them may have a very broad impact on a system. To find such types, you can use the query from RefType t, int c where c = count(RefType s | depends(s,t)) and c > 25 select t,c order by c desc The predicate depends(s,t) tests whether type s depends on type t. Very roughly, that means t is used somewhere within s. The results of the above query can be displayed as a bar chart; clicking on a bar takes you to the corresponding type definition. .QL helps you to give crisp, simple definitions of all the popular metrics. The SemmleCode documentation includes a full overview of the metrics library. Each metric has a page for entering comments - at Semmle, we love to see vigorous debate about the subtle points of every metric, and about the technical details of their definition in .QL. Do join us there! Re-using .QL queries .QL allows you to encapsulate common queries as methods in class definitions, which makes it easy to share libraries of queries with your friends and colleagues. To illustrate, let's define a subclass of RefType, with a new method for counting the number of fields: class MetricType extends RefType { int numberOfFields() { result = count(Field m | m.getDeclaringType() = this) } } In words, a method is defined by a relation between two special variables, this and result. Above, the result is just the number of methods that are declared in this type. The new class and method can then be immediately used in a select statement: from MetricType t, int n where n = t.numberOfFields() and n > 20 select t,n .QL supports overriding of methods, and that is often very convenient for tailoring checks or metrics to a particular application. SemmleCode puts you in the driving seat when it comes to quality audits: when you think of a new check, it usually takes only a few lines of .QL to implement it, and share it with other team members. Further information To find out more about writing queries and displaying results, read the introductory tutorial. To see how you can define your own classes, and how overriding works in .QL, read the advanced tutorial. There is a community page with forums, FAQs, a bugzilla, and links to further documentation. The development of SemmleCode is driven by the user community, so do let us know what you think! About the creators of SemmleCode Semmle Limited develops novel query technologies. Its first line of products is centred around .QL - an object-oriented query language for any type of structured data. It makes writing queries much easier and more efficient than with the de facto industry standard SQL. Because .QL is object-oriented, queries can be easily re-used or adapted to new situations. Our technology can be employed on all of the major relational database systems. .QL queries are translated (through Semmle's proprietary technology) to highly optimised SQL queries on these existing systems. You can therefore enjoy the benefits of .QL without migrating data to a new repository, and there is no risk of disruption when .QL is introduced in your organisation. As a demonstration of the power of .QL , Semmle distributes SemmleCode for free. Enjoy!
  2. Tried it. It's a cool product. In our organization we have large volume of code that kind of grew organically over the years without any design guidelines and patterns. This tool should help us get a handle on our code. I wish there was a way to run the queries from ant, so there we could compute various metrices as part of our build process. Pranab
  3. ant support[ Go to top ]

    Thanks for your comments. Indeed that's exactly the type of situation SemmleCode will help with! Ant support is a good suggestion. However, we're prioritising according to user requests, and this is the first one for ant support. Any other takers? The forums at http://semmle.com/forum/ are there to discuss feature requests... see you there!
  4. New version of SemmleCode[ Go to top ]

    A new version of SemmleCode has been released, see this announcement.