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

wurstscript / WurstScript / 271

29 Sep 2025 12:12PM UTC coverage: 64.649% (+2.4%) from 62.222%
271

Pull #1096

circleci

Frotty
Merge branch 'perf-improvements' of https://github.com/wurstscript/WurstScript into perf-improvements
Pull Request #1096: Perf improvements

18202 of 28155 relevant lines covered (64.65%)

0.65 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
    private final List<CompileError> errors   = new NotNullList<>();
1✔
14
    private final List<CompileError> warnings = new NotNullList<>();
1✔
15

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

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

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

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

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

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

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

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

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

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

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

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

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

82
    private static void addToBucket(Map<String, List<CompileError>> byFile, CompileError err) {
83
        final String file = err.getSource().getFile();
1✔
84
        byFile.computeIfAbsent(file, f -> new NotNullList<>()).add(err);
1✔
85
    }
1✔
86

87
    private static void removeFromBucket(Map<String, List<CompileError>> byFile, String file, CompileError err) {
88
        List<CompileError> bucket = byFile.get(file);
×
89
        if (bucket != null) {
×
90
            bucket.remove(err);
×
91
            if (bucket.isEmpty()) {
×
92
                byFile.remove(file);
×
93
            }
94
        }
95
    }
×
96
}
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