1 8 package com.mountainminds.eclemma.internal.core.analysis; 9 10 import com.mountainminds.eclemma.core.analysis.ILineCoverage; 11 12 18 public class Lines extends Counter implements ILineCoverage { 19 20 25 private static final int BLOCK_INCREMENT = 64; 26 27 28 private byte[] coverage = null; 29 30 private int firstline = 0; 31 32 private int lastline = 0; 33 34 private int offset = 0; 35 36 protected Lines() { 37 super(0, 0); 38 } 39 40 private int getBlockAlignedOffset(int line) { 41 return line - (line % BLOCK_INCREMENT); 42 } 43 44 private int getBlockAlignedSize(int size) { 45 return size + BLOCK_INCREMENT - (size % BLOCK_INCREMENT); 46 } 47 48 55 private void ensureCapacity(int line) { 56 if (coverage == null) { 57 firstline = line; 58 lastline = line; 59 offset = getBlockAlignedOffset(line); 60 coverage = new byte[BLOCK_INCREMENT]; 61 return; 62 } 63 if (firstline > line) { 64 firstline = line; 65 if (offset > line) { 66 int newoffset = getBlockAlignedOffset(line); 67 byte[] newcoverage = new byte[coverage.length + offset - newoffset]; 68 System.arraycopy(coverage, 0, newcoverage, offset - newoffset, 69 coverage.length); 70 offset = newoffset; 71 coverage = newcoverage; 72 } 73 return; 74 } 75 if (lastline < line) { 76 lastline = line; 77 if (line - offset >= coverage.length) { 78 byte[] newcoverage = new byte[getBlockAlignedSize(line - offset)]; 79 System.arraycopy(coverage, 0, newcoverage, 0, coverage.length); 80 coverage = newcoverage; 81 } 82 } 83 } 84 85 public void addLines(int lines[], boolean isCovered) { 86 for (int i = 0; i < lines.length; i++) { 87 int line = lines[i]; 88 ensureCapacity(line); 89 int idx = line - offset; 90 switch (coverage[idx]) { 91 case NO_CODE: 92 total++; 93 if (isCovered) 94 covered++; 95 break; 96 case NOT_COVERED: 97 if (isCovered) 98 covered++; 99 break; 100 } 101 coverage[idx] |= isCovered ? FULLY_COVERED : NOT_COVERED; 102 } 103 } 104 105 public Counter increment(int total, int covered) { 106 throw new UnsupportedOperationException (); 107 } 108 109 111 public byte[] getCoverage() { 112 return coverage; 113 } 114 115 public int getFirstLine() { 116 return firstline; 117 } 118 119 public int getLastLine() { 120 return lastline; 121 } 122 123 public int getOffset() { 124 return offset; 125 } 126 127 } 128 | Popular Tags |