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
/// An enum representing Java types
#[derive(Clone, Copy)]
pub enum Type<'a> {
  /// A boolean type
  Boolean,
  /// A byte type
  Byte,
  /// A char type
  Char,
  /// A short type
  Short,
  /// An int type
  Int,
  /// A long type
  Long,
  /// A float type
  Float,
  /// A double type
  Double,
  /// A void type
  Void,
  /// An object type
  Object(&'a str),
  /// An array type
  Array(&'a Type<'a>),
}

impl<'a> Type<'a> {
  /// Converts a Type into a String
  pub fn to_string(&self) -> String {
    let result = match self {
      Type::Boolean => String::from("Z"),
      Type::Byte => String::from("B"),
      Type::Char => String::from("C"),
      Type::Short => String::from("S"),
      Type::Int => String::from("I"),
      Type::Long => String::from("J"),
      Type::Float => String::from("F"),
      Type::Double => String::from("D"),
      Type::Void => String::from("V"),
      Type::Object(s) => format!("L{};", s),
      Type::Array(t) => format!("[{}", t.to_string()),
    };

    result
  }
}