AddressText.java

1
package com.rox.debug.breakpoints;
2
3
import com.rox.debug.labels.MemoryLabel;
4
5
import java.util.List;
6
import java.util.Optional;
7
import java.util.OptionalInt;
8
import java.util.regex.Pattern;
9
10
/** Typing and showing a breakpoint or watchpoint address - as hex, or by a {@link MemoryLabel}'s name. */
11
public final class AddressText {
12
    private static final Pattern HEX = Pattern.compile("(?:\\$|0[xX])?([0-9A-Fa-f]{1,4})");
13
14
    private AddressText(){
15
    }
16
17
    /**
18
     * {@code $C123}, {@code 0xC123} or {@code C123} - or a label's name (its first byte). A name that also reads as
19
     * hex, like {@code BEEF}, is the label.
20
     */
21
    public static OptionalInt parse(final String text, final List<MemoryLabel> labels){
22
        final String trimmed = text.trim();
23 2 1. lambda$parse$0 : replaced boolean return with true for com/rox/debug/breakpoints/AddressText::lambda$parse$0 → KILLED
2. lambda$parse$0 : replaced boolean return with false for com/rox/debug/breakpoints/AddressText::lambda$parse$0 → KILLED
        final Optional<MemoryLabel> label = labels.stream().filter(l -> l.name().equals(trimmed)).findFirst();
24 1 1. parse : negated conditional → KILLED
        if (label.isPresent()){
25 1 1. parse : replaced return value with null for com/rox/debug/breakpoints/AddressText::parse → KILLED
            return OptionalInt.of(label.get().start());
26
        }
27
        final var hex = HEX.matcher(trimmed);
28 2 1. parse : replaced return value with null for com/rox/debug/breakpoints/AddressText::parse → KILLED
2. parse : negated conditional → KILLED
        return hex.matches() ? OptionalInt.of(Integer.parseInt(hex.group(1), 16)) : OptionalInt.empty();
29
    }
30
31
    /** {@code $0042}, plus the name of the first label covering it: {@code $0042 PLAYER_HP}. */
32
    public static String describe(final int address, final List<MemoryLabel> labels){
33
        final String hex = String.format("$%04X", address);
34 1 1. describe : replaced return value with "" for com/rox/debug/breakpoints/AddressText::describe → KILLED
        return labels.stream()
35 5 1. lambda$describe$0 : changed conditional boundary → KILLED
2. lambda$describe$0 : changed conditional boundary → KILLED
3. lambda$describe$0 : negated conditional → KILLED
4. lambda$describe$0 : negated conditional → KILLED
5. lambda$describe$0 : replaced boolean return with true for com/rox/debug/breakpoints/AddressText::lambda$describe$0 → KILLED
                .filter(l -> l.start() <= address && address <= l.end())
36
                .findFirst()
37 1 1. lambda$describe$1 : replaced return value with "" for com/rox/debug/breakpoints/AddressText::lambda$describe$1 → KILLED
                .map(l -> hex + " " + l.name())
38
                .orElse(hex);
39
    }
40
}

Mutations

23

1.1
Location : lambda$parse$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:aLabelThatReadsAsHexIsTheLabel()]
replaced boolean return with true for com/rox/debug/breakpoints/AddressText::lambda$parse$0 → KILLED

2.2
Location : lambda$parse$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:aLabelThatReadsAsHexIsTheLabel()]
replaced boolean return with false for com/rox/debug/breakpoints/AddressText::lambda$parse$0 → KILLED

24

1.1
Location : parse
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:aLabelThatReadsAsHexIsTheLabel()]
negated conditional → KILLED

25

1.1
Location : parse
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:aLabelThatReadsAsHexIsTheLabel()]
replaced return value with null for com/rox/debug/breakpoints/AddressText::parse → KILLED

28

1.1
Location : parse
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[test-template:parsesHexWithOrWithoutAPrefix(java.lang.String)]/[test-template-invocation:#1]
replaced return value with null for com/rox/debug/breakpoints/AddressText::parse → KILLED

2.2
Location : parse
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[test-template:parsesHexWithOrWithoutAPrefix(java.lang.String)]/[test-template-invocation:#1]
negated conditional → KILLED

34

1.1
Location : describe
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
replaced return value with "" for com/rox/debug/breakpoints/AddressText::describe → KILLED

35

1.1
Location : lambda$describe$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
changed conditional boundary → KILLED

2.2
Location : lambda$describe$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
changed conditional boundary → KILLED

3.3
Location : lambda$describe$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
negated conditional → KILLED

4.4
Location : lambda$describe$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
negated conditional → KILLED

5.5
Location : lambda$describe$0
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
replaced boolean return with true for com/rox/debug/breakpoints/AddressText::lambda$describe$0 → KILLED

37

1.1
Location : lambda$describe$1
Killed by : com.rox.debug.breakpoints.AddressTextTest.[engine:junit-jupiter]/[class:com.rox.debug.breakpoints.AddressTextTest]/[method:describesALabelledAddressWithItsName()]
replaced return value with "" for com/rox/debug/breakpoints/AddressText::lambda$describe$1 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1