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

wurstscript / WurstScript / 228

29 Nov 2023 05:00PM UTC coverage: 62.48% (-0.09%) from 62.574%
228

push

circleci

web-flow
Show dialog for choosing game path, cleanup (#1083)

* show dialog for choosing game path

* cleanup code

* remove logs and refactor

* remove confusing mpq error, make some mpq loads readonly

17295 of 27681 relevant lines covered (62.48%)

0.62 hits per line

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

85.19
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imoptimizer/Replacer.java
1
package de.peeeq.wurstscript.translation.imoptimizer;
2

3
import de.peeeq.wurstscript.attributes.CompileError;
4
import de.peeeq.wurstscript.jassIm.Element;
5

6
// optimization for replaceBy
7
// remembers last position of elements with the assumption that the next element
8
// searched in the same parent will be in a similar position
9
public class Replacer {
1✔
10
    private int lastPos;
11

12
    public void hintPosition(int pos) {
13
        lastPos = pos;
1✔
14
    }
1✔
15

16
    public void replace(Element oldElement, Element newElement) {
17
        if (oldElement == newElement) {
1✔
18
            return;
×
19
        }
20
        Element parent = oldElement.getParent();
1✔
21
        if (parent == null) {
1✔
22
            throw new RuntimeException("Node not attached to tree.");
×
23
        }
24
        replaceInParent(parent, oldElement, newElement);
1✔
25
    }
1✔
26

27
    public void replaceInParent(Element parent, Element oldElement, Element newElement) {
28
        if (oldElement == newElement) {
1✔
29
            return;
×
30
        }
31
        int pos = -1;
1✔
32
        for (int j = 0; j < parent.size(); j++) {
1✔
33
            int i = (lastPos + j) % parent.size();
1✔
34
            Element element = parent.get(i);
1✔
35
            if (element == oldElement) {
1✔
36
                pos = i;
1✔
37
                break;
1✔
38
            }
39
        }
40
        if (pos < 0) {
1✔
41
            throw new CompileError(parent.attrTrace().attrSource(), "Could not find " + oldElement + " in " + parent);
×
42
        }
43
        Element oldParent = oldElement.getParent();
1✔
44
        parent.set(pos, newElement);
1✔
45
        if (oldParent != parent) {
1✔
46
            // was already moved elsewhere, so restore parent
47
            oldElement.setParent(oldParent);
1✔
48
        }
49
        lastPos = pos;
1✔
50
    }
1✔
51
}
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