An analysis context also represents the state of the analysis, which includes knowing which sources have been included in the analysis (either directly or indirectly) and the results of the analysis. Sources must be added and removed from the context using the method {@link #applyChanges(ChangeSet)}, which is also used to notify the context when sources have been modified and, consequently, previously known results might have been invalidated.
There are two ways to access the results of the analysis. The most common is to use one of the 'get' methods to access the results. The 'get' methods have the advantage that they will always return quickly, but have the disadvantage that if the results are not currently available they will return either nothing or in some cases an incomplete result. The second way to access results is by using one of the 'compute' methods. The 'compute' methods will always attempt to compute the requested results but might block the caller for a significant period of time.
When results have been invalidated, have never been computed (as is the case for newly added sources), or have been removed from the cache, they are not automatically recreated. They will only be recreated if one of the 'compute' methods is invoked.
However, this is not always acceptable. Some clients need to keep the analysis results up-to-date. For such clients there is a mechanism that allows them to incrementally perform needed analysis and get notified of the consequent changes to the analysis results. This mechanism is realized by the method {@link #performAnalysisTask()}.
Analysis engine allows for having more than one context. This can be used, for example, to perform one analysis based on the state of files on disk and a separate analysis based on the state of those files in open editors. It can also be used to perform an analysis based on a proposed future state, such as the state after a refactoring.
|
|
|
|