How to find most commonly referenced classes?

Is there some trick to find the most commonly used classes? I'm writing
javadoc, and I think a good metric is to document the top 20% frequently
used classes. However, I don't know how to measure this without writing
a plugin. Has anyone else done this using some clever trick?

4 comments

MetricsReloaded. Use the "Number of Dependents" metrics (there's a separate one for classes and interaces), and don't forget to exclude test classes (which should usually have zero dependents). To be precise, this gives number of classes or interfaces that a given class is used from, rather than a precise count of usages, but that should be a pretty good proxy.

MetricsReloaded will also tell you just what percentage of your methods or classes are javadoced, if you are interested in that.

In general, if you have a question you would like to ask of IDEA that starts with "How many" or "What percentage", the answer is available via MetricsReloaded.

--Dave Griffith

0

So I tried this, and it doesn't seem to work. It only returns a few
classes, and definitely not the most commonly used ones. I also get this
exception:

No message
java.lang.NullPointerException
at
com.siyeh.metrics.utils.StringToFractionMap.put(StringToFractionMap.java:43)
at
com.siyeh.metrics.metricModel.MetricsResultImpl.postValue(MetricsResultImpl.java:32)
at
com.siyeh.metrics.metricModel.MetricsResultImpl.postValue(MetricsResultImpl.java:22)
at
com.siyeh.metrics.metricModel.MetricsRunImpl.postMetric(MetricsRunImpl.java:45)
at
com.siyeh.metrics.execution.BaseMetricsCalculator.postMetric(BaseMetricsCalculator.java:183)
at
com.siyeh.metrics.classCalculators.NumDependentsClassCalculator.beforeClass(NumDependentsClassCalculator.java:19)
at com.siyeh.metrics.execution.Traversal.visitClass(Traversal.java:227)
at
com.intellij.psi.JavaElementVisitor.visitTypeParameter(JavaElementVisitor.java:372)
at
com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl.accept(PsiTypeParameterImpl.java:67)
at
com.intellij.psi.impl.source.TreeWrapperPsiElement.acceptChildren(TreeWrapperPsiElement.java:54)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:37)
at
com.intellij.psi.JavaElementVisitor.visitTypeParameterList(JavaElementVisitor.java:284)
at
com.intellij.psi.impl.source.tree.java.PsiTypeParameterListImpl.accept(PsiTypeParameterListImpl.java:19)
at
com.intellij.psi.impl.source.TreeWrapperPsiElement.acceptChildren(TreeWrapperPsiElement.java:54)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:37)
at
com.intellij.psi.JavaElementVisitor.visitClass(JavaElementVisitor.java:64)
at com.siyeh.metrics.execution.Traversal.visitClass(Traversal.java:229)
at com.intellij.psi.impl.source.PsiClassImpl.accept(PsiClassImpl.java:315)
at
com.intellij.psi.impl.source.TreeWrapperPsiElement.acceptChildren(TreeWrapperPsiElement.java:54)
at
com.intellij.psi.PsiRecursiveElementVisitor.visitElement(PsiRecursiveElementVisitor.java:37)
at
com.intellij.psi.JavaElementVisitor.visitFile(JavaElementVisitor.java:140)
at com.siyeh.metrics.execution.Traversal.visitFile(Traversal.java:219)
at
com.intellij.psi.JavaElementVisitor.visitJavaFile(JavaElementVisitor.java:348)
at com.siyeh.metrics.execution.Traversal.visitJavaFile(Traversal.java:151)
at
com.intellij.psi.impl.source.PsiJavaFileBaseImpl.accept(PsiJavaFileBaseImpl.java:88)
at
com.siyeh.metrics.execution.MetricsExecutionContextImpl$1.run(MetricsExecutionContextImpl.java:78)
at
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:0)
at
com.intellij.openapi.application.impl.ApplicationImpl$1MyThread.run(ApplicationImpl.java:3)


Dave Griffith wrote:

MetricsReloaded. Use the "Number of Dependents" metrics (there's a
separate one for classes and interaces), and don't forget to exclude
test classes (which should usually have zero dependents). To be
precise, this gives number of classes or interfaces that a given
class is used from, rather than a precise count of usages, but that
should be a pretty good proxy.

MetricsReloaded will also tell you just what percentage of your
methods or classes are javadoced, if you are interested in that.

In general, if you have a question you would like to ask of IDEA that
starts with "How many" or "What percentage", the answer is available
via MetricsReloaded.

--Dave Griffith

0

What version are you using of MetricsReloaded, and what version of IDEA?

Sixth and Red River Software
"Code with Grace and Verve"

0

Sixth and Red River Software wrote:

What version are you using of MetricsReloaded, and what version of IDEA?

Sixth and Red River Software
"Code with Grace and Verve"


Latest metricsreloaded, idea 5.1.1 EAP 4167

0

Please sign in to leave a comment.