View Javadoc
1   /*
2    * Copyright (c) 2006 JMockit developers
3    * This file is subject to the terms of the MIT license (see LICENSE.txt).
4    */
5   package mockit.coverage.dataItems;
6   
7   import edu.umd.cs.findbugs.annotations.NonNull;
8   import edu.umd.cs.findbugs.annotations.Nullable;
9   
10  import java.io.IOException;
11  import java.io.ObjectOutputStream;
12  import java.io.Serializable;
13  
14  import org.checkerframework.checker.index.qual.NonNegative;
15  
16  public abstract class FieldData implements Serializable {
17      private static final long serialVersionUID = 8565599590976858508L;
18  
19      @NonNegative
20      int readCount;
21      @NonNegative
22      int writeCount;
23      @Nullable
24      Boolean covered;
25  
26      private void writeObject(@NonNull ObjectOutputStream out) throws IOException {
27          isCovered();
28          out.defaultWriteObject();
29      }
30  
31      @NonNegative
32      public final int getReadCount() {
33          return readCount;
34      }
35  
36      @NonNegative
37      public final int getWriteCount() {
38          return writeCount;
39      }
40  
41      public final boolean isCovered() {
42          if (covered == null) {
43              covered = false;
44              markAsCoveredIfNoUnreadValuesAreLeft();
45          }
46  
47          return covered;
48      }
49  
50      abstract void markAsCoveredIfNoUnreadValuesAreLeft();
51  
52      final void addCountsFromPreviousTestRun(@NonNull FieldData previousInfo) {
53          readCount += previousInfo.readCount;
54          writeCount += previousInfo.writeCount;
55          covered = isCovered() || previousInfo.isCovered();
56      }
57  }