<p>The RFC for a Java class is set of all methods that can be invoked in response to a message to an object of the class or by some method in the class. 
RFC = M + R where 
M = Number of methods in the class.
R = Total number of other methods directly invoked from the M.</p>

<p>Thinking C is the .class and J is the .java file of which we need to calculate RFC.</p>

<pre>
class J{

 a(){}
 b(){}
 c(){
   e1.e();
   e1.f();
   e1.g();
 }
 h(){
   i.k();
   i.j();
  }
  m(){}
  n(){
   i.o();
   i.p();
   i.p();
   i.p();
  }
}
</pre>

<p>here M=6
and R=9  (Don't worry about call inside a loop. It's considered as a single call)</p>

<p>Calculating M is easy. Load C using classloader and use reflection to get the count of methods.</p>

<p>Calculating R is not direct. We need to count the number of method calls from the class. First level only. </p>

<p>For calculating R I must use regex. Usually format would be (calls without using . are not counted)</p>

<pre>
[variable_name].[method_name]([zero or more parameters]);
</pre>

<p>or</p>

<pre>
[variable_name].[method_name]([zero or more parameters])
</pre>

<p>with out semicolon when call return is directly becomes parameter to another method.
or  </p>

<pre>
[variable_name].[method_name]([zero or more parameters]).method2();
</pre>

<p>this becomes two method calls</p>

<p>What other patterns of the method call can you think of?  Is there any other way other than using RegEx that can be used to calculate R.</p>

<hr>

<p><strong>UPDATE:</strong><br>
<a href="https://stackoverflow.com/questions/19952/rfc-calculation-in-java-need-help-with-algorithm#19983" title="@McDowell">@McDowell</a>
Looks like using BCEL I can simplify the whole process. Let me try it.</p>

[{'answer_id': 19967, 'author': 'Nicolas', 'author_id': 1730, 'author_profile': 'https://Stackoverflow.com/users/1730', 'pm_score': 0, 'selected': False, 'text': '<p>You should find your answer in the <a href="http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html" rel="nofollow noreferrer">Java language specification</a>.</p>\n\n<p>You have forgot static method call, method call inside parameters...</p>\n'}, {'answer_id': 19973, 'author': 'kokos', 'author_id': 1065, 'author_profile': 'https://Stackoverflow.com/users/1065', 'pm_score': 0, 'selected': False, 'text': '<p>Calling a method using reflection (the name of the method is in a string).</p>\n'}, {'answer_id': 19983, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 3, 'selected': True, 'text': '<p>You could use the <a href="http://jakarta.apache.org/bcel/index.html" rel="nofollow noreferrer">Byte Code Engineering Library</a> with binaries. You can use a <a href="http://jakarta.apache.org/bcel/apidocs/org/apache/bcel/classfile/DescendingVisitor.html" rel="nofollow noreferrer">DescendingVisitor</a> to visit a class\' members and references. I\'ve used it to <a href="http://illegalargumentexception.blogspot.com/2008/04/java-finding-binary-class-dependencies.html" rel="nofollow noreferrer">find class dependencies</a>.</p>\n\n<p>Alternatively, you could reuse some model of the source files. I\'m pretty sure the Java editor in the <a href="http://www.eclipse.org/jdt/" rel="nofollow noreferrer">Eclipse JDT</a> is backed by some form of model.</p>\n'}, {'answer_id': 19998, 'author': 'Herms', 'author_id': 1409, 'author_profile': 'https://Stackoverflow.com/users/1409', 'pm_score': 0, 'selected': False, 'text': "<p>Does M include calls to its own methods?  Or calls to inner classes? For instance:</p>\n\n<pre><code>class J {\n  a() { }\n  b() { this.a(); }\n  c() { jj.aa(); }\n  d() { i.k(); }\n  e() { this.f().a(); }\n  f() { return this; }\n  g() { i.m().n(); }\n\n  class JJ {\n    aa() { a(); }\n  }\n}\n</code></pre>\n\n<p>What would the M value of this be?  There's only three function calls to a method not defined in this class (the calls in the d() and g() functions).  Do you want to include calls to inner classes, or calls to the main class made in the inner class?  Do you want to include calls to other methods on the same class?</p>\n\n<p>If you're looking at any method calls, regardless of the source, then a regex could probably work, but would be tricky to get right (does your regex properly ignore strings that contain method-call like contents?  Does it handle constructor calls properly?).  If you care about the source of the method call then regexes probably won't get you what you want.  You'd need to use reflection (though unfortunately I don't know enough about reflection to be helpful there).</p>\n"}]
['https://Stackoverflow.com/questions/19952', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/482/']