Skip to content

Commit d456753

Browse files
cdracmintellij-monorepo-bot
authored andcommitted
codestyle cleanup: notnull
GitOrigin-RevId: 525875990920936a8dfd6a9eb1ef47c896194899
1 parent d811e29 commit d456753

9 files changed

Lines changed: 50 additions & 51 deletions

File tree

platform/code-style-api/src/com/intellij/application/options/CodeStyle.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,21 @@ private CodeStyle() {
8787
public static @NotNull CodeStyleSettings getSettings(@NotNull Project project, @NotNull VirtualFile file) {
8888
CodeStyleSettings localOrTempSettings = getLocalOrTemporarySettings(project);
8989
if (localOrTempSettings != null) {
90-
if (LOG.isDebugEnabled()) {
91-
LOG.debug("localOrTemp settings for " + file.getName());
90+
if (LOG.isTraceEnabled()) {
91+
LOG.trace("localOrTemp settings for " + file.getName());
9292
}
9393
return localOrTempSettings;
9494
}
9595
return getCachedOrProjectSettings(project, file);
9696
}
9797

98-
public static CodeStyleSettings getSettings(@NotNull PsiFile file) {
98+
public static @NotNull CodeStyleSettings getSettings(@NotNull PsiFile file) {
9999
final Project project = file.getProject();
100100

101101
CodeStyleSettings localOrTempSettings = getLocalOrTemporarySettings(project);
102102
if (localOrTempSettings != null) {
103-
if (LOG.isDebugEnabled()) {
104-
LOG.debug("localOrTemp settings for " + file.getName());
103+
if (LOG.isTraceEnabled()) {
104+
LOG.trace("localOrTemp settings for " + file.getName());
105105
}
106106
return localOrTempSettings;
107107
}
@@ -117,7 +117,7 @@ public static CodeStyleSettings getSettings(@NotNull PsiFile file) {
117117
return getCachedOrProjectSettings(project, virtualFile);
118118
}
119119

120-
private static CodeStyleSettings getCachedOrProjectSettings(@NotNull Project project, @NotNull VirtualFile file) {
120+
private static @NotNull CodeStyleSettings getCachedOrProjectSettings(@NotNull Project project, @NotNull VirtualFile file) {
121121
CodeStyleSettings cachedSettings = CodeStyleCachingService.getInstance(project).tryGetSettings(file);
122122
if (LOG.isDebugEnabled()) {
123123
LOG.debug((cachedSettings != null ? "cached" : "project") + " settings for " + file.getName());
@@ -167,12 +167,12 @@ private static boolean hasLocalVirtualFile(@NotNull PsiFile file) {
167167
return virtualFile != null && virtualFile.isInLocalFileSystem();
168168
}
169169

170-
public static CodeStyleSettings getSettings(@NotNull Project project, @NotNull Document document) {
170+
public static @NotNull CodeStyleSettings getSettings(@NotNull Project project, @NotNull Document document) {
171171
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
172172
return file != null ? getSettings(file) : getSettings(project);
173173
}
174174

175-
public static CodeStyleSettings getSettings(@NotNull Editor editor) {
175+
public static @NotNull CodeStyleSettings getSettings(@NotNull Editor editor) {
176176
Project project = editor.getProject();
177177
VirtualFile file = editor.getVirtualFile();
178178
if (file != null && project != null) {
@@ -206,7 +206,7 @@ public static CodeStyleSettings getSettings(@NotNull Editor editor) {
206206
* @param <T> Settings class type.
207207
* @return The current custom settings associated with the PSI file.
208208
*/
209-
public static @NotNull <T extends CustomCodeStyleSettings> T getCustomSettings(@NotNull PsiFile file, Class<T> customSettingsClass) {
209+
public static @NotNull <T extends CustomCodeStyleSettings> T getCustomSettings(@NotNull PsiFile file, @NotNull Class<T> customSettingsClass) {
210210
CodeStyleSettings rootSettings = getSettings(file);
211211
return rootSettings.getCustomSettings(customSettingsClass);
212212
}
@@ -250,7 +250,7 @@ public static CodeStyleSettings getSettings(@NotNull Editor editor) {
250250
* @return The resulting indent options.
251251
* @see FileIndentOptionsProvider
252252
*/
253-
public static CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull Project project, @NotNull VirtualFile virtualFile) {
253+
public static @NotNull CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull Project project, @NotNull VirtualFile virtualFile) {
254254
CodeStyleSettings rootSetting = getSettings(project, virtualFile);
255255
return rootSetting.getIndentOptionsByFile(project, virtualFile, null);
256256
}
@@ -469,7 +469,7 @@ public static void reformatWithFileContext(@NotNull PsiFile fileToReformat, @Not
469469
* @return Test code style settings.
470470
*/
471471
@TestOnly
472-
public static CodeStyleSettings createTestSettings(@Nullable CodeStyleSettings baseSettings) {
472+
public static @NotNull CodeStyleSettings createTestSettings(@Nullable CodeStyleSettings baseSettings) {
473473
return CodeStyleSettingsManager.createTestSettings(baseSettings);
474474
}
475475

@@ -540,7 +540,7 @@ public static int getJoinedLinesSpacing(@NotNull Editor editor, @Nullable Langua
540540
* @return Test code style settings.
541541
*/
542542
@TestOnly
543-
public static CodeStyleSettings createTestSettings() {
543+
public static @NotNull CodeStyleSettings createTestSettings() {
544544
return CodeStyleSettingsManager.createTestSettings(null);
545545
}
546546

@@ -559,7 +559,7 @@ public static CodeStyleSettings createTestSettings() {
559559
* @param editor The current editor.
560560
* @param offset The offset to find the language at.
561561
*/
562-
public static CommonCodeStyleSettings getLocalLanguageSettings(Editor editor, int offset) {
562+
public static @NotNull CommonCodeStyleSettings getLocalLanguageSettings(@NotNull Editor editor, int offset) {
563563
PsiFile psiFile = PsiEditorUtil.getPsiFile(editor);
564564
Language language = PsiUtilCore.getLanguageAtOffset(psiFile, offset);
565565
return getLanguageSettings(psiFile, language);

platform/code-style-api/src/com/intellij/psi/codeStyle/CodeStyleSettings.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static class DefaultsHolder {
7272
/**
7373
* Produces the default configurable id for the configurables that didn't override it, produced by {@link CodeStyleSettingsProvider}.
7474
*/
75-
public static String generateConfigurableIdByLanguage(@NotNull Language language) {
75+
public static @NotNull String generateConfigurableIdByLanguage(@NotNull Language language) {
7676
return "preferences.sourceCode." + language.getID();
7777
}
7878

@@ -176,7 +176,7 @@ private void copyCustomSettingsFrom(@NotNull CodeStyleSettings from) {
176176
myRepeatAnnotations.addAll(from.myRepeatAnnotations);
177177
}
178178

179-
public void copyFrom(CodeStyleSettings from) {
179+
public void copyFrom(@NotNull CodeStyleSettings from) {
180180
CommonCodeStyleSettings.copyPublicFields(from, this);
181181
OTHER_INDENT_OPTIONS.copyFrom(from.OTHER_INDENT_OPTIONS);
182182
mySoftMargins.setValues(from.getDefaultSoftMargins());
@@ -273,13 +273,13 @@ public String getLineSeparator() {
273273

274274
/** @deprecated Use {@link com.intellij.psi.codeStyle.JavaCodeStyleSettings#getRepeatAnnotations()} */
275275
@Deprecated(forRemoval = true)
276-
public List<String> getRepeatAnnotations() {
276+
public @NotNull List<String> getRepeatAnnotations() {
277277
return myRepeatAnnotations;
278278
}
279279

280280
/** @deprecated Use {@link com.intellij.psi.codeStyle.JavaCodeStyleSettings#setRepeatAnnotations(List)} */
281281
@Deprecated(forRemoval = true)
282-
public void setRepeatAnnotations(List<String> repeatAnnotations) {
282+
public void setRepeatAnnotations(@NotNull List<String> repeatAnnotations) {
283283
myRepeatAnnotations.clear();
284284
myRepeatAnnotations.addAll(repeatAnnotations);
285285
}
@@ -412,14 +412,14 @@ public void setUseFqClassNames(boolean value) {
412412
/** @deprecated Use {@link com.intellij.psi.codeStyle.JavaCodeStyleSettings#getImportLayoutTable()} */
413413
@Deprecated
414414
@Override
415-
public PackageEntryTable getImportLayoutTable() {
415+
public @NotNull PackageEntryTable getImportLayoutTable() {
416416
return IMPORT_LAYOUT_TABLE;
417417
}
418418

419419
/** @deprecated Use {@link com.intellij.psi.codeStyle.JavaCodeStyleSettings#getPackagesToUseImportOnDemand()} */
420420
@Deprecated
421421
@Override
422-
public PackageEntryTable getPackagesToUseImportOnDemand() {
422+
public @NotNull PackageEntryTable getPackagesToUseImportOnDemand() {
423423
return PACKAGES_TO_USE_IMPORT_ON_DEMAND;
424424
}
425425

@@ -550,7 +550,7 @@ private static int getVersion(@NotNull Element element) {
550550
}
551551

552552
@Override
553-
public void readExternal(Element element) throws InvalidDataException {
553+
public void readExternal(@NotNull Element element) throws InvalidDataException {
554554
myVersion = getVersion(element);
555555
myCustomCodeStyleSettingsManager.notifySettingsBeforeLoading();
556556
myStoredOptions.processOptions(element);
@@ -609,7 +609,7 @@ public void readExternal(Element element) throws InvalidDataException {
609609
}
610610

611611
@Override
612-
public void writeExternal(Element element) throws WriteExternalException {
612+
public void writeExternal(@NotNull Element element) throws WriteExternalException {
613613
setVersion(element, myVersion);
614614
CodeStyleSettings defaultSettings = new CodeStyleSettings(true, false);
615615
DefaultJDOMExternalizer.write(this, element, myStoredOptions.createDiffFilter(this, defaultSettings));
@@ -641,7 +641,7 @@ public void writeExternal(Element element) throws WriteExternalException {
641641
}
642642
}
643643

644-
private static IndentOptions getDefaultIndentOptions(FileType fileType) {
644+
private static @NotNull IndentOptions getDefaultIndentOptions(@NotNull FileType fileType) {
645645
for (final FileTypeIndentOptionsFactory factory : CodeStyleSettingsService.getInstance().getFileTypeIndentOptionsFactories()) {
646646
if (factory.getFileType().equals(fileType)) {
647647
return getFileTypeIndentOptions(factory);
@@ -858,7 +858,7 @@ void unregisterAdditionalIndentOptions(@NotNull FileType fileType) {
858858
}
859859
}
860860

861-
private static IndentOptions getFileTypeIndentOptions(@NotNull FileTypeIndentOptionsFactory factory) {
861+
private static @NotNull IndentOptions getFileTypeIndentOptions(@NotNull FileTypeIndentOptionsFactory factory) {
862862
try {
863863
return factory.createIndentOptions();
864864
}
@@ -931,7 +931,7 @@ public boolean isBinary() {
931931
* @return Language-specific code style settings or shared settings if not found.
932932
* @see CommonCodeStyleSettingsManager#getCommonSettings
933933
*/
934-
public CommonCodeStyleSettings getCommonSettings(String langName) {
934+
public @NotNull CommonCodeStyleSettings getCommonSettings(@NotNull String langName) {
935935
return myCommonSettingsManager.getCommonSettings(langName);
936936
}
937937

@@ -1008,16 +1008,15 @@ public boolean isWrapOnTyping(@Nullable Language language) {
10081008
}
10091009

10101010
public enum WrapStyle implements PresentableEnum {
1011-
10121011
DO_NOT_WRAP(CommonCodeStyleSettings.DO_NOT_WRAP, CodeStyleBundle.messagePointer("wrapping.do.not.wrap")),
10131012
WRAP_AS_NEEDED(CommonCodeStyleSettings.WRAP_AS_NEEDED, CodeStyleBundle.messagePointer("wrapping.wrap.if.long")),
10141013
WRAP_ON_EVERY_ITEM(CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM, CodeStyleBundle.messagePointer("wrapping.chop.down.if.long")),
10151014
WRAP_ALWAYS(CommonCodeStyleSettings.WRAP_ALWAYS, CodeStyleBundle.messagePointer("wrapping.wrap.always"));
10161015

10171016
private final int myId;
1018-
private final Supplier<@Label String> myDescription;
1017+
private final @NotNull Supplier<@Label String> myDescription;
10191018

1020-
WrapStyle(int id, @NotNull Supplier<@Label String> description) {
1019+
WrapStyle(int id, @NotNull Supplier<@Label @NotNull String> description) {
10211020
myId = id;
10221021
myDescription = description;
10231022
}
@@ -1026,7 +1025,7 @@ public int getId() {
10261025
return myId;
10271026
}
10281027

1029-
@Override public @Label String getPresentableText() {
1028+
@Override public @Label @NotNull String getPresentableText() {
10301029
return myDescription.get();
10311030
}
10321031

@@ -1052,7 +1051,7 @@ public enum HtmlTagNewLineStyle implements PresentableEnum {
10521051
private final String myValue;
10531052
private final Supplier<@Label String> myDescription;
10541053

1055-
HtmlTagNewLineStyle(@NotNull String value, @NotNull Supplier<@Label String> description) {
1054+
HtmlTagNewLineStyle(@NotNull String value, @NotNull Supplier<@Label @NotNull String> description) {
10561055
myValue = value;
10571056
myDescription = description;
10581057
}
@@ -1062,7 +1061,7 @@ public String toString() {
10621061
return myValue;
10631062
}
10641063

1065-
@Override public @Label String getPresentableText() {
1064+
@Override public @Label @NotNull String getPresentableText() {
10661065
return myDescription.get();
10671066
}
10681067
}
@@ -1075,12 +1074,12 @@ public enum QuoteStyle implements PresentableEnum {
10751074
public final String quote;
10761075
private final Supplier<@Label String> myDescription;
10771076

1078-
QuoteStyle(@NotNull String quote, @NotNull Supplier<@Label String> description) {
1077+
QuoteStyle(@NotNull String quote, @NotNull Supplier<@Label @NotNull String> description) {
10791078
this.quote = quote;
10801079
myDescription = description;
10811080
}
10821081

1083-
@Override public @Label String getPresentableText() {
1082+
@Override public @Label @NotNull String getPresentableText() {
10841083
return myDescription.get();
10851084
}
10861085
}
@@ -1152,7 +1151,7 @@ public int getVersion() {
11521151
* @param language The language to set soft margins for.
11531152
* @param softMargins The soft margins to set.
11541153
*/
1155-
public void setSoftMargins(@NotNull Language language, List<Integer> softMargins) {
1154+
public void setSoftMargins(@NotNull Language language, @NotNull List<Integer> softMargins) {
11561155
CommonCodeStyleSettings languageSettings = myCommonSettingsManager.getCommonSettings(language);
11571156
assert languageSettings != null : "Settings for language " + language.getDisplayName() + " do not exist";
11581157
languageSettings.setSoftMargins(softMargins);
@@ -1169,15 +1168,15 @@ public void setSoftMargins(@NotNull Language language, List<Integer> softMargins
11691168
* Sets the default soft margins used for languages not defining them explicitly.
11701169
* @param softMargins The default soft margins.
11711170
*/
1172-
public void setDefaultSoftMargins(List<Integer> softMargins) {
1171+
public void setDefaultSoftMargins(@NotNull List<Integer> softMargins) {
11731172
mySoftMargins.setValues(softMargins);
11741173
}
11751174

11761175
public @NotNull ExcludedFiles getExcludedFiles() {
11771176
return myExcludedFiles;
11781177
}
11791178

1180-
public SimpleModificationTracker getModificationTracker() {
1179+
public @NotNull SimpleModificationTracker getModificationTracker() {
11811180
return myModificationTracker;
11821181
}
11831182

@@ -1201,8 +1200,8 @@ public void registerCustomSettings(@NotNull CustomCodeStyleSettingsFactory facto
12011200
myCustomCodeStyleSettingsManager.registerCustomSettings(this, factory);
12021201
}
12031202

1203+
@NotNull
12041204
CustomCodeStyleSettingsManager getCustomCodeStyleSettingsManager() {
12051205
return myCustomCodeStyleSettingsManager;
12061206
}
1207-
12081207
}

platform/code-style-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ protected boolean arrangementSettingsEqual(CommonCodeStyleSettings obj) {
12071207
return mySoftMargins.getValues();
12081208
}
12091209

1210-
public void setSoftMargins(List<Integer> values) {
1210+
public void setSoftMargins(@NotNull List<Integer> values) {
12111211
mySoftMargins.setValues(values);
12121212
}
12131213
}

platform/code-style-api/src/com/intellij/psi/codeStyle/FileTypeIndentOptionsFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
import com.intellij.openapi.fileTypes.FileType;
55
import org.jetbrains.annotations.ApiStatus;
6+
import org.jetbrains.annotations.NotNull;
67

78
@ApiStatus.Internal
89
public interface FileTypeIndentOptionsFactory {
10+
@NotNull
911
CommonCodeStyleSettings.IndentOptions createIndentOptions();
1012

13+
@NotNull
1114
FileType getFileType();
1215
}

platform/code-style-impl/src/com/intellij/application/options/codeStyle/cache/CodeStyleCachingServiceImpl.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,16 @@ public void scheduleWhenSettingsComputed(@NotNull PsiFile file, @NotNull Runnabl
115115
}
116116
}
117117

118-
private static class VirtualFileGetter implements Supplier<VirtualFile> {
119-
private final VirtualFile virtualFile;
120-
121-
private VirtualFileGetter(VirtualFile file) { virtualFile = file; }
122-
118+
private record VirtualFileGetter(@NotNull VirtualFile virtualFile) implements Supplier<VirtualFile> {
123119
@Override
124-
public VirtualFile get() {
120+
public @NotNull VirtualFile get() {
125121
return virtualFile;
126122
}
127123
}
128124

129-
private static class LightVirtualFileCopyGetter implements Supplier<VirtualFile> {
130-
private final LightVirtualFile virtualFile;
131-
132-
private LightVirtualFileCopyGetter(LightVirtualFile file) { virtualFile = file; }
133-
125+
private record LightVirtualFileCopyGetter(@NotNull LightVirtualFile virtualFile) implements Supplier<VirtualFile> {
134126
@Override
135-
public VirtualFile get() {
127+
public @NotNull VirtualFile get() {
136128
return getCopy(virtualFile);
137129
}
138130
}

platform/core-api/src/com/intellij/util/ui/PresentableEnum.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
package com.intellij.util.ui;
33

44
import com.intellij.openapi.util.NlsContexts;
5+
import org.jetbrains.annotations.NotNull;
56

67
public interface PresentableEnum {
8+
@NotNull
79
@NlsContexts.Label String getPresentableText();
810
}

platform/lang-api/src/com/intellij/psi/codeStyle/FileTypeIndentOptionsProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.intellij.openapi.fileTypes.FileType;
2121
import com.intellij.psi.PsiFile;
2222
import org.jetbrains.annotations.NonNls;
23+
import org.jetbrains.annotations.NotNull;
2324

2425
/**
2526
* Allows to specify indent options for specific file types as opposed to languages. For a language it is highly recommended to use
@@ -31,9 +32,11 @@ public interface FileTypeIndentOptionsProvider extends FileTypeIndentOptionsFact
3132
ExtensionPointName<FileTypeIndentOptionsProvider> EP_NAME = ExtensionPointName.create("com.intellij.fileTypeIndentOptionsProvider");
3233

3334
@Override
35+
@NotNull
3436
CommonCodeStyleSettings.IndentOptions createIndentOptions();
3537

3638
@Override
39+
@NotNull
3740
FileType getFileType();
3841

3942
@NonNls

platform/lang-impl/src/com/intellij/application/options/codeStyle/WrappingAndBracesPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void setValue(Object value, CodeStyleSettings settings) {
195195
}
196196
}
197197

198-
private static List<Integer> castToIntList(@Nullable Object value) {
198+
private static @NotNull List<Integer> castToIntList(@Nullable Object value) {
199199
if (value instanceof List && !((List<?>)value).isEmpty() && ((List<?>)value).get(0) instanceof Integer) {
200200
//noinspection unchecked
201201
return (List<Integer>)value;

python/python-syntax-core/src/com/jetbrains/python/formatter/PyCodeStyleSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public int asInt() {
3030
}
3131

3232
@Override
33-
public String getPresentableText() {
33+
public @NotNull String getPresentableText() {
3434
return PySyntaxCoreBundle.message(key);
3535
}
3636

0 commit comments

Comments
 (0)