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
        
20
        super(name);
21
        this.deleteAction = deleteAction;
22
    }
23
    
24
    @Override
25
    public void actionPerformed(ActionEvent e) {
26
        
27
        JTextComponent target = this.getTextComponent(e);
28
        
29 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
        if (Objects.nonNull(target) && target.isEditable()) {
30
            
31
            var caret = target.getCaret();
32
            int dot = caret.getDot();
33
            int mark = caret.getMark();
34
            
35 1 1. actionPerformed : negated conditional → NO_COVERAGE
            if (DefaultEditorKit.deletePrevCharAction.equals(this.getValue(Action.NAME))) {
36
                // @see javax/swing/text/DefaultEditorKit.java DeletePrevCharAction
37 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
                if (dot == 0 && mark == 0) {
38
                    return;
39
                }
40
            } else {
41
                
42
                // @see javax/swing/text/DefaultEditorKit.java DeleteNextCharAction
43
                var doc = target.getDocument();
44
                
45 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
                if (dot == mark && doc.getLength() == dot) {
46
                    return;
47
                }
48
            }
49
        }
50
        
51 1 1. actionPerformed : removed call to javax/swing/Action::actionPerformed → NO_COVERAGE
        this.deleteAction.actionPerformed(e);
52
    }
53
}

Mutations

29

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

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

35

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

37

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
negated conditional → NO_COVERAGE

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

51

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.16.1