symbolic_proguard/
lib.rs

1//! Provides proguard support.
2
3#![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/// A view over a proguard mapping text file.
25#[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    /// Creates a new proguard mapping view from a byte slice.
33    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    /// Returns the mapping UUID.
44    pub fn uuid(&self) -> Uuid {
45        self.inner.get().mapping.uuid()
46    }
47
48    /// Returns true if this file has line infos.
49    pub fn has_line_info(&self) -> bool {
50        self.inner.get().mapping.has_line_info()
51    }
52
53    /// Converts a dotted path.
54    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}