Skip to content

Commit 63733f7

Browse files
authored
Хранение стандартных реквизитов + небольшие правки (#523)
хранение стандартных реквизитов
1 parent 7341412 commit 63733f7

File tree

83 files changed

+26487
-2672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+26487
-2672
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses 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+
* MDClasses 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 MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdo.children;
23+
24+
import com.github._1c_syntax.bsl.mdo.AccessRightsOwner;
25+
import com.github._1c_syntax.bsl.mdo.Attribute;
26+
import com.github._1c_syntax.bsl.mdo.support.AttributeKind;
27+
import com.github._1c_syntax.bsl.mdo.support.IndexingType;
28+
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
29+
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
30+
import com.github._1c_syntax.bsl.support.SupportVariant;
31+
import com.github._1c_syntax.bsl.types.MdoReference;
32+
import com.github._1c_syntax.bsl.types.MultiLanguageString;
33+
import com.github._1c_syntax.bsl.types.MultiName;
34+
import com.github._1c_syntax.bsl.types.ValueTypeDescription;
35+
import lombok.AccessLevel;
36+
import lombok.Builder;
37+
import lombok.Builder.Default;
38+
import lombok.EqualsAndHashCode;
39+
import lombok.Getter;
40+
import lombok.ToString;
41+
import lombok.Value;
42+
43+
import java.util.List;
44+
45+
/**
46+
* Стандартный реквизит объекта
47+
*/
48+
@Value
49+
@Builder
50+
@ToString(of = {"uuid", "fullName"})
51+
@EqualsAndHashCode(of = {"uuid", "fullName"})
52+
public class StandardAttribute implements Attribute, AccessRightsOwner {
53+
54+
private static final List<RoleRight> POSSIBLE_RIGHTS = List.of(RoleRight.VIEW, RoleRight.EDIT);
55+
56+
/*
57+
* Для Attribute
58+
*/
59+
60+
/**
61+
* Равен UID владельца
62+
*/
63+
@Default
64+
String uuid = "";
65+
@Default
66+
MdoReference mdoReference = MdoReference.EMPTY;
67+
@Default
68+
String comment = "";
69+
@Default
70+
MultiLanguageString synonym = MultiLanguageString.EMPTY;
71+
@Default
72+
SupportVariant supportVariant = SupportVariant.NONE;
73+
@Default
74+
MdoReference owner = MdoReference.EMPTY;
75+
boolean passwordMode;
76+
@Default
77+
AttributeKind kind = AttributeKind.STANDARD;
78+
@Default
79+
@Getter(AccessLevel.NONE)
80+
ValueTypeDescription type = ValueTypeDescription.EMPTY;
81+
82+
/*
83+
* Свое
84+
*/
85+
86+
/**
87+
* Полное имя реквизита на обоих языках
88+
*/
89+
@Default
90+
MultiName fullName = MultiName.EMPTY;
91+
92+
/*
93+
* Свое
94+
*/
95+
96+
/**
97+
* Формат
98+
*/
99+
@Default
100+
MultiLanguageString format = MultiLanguageString.EMPTY;
101+
102+
/**
103+
* Формат редактирования
104+
*/
105+
@Default
106+
MultiLanguageString editFormat = MultiLanguageString.EMPTY;
107+
108+
/**
109+
* Выделять отрицательное
110+
*/
111+
boolean markNegatives;
112+
113+
/**
114+
* Маска
115+
*/
116+
@Default
117+
String mask = "";
118+
119+
/**
120+
* Многострочный режим
121+
*/
122+
boolean multiLine;
123+
124+
/**
125+
* Расширенное редактирование
126+
*/
127+
boolean extendedEdit;
128+
129+
/**
130+
* Заполнять из данных заполнения
131+
*/
132+
boolean fillFromFillingValue;
133+
134+
/**
135+
* Возвращает перечень возможных прав доступа
136+
*/
137+
public static List<RoleRight> possibleRights() {
138+
return POSSIBLE_RIGHTS;
139+
}
140+
141+
/**
142+
* Всегда собственный
143+
*/
144+
@Override
145+
public ObjectBelonging getObjectBelonging() {
146+
return ObjectBelonging.OWN;
147+
}
148+
149+
/**
150+
* Настроек индексирования у стандартных нет
151+
*/
152+
@Override
153+
public IndexingType getIndexing() {
154+
return IndexingType.DONT_INDEX;
155+
}
156+
157+
@Override
158+
public String getName() {
159+
return fullName.get();
160+
}
161+
162+
@Override
163+
public ValueTypeDescription getValueType() {
164+
return type;
165+
}
166+
167+
@Override
168+
public String getDescription(String code) {
169+
if (getSynonym().isEmpty()) {
170+
return fullName.get(code);
171+
}
172+
var description = getSynonym().get(code);
173+
if (description.isEmpty()) {
174+
description = getSynonym().getAny();
175+
}
176+
177+
if (description.isEmpty()) {
178+
description = fullName.get(code);
179+
}
180+
181+
return description;
182+
}
183+
}
Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
/*
2-
* This file is a part of MDClasses.
3-
*
4-
* Copyright (c) 2019 - 2025
5-
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6-
*
7-
* SPDX-License-Identifier: LGPL-3.0-or-later
8-
*
9-
* MDClasses 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-
* MDClasses 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 MDClasses.
21-
*/
22-
package com.github._1c_syntax.bsl.mdo.support;
23-
24-
import com.github._1c_syntax.bsl.types.EnumWithName;
25-
import com.github._1c_syntax.bsl.types.MultiName;
26-
import lombok.Getter;
27-
import lombok.ToString;
28-
import lombok.experimental.Accessors;
29-
30-
import java.util.Locale;
31-
import java.util.Map;
32-
33-
/**
34-
* Возможные варианты повторного использования значений модулей
35-
*/
36-
@ToString(of = "fullName")
37-
public enum ReturnValueReuse implements EnumWithName {
38-
DONT_USE("DontUse", "НеИспользовать"),
39-
DURING_REQUEST("DuringRequest", "НаВремяВызова"),
40-
DURING_SESSION("DuringSession", "НаВремяСеанса"),
41-
UNKNOWN("unknown", "неизвестный");
42-
43-
private static final Map<String, ReturnValueReuse> KEYS = EnumWithName.computeKeys(values());
44-
45-
@Getter
46-
@Accessors(fluent = true)
47-
private final MultiName fullName;
48-
49-
ReturnValueReuse(String nameEn, String nameRu) {
50-
this.fullName = MultiName.create(nameEn, nameRu);
51-
}
52-
53-
/**
54-
* Ищет элемент перечисления по именам (рус, анг)
55-
*
56-
* @param string Имя искомого элемента
57-
* @return Найденное значение, если не найден - то UNKNOWN
58-
*/
59-
public static ReturnValueReuse valueByName(String string) {
60-
return KEYS.getOrDefault(string.toLowerCase(Locale.ROOT), UNKNOWN);
61-
}
62-
}
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2025
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses 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+
* MDClasses 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 MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdo.support;
23+
24+
import com.github._1c_syntax.bsl.types.EnumWithName;
25+
import com.github._1c_syntax.bsl.types.MultiName;
26+
import lombok.Getter;
27+
import lombok.ToString;
28+
import lombok.experimental.Accessors;
29+
30+
import java.util.Locale;
31+
import java.util.Map;
32+
33+
/**
34+
* Возможные варианты повторного использования значений модулей
35+
*/
36+
@ToString(of = "fullName")
37+
public enum ReturnValueReuse implements EnumWithName {
38+
DONT_USE("DontUse", "НеИспользовать"),
39+
DURING_REQUEST("DuringRequest", "НаВремяВызова"),
40+
DURING_SESSION("DuringSession", "НаВремяСеанса"),
41+
UNKNOWN("unknown", "неизвестный");
42+
43+
private static final Map<String, ReturnValueReuse> KEYS = EnumWithName.computeKeys(values());
44+
45+
@Getter
46+
@Accessors(fluent = true)
47+
private final MultiName fullName;
48+
49+
ReturnValueReuse(String nameEn, String nameRu) {
50+
this.fullName = MultiName.create(nameEn, nameRu);
51+
}
52+
53+
/**
54+
* Ищет элемент перечисления по именам (рус, анг)
55+
*
56+
* @param string Имя искомого элемента
57+
* @return Найденное значение, если не найден - то UNKNOWN
58+
*/
59+
public static ReturnValueReuse valueByName(String string) {
60+
return KEYS.getOrDefault(string.toLowerCase(Locale.ROOT), UNKNOWN);
61+
}
62+
}

src/main/java/com/github/_1c_syntax/bsl/reader/common/context/AbstractReaderContext.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
import java.nio.file.Path;
4141
import java.util.ArrayList;
4242
import java.util.Collections;
43+
import java.util.Comparator;
4344
import java.util.List;
45+
import java.util.Locale;
46+
import java.util.Map;
47+
import java.util.concurrent.ConcurrentHashMap;
4448

4549
/**
4650
* Сохраняемый контекст при чтении файла
@@ -76,6 +80,7 @@ public abstract class AbstractReaderContext {
7680
/**
7781
* Режим поддержки
7882
*/
83+
@Getter
7984
protected SupportVariant supportVariant;
8085

8186
/**
@@ -87,6 +92,7 @@ public abstract class AbstractReaderContext {
8792
/**
8893
* Ссылка на текущий объект
8994
*/
95+
@Getter
9096
protected MdoReference mdoReference = MdoReference.EMPTY;
9197

9298
/**
@@ -110,9 +116,24 @@ public abstract class AbstractReaderContext {
110116
@Getter
111117
private Object lastValue;
112118

119+
/**
120+
* всякие прочитанные атрибуты
121+
*/
122+
@Getter
123+
private final Map<String, Object> cache;
124+
113125
protected AbstractReaderContext(@NonNull HierarchicalStreamReader reader) {
114126
currentPath = ExtendXStream.getCurrentPath(reader);
115127
mdReader = ExtendXStream.getCurrentMDReader(reader);
128+
129+
cache = new ConcurrentHashMap<>();
130+
}
131+
132+
protected AbstractReaderContext(@NonNull Path currentPath, @NonNull MDReader mdReader) {
133+
this.currentPath = currentPath;
134+
this.mdReader = mdReader;
135+
136+
cache = new ConcurrentHashMap<>();
116137
}
117138

118139
/**
@@ -122,7 +143,10 @@ protected AbstractReaderContext(@NonNull HierarchicalStreamReader reader) {
122143
* @param value устанавливаемое значение
123144
*/
124145
public void setValue(String methodName, Object value) {
125-
TransformationUtils.setValue(builder, methodName, value);
146+
if (value != null) {
147+
TransformationUtils.setValue(builder, methodName, value);
148+
cache.put(methodName.toLowerCase(Locale.ROOT), value);
149+
}
126150
}
127151

128152
/**
@@ -142,6 +166,11 @@ public Object build() {
142166
return TransformationUtils.build(builder, currentPath);
143167
}
144168

169+
@SuppressWarnings("unchecked")
170+
public <T> T getFromCache(@NonNull String key, T defaultValue) {
171+
return (T) cache.getOrDefault(key.toLowerCase(Locale.ROOT), defaultValue);
172+
}
173+
145174
protected void setValueModules() {
146175
var modules = readModules();
147176
if (!modules.isEmpty()) {
@@ -175,6 +204,7 @@ private List<Module> readModules() {
175204
}
176205
}
177206
);
207+
modules.sort(Comparator.comparing(Module::toString));
178208
return modules;
179209
}
180210
}

0 commit comments

Comments
 (0)