Search code examples
jqassistant

What is the semantic of "declaring a method"?


Based on the query defined in metric.xml I try to figure out how many methods a class declares:

MATCH
    (t:Type:File)-[:DECLARES]->(m:Method)
WHERE 
    t.fqn=~'.*MyException'
RETURN
    t.fqn as Type, COUNT(m) as MethodCount

It's 41.

I change the query to

MATCH
    (t:Class:File)-[:DECLARES]->(m:Method)
WHERE
    t.fqn=~'.*MyException'
RETURN
    t.fqn as Type, COUNT(m) as MethodCount

and I get 25 for the same class. Shouldn't it be the same result? If I open the class and count by hand, I find only 23. So what does it mean if a class or a type "declares" a method? It seems some inherited methods are counted too depending on :Type or :Class. And how do I get the "real" number of methods declared by the class itself without inherited methods?


Solution

  • The root cause is that the same exception type very likely is available as multiple nodes because it is contained in one artifact and required by others. To find the "real" node use the following query:

    MATCH
      (:Artifact)-[:CONTAINS]->(t:Type)-[:DECLARES]->(m:Method)
    WHERE
      t.fqn=~'.*MyException'
    RETURN
      t.fqn as Type, COUNT(m) as MethodCount