Skip to content

Commit

Permalink
feat(struct): add analysis java access
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 22, 2021
1 parent b2686ec commit 4bcff16
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
4 changes: 2 additions & 2 deletions plugins/coco_struct_analysis/src/coco_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub struct MethodInfo {
}

impl MethodInfo {
pub fn new(name: &str) -> Self {
pub fn new(name: &str, access: &str) -> Self {
MethodInfo {
name: name.to_string(),
access: "".to_string(),
access: access.to_string(),
return_type: "".to_string(),
}
}
Expand Down
52 changes: 38 additions & 14 deletions plugins/coco_struct_analysis/src/ctags_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ lazy_static! {
\t(?P<tag_type>[A-Za-z]+)"#
)
.unwrap();
static ref RE_CLASS: Regex = Regex::new(
r"(?x)
class:(?P<class_name>[A-Za-z0-9_\.]+)"
)
.unwrap();
static ref RE_CLASS: Regex = Regex::new(r"class:(?P<class_name>[A-Za-z0-9_\.]+)").unwrap();
static ref RE_ACCESS: Regex = Regex::new(r"access:(?P<access>[A-Za-z0-9_]+)").unwrap();
}

impl CtagsParser {
Expand Down Expand Up @@ -86,6 +83,33 @@ impl CtagsParser {

let captures = AVAILABLE_RE.captures(line).unwrap();

let clazz;
match self.lookup_class_from_map(line) {
None => return,
Some(clz) => clazz = clz,
}

let name = &captures["name"];
let tag_type = &captures["tag_type"];

let mut access = "";
if let Some(capts) = RE_ACCESS.captures(line) {
let match_access = &capts["access"];
match match_access {
"public" => access = "+",
"private" => access = "-",
"protected" => access = "#",
&_ => {}
}
}

if tag_type.eq("method") {
let method = MethodInfo::new(name, access);
clazz.method.push(method);
}
}

fn lookup_class_from_map(&mut self, line: &str) -> Option<&mut ClassInfo> {
let mut class_name = "".to_string();
if let Some(capts) = RE_CLASS.captures(line) {
class_name = capts["class_name"].to_string();
Expand All @@ -96,24 +120,20 @@ impl CtagsParser {
}

if class_name.len() <= 0 {
return;
return None;
}
let clazz;

let clazz: &mut ClassInfo;
match self.class_map.get_mut(&*class_name) {
Some(clz) => {
clazz = clz;
}
None => {
return;
return None;
}
};

let name = &captures["name"];
let tag_type = &captures["tag_type"];
if tag_type.eq("method") {
let method = MethodInfo::new(name);
clazz.method.push(method);
}
Some(clazz)
}

pub fn classes(&self) -> Vec<ClassInfo> {
Expand Down Expand Up @@ -158,5 +178,9 @@ mod test {
let classes = parser.classes();
assert_eq!(1, classes.len());
assert_eq!(9, classes[0].method.len());

let first_method = classes[0].method[0].clone();
assert_eq!("TypeName", first_method.name);
assert_eq!("-", first_method.access)
}
}

0 comments on commit 4bcff16

Please sign in to comment.