• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 266

29 Sep 2025 09:10AM UTC coverage: 62.244% (+0.02%) from 62.222%
266

Pull #1096

circleci

Frotty
Optimize imports
Pull Request #1096: Perf improvements

17480 of 28083 relevant lines covered (62.24%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.98
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/ErrorHandler.java
1
package de.peeeq.wurstscript.attributes;
2

3
import de.peeeq.wurstscript.attributes.CompileError.ErrorType;
4
import de.peeeq.wurstscript.gui.WurstGui;
5
import de.peeeq.wurstscript.utils.NotNullList;
6

7
import java.util.HashMap;
8
import java.util.List;
9
import java.util.Map;
10

11
public class ErrorHandler {
12

13
    // Public-facing lists (unchanged)
14
    private final List<CompileError> errors   = new NotNullList<>();
1✔
15
    private final List<CompileError> warnings = new NotNullList<>();
1✔
16

17
    // Per-file buckets to avoid O(all) scans
18
    private final Map<String, List<CompileError>> errorsByFile   = new HashMap<>();
1✔
19
    private final Map<String, List<CompileError>> warningsByFile = new HashMap<>();
1✔
20

21
    private final WurstGui gui;
22
    private boolean unitTestMode = false;
1✔
23

24
    public ErrorHandler(WurstGui gui) {
1✔
25
        this.gui = gui;
1✔
26
    }
1✔
27

28
    public int getErrorCount() {
29
        return errors.size();
1✔
30
    }
31

32
    public List<CompileError> getWarnings() {
33
        return warnings;
×
34
    }
35

36
    public List<CompileError> getErrors() {
37
        return errors;
×
38
    }
39

40
    public void setProgress(String message, double percent) {
41
        gui.sendProgress(message);
1✔
42
    }
1✔
43

44
    public WurstGui getGui() {
45
        return gui;
×
46
    }
47

48
    /** Called after makeCompileError() decides to keep it. */
49
    public void sendError(CompileError err) {
50
        if (err.getErrorType() == ErrorType.ERROR) {
1✔
51
            errors.add(err);
1✔
52
            addToBucket(errorsByFile, err);
1✔
53
        } else {
54
            warnings.add(err);
1✔
55
            addToBucket(warningsByFile, err);
1✔
56
        }
57
        gui.sendError(err);
1✔
58
    }
1✔
59

60
    public void enableUnitTestMode() {
61
        unitTestMode = true;
1✔
62
    }
1✔
63

64
    public boolean isUnitTestMode() {
65
        return unitTestMode;
1✔
66
    }
67

68
    // ---------- package-private helpers for ErrorHandling ----------
69

70
    List<CompileError> getBucketForFile(String file, ErrorType type) {
71
        return (type == ErrorType.ERROR) ? errorsByFile.get(file) : warningsByFile.get(file);
1✔
72
    }
73

74
    void removeFromGlobal(CompileError err) {
75
        final String file = err.getSource().getFile();
×
76
        if (err.getErrorType() == ErrorType.ERROR) {
×
77
            errors.remove(err);
×
78
            removeFromBucket(errorsByFile, file, err);
×
79
        } else {
80
            warnings.remove(err);
×
81
            removeFromBucket(warningsByFile, file, err);
×
82
        }
83
    }
×
84

85
    // ---------- internal helpers ----------
86

87
    private static void addToBucket(Map<String, List<CompileError>> byFile, CompileError err) {
88
        final String file = err.getSource().getFile();
1✔
89
        byFile.computeIfAbsent(file, f -> new NotNullList<>()).add(err);
1✔
90
    }
1✔
91

92
    private static void removeFromBucket(Map<String, List<CompileError>> byFile, String file, CompileError err) {
93
        List<CompileError> bucket = byFile.get(file);
×
94
        if (bucket != null) {
×
95
            bucket.remove(err);
×
96
            if (bucket.isEmpty()) {
×
97
                byFile.remove(file);
×
98
            }
99
        }
100
    }
×
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc