ITcore
From Intoj.org
Contents |
[edit] Type inference and refactoring
Type inference computes type annotations for program elements. It is most useful in languages in which type annotations for these elements are not mandatory ("untyped" languages). In typed languages such as Java, type inference can compute the difference between a declared and a derived (inferred) type.
In the context of refactoring statically type-checked, type-correct object-oriented programs, type inference can be used to change the declared types of program elements in one of two directions: to the more specific, or to the more general. The former is of interest for instance when type Object or a raw type is used where all objects are known to be of a more concrete class or parameterized type; such type inference is, e.g., the basis for the refactoring tool Infer Generic Type Arguments. The latter is useful for decoupling designs, for instance when turning a monolithic application into a framework; it is the basis of our Infer Type refactoring and also of Generalize Declared Type and Use Interface Where Possible (both exisiting Eclipse JDT refactoting tools).
[edit] Design of ITcore
ITcore currently consists of two major parts: a constraint set builder and a constraint solver.
[edit] Constraint set builder
The constraint set builder of ITcore is relatively independent of the specific type inference purpose (cf. above): starting with an initial set of declaration elements, it generates a set of type constraints simply by applying the typing rules of Java. The constraints generated by ITcore are similar to that of Infer Generic Type Arguments in that parameterized types are decomposed and separate constraint variables for all type arguments are created. For assignments, individual constraints are generated for the main types and all type arguments. If the receiver of a method invocation is a parameterized type, method and type arguments are also connected through constraints.
[edit] Constraint solver
The constraint solver of ITcore is currently the reimplementation of the type inference algorithm of an older version of Infer Type. It computes for a given declaration element its maximally general type (interface or abstract class), i.e., that type that contains only the members accessed through the declaration element and the ones it gets assigned to. The inferred type is always "minimal" in the sense that if a declaration element is typed with its inferred type, no member can be removed from the type without introducing a typing error.
ITcore will provide for the possibility to use alternative constraint solvers.
[edit] How ITcore is different
ITcore differs from the engines of its predecessors in various respects:
- The constraints generated by ITcore cover the complete type system of Java 5. This lets ITcore change type arguments including those of nested parametric types, as e.g. Test in class MyComparator implements Comparator<Test>. (Only type bounds are currently not considered for change.)
- ITcore attaches to each constraint variable (representing a declaration element) the required protocol (the access set) of that element, which is the basis for the creation of new types during the solution of the constraint set.
- The constraint solution procedure works constructively, by visiting the nodes of the constraint graph reachable from the start element(s) in depth-first order and collecting the (transitively determined) access sets in the nodes. After the traversal, the new type for the start element has been determined and is created. A second traversal then satisfies all type constraints, by introducing the new type (and possibly others) where necessary.
[edit] ITcore switches
In order to be generally usable, ITcore can be parameterized by a number of switches.
[edit] Tools based on ITcore
[edit] ITcore API
All applications access ITcore through its API.
[edit] Download
- Download (coming soon). Please download Infer Type in the meantime!
