• 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

87.5
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/ErrorHandling.java
1
package de.peeeq.wurstscript.attributes;
2

3
import de.peeeq.wurstscript.ast.CompilationUnit;
4
import de.peeeq.wurstscript.ast.Element;
5
import de.peeeq.wurstscript.ast.WurstModel;
6
import de.peeeq.wurstscript.attributes.CompileError.ErrorType;
7
import de.peeeq.wurstscript.parser.WPos;
8
import org.eclipse.jdt.annotation.Nullable;
9

10
import java.util.List;
11
import java.util.ListIterator;
12

13
public class ErrorHandling {
×
14

15
    public static void addError(Element e, String msg) {
16
        addErrorOrWarning(e, msg, ErrorType.ERROR);
1✔
17
    }
1✔
18

19
    public static void addWarning(Element e, String msg) {
20
        addErrorOrWarning(e, msg, ErrorType.WARNING);
1✔
21
    }
1✔
22

23
    private static void addErrorOrWarning(Element e, String msg,
24
                                          ErrorType errorType) throws CompileError {
25
        ErrorHandler handler = e.getErrorHandler();
1✔
26
        CompileError c = makeCompileError(e, msg, handler, errorType);
1✔
27
        if (c != null) {
1✔
28
            handler.sendError(c);
1✔
29
        }
30
    }
1✔
31

32
    private static @Nullable CompileError makeCompileError(
33
        Element e, String msg, ErrorHandler handler, CompileError.ErrorType errorType) throws CompileError {
34

35
        // Preserve unit-test semantics (throw eagerly)
36
        if (errorType == ErrorType.ERROR && handler.isUnitTestMode()) {
1✔
37
            throw new CompileError(e.attrErrorPos(), msg);
1✔
38
        }
39

40
        // Eager pos (like original), but we will only scan the same-file bucket
41
        WPos pos = e.attrErrorPos();
1✔
42
        final String file = pos.getFile();
1✔
43
        final int left  = pos.getLeftPos();
1✔
44
        final int right = pos.getRightPos();
1✔
45

46
        // Fast path: no existing items for this file
47
        List<CompileError> bucket = handler.getBucketForFile(file, errorType);
1✔
48
        if (bucket != null && !bucket.isEmpty()) {
1✔
49
            // Compare only within this file
50
            ListIterator<CompileError> it = bucket.listIterator();
1✔
51
            while (it.hasNext()) {
1✔
52
                CompileError err = it.next();
1✔
53
                WPos ep = err.getSource();
1✔
54
                // same file by construction
55
                final int eLeft  = ep.getLeftPos();
1✔
56
                final int eRight = ep.getRightPos();
1✔
57

58
                if (bigger(eLeft, eRight, left, right)) {
1✔
59
                    // remove bigger error and keep going (might remove multiple)
60
                    it.remove();              // from file bucket
×
61
                    handler.removeFromGlobal(err); // from global list
×
62
                } else if (bigger(left, right, eLeft, eRight) || equal(left, right, eLeft, eRight)) {
1✔
63
                    // do not add smaller or equal errors
64
                    return null;
1✔
65
                }
66
            }
1✔
67
        }
68

69
        return new CompileError(pos, msg, errorType);
1✔
70
    }
71

72
    private static boolean equal(int aL, int aR, int bL, int bR) {
73
        return aL == bL && aR == bR;
1✔
74
    }
75

76
    private static boolean bigger(int aL, int aR, int bL, int bR) {
77
        return (aL <= bL && aR >  bR) || (aL <  bL && aR >= bR);
1✔
78
    }
79

80
    public static ErrorHandler getErrorHandler(Element e) {
81
        if (e.getParent() == null) {
1✔
82
            throw new Error("Trying to get error handler of element not attached to root:\n" + e);
×
83
        }
84
        return e.getParent().getErrorHandler();
1✔
85
    }
86

87
    public static ErrorHandler getErrorHandler(CompilationUnit e) {
88
        return e.getCuInfo().getCuErrorHandler();
1✔
89
    }
90

91
    public static ErrorHandler getErrorHandler(WurstModel m) {
92
        for (CompilationUnit cu : m) {
1✔
93
            return cu.getCuInfo().getCuErrorHandler();
1✔
94
        }
95
        throw new Error("Empty model.");
×
96
    }
97
}
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