|
| 1 | +import { PythonClass } from '../../packageData/model/PythonClass'; |
| 2 | +import { PythonFunction } from '../../packageData/model/PythonFunction'; |
| 3 | +import { PythonModule } from '../../packageData/model/PythonModule'; |
| 4 | +import { PythonParameter } from '../../packageData/model/PythonParameter'; |
| 5 | +import { PythonDeclaration } from '../../packageData/model/PythonDeclaration'; |
| 6 | +import { UsageCountStore } from '../../usages/model/UsageCountStore'; |
| 7 | +import { AbstractPythonFilter } from './AbstractPythonFilter'; |
| 8 | +import { AnnotationStore, ReviewResult } from '../../annotations/versioning/AnnotationStoreV2'; |
| 9 | + |
| 10 | +/** |
| 11 | + * Keeps only declarations that have the @remove annotation directly or have an ancestor with this annotation. |
| 12 | + */ |
| 13 | +export class RemovedFilter extends AbstractPythonFilter { |
| 14 | + shouldKeepModule(pythonModule: PythonModule, annotations: AnnotationStore, usages: UsageCountStore): boolean { |
| 15 | + return this.shouldKeepDeclaration(pythonModule, annotations, usages); |
| 16 | + } |
| 17 | + |
| 18 | + shouldKeepClass(pythonClass: PythonClass, annotations: AnnotationStore, usages: UsageCountStore): boolean { |
| 19 | + return this.shouldKeepDeclaration(pythonClass, annotations, usages); |
| 20 | + } |
| 21 | + |
| 22 | + shouldKeepFunction(pythonFunction: PythonFunction, annotations: AnnotationStore, usages: UsageCountStore): boolean { |
| 23 | + return this.shouldKeepDeclaration(pythonFunction, annotations, usages); |
| 24 | + } |
| 25 | + |
| 26 | + shouldKeepParameter( |
| 27 | + pythonParameter: PythonParameter, |
| 28 | + annotations: AnnotationStore, |
| 29 | + usages: UsageCountStore, |
| 30 | + ): boolean { |
| 31 | + return this.shouldKeepDeclaration(pythonParameter, annotations, usages); |
| 32 | + } |
| 33 | + |
| 34 | + shouldKeepDeclaration( |
| 35 | + pythonDeclaration: PythonDeclaration, |
| 36 | + annotations: AnnotationStore, |
| 37 | + _usages: UsageCountStore, |
| 38 | + ): boolean { |
| 39 | + return [...pythonDeclaration.ancestorsOrSelf()].some((ancestor) => { |
| 40 | + const annotation = annotations.removeAnnotations[ancestor.id]; |
| 41 | + return annotation && !annotation.isRemoved && annotation.reviewResult !== ReviewResult.Wrong; |
| 42 | + }); |
| 43 | + } |
| 44 | +} |
0 commit comments