Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2025
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* MDClasses is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* MDClasses is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.bsl.mdo.children;

import com.github._1c_syntax.bsl.mdo.AccessRightsOwner;
import com.github._1c_syntax.bsl.mdo.Attribute;
import com.github._1c_syntax.bsl.mdo.support.AttributeKind;
import com.github._1c_syntax.bsl.mdo.support.IndexingType;
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
import com.github._1c_syntax.bsl.support.SupportVariant;
import com.github._1c_syntax.bsl.types.MdoReference;
import com.github._1c_syntax.bsl.types.MultiLanguageString;
import com.github._1c_syntax.bsl.types.MultiName;
import com.github._1c_syntax.bsl.types.ValueTypeDescription;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;

import java.util.List;

/**
* Стандартный реквизит объекта
*/
@Value
@Builder
@ToString(of = {"uuid", "fullName"})
@EqualsAndHashCode(of = {"uuid", "fullName"})
public class StandardAttribute implements Attribute, AccessRightsOwner {

private static final List<RoleRight> POSSIBLE_RIGHTS = List.of(RoleRight.VIEW, RoleRight.EDIT);

/*
* Для Attribute
*/

/**
* Равен UID владельца
*/
@Default
String uuid = "";
@Default
MdoReference mdoReference = MdoReference.EMPTY;
@Default
String comment = "";
@Default
MultiLanguageString synonym = MultiLanguageString.EMPTY;
@Default
SupportVariant supportVariant = SupportVariant.NONE;
@Default
MdoReference owner = MdoReference.EMPTY;
boolean passwordMode;
@Default
AttributeKind kind = AttributeKind.STANDARD;
@Default
@Getter(AccessLevel.NONE)
ValueTypeDescription type = ValueTypeDescription.EMPTY;

/*
* Свое
*/

/**
* Полное имя реквизита на обоих языках
*/
@Default
MultiName fullName = MultiName.EMPTY;

/*
* Свое
*/

/**
* Формат
*/
@Default
MultiLanguageString format = MultiLanguageString.EMPTY;

/**
* Формат редактирования
*/
@Default
MultiLanguageString editFormat = MultiLanguageString.EMPTY;

/**
* Выделять отрицательное
*/
boolean markNegatives;

/**
* Маска
*/
@Default
String mask = "";

/**
* Многострочный режим
*/
boolean multiLine;

/**
* Расширенное редактирование
*/
boolean extendedEdit;

/**
* Заполнять из данных заполнения
*/
boolean fillFromFillingValue;

/**
* Возвращает перечень возможных прав доступа
*/
public static List<RoleRight> possibleRights() {
return POSSIBLE_RIGHTS;
}

/**
* Всегда собственный
*/
@Override
public ObjectBelonging getObjectBelonging() {
return ObjectBelonging.OWN;
}

/**
* Настроек индексирования у стандартных нет
*/
@Override
public IndexingType getIndexing() {
return IndexingType.DONT_INDEX;
}

@Override
public String getName() {
return fullName.get();
}

@Override
public ValueTypeDescription getValueType() {
return type;
}

@Override
public String getDescription(String code) {
if (getSynonym().isEmpty()) {
return fullName.get(code);
}
var description = getSynonym().get(code);
if (description.isEmpty()) {
description = getSynonym().getAny();
}

if (description.isEmpty()) {
description = fullName.get(code);
}

return description;
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2025
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* MDClasses is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* MDClasses is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.bsl.mdo.support;
import com.github._1c_syntax.bsl.types.EnumWithName;
import com.github._1c_syntax.bsl.types.MultiName;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Accessors;
import java.util.Locale;
import java.util.Map;
/**
* Возможные варианты повторного использования значений модулей
*/
@ToString(of = "fullName")
public enum ReturnValueReuse implements EnumWithName {
DONT_USE("DontUse", "НеИспользовать"),
DURING_REQUEST("DuringRequest", "НаВремяВызова"),
DURING_SESSION("DuringSession", "НаВремяСеанса"),
UNKNOWN("unknown", "неизвестный");
private static final Map<String, ReturnValueReuse> KEYS = EnumWithName.computeKeys(values());
@Getter
@Accessors(fluent = true)
private final MultiName fullName;
ReturnValueReuse(String nameEn, String nameRu) {
this.fullName = MultiName.create(nameEn, nameRu);
}
/**
* Ищет элемент перечисления по именам (рус, анг)
*
* @param string Имя искомого элемента
* @return Найденное значение, если не найден - то UNKNOWN
*/
public static ReturnValueReuse valueByName(String string) {
return KEYS.getOrDefault(string.toLowerCase(Locale.ROOT), UNKNOWN);
}
}
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2025
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* MDClasses is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* MDClasses is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.bsl.mdo.support;

import com.github._1c_syntax.bsl.types.EnumWithName;
import com.github._1c_syntax.bsl.types.MultiName;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Locale;
import java.util.Map;

/**
* Возможные варианты повторного использования значений модулей
*/
@ToString(of = "fullName")
public enum ReturnValueReuse implements EnumWithName {
DONT_USE("DontUse", "НеИспользовать"),
DURING_REQUEST("DuringRequest", "НаВремяВызова"),
DURING_SESSION("DuringSession", "НаВремяСеанса"),
UNKNOWN("unknown", "неизвестный");

private static final Map<String, ReturnValueReuse> KEYS = EnumWithName.computeKeys(values());

@Getter
@Accessors(fluent = true)
private final MultiName fullName;

ReturnValueReuse(String nameEn, String nameRu) {
this.fullName = MultiName.create(nameEn, nameRu);
}

/**
* Ищет элемент перечисления по именам (рус, анг)
*
* @param string Имя искомого элемента
* @return Найденное значение, если не найден - то UNKNOWN
*/
public static ReturnValueReuse valueByName(String string) {
return KEYS.getOrDefault(string.toLowerCase(Locale.ROOT), UNKNOWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Сохраняемый контекст при чтении файла
Expand Down Expand Up @@ -76,6 +80,7 @@ public abstract class AbstractReaderContext {
/**
* Режим поддержки
*/
@Getter
protected SupportVariant supportVariant;

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

/**
Expand All @@ -110,9 +116,24 @@ public abstract class AbstractReaderContext {
@Getter
private Object lastValue;

/**
* всякие прочитанные атрибуты
*/
@Getter
private final Map<String, Object> cache;

protected AbstractReaderContext(@NonNull HierarchicalStreamReader reader) {
currentPath = ExtendXStream.getCurrentPath(reader);
mdReader = ExtendXStream.getCurrentMDReader(reader);

cache = new ConcurrentHashMap<>();
}

protected AbstractReaderContext(@NonNull Path currentPath, @NonNull MDReader mdReader) {
this.currentPath = currentPath;
this.mdReader = mdReader;

cache = new ConcurrentHashMap<>();
}

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

/**
Expand All @@ -142,6 +166,11 @@ public Object build() {
return TransformationUtils.build(builder, currentPath);
}

@SuppressWarnings("unchecked")
public <T> T getFromCache(@NonNull String key, T defaultValue) {
return (T) cache.getOrDefault(key.toLowerCase(Locale.ROOT), defaultValue);
}

protected void setValueModules() {
var modules = readModules();
if (!modules.isEmpty()) {
Expand Down Expand Up @@ -175,6 +204,7 @@ private List<Module> readModules() {
}
}
);
modules.sort(Comparator.comparing(Module::toString));
return modules;
}
}
Loading
Loading