| 
 | 1 | +/**  | 
 | 2 | + *  | 
 | 3 | + */  | 
 | 4 | +package com.e1c.v8codestyle.bsl.check;  | 
 | 5 | + | 
 | 6 | +import java.util.Collection;  | 
 | 7 | +import java.util.HashMap;  | 
 | 8 | +import java.util.Map;  | 
 | 9 | +import java.util.Set;  | 
 | 10 | + | 
 | 11 | +import org.eclipse.xtext.util.Pair;  | 
 | 12 | +import org.eclipse.xtext.util.Tuples;  | 
 | 13 | + | 
 | 14 | +import com._1c.g5.v8.dt.lcore.util.CaseInsensitiveString;  | 
 | 15 | +import com._1c.g5.v8.dt.platform.IEObjectTypeNames;  | 
 | 16 | +import com.google.inject.Singleton;  | 
 | 17 | + | 
 | 18 | +/**  | 
 | 19 | + * @author Dmitriy Marmyshev  | 
 | 20 | + *  | 
 | 21 | + */  | 
 | 22 | +@Singleton  | 
 | 23 | +public class LocalizableRegistry  | 
 | 24 | +{  | 
 | 25 | + | 
 | 26 | +    private Map<CaseInsensitiveString, Collection<Integer>> staticInvocation;  | 
 | 27 | + | 
 | 28 | +    private Map<Pair<CaseInsensitiveString, Integer>, Collection<String>> dynamicInvocation;  | 
 | 29 | + | 
 | 30 | +    private Map<CaseInsensitiveString, Collection<String>> dynamicProperties;  | 
 | 31 | + | 
 | 32 | +    private volatile boolean initialized;  | 
 | 33 | + | 
 | 34 | +    public Collection<Integer> getStaticInvocationParameters(String methodName)  | 
 | 35 | +    {  | 
 | 36 | +        if (methodName == null)  | 
 | 37 | +        {  | 
 | 38 | +            return Set.of();  | 
 | 39 | +        }  | 
 | 40 | +        checkInit();  | 
 | 41 | + | 
 | 42 | +        return staticInvocation.getOrDefault(new CaseInsensitiveString(methodName), Set.of());  | 
 | 43 | +    }  | 
 | 44 | + | 
 | 45 | +    public Collection<String> getDynamicTypesForMethod(String methodName, int index)  | 
 | 46 | +    {  | 
 | 47 | +        if (methodName == null || index < 0)  | 
 | 48 | +        {  | 
 | 49 | +            return Set.of();  | 
 | 50 | +        }  | 
 | 51 | + | 
 | 52 | +        checkInit();  | 
 | 53 | + | 
 | 54 | +        return dynamicInvocation.getOrDefault(Tuples.create(new CaseInsensitiveString(methodName), index), Set.of());  | 
 | 55 | +    }  | 
 | 56 | + | 
 | 57 | +    public Collection<String> getDynamicTypesForProperty(String propertyName)  | 
 | 58 | +    {  | 
 | 59 | +        if (propertyName == null)  | 
 | 60 | +        {  | 
 | 61 | +            return Set.of();  | 
 | 62 | +        }  | 
 | 63 | + | 
 | 64 | +        checkInit();  | 
 | 65 | + | 
 | 66 | +        return dynamicProperties.getOrDefault(new CaseInsensitiveString(propertyName), Set.of());  | 
 | 67 | +    }  | 
 | 68 | + | 
 | 69 | +    private void checkInit()  | 
 | 70 | +    {  | 
 | 71 | +        if (initialized)  | 
 | 72 | +        {  | 
 | 73 | +            return;  | 
 | 74 | +        }  | 
 | 75 | + | 
 | 76 | +        init();  | 
 | 77 | +    }  | 
 | 78 | + | 
 | 79 | +    private synchronized void init()  | 
 | 80 | +    {  | 
 | 81 | +        if (initialized)  | 
 | 82 | +        {  | 
 | 83 | +            return;  | 
 | 84 | +        }  | 
 | 85 | + | 
 | 86 | +        initStaticInvocation();  | 
 | 87 | +        initDynamicInvocation();  | 
 | 88 | +        initDynamicProperties();  | 
 | 89 | + | 
 | 90 | +        initialized = true;  | 
 | 91 | +    }  | 
 | 92 | + | 
 | 93 | +    private void initStaticInvocation()  | 
 | 94 | +    {  | 
 | 95 | +        // Global context method name and index of localizable string parameter  | 
 | 96 | +        Map<CaseInsensitiveString, Collection<Integer>> invocations = new HashMap<>();  | 
 | 97 | +        invocations.put(new CaseInsensitiveString("ПоказатьВопрос"), Set.of(1, 5)); //$NON-NLS-1$  | 
 | 98 | +        invocations.put(new CaseInsensitiveString("ShowQueryBox"), Set.of(1, 5)); //$NON-NLS-1$  | 
 | 99 | +        invocations.put(new CaseInsensitiveString("Вопрос"), Set.of(0, 4)); //$NON-NLS-1$  | 
 | 100 | +        invocations.put(new CaseInsensitiveString("DoQueryBox"), Set.of(0, 4)); //$NON-NLS-1$  | 
 | 101 | +        invocations.put(new CaseInsensitiveString("Сообщить"), Set.of(0)); //$NON-NLS-1$  | 
 | 102 | +        invocations.put(new CaseInsensitiveString("Message"), Set.of(0)); //$NON-NLS-1$  | 
 | 103 | +        invocations.put(new CaseInsensitiveString("Состояние"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 104 | +        invocations.put(new CaseInsensitiveString("Status"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 105 | +        invocations.put(new CaseInsensitiveString("ПоказатьОповещениеПользователя"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 106 | +        invocations.put(new CaseInsensitiveString("ShowUserNotification"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 107 | +        invocations.put(new CaseInsensitiveString("ПоказатьПредупреждение"), Set.of(1, 3)); //$NON-NLS-1$  | 
 | 108 | +        invocations.put(new CaseInsensitiveString("ShowMessageBox"), Set.of(1, 3)); //$NON-NLS-1$  | 
 | 109 | +        invocations.put(new CaseInsensitiveString("Предупреждение"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 110 | +        invocations.put(new CaseInsensitiveString("DoMessageBox"), Set.of(0, 2)); //$NON-NLS-1$  | 
 | 111 | + | 
 | 112 | +        staticInvocation = Map.copyOf(invocations);  | 
 | 113 | +    }  | 
 | 114 | + | 
 | 115 | +    private void initDynamicInvocation()  | 
 | 116 | +    {  | 
 | 117 | +        //@formatter:off  | 
 | 118 | + | 
 | 119 | +        // Object's method name and index of localizable string parameter, and collection of object's type names  | 
 | 120 | +        dynamicInvocation = Map.of(  | 
 | 121 | +            Tuples.create(new CaseInsensitiveString("Добавить"), 1), Set.of(IEObjectTypeNames.VALUE_LIST), //$NON-NLS-1$  | 
 | 122 | +            Tuples.create(new CaseInsensitiveString("Add"), 1), Set.of(IEObjectTypeNames.VALUE_LIST) //$NON-NLS-1$  | 
 | 123 | +            );  | 
 | 124 | + | 
 | 125 | +      //@formatter:on  | 
 | 126 | + | 
 | 127 | +    }  | 
 | 128 | + | 
 | 129 | +    private void initDynamicProperties()  | 
 | 130 | +    {  | 
 | 131 | +        //@formatter:off  | 
 | 132 | + | 
 | 133 | +        // Types that contains property Title  | 
 | 134 | +        Set<String> titleTypes = Set.of(  | 
 | 135 | +            IEObjectTypeNames.FORM_FIELD,  | 
 | 136 | +            IEObjectTypeNames.FORM_GROUP,  | 
 | 137 | +            IEObjectTypeNames.FORM_TABLE,  | 
 | 138 | +            IEObjectTypeNames.FORM_DECORATION,  | 
 | 139 | +            IEObjectTypeNames.FORM_COMMAND,  | 
 | 140 | +            "FormAttribute", //$NON-NLS-1$  | 
 | 141 | +            "FormItemAddition", //$NON-NLS-1$  | 
 | 142 | +            IEObjectTypeNames.FORM_BUTTON,  | 
 | 143 | +            IEObjectTypeNames.CLIENT_APPLICATION_FORM,  | 
 | 144 | +            "ConditionalAppearenceItem", //$NON-NLS-1$  | 
 | 145 | +            "AppearenceSettingItem", //$NON-NLS-1$  | 
 | 146 | +            "CollaborationSystemConversation", //$NON-NLS-1$  | 
 | 147 | +            "DeliverableNotification", //$NON-NLS-1$  | 
 | 148 | +            "RepresentableDocumentBatch", //$NON-NLS-1$  | 
 | 149 | +            "HTMLDocument", //$NON-NLS-1$  | 
 | 150 | +            "ValueTableColumn", //$NON-NLS-1$  | 
 | 151 | +            "ValueTreeColumn", //$NON-NLS-1$  | 
 | 152 | +            "DataCompositionAreaTemplateValueCollectionHeaderCell", //$NON-NLS-1$  | 
 | 153 | +            IEObjectTypeNames.DATA_COMPOSITION_USER_FIELD_EXPRESSION,  | 
 | 154 | +            IEObjectTypeNames.DATA_COMPOSITION_USER_FIELD_CASE,  | 
 | 155 | +            IEObjectTypeNames.DATA_COMPOSITION_SELECTED_FIELD_GROUP,  | 
 | 156 | +            IEObjectTypeNames.DATA_COMPOSITION_SELECTED_FIELD,  | 
 | 157 | +            IEObjectTypeNames.DATA_COMPOSITION_FILTER_AVAILABLE_FIELD,  | 
 | 158 | +            "NestedDataCompositionSchema", //$NON-NLS-1$  | 
 | 159 | +            "DataCompositionSchemaParameter", //$NON-NLS-1$  | 
 | 160 | +            "DataCompositionSchemaNestedDataSet", //$NON-NLS-1$  | 
 | 161 | +            "DataCompositionSchemaDataSetFieldFolder", //$NON-NLS-1$  | 
 | 162 | +            "DataCompositionSchemaDataSetField", //$NON-NLS-1$  | 
 | 163 | +            "DataCompositionSchemaCalculatedField", //$NON-NLS-1$  | 
 | 164 | +            IEObjectTypeNames.DATA_ANALYSIS_PARAMETERS,  | 
 | 165 | +            "GanttChartPlotArea", //$NON-NLS-1$  | 
 | 166 | +            "FileDialog" //$NON-NLS-1$  | 
 | 167 | +            );  | 
 | 168 | + | 
 | 169 | +        // Types that contains property ToolTip  | 
 | 170 | +        // TODO add all types with tooltip  | 
 | 171 | +        Set<String> toolTipTypes = Set.of(  | 
 | 172 | +            IEObjectTypeNames.FORM_FIELD,  | 
 | 173 | +            IEObjectTypeNames.FORM_GROUP,  | 
 | 174 | +            IEObjectTypeNames.FORM_TABLE,  | 
 | 175 | +            IEObjectTypeNames.FORM_DECORATION,  | 
 | 176 | +            IEObjectTypeNames.FORM_COMMAND,  | 
 | 177 | +            "FormItemAddition", //$NON-NLS-1$  | 
 | 178 | +            "DateAppearence" //$NON-NLS-1$  | 
 | 179 | +            );  | 
 | 180 | + | 
 | 181 | +        // TODO add types of graphical scheme with Description  | 
 | 182 | + | 
 | 183 | +        // TODO add types of DCS with Presentation  | 
 | 184 | + | 
 | 185 | +        // Localizable property name, and collection of types  | 
 | 186 | +        dynamicProperties = Map.of(  | 
 | 187 | +            new CaseInsensitiveString("Подсказка"), toolTipTypes, //$NON-NLS-1$  | 
 | 188 | +            new CaseInsensitiveString("ToolTip"), toolTipTypes, //$NON-NLS-1$  | 
 | 189 | +            new CaseInsensitiveString("ПодсказкаВвода"), Set.of("FormFieldExtenstionForTextBox"), //$NON-NLS-1$  | 
 | 190 | +            new CaseInsensitiveString("InputHint"), Set.of("FormFieldExtenstionForTextBox"), //$NON-NLS-1$  | 
 | 191 | +            new CaseInsensitiveString("Заголовок"), titleTypes, //$NON-NLS-1$  | 
 | 192 | +            new CaseInsensitiveString("Title"), titleTypes //$NON-NLS-1$  | 
 | 193 | +            );  | 
 | 194 | +        //@formatter:on  | 
 | 195 | + | 
 | 196 | +    }  | 
 | 197 | + | 
 | 198 | +}  | 
0 commit comments