Skip to content

Commit

Permalink
remove unused block start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Jun 16, 2022
1 parent db808af commit 42d7385
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 45 deletions.
Expand Up @@ -28,8 +28,6 @@ class BlockCoverageDataLoader extends DataLoader<BlockCoverage> {
private static final String METHOD = "method";
private static final String CLASSNAME = "classname";
private static final String NUMBER = "number";
private static final String FIRST_INSN = "firstInstruction";
private static final String LAST_INSN = "lastInstruction";

private static final String OPEN_PAREN = "(";

Expand Down Expand Up @@ -75,11 +73,9 @@ private BlockLocation toBlockLocation(StartElement enclosingNode) {
String method = getAttributeValue(enclosingNode, METHOD);
String methodName = method.substring(0, method.indexOf(OPEN_PAREN));
int blockNum = getAttributeValueAsInt(enclosingNode, NUMBER);
int firstInstruction = getAttributeValueAsInt(enclosingNode, FIRST_INSN);
int lastInstruction = getAttributeValueAsInt(enclosingNode, LAST_INSN);
String methodDesc = method.substring(method.indexOf(OPEN_PAREN));
Location location = new Location(className, methodName, methodDesc);
block = new BlockLocation(location, blockNum, firstInstruction, lastInstruction);
block = new BlockLocation(location, blockNum);
return block;
}

Expand Down
Expand Up @@ -59,7 +59,7 @@ private void handleProbes(final SafeDataInputStream is) {
// nb, convert from classwide id to method scoped index within
// BlockLocation
this.probeToBlock.put(CodeCoverageStore.encode(classId, i),
new BlockLocation(loc, i - first, is.readInt(), is.readInt()));
new BlockLocation(loc, i - first));
}
}

Expand Down
Expand Up @@ -50,8 +50,6 @@ private void writeLineCoverage(final BlockCoverage each, final Writer out) {
+ " method='"
+ StringUtil.escapeBasicHtmlChars(l.getMethodName()) + StringUtil.escapeBasicHtmlChars(l.getMethodDesc())
+ "' number='" + each.getBlock().getBlock()
+ "' firstInstruction='" + each.getBlock().getFirstInsnInBlock()
+ "' lastInstruction='" + each.getBlock().getLastInsnInBlock()
+ "'>");
write(out, "<tests>\n");
final List<String> ts = new ArrayList<>(each.getTests());
Expand Down
Expand Up @@ -37,7 +37,7 @@ public List<TestInfo> assignTests(MutationDetails mutation) {

private Collection<TestInfo> pickTests(MutationDetails mutation) {
return mutation.getBlocks().stream()
.map(block -> new BlockLocation(mutation.getId().getLocation(), block, -1, -1))
.map(block -> new BlockLocation(mutation.getId().getLocation(), block))
.flatMap(loc -> this.coverage.getTestsForBlockLocation(loc).stream())
.collect(Collectors.toCollection(() -> new HashSet<>()));
}
Expand Down
Expand Up @@ -290,7 +290,7 @@ private CoverageResult makeCoverageResult(final String clazz,
private Collection<BlockLocation> makeCoverage(final String clazz,
final int block) {
final BlockLocation cs = new BlockLocation(Location.location(
ClassName.fromString(clazz), "foo", "V"), block, -1, -1);
ClassName.fromString(clazz), "foo", "V"), block);

return Collections.singleton(cs);
}
Expand Down
18 changes: 2 additions & 16 deletions pitest/src/main/java/org/pitest/coverage/BlockLocation.java
Expand Up @@ -9,21 +9,15 @@ public final class BlockLocation {

private final Location location;
private final int block;
private final int firstInsnInBlock;
private final int lastInsnInBlock;

public BlockLocation(final Location location, final int block,
final int firstInsnInBlock, final int lastInsnInBlock) {
public BlockLocation(final Location location, final int block) {
this.location = location;
this.block = block;
// what are these for?
this.firstInsnInBlock = firstInsnInBlock;
this.lastInsnInBlock = lastInsnInBlock;
}

public static BlockLocation blockLocation(final Location location,
final int block ) {
return new BlockLocation(location, block, -1, -1);
return new BlockLocation(location, block);
}

public boolean isFor(final ClassName clazz) {
Expand All @@ -38,14 +32,6 @@ public Location getLocation() {
return this.location;
}

public int getFirstInsnInBlock() {
return firstInsnInBlock;
}

public int getLastInsnInBlock() {
return lastInsnInBlock;
}

@Override
public int hashCode() {
return Objects.hash(location, block);
Expand Down
Expand Up @@ -40,7 +40,7 @@ public void visitEnd() {
this.parent.registerProbes(blocks.size());

CodeCoverageStore.registerMethod(this.classId, this.name, this.desc,
this.probeOffset, (this.probeOffset + blocks.size()) - 1, blocks);
this.probeOffset, (this.probeOffset + blocks.size()) - 1);

final DefaultInstructionCounter counter = new DefaultInstructionCounter();
accept(new InstructionTrackingMethodVisitor(
Expand Down
Expand Up @@ -43,8 +43,7 @@ public Map<BlockLocation, Set<Integer>> mapLines(final ClassName clazz) {
final List<Block> blocks = ControlFlowAnalyser.analyze(mn);
for (int i = 0; i != blocks.size(); i++) {
final Block each = blocks.get(i);
final BlockLocation bl = new BlockLocation(l, i,
each.getFirstInstruction(), each.getLastInstruction());
final BlockLocation bl = new BlockLocation(l, i);
map.put(bl, each.getLines());
}

Expand Down
Expand Up @@ -4,7 +4,6 @@
import java.util.Collection;

import org.pitest.coverage.CoverageReceiver;
import org.pitest.coverage.analysis.Block;
import org.pitest.testapi.Description;
import org.pitest.util.ExitCode;
import org.pitest.util.Id;
Expand Down Expand Up @@ -55,17 +54,13 @@ public synchronized void registerClass(final int id, final String className) {

@Override
public synchronized void registerProbes(int classId, String methodName,
String methodDesc, int firstProbe, int lastProbe, Iterable<Block> blocks) {
String methodDesc, int firstProbe, int lastProbe) {
this.dos.writeByte(Id.PROBES);
this.dos.writeInt(classId);
this.dos.writeString(methodName);
this.dos.writeString(methodDesc);
this.dos.writeInt(firstProbe);
this.dos.writeInt(lastProbe);
for (Block b : blocks) {
this.dos.writeInt(b.getFirstInstruction());
this.dos.writeInt(b.getLastInstruction());
}
}

}
7 changes: 2 additions & 5 deletions pitest/src/main/java/sun/pitest/CodeCoverageStore.java
Expand Up @@ -27,8 +27,6 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import org.pitest.coverage.analysis.Block;

/**
* Store for line visit information.
*/
Expand Down Expand Up @@ -97,10 +95,9 @@ public static int registerClass(final String className) {
}

public static void registerMethod(final int clazz, final String methodName,
final String methodDesc, final int firstProbe, final int lastProbe,
Iterable<Block> blocks) {
final String methodDesc, final int firstProbe, final int lastProbe) {
invokeQueue.registerProbes(clazz, methodName, methodDesc, firstProbe,
lastProbe, blocks);
lastProbe);
}

private static synchronized int nextId() {
Expand Down
4 changes: 1 addition & 3 deletions pitest/src/main/java/sun/pitest/InvokeReceiver.java
@@ -1,12 +1,10 @@
package sun.pitest;

import org.pitest.coverage.analysis.Block;

public interface InvokeReceiver {

void registerClass(int id, String className);

void registerProbes(int classId, String methodName, String methodDesc,
int firstProbe, int lastProbe, Iterable<Block> blocks);
int firstProbe, int lastProbe);

}
Expand Up @@ -37,7 +37,7 @@ public void shouldCalculateCorrectNumberOfCoveredBlocksWhenMultiplesClassesHaveC
private BlockLocation makeCoverage(final String name, final int block) {
final Location l = Location.location(ClassName.fromString(name),
"amethod", "methodDesc");
return new BlockLocation(l, block, 0, 1);
return new BlockLocation(l, block);
}

}
Expand Up @@ -36,7 +36,7 @@ public void shouldMapAllLinesWhenMethodContainsSingleBlock() throws Exception {

final Location l = Location.location(ClassName.fromClass(OneBlock.class),
"foo", "()I");
final BlockLocation bl = new BlockLocation(l, 0, -1, -1);
final BlockLocation bl = new BlockLocation(l, 0);

assertThat(actual.get(bl)).containsOnly(5);

Expand Down

0 comments on commit 42d7385

Please sign in to comment.