1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use kodept_ast::graph::GenericASTNode;
use kodept_ast::visitor::TraversingResult;
use kodept_ast::visitor::visit_side::RefVisitGuard;
use kodept_core::code_point::CodePoint;

use crate::traits::{Context, UnrecoverableError};

pub trait Analyzer {
    type Error: Into<UnrecoverableError>;
    type Node<'n>: TryFrom<&'n GenericASTNode>;

    fn analyze<'n, 'c, C: Context<'c>>(
        &self,
        guard: RefVisitGuard<Self::Node<'n>>,
        context: &mut C,
    ) -> TraversingResult<Self::Error>;
}

pub trait AccessExt {
    fn or_unknown(self) -> Vec<CodePoint>;
}

impl AccessExt for Option<CodePoint> {
    fn or_unknown(self) -> Vec<CodePoint> {
        self.map_or(vec![], |it| vec![it])
    }
}

impl AccessExt for Option<Vec<CodePoint>> {
    fn or_unknown(self) -> Vec<CodePoint> {
        self.unwrap_or_default()
    }
}