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

wurstscript / WurstScript / 214

08 Nov 2023 04:21PM UTC coverage: 62.602% (-0.007%) from 62.609%
214

push

circleci

Frotty
Fix renaming array symbols

17297 of 27630 relevant lines covered (62.6%)

0.63 hits per line

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

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/GetUsages.java
1
package de.peeeq.wurstio.languageserver.requests;
2

3
import de.peeeq.wurstio.languageserver.ModelManager;
4
import de.peeeq.wurstio.languageserver.BufferManager;
5
import de.peeeq.wurstio.languageserver.Convert;
6
import de.peeeq.wurstio.languageserver.WFile;
7
import de.peeeq.wurstscript.ast.*;
8
import de.peeeq.wurstscript.utils.Utils;
9
import org.eclipse.lsp4j.*;
10

11
import java.util.*;
12

13
public class GetUsages extends UserRequest<List<GetUsages.UsagesData>> {
14

15
    private final WFile wFile;
16
    private final String buffer;
17
    private final int line;
18
    private final int column;
19
    private final boolean global;
20

21

22

23
    public GetUsages(TextDocumentPositionParams position, BufferManager bufferManager, boolean global) {
×
24
        this.wFile = WFile.create(position.getTextDocument().getUri());
×
25
        this.buffer = bufferManager.getBuffer(position.getTextDocument());
×
26
        this.line = position.getPosition().getLine() + 1;
×
27
        this.column = position.getPosition().getCharacter() + 1;
×
28
        this.global = global;
×
29
    }
×
30

31

32
    @Override
33
    public List<UsagesData> execute(ModelManager modelManager) {
34
        CompilationUnit cu = modelManager.replaceCompilationUnitContent(wFile, buffer, false);
×
35
        if (cu == null) {
×
36
            return Collections.emptyList();
×
37
        }
38
        Optional<Element> astElem = Utils.getAstElementAtPos(cu, line, column, false);
×
39
        Optional<NameDef> nameDef = astElem.flatMap(elem -> Optional.ofNullable(elem.tryGetNameDef()));
×
40
        List<UsagesData> usages = new ArrayList<>();
×
41
        if (nameDef.isPresent()) {
×
42

43
            if (global || nameDef.get().getSource().getFile().equals(wFile.toString())) {
×
44
                // add declaration
45
                usages.add(
×
46
                    new UsagesData(Convert.posToLocation(nameDef.get().attrErrorPos()), DocumentHighlightKind.Write));
×
47
            }
48
            Deque<Element> todo = new ArrayDeque<>();
×
49
            if (global) {
×
50
                todo.push(modelManager.getModel());
×
51
            } else {
52
                todo.push(cu);
×
53
            }
54
            while (!todo.isEmpty()) {
×
55
                Element e = todo.pop();
×
56
                // visit children:
57
                for (int i = 0; i < e.size(); i++) {
×
58
                    todo.push(e.get(i));
×
59
                }
60
                NameDef e_def = e.tryGetNameDef();
×
61
                if (e_def == nameDef.get()) {
×
62
                    if (e instanceof ExprVarArrayAccess) {
×
63
                        e = ((ExprVarArrayAccess) e).getVarNameId();
×
64
                    }
65
                    Location location = Convert.posToLocation(e.attrErrorPos());
×
66
                    UsagesData usagesData = new UsagesData(location, DocumentHighlightKind.Read);
×
67
                    usages.add(usagesData);
×
68
                }
69
            }
×
70
        }
71

72
        return usages;
×
73
    }
74

75
    public static class UsagesData {
76
        private Location location;
77
        private DocumentHighlightKind kind;
78

79

80
        public UsagesData(Location location, DocumentHighlightKind kind) {
×
81
            this.location = location;
×
82
            this.kind = kind;
×
83
        }
×
84

85
        public String getFilename() {
86
            return location.getUri();
×
87
        }
88

89
        public void setFilename(String filename) {
90
            location.setUri(filename);
×
91
        }
×
92

93
        public Range getRange() {
94
            return location.getRange();
×
95
        }
96

97
        public void setRange(Range range) {
98
            location.setRange(range);
×
99
        }
×
100

101
        public DocumentHighlightKind getKind() {
102
            return kind;
×
103
        }
104

105
        public void setKind(DocumentHighlightKind kind) {
106
            this.kind = kind;
×
107
        }
×
108

109
        public Location getLocation() {
110
            return location;
×
111
        }
112

113
        public DocumentHighlight toDocumentHighlight() {
114
            return new DocumentHighlight(location.getRange(), kind);
×
115
        }
116

117
    }
118
}
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