Federico Tomassetti | f81802b | 2016-09-21 10:24:09 +0200 | [diff] [blame] | 1 | # Architecture and Design |
| 2 | |
Federico Tomassetti | 9dcca18 | 2016-10-20 22:27:51 +0200 | [diff] [blame] | 3 | This document describe the architecture and design of JavaSymbolSolver. |
Federico Tomassetti | f81802b | 2016-09-21 10:24:09 +0200 | [diff] [blame] | 4 | |
| 5 | ## Goal of the project |
| 6 | |
| 7 | The basic idea is to be able to resolve all sorts of symbols: |
| 8 | |
| 9 | * field, variable, parameter references |
| 10 | * type references |
| 11 | * calculate the type of expressions |
| 12 | * determine which methods are invoked out of the several overload possible |
Federico Tomassetti | 9dcca18 | 2016-10-20 22:27:51 +0200 | [diff] [blame] | 13 | |
| 14 | # Organization |
| 15 | |
| 16 | The project is divided in four modules: |
| 17 | |
| 18 | * **model**: it contains the interfaces of all declarations used by JavaSymbolSolver such as _ClassDeclaration_, _ParameterDeclaration_, _MethodDeclaration_, etc. |
| 19 | * **logic**: it contains general logic to operate on declarations, for example to perform method resolution |
| 20 | * **core**: it contains most of the implementation including all the implementation of all the interfaces for source code (using JavaParser), compiled code (using Javassist) and JRE standard libraries (using reflection) |
| 21 | * **examples**: examples of possible usages of JavaSymbolSolver |
Federico Tomassetti | f81802b | 2016-09-21 10:24:09 +0200 | [diff] [blame] | 22 | |
| 23 | # Strategy |
| 24 | |
| 25 | ## Resolving types |
| 26 | |
| 27 | Given a reference to a declared type such as `Object`, `java.lang.String`, or `Foo` we need to figure out to which declaration |
| 28 | it corresponds. Declarations can derive from three sources: |
| 29 | |
| 30 | * Compiled classes (class files contained in a directory or a JAR file) |
| 31 | * Java source code |
| 32 | * Classes from the JRE for which we do not have JAR classes. We access them through reflection |
| 33 | |
| 34 | To each of these types correspond an implementation of a `TypeSolver`. |
| 35 | |
| 36 | We consider the way Java resolve types (considering imports, using simple names for classes in the same package, usage |
| 37 | of canonical names) and we look at the different sources we have to find the types definitions. |
| 38 | |
| 39 | # Resources |
| 40 | |
| 41 | TODO: link to articles on tomassetti.me |