JTL – the Java Tools Language Tal Cohen Joseph (Yossi) Gil ∗ Itay Maman Department of Computer Science Technion—Israel Institute of Technology Technion City, Haifa 32000, Israel ctal, yogi, imaman @ cs.technion.ac.il Abstract We present an overview of JTL (the Java Tools Language, pro- nounced “Gee-tel”), a novel language for querying JAVA [8] pro- grams. JTL was designed to serve the development of source code software tools for JAVA, and as a small language to aid program- ming language extensions to JAVA. Applications include defini- tion of pointcuts for aspect-oriented programming, fixing type con- straints for generic programming, specification of encapsulation policies, definition of micro-patterns, etc. We argue that the JTL expression of each of these is systematic, concise, intuitive and gen- eral. JTL relies on a simply-typed relational database for program representation, rather than an abstract syntax tree. The underlying semantics of the language is restricted to queries formulated in First Order Predicate Logic augmented with transitive closure ( FOPL * ). Special effort was taken to ensure terse, yet readable expression of logical conditions. The JTL pattern public abstract class, for example, matches all abstract classes which are publicly acces- sible, while class { public clone(); } matches all classes in which method clone is public. To this end, JTL relies on a DATALOG-like syntax and semantics, enriched with quantifiers and pattern matching which all but entirely eliminate the need for re- cursive calls. JTL’s query analyzer gives special attention to the fragility of the “closed world assumption” in examining JAVA software, and determines whether a query relies on such an assumption. The performance of the JTL interpreter is comparable to that of JQuery after it generated its database cache, and at least an order of magnitude faster when the cache has to be rebuilt. Categories and Subject Descriptors D.3.0 [Programming Lan- guages]: General; D.2.3 [Software Engineering]: Coding Tools and Techniques General Terms Design, Languages Keywords Declarative Programming, Reverse Engineering * Research supported in part by the IBM faculty award Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. OOPSLA’06 October 22–26, 2006, Portland, Oregon, USA. Copyright c 2006 ACM 1-59593-348-4/06/0010. . . $5.00. 1. Introduction The designers of frontier programming paradigms and constructs often choose, especially when static typing is an issue, to test- bed, experiment, and even fully implement the new idea by an extension to the JAVA programming language. Examples include ASPECTJ [52], JAM [5], Chai [71], OpenJava [76], the host of type systems supported by pluggable type systems [6], and many more. A prime component in the interaction of such an extension with the language core is the mechanism for selecting program elements to which the extension applies: The pointcuts of ASPECTJ, for example, select the point in the code on which an aspect is to be applied. Also, a key issue of implementing the conclusions of a genericity treatise [31,51] is checking whether a given set of classes are legible as parameters for a given generic construct—what the community calls a concept. JTL (the Java Tools Language) is a declarative language, be- longing in the logic-programming paradigm, designed for the task of selecting JAVA program elements. Two primary applications were in mind at the time when the language was first conceived: (a) Join-point selection for aspect-oriented programming, where JTL can serve as a powerful substitute of ASPECTJ’s pointcut syntax, and, (b) expressing the conditions making up concepts, and in particular multi-type concepts, for use in generic programming. As JTL took shape and grew older it became clear it can be used not only for language extension, but also for other software engi- neering tasks, primarily as a tool to assist programmers understand the code they must modify. This particular problem of program un- derstanding even if it is far from being entirely solved by JTL, is dear to our hearts: First, software development activities in indus- try include (and probably more and more so) the integration of new functionalities in existing code Second, maintenance remains a ma- jor development cost factor. JTL’s focus is on the modules in which the code is organized, packages, classes, methods, variables, including their names, types, parameters, accessibility level and other attributes. JTL can also in- spect the interrelations of these modules, including questions such as which classes exist in a given unit, which methods does a given method invoke, etc. Additionally, JTL can inspect the imperative parts of the code by means of dataflow analysis. The extension of JTL to deal with with control-flow aspects of the code is left for further research. 1.1 Three Introductory Examples JTL syntax is terse and intuitive; just as in AWK [1], one-line programs are abundant, and are readily wrapped within a single string. In many cases, the JTL pattern for matching a JAVA program 89