Statically typed languages allow many errors to be detected at compile-time. However, many errors that could be detected statically cannot be expressed using today's type systems. We describe a compile-time reflection framework for Java which allows for static checking of structural constraints. 1 Overview In any reasonably sized software development project, there are rules constraining the structure of the application under development that must be obeyed by the programmers, ranging from simple coding conventions to design constraints caused by, e.g., using design patterns. Although most of these constraints could be enforced at compile-time, few tools exist that can support static checking of programmer-defined constraints in a way that is both expressive and useable for everyday programmers. We have implemented a system called CoffeeStrainer 1 that supports compile-time checking of stylistic constraints, implementation constraints, and design constraints for Java programs. Constraints may be specified by programmers, or re-used from a library of constraints. The system is useful for several reasons: for software deve- lopment teams, it allows the specification of coding rules that can be enforced automa- tically; for framework developers, it allows the specification of rules for using the framework correctly; for framework users, it can warn of incorrect uses or specializations of the framework. For checking a program, CoffeeStrainer builds an object-oriented representation of the program. This representation consists of the program's abstract syntax tree en- riched by additional information obtained by name analysis (associating each use of a name with its declaration) and type analysis (associating each expression with its static type). It contains objects for each of the elements that make up a base-level program: class objects, method objects, statement objects, expression objects, and so on. Then, checking structural properties of the program involves a traversal of this en- riched abstract syntax tree, performing checks at various points during the traversal depending on the type of the object at hand. To determine the checks that are perfor-
['Boris Bokowski']
CoffeeStrainer - Statically Checking Structural Constraints on Java Programs