Skip to content

Commit f52baa3

Browse files
committed
#2882 Got rid of a service query from the extension class loading
Moved constants to the static class fields (this also should fix the issue with localization language switch on the fly) Fixes #2882
1 parent 1dd6fd5 commit f52baa3

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

plugin/core/src/main/java/com/perl5/lang/perl/idea/formatter/settings/PerlLanguageCodeStyleSettingsProvider.java

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2023 Alexandr Evstigneev
2+
* Copyright 2015-2024 Alexandr Evstigneev
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import com.intellij.application.options.SmartIndentOptionsEditor;
2222
import com.intellij.lang.Language;
2323
import com.intellij.openapi.application.ApplicationBundle;
24+
import com.intellij.openapi.util.NlsContexts.Label;
2425
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable;
2526
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizableOptions;
2627
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
@@ -36,28 +37,30 @@
3637

3738

3839
public class PerlLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider {
39-
private static final String GROUP_QW = PerlBundle.message("perl.qw.list");
40-
private static final String GROUP_QUOTATION = PerlBundle.message("perl.formatting.group.optional.quotation");
41-
private static final String GROUP_DEREFERENCE = PerlBundle.message("perl.formatting.group.dereferencing");
42-
private static final String GROUP_PARENTHESES = PerlBundle.message("perl.formatting.group.optional.parentheses");
43-
private static final String GROUP_COMPOUND = PerlBundle.message("perl.formatting.group.compound");
44-
private static final String GROUP_NAMESPACE = PerlBundle.message("perl.formatting.brace.style.namespace");
45-
private static final String GROUP_SUB = PerlBundle.message("perl.formatting.brace.style.sub");
46-
private static final String GROUP_VARIABLE_DECLARATION = PerlBundle.message("perl.formatting.wrap.variable.declarations");
47-
private static final String GROUP_COMMENT = CodeStyleSettingsCustomizableOptions.getInstance().WRAPPING_COMMENTS;
48-
private static final String GROUP_ANNOTATIONS = PerlBundle.message("perl.formatting.group.annotations");
49-
private static final String GROUP_LIST = CodeStyleSettingsCustomizableOptions.getInstance().WRAPPING_ARRAY_INITIALIZER;
50-
private static final String GROUP_ATTRIBUTES_WRAP = PerlBundle.message("perl.formatting.wrap.attributes");
51-
private static final String GROUP_COMMA = PerlBundle.message("perl.formatting.comma.after.hash.value");
52-
53-
private static final String DEFAULT_CODE_SAMPLE = PerlBundle.message("perl.code.sample.nyi");
54-
private static final String SPACING_CODE_SAMPLE = readCodeSample("spaces");
55-
private static final String INDENT_CODE_SAMPLE = readCodeSample("indents");
56-
private static final String WRAPPING_CODES_SAMPLE = readCodeSample("wrapping");
57-
private static final String LANGUAGE_SPECIFIC_CODE_SAMPLE = readCodeSample("perl5");
40+
private static class Localization {
41+
@SuppressWarnings("DialogTitleCapitalization") private final @Label String GROUP_QW = PerlBundle.message("perl.qw.list");
42+
private final @Label String GROUP_QUOTATION = PerlBundle.message("perl.formatting.group.optional.quotation");
43+
private final @Label String GROUP_DEREFERENCE = PerlBundle.message("perl.formatting.group.dereferencing");
44+
private final @Label String GROUP_PARENTHESES = PerlBundle.message("perl.formatting.group.optional.parentheses");
45+
private final @Label String GROUP_COMPOUND = PerlBundle.message("perl.formatting.group.compound");
46+
private final @Label String GROUP_NAMESPACE = PerlBundle.message("perl.formatting.brace.style.namespace");
47+
private final @Label String GROUP_SUB = PerlBundle.message("perl.formatting.brace.style.sub");
48+
private final @Label String GROUP_VARIABLE_DECLARATION = PerlBundle.message("perl.formatting.wrap.variable.declarations");
49+
private final @Label String GROUP_COMMENT = CodeStyleSettingsCustomizableOptions.getInstance().WRAPPING_COMMENTS;
50+
private final @Label String GROUP_ANNOTATIONS = PerlBundle.message("perl.formatting.group.annotations");
51+
private final @Label String GROUP_LIST = CodeStyleSettingsCustomizableOptions.getInstance().WRAPPING_ARRAY_INITIALIZER;
52+
private final @Label String GROUP_ATTRIBUTES_WRAP = PerlBundle.message("perl.formatting.wrap.attributes");
53+
private final @Label String GROUP_COMMA = PerlBundle.message("perl.formatting.comma.after.hash.value");
54+
}
55+
56+
static final String SPACING_CODE_SAMPLE = readCodeSample("spaces");
57+
static final String INDENT_CODE_SAMPLE = readCodeSample("indents");
58+
static final String WRAPPING_CODES_SAMPLE = readCodeSample("wrapping");
59+
static final String LANGUAGE_SPECIFIC_CODE_SAMPLE = readCodeSample("perl5");
5860

5961
@Override
6062
public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) {
63+
var localization = new Localization();
6164
var customizableOptions = CodeStyleSettingsCustomizableOptions.getInstance();
6265
if (settingsType == SPACING_SETTINGS) {
6366
consumer.showStandardOptions(
@@ -156,9 +159,10 @@ public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @
156159
PerlBundle.message("perl.formatting.within.array"),
157160
customizableOptions.SPACES_WITHIN);
158161

162+
@SuppressWarnings("DialogTitleCapitalization") var qwTitle = PerlBundle.message("perl.qw.list");
159163
consumer.showCustomOption(PerlCodeStyleSettings.class,
160164
"SPACE_WITHIN_QW_QUOTES",
161-
PerlBundle.message("perl.qw.list"),
165+
qwTitle,
162166
customizableOptions.SPACES_WITHIN);
163167
}
164168
else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) {
@@ -209,83 +213,84 @@ else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) {
209213
consumer.showCustomOption(PerlCodeStyleSettings.class,
210214
"ALIGN_COMMENTS_ON_CONSEQUENT_LINES",
211215
PerlBundle.message("perl.formatting.align.comments.in.list"),
212-
GROUP_COMMENT);
216+
localization.GROUP_COMMENT);
213217

214218
consumer.showCustomOption(PerlCodeStyleSettings.class,
215219
"ALIGN_ANNOTATION_TYPE_SPECIFIERS",
216220
PerlBundle.message("perl.formatting.align.type.specifiers"),
217-
GROUP_ANNOTATIONS);
221+
localization.GROUP_ANNOTATIONS);
218222

219223

220224
consumer.showCustomOption(PerlCodeStyleSettings.class,
221225
"VARIABLE_DECLARATION_WRAP",
222-
GROUP_VARIABLE_DECLARATION,
226+
localization.GROUP_VARIABLE_DECLARATION,
223227
null,
224228
AFTER, "METHOD_PARAMETERS_WRAP",
225229
customizableOptions.WRAP_OPTIONS, WRAP_VALUES);
226230

227231
consumer.showCustomOption(PerlCodeStyleSettings.class,
228232
"ALIGN_VARIABLE_DECLARATIONS",
229233
ApplicationBundle.message("wrapping.align.when.multiline"),
230-
GROUP_VARIABLE_DECLARATION
234+
localization.GROUP_VARIABLE_DECLARATION
231235
);
232236

233237
consumer.showCustomOption(PerlCodeStyleSettings.class,
234238
"BRACE_STYLE_NAMESPACE",
235239
customizableOptions.WRAPPING_BRACES,
236-
GROUP_NAMESPACE,
240+
localization.GROUP_NAMESPACE,
237241
BRACE_PLACEMENT_OPTIONS
238242
);
239243

240244
consumer.showCustomOption(PerlCodeStyleSettings.class,
241245
"BRACE_STYLE_SUB",
242246
customizableOptions.WRAPPING_BRACES,
243-
GROUP_SUB,
247+
localization.GROUP_SUB,
244248
BRACE_PLACEMENT_OPTIONS
245249
);
246250

251+
@SuppressWarnings("DialogTitleCapitalization") var ifElseTitle = PerlBundle.message("perl.formatting.compound.secondary");
247252
consumer.showCustomOption(PerlCodeStyleSettings.class,
248253
"ELSE_ON_NEW_LINE",
249-
PerlBundle.message("perl.formatting.compound.secondary"),
250-
GROUP_COMPOUND
254+
ifElseTitle,
255+
localization.GROUP_COMPOUND
251256
);
252257

253258
consumer.showCustomOption(PerlCodeStyleSettings.class,
254259
"BRACE_STYLE_COMPOUND",
255260
customizableOptions.WRAPPING_BRACES,
256-
GROUP_COMPOUND,
261+
localization.GROUP_COMPOUND,
257262
BRACE_PLACEMENT_OPTIONS
258263
);
259264

260265
consumer.showCustomOption(PerlCodeStyleSettings.class,
261266
"ATTRIBUTES_WRAP",
262-
GROUP_ATTRIBUTES_WRAP,
267+
localization.GROUP_ATTRIBUTES_WRAP,
263268
null,
264269
customizableOptions.WRAP_OPTIONS, WRAP_VALUES);
265270

266271
consumer.showCustomOption(PerlCodeStyleSettings.class,
267272
"ALIGN_ATTRIBUTES",
268273
ApplicationBundle.message("wrapping.align.when.multiline"),
269-
GROUP_ATTRIBUTES_WRAP
274+
localization.GROUP_ATTRIBUTES_WRAP
270275
);
271276

272277
consumer.renameStandardOption("ARRAY_INITIALIZER_WRAP", PerlBundle.message("perl.formatting.align.list.elements"));
273278
consumer.showCustomOption(PerlCodeStyleSettings.class,
274279
"ALIGN_FAT_COMMA",
275280
PerlBundle.message("perl.formatting.align.fat.comma"),
276-
GROUP_LIST);
281+
localization.GROUP_LIST);
277282

278283
consumer.showCustomOption(PerlCodeStyleSettings.class,
279284
"QW_LIST_WRAP",
280-
GROUP_QW,
285+
localization.GROUP_QW,
281286
null,
282287
AFTER, "ARRAY_INITIALIZER_WRAP",
283288
customizableOptions.WRAP_OPTIONS, WRAP_VALUES
284289
);
285290
consumer.showCustomOption(PerlCodeStyleSettings.class,
286291
"ALIGN_QW_ELEMENTS",
287292
PerlBundle.message("perl.formatting.align.qw.elements"),
288-
GROUP_QW);
293+
localization.GROUP_QW);
289294

290295
consumer.showCustomOption(PerlCodeStyleSettings.class,
291296
"ALIGN_RIGHTWARD_CALLS",
@@ -297,47 +302,46 @@ else if (settingsType == LANGUAGE_SPECIFIC) {
297302
consumer.showCustomOption(PerlCodeStyleSettings.class,
298303
"OPTIONAL_QUOTES",
299304
PerlBundle.message("perl.formatting.quotation.before.fatcomma"),
300-
GROUP_QUOTATION,
305+
localization.GROUP_QUOTATION,
301306
OPTIONS_DEFAULT);
302307

303308
consumer.showCustomOption(PerlCodeStyleSettings.class,
304309
"OPTIONAL_QUOTES_HASH_INDEX",
305310
PerlBundle.message("perl.formatting.quotation.hash.index"),
306-
GROUP_QUOTATION,
311+
localization.GROUP_QUOTATION,
307312
OPTIONS_DEFAULT);
308313

309314
consumer.showCustomOption(PerlCodeStyleSettings.class,
310315
"OPTIONAL_QUOTES_HEREDOC_OPENER",
311316
PerlBundle.message("perl.formatting.quotation.heredoc.opener"),
312-
GROUP_QUOTATION,
317+
localization.GROUP_QUOTATION,
313318
OPTIONS_DEFAULT);
314319

315320
consumer.showCustomOption(PerlCodeStyleSettings.class,
316321
"OPTIONAL_DEREFERENCE",
317322
PerlBundle.message("perl.formatting.deref.indexes"),
318-
GROUP_DEREFERENCE,
323+
localization.GROUP_DEREFERENCE,
319324
OPTIONS_DEFAULT);
320325

321326
consumer.showCustomOption(PerlCodeStyleSettings.class,
322327
"OPTIONAL_DEREFERENCE_HASHREF_ELEMENT",
323328
PerlBundle.message("perl.formatting.hashref.element"),
324-
GROUP_DEREFERENCE,
329+
localization.GROUP_DEREFERENCE,
325330
OPTIONS_HASHREF_ELEMENT);
326331

327332
consumer.showCustomOption(PerlCodeStyleSettings.class,
328333
"OPTIONAL_DEREFERENCE_SIMPLE",
329334
PerlBundle.message("perl.formatting.simple.dereference"),
330-
GROUP_DEREFERENCE,
335+
localization.GROUP_DEREFERENCE,
331336
OPTIONS_SIMPLE_DEREF_STYLE);
332337

333338
consumer.showCustomOption(PerlCodeStyleSettings.class,
334339
"OPTIONAL_PARENTHESES",
335340
PerlBundle.message("perl.formatting.statement.modifiers"),
336-
GROUP_PARENTHESES,
341+
localization.GROUP_PARENTHESES,
337342
OPTIONS_DEFAULT);
338343

339-
// consumer.showCustomOption(PerlCodeStyleSettings.class, "OPTIONAL_SEMI", PERL_OPTION_OPTIONAL_SEMI, OPTIONAL_ELEMENTS_GROUP, PerlCodeStyleSettings.OptionalConstructions.OPTIONS_DEFAULT);
340-
344+
//noinspection DialogTitleCapitalization
341345
consumer.showCustomOption(PerlCodeStyleSettings.class,
342346
"MAIN_FORMAT",
343347
PerlBundle.message("perl.formatting.main.format"),
@@ -347,7 +351,7 @@ else if (settingsType == LANGUAGE_SPECIFIC) {
347351
consumer.showCustomOption(PerlCodeStyleSettings.class,
348352
"OPTIONAL_TRAILING_COMMA",
349353
PerlBundle.message("label.before.newline.hash.array"),
350-
GROUP_COMMA,
354+
localization.GROUP_COMMA,
351355
OPTIONS_DEFAULT);
352356
}
353357
}
@@ -384,7 +388,7 @@ else if (settingsType == WRAPPING_AND_BRACES_SETTINGS) {
384388
else if (settingsType == LANGUAGE_SPECIFIC) {
385389
return LANGUAGE_SPECIFIC_CODE_SAMPLE;
386390
}
387-
return DEFAULT_CODE_SAMPLE;
391+
return PerlBundle.message("perl.code.sample.nyi");
388392
}
389393

390394
@Override

0 commit comments

Comments
 (0)