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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
use super::*; pub trait ImportReceiver { fn receive(&mut self, ty: &ClassType); fn import_all<T>(&mut self, sources: &Vec<T>) where T: Imports, Self: Sized, { for source in sources { source.imports(self); } } } pub trait Imports { fn imports<I>(&self, &mut I) where I: ImportReceiver; } impl Imports for Element { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { match *self { Inner(ref elements) => receiver.import_all(elements), Push(ref statement) => statement.imports(receiver), Concat(ref statement) => statement.imports(receiver), Nested(ref nested) => { (*nested).imports(receiver); } _ => {} } } } impl Imports for Variable { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { match *self { Variable::Type(ref ty) => { ty.imports(receiver); } Variable::Statement(ref stmt) => { stmt.imports(receiver); } Variable::Element(ref element) => { element.imports(receiver); } _ => {} } } } impl Imports for Statement { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { receiver.import_all(&self.parts); } } impl Imports for Elements { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { receiver.import_all(&self.elements); } } impl Imports for ClassType { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { receiver.receive(self); receiver.import_all(&self.arguments); } } impl Imports for Type { fn imports<I>(&self, receiver: &mut I) where I: ImportReceiver, { match *self { Type::Class(ref class) => class.imports(receiver), _ => {} }; } }