use crate::graph::Edge;
use crate::graph::HeuristicTier;
use crate::graph::SemanticProvenance;
#[cfg(test)]
pub(crate) const VOCABULARY: [&str; 11] = [
"exact",
"semantic",
"semantic-discovered",
"heuristic-ext",
"heuristic-guess",
"heuristic",
"ambiguous",
"unresolved",
"declared",
"derived",
"convention",
];
pub(crate) const EXACT: &str = "exact";
pub(crate) const SEMANTIC: &str = "semantic";
pub(crate) const SEMANTIC_DISCOVERED: &str = "semantic-discovered";
pub(crate) const HEURISTIC_EXT: &str = "heuristic-ext";
pub(crate) const HEURISTIC_GUESS: &str = "heuristic-guess";
pub(crate) const HEURISTIC: &str = "heuristic";
pub(crate) const AMBIGUOUS: &str = "ambiguous";
pub(crate) const UNRESOLVED: &str = "unresolved";
pub(crate) const DECLARED: &str = "declared";
pub(crate) const DERIVED: &str = "derived";
pub(crate) const CONVENTION: &str = "convention";
pub(crate) fn edge_evidence(edge: &Edge) -> &'static str {
match edge {
Edge::Inherits { heuristic, .. } | Edge::UsesType { heuristic, .. } => {
if *heuristic {
HEURISTIC
} else {
EXACT
}
}
Edge::UsesMember {
heuristic,
tier,
source,
..
} => match (source, tier, heuristic) {
(Some(SemanticProvenance::Semantic), _, _) => SEMANTIC,
(Some(SemanticProvenance::SemanticDiscovered), _, _) => SEMANTIC_DISCOVERED,
(None, Some(HeuristicTier::Ext), _) => HEURISTIC_EXT,
(None, Some(HeuristicTier::Guess), _) => HEURISTIC_GUESS,
(None, None, true) => HEURISTIC,
(None, None, false) => EXACT,
},
Edge::Imports { .. } => DECLARED,
Edge::Ambiguous { .. } => AMBIGUOUS,
Edge::CtorDi { resolution, .. } => match resolution.as_str() {
"plain" | "closed" | "open-generic" => EXACT,
"ambiguous" => AMBIGUOUS,
_ => UNRESOLVED,
},
Edge::Import { .. }
| Edge::Call { .. }
| Edge::JsxUse { .. }
| Edge::Dispatch { .. }
| Edge::Implements { .. }
| Edge::Overrides { .. } => EXACT,
Edge::BusHop { .. } => DERIVED,
}
}