SilentDeleteTextAction.java

1
package com.jsql.view.swing.text.action;
2
3
import javax.swing.*;
4
import javax.swing.text.DefaultEditorKit;
5
import javax.swing.text.JTextComponent;
6
import javax.swing.text.TextAction;
7
import java.awt.event.ActionEvent;
8
import java.util.Objects;
9
10
/**
11
 * Action to cancel Beep sound when deleting last character.
12
 * Used on TextField.
13
 */
14
public class SilentDeleteTextAction extends TextAction {
15
    
16
    private final transient Action deleteAction;
17
    
18
    public SilentDeleteTextAction(String name, Action deleteAction) {
19
        super(name);
20
        this.deleteAction = deleteAction;
21
    }
22
    
23
    @Override
24
    public void actionPerformed(ActionEvent e) {
25
        JTextComponent target = this.getTextComponent(e);
26 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
        if (Objects.nonNull(target) && target.isEditable()) {
27
            var caret = target.getCaret();
28
            int dot = caret.getDot();
29
            int mark = caret.getMark();
30
            
31 1 1. actionPerformed : negated conditional → NO_COVERAGE
            if (DefaultEditorKit.deletePrevCharAction.equals(this.getValue(Action.NAME))) {
32
                // @see javax/swing/text/DefaultEditorKit.java DeletePrevCharAction
33 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
                if (dot == 0 && mark == 0) {
34
                    return;
35
                }
36
            } else {
37
                // @see javax/swing/text/DefaultEditorKit.java DeleteNextCharAction
38
                var doc = target.getDocument();
39 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
                if (dot == mark && doc.getLength() == dot) {
40
                    return;
41
                }
42
            }
43
        }
44
        
45 1 1. actionPerformed : removed call to javax/swing/Action::actionPerformed → NO_COVERAGE
        this.deleteAction.actionPerformed(e);
46
    }
47
}

Mutations

26

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

31

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

33

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

39

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

45

1.1
Location : actionPerformed
Killed by : none
removed call to javax/swing/Action::actionPerformed → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1