Skip to content

Commit ec1370d

Browse files
Added dependency extraction strategy documentation
1 parent 782d917 commit ec1370d

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
# Extraction Strategy: Overview
1+
# Extraction Strategies
22
-> the extraction of language concepts is achieved by an implementation of the [LCE Architecture](https://jqassistant-plugin.github.io/jqassistant-lce-docs/)
33

4+
**Information Sources:**
45
- the main source of information for extracting concepts from TS source code is the ESLint AST (provided through `@typescript-eslint/typescript-estree`)
56
- use [ESLint Playground](https://typescript-eslint.io/play/) to easily explore the data structures
6-
- all concepts have to be extracted within a single traversal of the ESLint AST
7-
- separate/additional sub-tree traversals are not allowed
87
- additional information, mostly related to types, is extracted via the native TypeScript Compiler API (for more information see [here](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) and [here](https://github.com/microsoft/TypeScript-Compiler-Notes/blob/main/README.md)), especially the TypeChecker
98
- direct translation between nodes of the two different ASTs can easily be done via the `services` global context
10-
- the Compiler API should be used sparingly, as it is less developer-friendly than the ESLint API
9+
- the Compiler API should be used sparingly, as it is less developer-friendly than the ESLint API
10+
11+
**General Guidelines:**
12+
- all concepts have to be extracted within a single traversal of the ESLint AST
13+
- separate/additional sub-tree traversals are not allowed
14+
15+
**Currently Implemented Extraction Strategies:**
16+
- [[Extraction Strategy - Dependencies|Dependencies and FQNs]]
17+
- Types
18+
- Values
19+
- Imports
20+
- Exports
21+
- Classes and Interfaces
22+
- Function Declarations
23+
- Variable Declarations
24+
- Type Aliases
25+
- Enums
26+
- Decorators
27+
- Code Coordinates
28+
- Special Case: Indexed Access Types
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Extraction Strategy: Dependencies and FQNs
2+
**Goal:** Creation of [[Node Relation - Dependencies|DEPENDS_ON]] relations between the various concept nodes
3+
4+
**Strategy:**
5+
1. LCE: While traversing the AST register all referenced identifiers as dependencies (with source and target [[Node Properties - Fully Qualified Names|FQN]]) in a central data structure
6+
2. LCE: After finishing the traversal aggregate all detected dependencies and store them as [[Concepts|concepts]]
7+
- Note: as [[Node Properties - Fully Qualified Names|FQNs]] can't always be resolved fully during the traversal, a resolution of them has to precede the dependency aggregation
8+
3. jQA Plugin: Create dependencies using the stored [[Node Properties - Fully Qualified Names|global FQNs]]
9+
4. jQA Plugin: Fill in all transitive dependencies via Cypher queries
10+
11+
**Central Components:**
12+
- `LCEDependency`: concept that represents a direct dependency observed in the code
13+
- for transitive dependencies see `DependencyResolver`
14+
- `DependencyResolutionProcessor`: processor that resolves [[Node Properties - Fully Qualified Names|FQN]] references and collects registered dependencies within the AST
15+
- executed on the root node of the AST of each source file
16+
- registers [[Local Contexts]] that serve as indexes for registering declarations and dependencies within the module as well as schedule [[Node Properties - Fully Qualified Names|FQN]] resolutions at the end of the AST traversal
17+
- provides static utility methods for the construction of [[Node Properties - Fully Qualified Names|FQNs]] and the interaction with the [[Local Contexts]] from above
18+
- `IdentifierDependencyProcessor`: processor that registers dependencies for all referenced identifiers within the code that are not part of one of the other processed declaration constructs
19+
- `MemberExpressionDependencyProcessor` handles dependency registration specifically for member expressions (e.g. `myObj.b`)
20+
- `ScopeProcessor`/`DeclarationScopeProcessor`: processors that register (un)named [[Node Properties - Fully Qualified Names|FQN]] scopes at all relevant points of the AST traversal to aid [[Node Properties - Fully Qualified Names|FQN]] construction
21+
- `DependencyResolver` (Java): creates [[Node Relation - Dependencies|DEPENDS_ON]] relations for the extracted direct dependencies and fills in all transitive dependencies via Cypher queries
22+
- in a final step all [[Node Relation - Dependencies|DEPENDS_ON]] relations are aggregated

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The tool currently only supports projects using ECMAScript modules.
4646
This plugin is based on the [LCE Architecture](https://jqassistant-plugin.github.io/jqassistant-lce-docs/).
4747
- [[Codebase Layout]]
4848
- [[Extensions]]
49+
- *TODO: Testing Strategy*
4950

5051
**Base LCE Architecture Implementation:**
5152
- [[Concepts]]
@@ -56,4 +57,5 @@ This plugin is based on the [LCE Architecture](https://jqassistant-plugin.github
5657
- [[Utilities]]
5758

5859
**Extraction Strategies:**
59-
- *[[Extraction Strategy - Overview|Overview]]*
60+
- *[[Extraction Strategies|Overview]]*
61+
- [[Extraction Strategy - Dependencies|Dependencies and FQNs]]

docs/usage/Node Properties - Fully Qualified Names.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
aliases:
33
- local FQN
44
- global FQN
5+
- FQN
56
---
67
# Fully Qualified Names (FQNs)
78
-> node properties that uniquely identify a concept within or across projects

typescript/src/core/processors/dependency-resolution.processor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export type DeclarationIndex = Map<string, Map<string, FQN>>;
2323
*/
2424
export type FQNResolverContext = Array<[string[], string, LCENamedConcept]>;
2525

26+
/**
27+
* Stores the identifiers for the declaration that encompasses the currently traversed part of the AST.
28+
* Multiple of these scopes can be set as Local Contexts on different levels to express nested scopes (e.g a method within a class).
29+
*
30+
* see `DependencyResolutionProcessor` for more detail.
31+
*/
2632
export interface FQNScope {
2733
globalIdentifier: string;
2834
localIdentifier: string;

typescript/src/core/processors/instructional-code.processor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { ExecutionCondition } from "../execution-condition";
88
import { Processor } from "../processor";
99
import { getParentPropName } from "../utils/processor.utils";
1010
import { ClassTraverser } from "../traversers/class.traverser";
11-
import { ArrowFunctionExpressionTraverser, MemberExpressionTraverser, TaggedTemplateExpressionTraverser } from "../traversers/expression.traverser";
11+
import {
12+
ArrowFunctionExpressionTraverser,
13+
MemberExpressionTraverser,
14+
TaggedTemplateExpressionTraverser
15+
} from "../traversers/expression.traverser";
1216
import { FunctionTraverser } from "../traversers/function.traverser";
1317
import { MethodTraverser } from "../traversers/method.traverser";
1418
import { PropertyTraverser } from "../traversers/property.traverser";
@@ -18,6 +22,9 @@ import { TypeAliasDeclarationTraverser } from "../traversers/type-alias-declarat
1822
import { CoreContextKeys } from "../context.keys";
1923
import { TraverserContext } from "../traverser";
2024

25+
/**
26+
* Registers unnamed `FQNScope` local contexts for all nodes that create a new anonymous scope.
27+
*/
2128
export class ScopeProcessor extends Processor {
2229
public executionCondition: ExecutionCondition = new ExecutionCondition(
2330
[AST_NODE_TYPES.BlockStatement, AST_NODE_TYPES.ForStatement, AST_NODE_TYPES.ForInStatement, AST_NODE_TYPES.ForOfStatement],
@@ -29,6 +36,9 @@ export class ScopeProcessor extends Processor {
2936
}
3037
}
3138

39+
/**
40+
* Registers named `FQNScope` local contexts for all declaration nodes.
41+
*/
3242
export class DeclarationScopeProcessor extends Processor {
3343
public executionCondition: ExecutionCondition = new ExecutionCondition(
3444
[

0 commit comments

Comments
 (0)