Skip to content

Commit 27c2687

Browse files
committed
Refactor: rename.
uncovered -> not-yet-covered.
1 parent d897c57 commit 27c2687

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/main/java/com/oracle/simpletool/SimpleCodeCoverageInstrument.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public final class SimpleCodeCoverageInstrument extends TruffleInstrument {
5454
* but not yet executed {@link SourceSection}s. This is used to calculate
5555
* the coverage for each {@link Source}.
5656
*/
57-
private final Map<Source, Set<SourceSection>> sourceToUncoveredSections = new HashMap<>();
57+
private final Map<Source, Set<SourceSection>> sourceToNotYetCoveredSections = new HashMap<>();
5858

59-
public Map<Source, Set<SourceSection>> getSourceToUncoveredSections() {
60-
return sourceToUncoveredSections;
59+
public Map<Source, Set<SourceSection>> getSourceToNotYetCoveredSections() {
60+
return sourceToNotYetCoveredSections;
6161
}
6262

6363
/**
@@ -123,7 +123,7 @@ protected void onCreate(final Env env) {
123123
* factory produces {@link Node Truffle Nodes} that will be inserted into
124124
* the AST at positions specified by the filter. Each of the inserted nodes
125125
* will, once executed, remove the corresponding source section from the
126-
* {@link #sourceToUncoveredSections set of unexecuted source sections}.
126+
* {@link #sourceToNotYetCoveredSections set of unexecuted source sections}.
127127
*
128128
* @param env The environment, used to get the {@link Instrumenter}
129129
*/
@@ -163,28 +163,28 @@ private void ensurePrintCoverage(final Env env) {
163163
*/
164164
private void printResults(final Env env) {
165165
final PrintStream printStream = new PrintStream(env.out());
166-
for (Source source : sourceToUncoveredSections.keySet()) {
166+
for (Source source : sourceToNotYetCoveredSections.keySet()) {
167167
final String path = source.getPath();
168168
final int lineCount = source.getLineCount();
169-
final List<Integer> uncoveredLineNumbers = uncoveredLineNumbers(source);
170-
final int uncoveredLineCount = uncoveredLineNumbers.size();
171-
double coveredPercentage = 100 * ((double) lineCount - uncoveredLineCount) / lineCount;
169+
final List<Integer> notYetCoveredLineNumbers = notYetCoveredLineNumbers(source);
170+
final int notYetCoveredSize = notYetCoveredLineNumbers.size();
171+
double coveredPercentage = 100 * ((double) lineCount - notYetCoveredSize) / lineCount;
172172
printStream.println("==");
173173
printStream.println("Coverage of " + path + " is " + String.format("%.2f%%", coveredPercentage));
174174
printStream.println("Lines not covered by execution:");
175-
for (Integer uncoveredLineNumber : uncoveredLineNumbers) {
176-
printStream.println(uncoveredLineNumber + " " + source.getCharacters(uncoveredLineNumber));
175+
for (Integer notYetCoveredLineNumber : notYetCoveredLineNumbers) {
176+
printStream.println(notYetCoveredLineNumber + " " + source.getCharacters(notYetCoveredLineNumber));
177177
}
178178
}
179179
}
180180

181181
/**
182182
* @param source
183-
* @return A sorted list of line numers for uncovered lines of source code
184-
* in the given {@link Source}
183+
* @return A sorted list of line numbers for not-yet-covered lines of source
184+
* code in the given {@link Source}
185185
*/
186-
public List<Integer> uncoveredLineNumbers(final Source source) {
187-
Set<SourceSection> sections = sourceToUncoveredSections.get(source);
186+
public List<Integer> notYetCoveredLineNumbers(final Source source) {
187+
Set<SourceSection> sections = sourceToNotYetCoveredSections.get(source);
188188
Set<Integer> linesNotCovered = new HashSet<>();
189189
for (SourceSection ss : sections) {
190190
for (int i = ss.getStartLine(); i <= ss.getEndLine(); i++) {
@@ -229,7 +229,7 @@ private class GatherSourceSectionsListener implements LoadSourceSectionListener
229229
*
230230
* @param event information about the event. We use this information to
231231
* keep our
232-
* {@link #sourceToUncoveredSections set of uncovered} {@link SourceSection}s
232+
* {@link #sourceToNotYetCoveredSections set of not-yet-covered} {@link SourceSection}s
233233
* up to date.
234234
*/
235235
@Override
@@ -238,7 +238,7 @@ public void onLoad(LoadSourceSectionEvent event) {
238238
final Source source = sourceSection.getSource();
239239
// TODO: This should not be necesery becuase of the filter. Bug!
240240
if (!source.isInternal()) {
241-
sourceToUncoveredSections.computeIfAbsent(source, (Source s) -> {
241+
sourceToNotYetCoveredSections.computeIfAbsent(source, (Source s) -> {
242242
return new HashSet<>();
243243
}).add(sourceSection);
244244
}
@@ -270,7 +270,7 @@ public ExecutionEventNode create(final EventContext ec) {
270270
* expressions in our case as defined by the filter given to the
271271
* {@link Instrumenter} in {@link #onCreate(com.oracle.truffle.api.instrumentation.TruffleInstrument.Env)
272272
* }), and removes the "wrapped" {@link SourceSection} from the set
273-
* {@link #sourceToUncoveredSections uncovered} {@link SourceSection}.
273+
* {@link #sourceToNotYetCoveredSections not-yet-covered} {@link SourceSection}.
274274
*/
275275
class CoverageNode extends ExecutionEventNode {
276276

@@ -290,7 +290,8 @@ private CoverageNode(SourceSection instrumentedSourceSection) {
290290
* The {@link ExecutionEventNode} class let's us define several events
291291
* that we can intercept. The one of interest to us is {@link ExecutionEventNode#onReturnValue(com.oracle.truffle.api.frame.VirtualFrame, java.lang.Object)
292292
* } as we wish to remove this nodes {@link #instrumentedSourceSection}
293-
* from the {@link #sourceToUncoveredSections set of uncovered nodes}
293+
* from the
294+
* {@link #sourceToNotYetCoveredSections set of not-yet-covered nodes}
294295
* only once the node is successfully executed (as oppose to, for
295296
* example, {@link ExecutionEventNode#onReturnExceptional(com.oracle.truffle.api.frame.VirtualFrame, java.lang.Throwable)
296297
* }).
@@ -333,7 +334,7 @@ public void onReturnValue(VirtualFrame vFrame, Object result) {
333334
final Source source = instrumentedSourceSection.getSource();
334335
// TODO: This should not be necesery becuase of the filter. Bug!
335336
if (!source.isInternal()) {
336-
sourceToUncoveredSections.get(source).remove(instrumentedSourceSection);
337+
sourceToNotYetCoveredSections.get(source).remove(instrumentedSourceSection);
337338
}
338339
}
339340
}

src/test/java/com/oracle/simpletool/test/SimpleCodeCoverageInstrumentTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ private void assertCorrect(final Context context) {
4545
get(SimpleCodeCoverageInstrument.ID).
4646
lookup(SimpleCodeCoverageInstrument.class);
4747
// We then use the looked up service to assert that it behaves as expected, just like in any other test.
48-
Map<com.oracle.truffle.api.source.Source, Set<SourceSection>> sourceToUncoveredSections = coverage.getSourceToUncoveredSections();
49-
Assert.assertEquals(1, sourceToUncoveredSections.size());
50-
sourceToUncoveredSections.forEach((com.oracle.truffle.api.source.Source s, Set<SourceSection> v) -> {
51-
List<Integer> uncoveredLineNumbers = coverage.uncoveredLineNumbers(s);
48+
Map<com.oracle.truffle.api.source.Source, Set<SourceSection>> sourceToNotYetCoveredSections = coverage.getSourceToNotYetCoveredSections();
49+
Assert.assertEquals(1, sourceToNotYetCoveredSections.size());
50+
sourceToNotYetCoveredSections.forEach((com.oracle.truffle.api.source.Source s, Set<SourceSection> v) -> {
51+
List<Integer> notYetCoveredLineNumbers = coverage.notYetCoveredLineNumbers(s);
5252
Object[] expected = new Integer[]{47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 61, 67};
53-
Assert.assertArrayEquals(expected, uncoveredLineNumbers.toArray());
53+
Assert.assertArrayEquals(expected, notYetCoveredLineNumbers.toArray());
5454
});
5555
}
5656
}

0 commit comments

Comments
 (0)