aboutsummaryrefslogtreecommitdiff
path: root/mingling_pathf/src/pattern_analyzer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_pathf/src/pattern_analyzer.rs')
-rw-r--r--mingling_pathf/src/pattern_analyzer.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/mingling_pathf/src/pattern_analyzer.rs b/mingling_pathf/src/pattern_analyzer.rs
index 3765971..5b25c15 100644
--- a/mingling_pathf/src/pattern_analyzer.rs
+++ b/mingling_pathf/src/pattern_analyzer.rs
@@ -31,7 +31,7 @@ pub fn init_with_config(config: PathfinderConfig) -> PatternAnalyzer {
analyzer.add_pattern(BasicStructPattern);
analyzer.add_pattern(PackPattern);
analyzer.add_pattern(GroupPattern);
- analyzer.add_pattern(GrouppedDerivePattern);
+ analyzer.add_pattern(GroupedDerivePattern);
analyzer.add_pattern(ChainPattern);
analyzer.add_pattern(RendererPattern);
analyzer.add_pattern(HelpPattern);
@@ -48,6 +48,28 @@ pub struct AnalyzeItem {
pub module: String,
/// The name of the item itself, e.g. `"HashMap"`, `"AnalyzeResult"`, etc.
pub item_name: String,
+ /// Whether the item is from an external crate (resolved via `use`), bypassing the file's own module path.
+ pub is_foreign: bool,
+}
+
+impl AnalyzeItem {
+ /// Creates a local `AnalyzeItem` (not foreign, will be prefixed with the file's module path).
+ pub fn local(module: String, item_name: String) -> Self {
+ Self {
+ module,
+ item_name,
+ is_foreign: false,
+ }
+ }
+
+ /// Creates a foreign `AnalyzeItem` (resolved via `use`, the `module` field is the full import path).
+ pub fn foreign(module: String, item_name: String) -> Self {
+ Self {
+ module,
+ item_name,
+ is_foreign: true,
+ }
+ }
}
/// Collection of analysis results
@@ -100,10 +122,12 @@ pub struct PatternAnalyzer {
}
impl PatternAnalyzer {
+ /// Creates a new empty `PatternAnalyzer`.
pub fn new() -> Self {
Self::default()
}
+ /// Registers a new pattern for analysis.
pub fn add_pattern(&mut self, pattern: impl AnalyzePattern + 'static) {
self.patterns.push(Box::new(pattern));
}