1 8 package com.mountainminds.eclemma.internal.core.analysis; 9 10 import org.eclipse.core.resources.IResource; 11 12 import com.mountainminds.eclemma.core.analysis.ICounter; 13 import com.mountainminds.eclemma.core.analysis.IJavaElementCoverage; 14 import com.mountainminds.eclemma.core.analysis.ILineCoverage; 15 16 22 public class JavaElementCoverage implements IJavaElementCoverage { 23 24 private Counter typeCounter; 25 private Counter methodCounter; 26 private Counter blockCounter; 27 private Counter lineCounter; 28 private Counter instructionsCounter; 29 30 private final JavaElementCoverage parent; 31 private final Lines lines; 32 private final long modificationStamp; 33 34 public JavaElementCoverage(JavaElementCoverage parent, boolean haslines, long stamp) { 35 this.parent = parent; 36 typeCounter = Counter.COUNTER_0_0; 37 methodCounter = Counter.COUNTER_0_0; 38 blockCounter = Counter.COUNTER_0_0; 39 instructionsCounter = Counter.COUNTER_0_0; 40 lineCounter = haslines ? null : Counter.COUNTER_0_0; 41 modificationStamp = stamp; 42 this.lines = haslines ? new Lines() : null; 43 } 44 45 public JavaElementCoverage(JavaElementCoverage parent, boolean haslines, IResource resource) { 46 this(parent, haslines, resource == null ? 0 : resource.getModificationStamp()); 47 } 48 49 50 public void addBlock(int instructions, int[] lines, boolean covered) { 51 addBlock(instructions, lines, covered, 0, 0); 52 } 53 54 private void addBlock(int instructions, int[] lines, boolean covered, int totalLineDelta, int coveredLineDelta) { 55 blockCounter = blockCounter.increment(1, covered ? 1 : 0); 56 instructionsCounter = instructionsCounter.increment(instructions, covered ? instructions : 0); 57 if (this.lines == null) { 58 lineCounter = lineCounter.increment(totalLineDelta, coveredLineDelta); 59 if (parent != null) { 60 parent.addBlock(instructions, lines, covered, totalLineDelta, coveredLineDelta); 61 } 62 } else { 63 if (lines != null) { 64 long totalDelta = this.lines.getTotalCount(); 65 long coveredDelta = this.lines.getCoveredCount(); 66 this.lines.addLines(lines, covered); 67 if (parent != null) { 68 totalDelta = this.lines.getTotalCount() - totalDelta; 69 coveredDelta = this.lines.getCoveredCount() - coveredDelta; 70 parent.addBlock(instructions, lines, covered, (int) totalDelta, (int) coveredDelta); 71 } 72 } 73 } 74 } 75 76 public void addMethod(boolean covered) { 77 methodCounter = methodCounter.increment(1, covered ? 1 : 0); 78 if (parent != null) { 79 parent.addMethod(covered); 80 } 81 } 82 83 public void addType(boolean covered) { 84 typeCounter = typeCounter.increment(1, covered ? 1 : 0); 85 if (parent != null) { 86 parent.addType(covered); 87 } 88 } 89 90 92 public ICounter getBlockCounter() { 93 return blockCounter; 94 } 95 96 public ICounter getLineCounter() { 97 if (lines == null) { 98 return lineCounter; 99 } else { 100 return lines; 101 } 102 } 103 104 public ICounter getInstructionCounter() { 105 return instructionsCounter; 106 } 107 108 public ILineCoverage getLineCoverage() { 109 return lines; 110 } 111 112 public ICounter getMethodCounter() { 113 return methodCounter; 114 } 115 116 public ICounter getTypeCounter() { 117 return typeCounter; 118 } 119 120 public long getResourceModificationStamp() { 121 return modificationStamp; 122 } 123 124 } 125 | Popular Tags |