1#![warn(missing_docs)]
4
5use std::io;
6
7use proguard::{ProguardMapper, ProguardMapping, StackFrame};
8
9use symbolic_common::{AsSelf, ByteView, SelfCell, Uuid};
10
11struct Inner<'a> {
12 mapping: ProguardMapping<'a>,
13 mapper: ProguardMapper<'a>,
14}
15
16impl<'slf, 'a: 'slf> AsSelf<'slf> for Inner<'a> {
17 type Ref = Inner<'slf>;
18
19 fn as_self(&'slf self) -> &Self::Ref {
20 &self
21 }
22}
23
24#[deprecated = "use the `proguard` crate directly"]
26pub struct ProguardMappingView<'a> {
27 inner: SelfCell<ByteView<'a>, Inner<'a>>,
28}
29
30#[allow(deprecated)]
31impl<'a> ProguardMappingView<'a> {
32 pub fn parse(byteview: ByteView<'a>) -> Result<Self, io::Error> {
34 let inner = SelfCell::new(byteview, |data| {
35 let mapping = ProguardMapping::new(unsafe { &*data });
36 let mapper = ProguardMapper::new(mapping.clone());
37 Inner { mapping, mapper }
38 });
39
40 Ok(ProguardMappingView { inner })
41 }
42
43 pub fn uuid(&self) -> Uuid {
45 self.inner.get().mapping.uuid()
46 }
47
48 pub fn has_line_info(&self) -> bool {
50 self.inner.get().mapping.has_line_info()
51 }
52
53 pub fn convert_dotted_path(&self, path: &str, lineno: u32) -> String {
55 let mapper = &self.inner.get().mapper;
56
57 let mut iter = path.splitn(2, ':');
58 let cls_name = iter.next().unwrap_or("");
59 match iter.next() {
60 Some(meth_name) => {
61 let mut mapped =
62 mapper.remap_frame(&StackFrame::new(cls_name, meth_name, lineno as usize));
63 match mapped.next() {
64 Some(frame) => format!("{}:{}", frame.class(), frame.method()),
65 None => path.to_string(),
66 }
67 }
68 None => mapper.remap_class(cls_name).unwrap_or(cls_name).to_string(),
69 }
70 }
71}