Skip to content

Commit 54d7a37

Browse files
committed
Интернирование reference.model.symbol при наполнении референс индекса
1 parent 91a823a commit 54d7a37

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1-
package com.github._1c_syntax.bsl.languageserver.references;public class GenericInterner {
1+
/*
2+
* This file is a part of BSL Language Server.
3+
*
4+
* Copyright (c) 2018-2022
5+
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* BSL Language Server is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* BSL Language Server is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with BSL Language Server.
21+
*/
22+
package com.github._1c_syntax.bsl.languageserver.references;
23+
24+
import java.util.Map;
25+
import java.util.concurrent.ConcurrentHashMap;
26+
27+
public class GenericInterner<T> {
28+
29+
private final Map<T, T> map = new ConcurrentHashMap<>();
30+
31+
public T intern(T object) {
32+
var exist = map.putIfAbsent(object, object);
33+
return (exist == null) ? object : exist;
34+
}
35+
36+
public void clear() {
37+
map.clear();
38+
}
239
}

src/main/java/com/github/_1c_syntax/bsl/languageserver/references/ReferenceIndex.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ public void addMethodCall(URI uri, String mdoRef, ModuleType moduleType, String
178178
.scopeName("")
179179
.symbolKind(SymbolKind.Method)
180180
.symbolName(symbolNameCanonical)
181-
.build();
181+
.build()
182+
.intern();
182183

183184
var location = new Location(uri, range);
184185
var symbolOccurrence = SymbolOccurrence.builder()
@@ -218,7 +219,8 @@ public void addVariableUsage(URI uri,
218219
.scopeName(methodNameCanonical)
219220
.symbolKind(SymbolKind.Variable)
220221
.symbolName(variableNameCanonical)
221-
.build();
222+
.build()
223+
.intern();
222224

223225
var location = new Location(uri, range);
224226

src/main/java/com/github/_1c_syntax/bsl/languageserver/references/model/Symbol.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package com.github._1c_syntax.bsl.languageserver.references.model;
2323

24+
import com.github._1c_syntax.bsl.languageserver.references.GenericInterner;
2425
import com.github._1c_syntax.bsl.types.ModuleType;
2526
import lombok.AllArgsConstructor;
2627
import lombok.Builder;
@@ -38,6 +39,8 @@
3839
@Builder
3940
public class Symbol implements Comparable<Symbol> {
4041

42+
private static GenericInterner<Symbol> interner = new GenericInterner<>();
43+
4144
/**
4245
* Cсылка на объект метаданных в формате ВидОбъектаМетаданных.ИмяОбъекта, в котором расположен символ.
4346
*/
@@ -63,6 +66,10 @@ public class Symbol implements Comparable<Symbol> {
6366
*/
6467
String symbolName;
6568

69+
public Symbol intern() {
70+
return interner.intern(this);
71+
}
72+
6673
@Override
6774
public int compareTo(@NotNull Symbol o) {
6875
if (this.equals(o)) {

0 commit comments

Comments
 (0)