rusty_javac/ty/
method_sig.rs1use crate::ty::{Ty, TypeParam};
2use ustr::Ustr;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct MethodSig {
6 pub name: Ustr,
7 pub params: Vec<Ty>,
8 pub return_type: Ty,
9 pub type_params: Vec<TypeParam>,
10 pub access_flags: u16,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14pub struct FieldSig {
15 pub name: Ustr,
16 pub ty: Ty,
17 pub access_flags: u16,
18}
19
20impl MethodSig {
21 pub fn new(name: Ustr, params: Vec<Ty>, return_type: Ty) -> Self {
22 Self {
23 name,
24 params,
25 return_type,
26 type_params: Vec::new(),
27 access_flags: 0,
28 }
29 }
30
31 pub fn descriptor(&self) -> String {
32 let mut desc = String::from("(");
33 for p in &self.params {
34 desc.push_str(&p.erasure().descriptor());
35 }
36 desc.push(')');
37 desc.push_str(&self.return_type.erasure().descriptor());
38 desc
39 }
40
41 pub fn param_count(&self) -> usize {
42 self.params.len()
43 }
44
45 pub fn param_slots(&self) -> usize {
46 self.params.iter().map(|t| t.erasure().size()).sum()
47 }
48}