Skip to content

Commit

Permalink
feat(struct): add file & lang in output
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 23, 2021
1 parent 5aee308 commit d656844
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/coco_struct_analysis/src/coco_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ impl MethodInfo {
pub struct ClassInfo {
pub name: String,
pub id: i32,
pub file: String,
pub lang: String,
pub parents: Vec<String>,
pub members: Vec<MemberInfo>,
pub methods: Vec<MethodInfo>,
Expand All @@ -48,6 +50,8 @@ impl ClassInfo {
ClassInfo {
name: class_name.to_string(),
id: 0,
file: "".to_string(),
lang: "".to_string(),
parents: vec![],
members: vec![],
methods: vec![],
Expand Down
9 changes: 9 additions & 0 deletions plugins/coco_struct_analysis/src/ctags_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ impl CtagsParser {
pub fn parse_class(&mut self, line: &str) {
if let Some(captures) = CLASS_RE.captures(line) {
let class_name = &captures["class_name"];
let file_name = &captures["file_name"];
let mut clazz = ClassInfo::new(class_name);
clazz.file = file_name.to_string();

if let Some(inherits_capts) = INHERITS_RE.captures(line) {
let inherits_str = &inherits_capts["inherits"];
Expand Down Expand Up @@ -160,6 +162,7 @@ impl CtagsParser {

let lang_capts = RE_LANGUAGE.captures(line).unwrap();
let language = &lang_capts["language"];
clazz.lang = language.to_string();

let without_keywords = CtagsParser::remove_keywords(line.to_string());
let match_type = RE_TYPE.captures(without_keywords.as_str());
Expand Down Expand Up @@ -283,6 +286,9 @@ MethodIdentifier SubscriberRegistry.java /^ private static final class MethodId
assert_eq!(1, classes.len());
assert_eq!(9, classes[0].methods.len());

assert_eq!("Java", classes[0].lang);
assert_eq!("TypeName.java", classes[0].file);

let first_method = classes[0].methods[0].clone();
assert_eq!("description", first_method.name);
assert_eq!("+", first_method.access)
Expand All @@ -295,6 +301,8 @@ MethodIdentifier SubscriberRegistry.java /^ private static final class MethodId
let classes = parser.classes();

assert_eq!(1, classes.len());
assert_eq!("Rust", classes[0].lang);
assert_eq!("coco_swagger/src/lib.rs", classes[0].file);
let methods = classes[0].methods.clone();
assert_eq!(5, methods.len());
assert_eq!("default", methods[0].name);
Expand All @@ -309,6 +317,7 @@ MethodIdentifier SubscriberRegistry.java /^ private static final class MethodId
assert_eq!(5, classes.len());

let string_field = classes[2].clone();
assert_eq!("C", string_field.lang);
assert_eq!("IntFieldOrm", string_field.name);
assert_eq!(1, string_field.parents.len());
assert_eq!("IFieldOrm", string_field.parents[0]);
Expand Down

0 comments on commit d656844

Please sign in to comment.