JDK 7 code statistics

Published on May 24, 2015

JDK 7 code statistics

    I wanted to get the statistics of Java sources and find out how many parameters there are on average for methods, methods in classes, constructors, etc. The question is not entirely idle, because on the basis of this data we can calculate the optimal default size for containers for these entities in the software Code Models (AST) to save memory. In particular, we are talking about the Spoon project . Using this library, I did the analysis, by the way.

    What could be more logical than testing the JDK source statistics to make some assumptions about any Java code. Along the way, I collected the most unusual instances - for example, methods with the largest number of parameters.

    To look at them, google the signature - the first link should be to Javadoc or to GrepCode. Or, if you have IntelliJ IDEA open in front of you, simply insert the class or method name after pressing Shift four times.

    I limited myself to the java. *, Javax. * And org. * Packages, as well as JDK 7, not 8, because the bugs of the Eclipse compiler on which Spoon is based do not allow building AST.

    From the point of view of statistics - I consider it a good assumption that the quantities of all the entities under consideration are distributed according to Poisson's law , therefore the only number - the average value - describes the whole distribution well.

    But, if desired, you can conduct a deeper analysis, or test your project: gist.github.com/leventov/1f8d8d470b9632bc3cc3

    Method Parameters


    Average: 1,063

    Qty Method
    12 java.lang.String layoutCompoundLabel (javax.swing.JComponent, java.awt.FontMetrics, java.lang.String, javax.swing.Icon, int, int, int, int, java.awt.Rectangle, java.awt.Rectangle , java.awt.Rectangle, int)
    12 void drawChunk (java.awt.Image, java.awt.Graphics, boolean, int, int, int, int, int, int, int, int, boolean)
    12 java.lang.String layoutText (javax.swing.plaf.synth.SynthContext, java.awt.FontMetrics, java.lang.String, javax.swing.Icon, int, int, int, int, java.awt.Rectangle, java .awt.Rectangle, java.awt.Rectangle, int)
    14 void paintRow (javax.swing.tree.TreeCellRenderer, javax.swing.tree.DefaultTreeCellRenderer, javax.swing.plaf.synth.SynthContext, javax.swing.plaf.synth.SynthContext, java.awtavaGramics , java.awt.Insets, java.awt.Rectangle, java.awt.Rectangle, javax.swing.tree.TreePath, int, boolean, boolean, boolean)
    15 void initMouseEvent (java.lang.String, boolean, boolean, org.w3c.dom.views.AbstractView, int, int, int, int, int, boolean, boolean, boolean, boolean, short, org.w3c.dom.events .EventTarget)
    sixteen void setRaster (int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)


    Typical Method Parameters


    Average: 0.010

    Qty method
    2 <K, V> java.util.Map checkedMap (java.util.Map, java.lang.Class, java.lang.Class)
    2 <K, V> K keyOrNull (java.util.TreeMap $ Entry)
    2 <K, V> java.util.concurrent.ConcurrentHashMap $ HashEntry entryAt (java.util.concurrent.ConcurrentHashMap $ HashEntry [], int)
    2 <U, W> java.util.concurrent.atomic.AtomicReferenceFieldUpdater newUpdater (java.lang.Class, java.lang.Class, java.lang.String)
    2 <K, V> java.util.Map newHashMap ()
    2 <M, I> javax.swing.RowFilter andFilter (java.lang.Iterable)
    2 <R, P> R accept (javax.lang.model.element.AnnotationValueVisitor, P)
    2 <R, P> R accept (javax.lang.model.element.ElementVisitor, P)
    2 <R, P> R accept (javax.lang.model.type.TypeVisitor, P)
    3 <K, V, T> java.util.Collections $ CheckedMap $ CheckedEntrySet $ ​​CheckedEntry checkedEntry (java.util.Map $ Entry, java.lang.Class)


    Constructor Options


    Average: 1,207

    Qty Constructor
    12 java.awt.LinearGradientPaintContext (java.awt.LinearGradientPaint, java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderH. awt.geom.Point2D, java.awt.geom.Point2D, float [], java.awt.Color [], java.awt.MultipleGradientPaint $ CycleMethod, java.awt.MultipleGradientPaint $ ColorSpaceType)
    12 java.lang.management.ThreadInfo (java.lang.Thread, int, java.lang.Object, java.lang.Thread, long, long, long, long, java.lang.StackTraceElement [], java.lang.Object [ ], int [], java.lang.Object [])
    12 javax.swing.event.MenuDragMouseEvent (java.awt.Component, int, long, int, int, int, int, int, int, boolean, javax.swing.MenuElement [], javax.swing.MenuSelectionManager)
    13 java.awt.event.MouseWheelEvent (java.awt.Component, int, long, int, int, int, int, int, int, boolean, int, int, int)
    13 java.util.SimpleTimeZone (int, java.lang.String, int, int, int, int, int, int, int, int, int, int, int)
    14 java.awt.event.MouseWheelEvent (java.awt.Component, int, long, int, int, int, int, int, int, boolean, int, int, int, double)
    15 java.awt.RadialGradientPaintContext (java.awt.RadialGradientPaint, java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.attrent float, float, float, float, float [], java.awt.Color [], java.awt.MultipleGradientPaint $ CycleMethod, java.awt.MultipleGradientPaint $ ColorSpaceType)
    sixteen javax.imageio.spi.ImageReaderWriterSpi (java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], java.lang.String [], java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], boolean, java.lang.String, java.lang.String, java.lang.String [ ], java.lang.String [])
    18 javax.imageio.spi.ImageReaderSpi (java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], java.lang.String [], java.lang.String, java.lang.Class [], java.lang.String [], boolean, java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], boolean, java. lang.String, java.lang.String, java.lang.String [], java.lang.String [])
    18 javax.imageio.spi.ImageWriterSpi (java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], java.lang.String [], java.lang.String, java.lang.Class [], java.lang.String [], boolean, java.lang.String, java.lang.String, java.lang.String [], java.lang.String [], boolean, java. lang.String, java.lang.String, java.lang.String [], java.lang.String [])

    Typical Design Parameters


    Average: 0.001

    Many do not even know what happens. Four classes with parameterized constructors were found in the JDK. Although I had occasion to try on this chip in practice, and, it seems, not even once.
    Qty Constructor
    one javax.management.StandardEmitterMBean (T, java.lang.Class, boolean, javax.management.NotificationEmitter)
    one javax.management.StandardMBean (T, java.lang.Class)
    one javax.management.openmbean.OpenMBeanAttributeInfoSupport (java.lang.String, java.lang.String, javax.management.openmbean.OpenType, boolean, boolean, boolean, T)
    one javax.management.openmbean.OpenMBeanParameterInfoSupport (java.lang.String, java.lang.String, javax.management.openmbean.OpenType, T)


    Typical class parameters


    Average: 0.117

    Unexpectedly, not a single class was found with more than three typical parameters. My personal best is 8.
    Qty Class
    2 class javax.swing.DefaultRowSorter
    2 class javax.swing.DefaultRowSorter $ ModelWrapper
    2 class javax.swing.RowFilter
    2 class javax.swing.RowFilter $ AndFilter
    2 class javax.swing.RowFilter $ Entry
    2 class javax.swing.RowFilter $ NotFilter
    2 class javax.swing.RowFilter $ OrFilter
    2 class javax.swing.SwingWorker
    2 class javax.xml.bind.annotation.adapters.XmlAdapter
    3 class java.util.Collections $ CheckedMap $ CheckedEntrySet $ ​​CheckedEntry

    Implemented Interfaces


    Average: 0.555

    Qty Class
    6 class javax.swing.plaf.basic.BasicComboBoxUI $ Handler
    6 class javax.swing.plaf.basic.BasicTabbedPaneUI $ Handler
    6 class javax.swing.plaf.basic.BasicTableUI $ Handler
    6 class javax.swing.text.JTextComponent $ AccessibleJTextComponent
    7 class javax.swing.JTable
    7 class javax.swing.JTable $ AccessibleJTable
    7 class javax.swing.plaf.basic.BasicInternalFrameUI $ Handler
    7 class javax.swing.plaf.basic.BasicListUI $ Handler
    ten class javax.swing.plaf.basic.BasicTreeUI $ Handler
    17 class java.awt.AWTEventMulticaster

    Anonymous initialization blocks


    Average: 0.057

    Here, on the contrary, JDK authors love initialization blocks more than me. I have never written more than one block per class.
    Qty Class
    2 class javax.management.remote.rmi.RMIConnector
    2 class javax.swing.text.html.HTML
    3 class java.lang.invoke.CallSite
    3 class java.lang.invoke.MethodHandle
    3 class java.lang.invoke.MethodHandleNatives
    3 class java.math.BigInteger
    3 class java.net.InetAddress
    3 class java.util.zip.ZipFile
    3 class javax.swing.text.rtf.RTFReader
    6 class java.lang.invoke.LambdaForm

    Fields


    Average: 3,861

    Qty Class
    84 class java.awt.Event
    84 class java.util.Calendar
    93 class javax.swing.plaf.nimbus.InternalFrameTitlePaneMaximizeButtonPainter
    98 class java.awt.Component
    99 enum java.lang.Character $ UnicodeScript
    130 class java.awt.color.ICC_Profile
    140 class javax.swing.plaf.nimbus.FileChooserPainter
    209 class java.awt.event.KeyEvent
    213 class java.lang.Character $ UnicodeBlock
    223 class java.awt.PageAttributes $ MediaType

    Constructors


    Average: 1,467

    Qty Class
    ten class java.lang.invoke.MemberName
    ten class java.net.Socket
    ten class java.sql.BatchUpdateException
    12 class java.math.BigInteger
    13 class java.util.Scanner
    14 class java.awt.Dialog
    sixteen class java.util.Formatter
    sixteen class javax.swing.JDialog
    17 class java.lang.String
    17 class java.math.BigDecimal

    Methods


    Average: 8,003

    Qty Class
    137 class javax.swing.plaf.synth.ParsedSynthStyle $ DelegatingPainter
    143 class javax.swing.plaf.nimbus.SynthPainterImpl
    143 class javax.swing.plaf.synth.ImagePainter
    145 class java.awt.Window
    147 class javax.swing.JTree
    148 class javax.swing.plaf.nimbus.FileChooserPainter
    152 class java.awt.Container
    187 class javax.swing.JComponent
    196 class javax.swing.JTable
    331 class java.awt.Component

    Nested Classes


    Average: 0.327

    Qty Class
    20 class javax.swing.plaf.metal.MetalBorders
    20 class javax.swing.text.html.CSS
    21 class javax.swing.plaf.basic.BasicTreeUI
    21 class javax.swing.text.html.HTMLDocument $ HTMLReader
    27 class java.beans.MetaData $ java_util_Collections
    thirty class javax.swing.plaf.metal.MetalIconFactory
    33 class javax.swing.text.DefaultEditorKit
    36 class java.util.Collections
    48 class java.beans.MetaData
    59 class java.util.regex.Pattern