Java reference loaders design
Description | Design document for Java reference loaders. These loaders resolve type names to fully qualified names and establish links between type reference and type definition, variable reference and variable definition, method call and method definition, constructor call and constructor definition, as well as inheritance relationships ("is kind of"). |
Id | 153 |
Last modified | Sun Sep 09 01:08:56 EDT 2007 |
GUID | aec843f43fcf8d05c7f078ad8aca61a2d5cb471d |
Glossary |
Mesopotamia glossary
|
Loading references is a process which includes several steps. Each step is implemented by a loader.
Class, method and field loader
Stores information about non-private classes, fields and methods to the database. This loader does not resolve parameter and variable types to fully qualified names. This loader uses SyntaxTree created by AstLoader and available through AstLoader.getData() method. Therefore this loader depends on "ast" loader.
Type resolver
This loader depends on class, method and field loader and also uses Library interface. It resolves type names to fully qualified names. This information is stored in the database model for non-private members and in loader data for private members, variable definitions and method/constructor parameters.
Provider resolver
Provider resolver depends on type resolver. This loader links
- Variable references to variable/field/parameter definitions
- Method calls to method definitions
- Constructor invocations (new XXX(...)) to constructor definitions.
Classes and interfaces to represent reference information
Library
This interface shall have a method JavaClass findClass(String className). There shall be implementations which wrap classloader and Mesopotamia scan. There should also be Composite library implementation which combines multiple libraries to look like one.
JavaClass
Provides information about Java class similar to java.lang.Class.
Constructor
Provides information about constructor similar to java.lang.reflect.Constructor
Method
Provides information about method similar to java.lang.reflect.Method
Field
Provides information about field similar to java.lang.reflect.Field
...
Special considerations
In the case of uncompilable codebases, e.g. when classpath entries are not known, it might be not possible to resolve reference information with 100% precision. This situation is possible with start imports, static imports and when inheritance information cannot be reconstructed.
E.g. compilation unit imports
com.somecompany.* and defines class ABC which extends class XYZ. Class ABC defines a field
str of type String and a method which throws Exception. If we don't have access to class XYZ then String type might be java.lang.String, com.somecompany.String or com.comecompany.XYZ.String. Classes which represent field, method, class shall provide means to communicate to the application the ambiguity of referencing.
E.g. there might be an interface AmbiguousReference
with a method List getOtherCandidates(). In the example above TypeDefinition returned from
str's getType() method shall also implement AmbiguousReference. If the definition itself points to java.lang.String then other candidates shall include com.somecompany.String and com.comecompany.XYZ.String.
Tables
All the tables shall use surrogate autogenerated integer primary keys. Table structures below are not final. E.g. type arguments are not taken into account. Additional tables and columns might be required to model
parameterized types or to store intermediate information, e.g. name. Also table structure below don't allow "candidate" references. E.g. method references a single return type. Actual implementations shall implement one-to-many relationship between variable definitions, paramerer definitions and types; method calls and methods. Helper tables shall have
position or
probability column to order reference target candidates.
Package
Actual table name shall be JPACKAGE to avoid clash with database reserved words. Fields:
- ID integer identity not null primary key
- SCAN_ID reference to scan. On delete cascade
- NAME varchar not null
Type
Class or interface defined in the scan or external. Fields:
- ID integer identity not null primary key,
- NAME class name without package name
- PACKAGE_ID integer not null. References package id. On delete cascade.
- IS_INTERFACE bit or number(1) not null default 0
- SOURCE_UNIT_ID integer. Reference to source unit for classes/interfaces defined in the scan.
- LANGUAGE_ELEMENT_ID integer. Id of the language element for types defined in the scan.
- SUPERCLASS_ID integer. Reference to superclass.
- ENCLOSING_TYPE_ID integer reference to enclosing type.
- FLAGS Helper field to keep additional information.
- SCOPE or VISIBILITY - package, protected, public.
Method
Method. Fields
- ID primary key identity
- TYPE_ID not null on delete cascade. Reference to type (class or interface).
- RETURN_TYPE_ID reference to enclosing type
- NAME varchar not null.
- SCOPE or VISIBILITY - package, protected, public.
Method parameters
- ID integer identity primary key.
- METHOD_ID integer reference to method. On delete cascade.
- PARAM_POSITION integer. not null. METHOD_ID AND PARAM_POSITION constitute unique index.
- NAME varchar.
- PARAM_TYPE reference to parameter type. not null..
Method throws
- METHOD_ID integer not null references method. on delete cascade.
- THROWABLE_TYPE_ID integer not null references throwable type.
- THROWABLE_POSITION integer not null. Position in the list of throws.
All fields constitute primary key.
Constructor
Constructor table structure is similar to method without name and return type columns.
Constructor parameters
Same as method parameters.
Constructor throws
- CONSTRUCTOR_ID integer not null references method. on delete cascade.
- THROWABLE_TYPE_ID integer not null references throwable type.
- THROWABLE_POSITION integer not null. Position in the list of throws.
All fields constitute primary key.
Field
- ID integer identity primary key
- DECLARING_TYPE_ID integer reference to declaring type. on delete cascade
- TYPE_ID integer not null. Reference to field type.
- NAME varchar. NAME and DECLARING_TYPE_ID constitute unique index.
- SCOPE or VISIBILITY: public, protected or package.
Implemented interfaces
- CLASS_ID integer not null on delete cascade. References class which implements interface.
- INTERFACE_ID integer not null. Referneces implemented interface.
- INTERFACE_POSITION integer not null. Position of the implemented interface.
All fields constitute primary key.
Task list
- Create MSPT_JAVA schema and tables.
- Generate database engine and data classes with SQLC.
- Implement Term 273loaders and data classes to represent reference information.
- Subclass Term 269language elements which represent references with extended versions. Extended versions will be instantiated if required load level is reached.
- TypeSpecificationEx shall extend TypeScpecification and have methods to obtain fully qualified type name, member and inheritance information, and navigate to the type definition if the type defined in the repository (not obtained from classloader).
- Variable/parameter reference shall be extended to provide information about variable type (type spec) and point to variable/parameter definition (if definition is in the repository).
- Method and constructor calls (new) shall be extended to point to method/constructor definiton (if in the repository) and provide information about the method similar to one provided by Method and Constructor classes in Java reflection package.
- Create additional Java language module initialization scripts, add new loaders, dependencies, and language element definitions for the new xxxEx classes.
- Prepare installation instruction and package the solution.