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

wurstscript / WurstScript / 195

09 Oct 2023 10:08PM UTC coverage: 63.447% (+0.006%) from 63.441%
195

Pull #1079

circleci

Frotty
small performance fixes
Pull Request #1079: small performance fixes

17146 of 27024 relevant lines covered (63.45%)

0.63 hits per line

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

79.07
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/parser/WPos.java
1
package de.peeeq.wurstscript.parser;
2

3
import de.peeeq.wurstscript.utils.LineOffsets;
4
import org.eclipse.jdt.annotation.Nullable;
5

6
import java.util.regex.Matcher;
7
import java.util.regex.Pattern;
8

9
public class WPos {
10
    private final String file;
11
    private final @Nullable LineOffsets lineOffsets;
12
    private final int leftPos;
13
    private final int rightPos;
14

15
    public WPos(String file, @Nullable LineOffsets lineOffsets, int leftPos, int rightPos) {
1✔
16
        this.file = file;
1✔
17
        this.lineOffsets = lineOffsets;
1✔
18
        this.leftPos = leftPos;
1✔
19
        this.rightPos = rightPos;
1✔
20
    }
1✔
21

22
    public String getFile() {
23
        return file;
1✔
24
    }
25

26
    public @Nullable LineOffsets getLineOffsets() {
27
        return lineOffsets;
1✔
28
    }
29

30
    public int getLeftPos() {
31
        return leftPos;
1✔
32
    }
33

34
    public int getRightPos() {
35
        return rightPos;
1✔
36
    }
37

38

39
    public int getLine() {
40
        LineOffsets lo = lineOffsets;
1✔
41
        if (lo == null)
1✔
42
            return 0;
×
43
        return lo.getLine(leftPos);
1✔
44
    }
45

46
    public int getEndLine() {
47
        LineOffsets lo = lineOffsets;
1✔
48
        if (lo == null)
1✔
49
            return 0;
×
50
        return lo.getLine(rightPos);
1✔
51
    }
52

53
    public int getStartColumn() {
54
        LineOffsets lo = lineOffsets;
1✔
55
        if (lo == null)
1✔
56
            return 0;
×
57
        return lo.getColumn(leftPos);
1✔
58
    }
59

60
    public int getEndColumn() {
61
        LineOffsets lo = lineOffsets;
1✔
62
        if (lo == null)
1✔
63
            return 0;
×
64
        return lo.getColumn(rightPos);
1✔
65
    }
66

67
    public WPos withRightPos(int rightPos) {
68
        return new WPos(file, lineOffsets, leftPos, rightPos);
1✔
69
    }
70

71
    @Override
72
    public String toString() {
73
        // returning empty string to make AST.toString more readable
74
        return "";
1✔
75
    }
76

77
    public String print() {
78
        return "[" + file + " line " + getLine() + "]";
×
79
    }
80

81
    private static final Pattern p = Pattern.compile("^.*[/\\\\]([^/\\\\]+)\\.[^.]*$");
1✔
82

83
    public String printShort() {
84
        String shortFile = file;
1✔
85
        Matcher m = p.matcher(file);
1✔
86
        if (m.find()) {
1✔
87
            shortFile = m.group(1);
1✔
88
        }
89
        return shortFile + ", line " + getLine();
1✔
90
    }
91

92
    public WPos withLeftPos(int leftPos) {
93
        return new WPos(file, lineOffsets, leftPos, rightPos);
1✔
94
    }
95

96
    public WPos withFile(String file) {
97
        return new WPos(file, lineOffsets, leftPos, rightPos);
1✔
98
    }
99

100
    public String shortFile() {
101
        String s = getFile();
×
102
        s = s.substring(s.lastIndexOf("lib/") + 4);
×
103
        s = s.replace(".wurst", "");
×
104
        return s;
×
105
    }
106

107
    /**
108
     * makes this position artificial by setting the rightPost = leftPos-1
109
     */
110
    public WPos artificial() {
111
        return new WPos(file, lineOffsets, leftPos, leftPos - 1);
1✔
112
    }
113

114
    /**
115
     * an artificial position is one created by the compiler (the element is not directly part of the input file)
116
     */
117
    public boolean isArtificial() {
118
        return getRightPos() < getLeftPos();
1✔
119
    }
120

121
}
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