This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
CoverageAnnotation.java
79 lines (68 loc) · 2.79 KB
/
CoverageAnnotation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
* Copyright (c) 2006, 2016 Mountainminds GmbH & Co. KG and Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Marc R. Hoffmann - initial API and implementation
*
******************************************************************************/
package com.mountainminds.eclemma.internal.ui.annotation;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.osgi.util.NLS;
import org.jacoco.core.analysis.ICounter;
import org.jacoco.core.analysis.ILine;
import com.mountainminds.eclemma.internal.ui.UIMessages;
/**
* Annotation object that includes its position information to avoid internal
* mappings.
*/
public class CoverageAnnotation extends Annotation {
private static final String FULL_COVERAGE = "com.mountainminds.eclemma.ui.fullCoverageAnnotation"; //$NON-NLS-1$
private static final String PARTIAL_COVERAGE = "com.mountainminds.eclemma.ui.partialCoverageAnnotation"; //$NON-NLS-1$
private static final String NO_COVERAGE = "com.mountainminds.eclemma.ui.noCoverageAnnotation"; //$NON-NLS-1$
private final Position position;
private final ILine line;
public CoverageAnnotation(int offset, int length, ILine line) {
super(getAnnotationID(line), false, null);
this.line = line;
position = new Position(offset, length);
}
public Position getPosition() {
return position;
}
public ILine getLine() {
return line;
}
public String getText() {
final ICounter branches = line.getBranchCounter();
switch (branches.getStatus()) {
case ICounter.NOT_COVERED:
return NLS.bind(UIMessages.AnnotationTextAllBranchesMissed_message,
Integer.valueOf(branches.getMissedCount()));
case ICounter.FULLY_COVERED:
return NLS.bind(UIMessages.AnnotationTextAllBranchesCovered_message,
Integer.valueOf(branches.getTotalCount()));
case ICounter.PARTLY_COVERED:
return NLS.bind(UIMessages.AnnotationTextSomeBranchesMissed_message,
Integer.valueOf(branches.getMissedCount()),
Integer.valueOf(branches.getTotalCount()));
default:
return null;
}
}
private static String getAnnotationID(ILine line) {
switch (line.getStatus()) {
case ICounter.FULLY_COVERED:
return FULL_COVERAGE;
case ICounter.PARTLY_COVERED:
return PARTIAL_COVERAGE;
case ICounter.NOT_COVERED:
return NO_COVERAGE;
}
throw new AssertionError(line.getStatus());
}
}