Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-1192

Create ClassInfo objects for anonymous inline classes

    XMLWordPrintable

Details

    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

    Description

      During implementation of CLOV-1162 I've found that anonymous inline classes does not have their own ClassInfo object crated. Instead of this, methods of inline class are added to the enclosing class.

      For instance, a following code:

      public class AggregatedMetrics {
          /**
           * Inner class, case with a method having an inline anonymous class
           * statements = 3 (sum of direct methods' statements)
           * aggregatedStatements = 5 (sum of direct methods' aggregated statements)
           */
          class C {
              /**
               * Method: statements = 2; aggregatedStatements = 4 (method's statements + inline class aggregated statements)
               */
              Iterator methodThree() {
                  int d = 4;
                  /**
                   * Inline class: statements = aggregatedStatements = 2 (sum of its methods)
                   */
                  return new InstrumentationSessionImplTestSample2() {
                      /** statements = aggregatedStatements = 1 */
                      public boolean hasNext() {
                          return false;
                      }
      
                      /** statements = aggregatedStatements = 1 */
                      public Object next() {
                          return null;
                      }
      
                      /** statements = aggregatedStatements = 0 */
                      public void remove() {
      
                      }
                  };
              }
      
              /** statements = aggregatedStatements = 1 */
              void methodFour() {
                  int e = 5;
              }
          }
      }
      

      is stored in clover database in this way:

      <class name="AggregatedMetrics.C" qualifiedName="AggregatedMetrics.C">
      	<metrics  statements="5" aggregatedStatements="5"/>
      	<method name="hasNext() : boolean">
      		<metrics  statements="1" aggregatedStatements="1"/>
      	</method>
      	<method name="next() : Object">
      		<metrics  statements="1" aggregatedStatements="1"/>
      	</method>
      	<method name="remove() : void">
      		<metrics  statements="0" aggregatedStatements="0"/>
      	</method>
      	<method name="methodThree() : Iterator">
      		<metrics  statements="2" aggregatedStatements="2"/>
      	</method>
      	<method name="methodFour() : void">
      		<metrics  statements="1" aggregatedStatements="1"/>
      	</method>
      </class>
      

      It means that on reports the AggregatedMetrics.C class is presented as having 5 methods, while it has 2 actually.

      It's not a bug. There was a design decision to not present anonymous classes in a report.

      Possible improvement:

      • create ClassInfo objects for anonymous classes
      • add option for reporting whether to show anonymous classes (like InstrumentationSessionImplTestSample2$1) or not

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mparfianowicz Marek Parfianowicz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: