Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package dev.ionfusion.fusion.cli.cover;

import static dev.ionfusion.fusion._Private_Trampoline.discoverModulesInRepository;
import static dev.ionfusion.runtime._private.cover.CoverageDatabase.SRCLOC_COMPARE;
import static dev.ionfusion.runtime.base.SourceLocation.compareByLineColumn;
import static dev.ionfusion.runtime.base.SourceName.FUSION_SOURCE_EXTENSION;
import static java.nio.file.Files.walkFileTree;

Expand Down Expand Up @@ -421,9 +421,9 @@ private void renderSource(HtmlWriter sourceHtml,
SourceLocation coverageLoc = locations[locationIndex];

// We shouldn't skip past a known location.
assert SRCLOC_COMPARE.compare(currentLoc, coverageLoc) <= 0;
assert compareByLineColumn(currentLoc, coverageLoc) <= 0;

if (SRCLOC_COMPARE.compare(currentLoc, coverageLoc) == 0)
if (compareByLineColumn(currentLoc, coverageLoc) == 0)
{
boolean covered =
myDatabase.locationCovered(coverageLoc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -41,45 +40,6 @@
*/
public class CoverageDatabase
{
private static final class SourceNameComparator
implements Comparator<SourceName>
{
@Override
public int compare(SourceName a, SourceName b)
{
return a.display().compareTo(b.display());
}
}

static final Comparator<SourceName> SRCNAME_COMPARE =
new SourceNameComparator();


/**
* Compares locations by line/column, ignoring the offset.
*/
private static final class SourceLocationComparator
implements Comparator<SourceLocation>
{
@Override
public int compare(SourceLocation a, SourceLocation b)
{
if (a.getLine() < b.getLine()) return -1;
if (a.getLine() > b.getLine()) return 1;

if (a.getColumn() < b.getColumn()) return -1;
if (a.getColumn() > b.getColumn()) return 1;

return 0;
}
}

public static final Comparator<SourceLocation> SRCLOC_COMPARE =
new SourceLocationComparator();


//=========================================================================

private final Set<File> myRepositories = new HashSet<>();

private final Map<SourceLocation,Boolean> myLocations = new HashMap<>();
Expand Down Expand Up @@ -206,7 +166,7 @@ SourceName[] sortedNames()

SourceName[] sourceArray = sourceSet.toArray(new SourceName[0]);

Arrays.sort(sourceArray, SRCNAME_COMPARE);
Arrays.sort(sourceArray, SourceName::compareByDisplay);

return sourceArray;
}
Expand Down Expand Up @@ -235,7 +195,7 @@ public synchronized SourceLocation[] sortedLocations(SourceName name)

SourceLocation[] locsArray = locsList.toArray(new SourceLocation[0]);

Arrays.sort(locsArray, SRCLOC_COMPARE);
Arrays.sort(locsArray, SourceLocation::compareByLineColumn);

return locsArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public long getStartOffset()
}


//==================================================================================
// Concrete implementations

private static final class Shorts
extends SourceLocation
{
Expand Down Expand Up @@ -186,6 +189,9 @@ public long getStartOffset()
}


//==================================================================================


/**
* Returns an instance that represents an unknown location in the given
* source.
Expand Down Expand Up @@ -442,4 +448,24 @@ public int hashCode()
result ^= (result << 29) ^ (result >> 3);
return result;
}


/**
* Compares locations by line then column, ignoring the source-name and offset.
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
*
* @return a negative integer, zero, or a positive integer as the first argument is
* less than, equal to, or greater than the second.
*/
public static int compareByLineColumn(SourceLocation o1, SourceLocation o2)
{
int result = Long.compare(o1.getLine(), o2.getLine());
if (result == 0)
{
result = Long.compare(o1.getColumn(), o2.getColumn());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ public int hashCode()
}


/**
* Compares sources by their {@linkplain #display() display form}.
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
*
* @return a negative integer, zero, or a positive integer as the first argument is
* less than, equal to, or greater than the second.
*/
public static int compareByDisplay(SourceName o1, SourceName o2)
{
return o1.display().compareTo(o2.display());
}


//=========================================================================


Expand Down