Counting number of inherited method per project

22 views
Skip to first unread message

na...@northern.edu.pk

unread,
Aug 20, 2017, 5:50:49 AM8/20/17
to Boa Language and Infrastructure User Forum
hi,
I want to count the number of inherited methods per project and number of total methods per project. I have written this script, but there are errors, kindly see if i have misused any of the language construct or something
Regards Nawaz
p: Project = input;
MIF: output collection[string][int][int] of int;
TPP := 0;
IMPP := 0;


getTotalMPP:= function():int{
    count := 0;
    visitor(p,visitor{
        before node: Declaration ->{
            if(node.kind == TypeKind.CLASS){
                count = len(node.Methods);
            }
        }   
       
    }); # end of visitor  
 
  return count; 
};


visit(p, visitor {
        before node: CodeRepository -> {
            snapshot := getsnapshot(node,"SOURCE_JAVA_JLS");
            foreach (i: int; def(snapshot[i]))
                visit(snapshot[i]);
               
            # getTotal Methods for the Project
            TPP := getTotalMPP();
            res += IMPP/TMPP;
           
            MIF[p.id][temp][IMPP] << res;
            stop;
        }
       
       
        before node: Declaration ->{
            if(node.kind == TypeKind.CLASS){
                foreach(i:int; def(node.parents[i])){
                    if(node.parents[i].kind == TypeKind.CLASS){
                      foreach(j: int; (has_modifier_public(node.parents[i].methods[j]) || has_modifier_protected(node.parents[i].methods[j])){
                          IMPP++;
                      }
                       
                    }
                }
               
            stop;
        } 
   
});

Robert Dyer

unread,
Aug 20, 2017, 1:02:57 PM8/20/17
to Boa Language and Infrastructure User Forum
Hi Nawaz,

First, we have an example query that might help you:


This computes the number of public methods in a class.

Second, your specific problem is in using the match() function.  This expects a regular expression.  The strings you are passing in most likely need escaped as they are being treated as a regular expression.

Depending on what you want, the best solution would be to use == to test exact equality of the strings, or to use strfind() to try to find one string inside the other.

- Robert
Reply all
Reply to author
Forward
0 new messages