From 42c9ce8d1deb2f6f33cf0715aff029f11e574463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Tue, 23 Nov 2021 13:32:01 +0100 Subject: [PATCH] code samples: @Nullable cleanup --- .../sdk/action/DynamicActionGroup.java | 3 +- .../sdk/liveTemplates/TitleCaseMacro.java | 4 +-- .../intellij/sdk/module/DemoModuleType.java | 9 +++--- .../sdk/language/psi/SimpleProperty.java | 7 ++--- .../language/psi/impl/SimplePropertyImpl.java | 12 ++++---- .../SimpleChooseByNameContributor.java | 8 ++---- .../sdk/language/SimpleColorSettingsPage.java | 10 +++---- .../language/SimpleCompletionContributor.java | 4 +-- .../sdk/language/SimpleFoldingBuilder.java | 5 ++-- .../sdk/language/SimpleReference.java | 8 ++---- .../language/SimpleReferenceContributor.java | 7 ++--- .../language/SimpleStructureViewElement.java | 5 ++-- .../language/SimpleStructureViewModel.java | 2 +- .../sdk/language/SimpleSyntaxHighlighter.java | 28 ++++++++++--------- 14 files changed, 50 insertions(+), 62 deletions(-) diff --git a/action_basics/src/main/java/org/intellij/sdk/action/DynamicActionGroup.java b/action_basics/src/main/java/org/intellij/sdk/action/DynamicActionGroup.java index a45ed701d..4ceea8458 100644 --- a/action_basics/src/main/java/org/intellij/sdk/action/DynamicActionGroup.java +++ b/action_basics/src/main/java/org/intellij/sdk/action/DynamicActionGroup.java @@ -25,9 +25,8 @@ public class DynamicActionGroup extends ActionGroup { * @return AnAction[] An instance of {@link AnAction}, in this case containing a single instance of the * {@link PopupDialogAction} class. */ - @NotNull @Override - public AnAction[] getChildren(AnActionEvent e) { + public AnAction @NotNull [] getChildren(AnActionEvent e) { return new AnAction[]{ new PopupDialogAction("Action Added at Runtime", "Dynamic Action Demo", SdkIcons.Sdk_default_icon) }; diff --git a/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java b/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java index 391accdd1..d8a189aa9 100644 --- a/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java +++ b/live_templates/src/main/java/org/intellij/sdk/liveTemplates/TitleCaseMacro.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.liveTemplates; @@ -21,7 +21,7 @@ public class TitleCaseMacro extends MacroBase { } @Override - protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) { + protected Result calculateResult(Expression @NotNull [] params, ExpressionContext context, boolean quick) { // Retrieve the text from the macro or selection, if any is available. String text = getTextResult(params, context, true); if (text == null) { diff --git a/module/src/main/java/org/intellij/sdk/module/DemoModuleType.java b/module/src/main/java/org/intellij/sdk/module/DemoModuleType.java index b62807d91..5e60e46b6 100644 --- a/module/src/main/java/org/intellij/sdk/module/DemoModuleType.java +++ b/module/src/main/java/org/intellij/sdk/module/DemoModuleType.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.module; @@ -48,11 +48,10 @@ public class DemoModuleType extends ModuleType { return SdkIcons.Sdk_default_icon; } - @NotNull @Override - public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, - @NotNull DemoModuleBuilder moduleBuilder, - @NotNull ModulesProvider modulesProvider) { + public ModuleWizardStep @NotNull [] createWizardSteps(@NotNull WizardContext wizardContext, + @NotNull DemoModuleBuilder moduleBuilder, + @NotNull ModulesProvider modulesProvider) { return super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider); } diff --git a/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java b/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java index 061a0a9a8..a6e51b1ec 100644 --- a/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java +++ b/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java @@ -1,10 +1,9 @@ // This is a generated file. Not intended for manual editing. package org.intellij.sdk.language.psi; -import java.util.List; -import org.jetbrains.annotations.*; -import com.intellij.psi.PsiElement; import com.intellij.navigation.ItemPresentation; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; public interface SimpleProperty extends SimpleNamedElement { @@ -14,7 +13,7 @@ public interface SimpleProperty extends SimpleNamedElement { String getName(); - PsiElement setName(String newName); + PsiElement setName(@NotNull String newName); PsiElement getNameIdentifier(); diff --git a/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java b/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java index 9f6fb4801..824ff00e3 100644 --- a/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java +++ b/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java @@ -1,15 +1,13 @@ // This is a generated file. Not intended for manual editing. package org.intellij.sdk.language.psi.impl; -import java.util.List; -import org.jetbrains.annotations.*; import com.intellij.lang.ASTNode; +import com.intellij.navigation.ItemPresentation; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.util.PsiTreeUtil; -import static org.intellij.sdk.language.psi.SimpleTypes.*; -import org.intellij.sdk.language.psi.*; -import com.intellij.navigation.ItemPresentation; +import org.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleVisitor; +import org.jetbrains.annotations.NotNull; public class SimplePropertyImpl extends SimpleNamedElementImpl implements SimpleProperty { @@ -43,7 +41,7 @@ public class SimplePropertyImpl extends SimpleNamedElementImpl implements Simple } @Override - public PsiElement setName(String newName) { + public PsiElement setName(@NotNull String newName) { return SimplePsiImplUtil.setName(this, newName); } diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java index 7e69044b0..601b48851 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -13,9 +13,8 @@ import java.util.List; public class SimpleChooseByNameContributor implements ChooseByNameContributor { - @NotNull @Override - public String[] getNames(Project project, boolean includeNonProjectItems) { + public String @NotNull [] getNames(Project project, boolean includeNonProjectItems) { List properties = SimpleUtil.findProperties(project); List names = new ArrayList<>(properties.size()); for (SimpleProperty property : properties) { @@ -26,9 +25,8 @@ public class SimpleChooseByNameContributor implements ChooseByNameContributor { return names.toArray(new String[names.size()]); } - @NotNull @Override - public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) { + public NavigationItem @NotNull [] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) { // TODO: include non project items List properties = SimpleUtil.findProperties(project, name); return properties.toArray(new NavigationItem[properties.size()]); diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java index be451f355..a3b041e9a 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -19,7 +19,7 @@ public class SimpleColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY), new AttributesDescriptor("Separator", SimpleSyntaxHighlighter.SEPARATOR), new AttributesDescriptor("Value", SimpleSyntaxHighlighter.VALUE), - new AttributesDescriptor("Bad Value", SimpleSyntaxHighlighter.BAD_CHARACTER) + new AttributesDescriptor("Bad value", SimpleSyntaxHighlighter.BAD_CHARACTER) }; @Nullable @@ -57,15 +57,13 @@ public class SimpleColorSettingsPage implements ColorSettingsPage { return null; } - @NotNull @Override - public AttributesDescriptor[] getAttributeDescriptors() { + public AttributesDescriptor @NotNull [] getAttributeDescriptors() { return DESCRIPTORS; } - @NotNull @Override - public ColorDescriptor[] getColorDescriptors() { + public ColorDescriptor @NotNull [] getColorDescriptors() { return ColorDescriptor.EMPTY_ARRAY; } diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java index 8db5832bd..f68870441 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -13,7 +13,7 @@ public class SimpleCompletionContributor extends CompletionContributor { public SimpleCompletionContributor() { extend(CompletionType.BASIC, PlatformPatterns.psiElement(SimpleTypes.VALUE), - new CompletionProvider() { + new CompletionProvider<>() { public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) { diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java index 40ef96221..90c8df4f6 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -23,9 +23,8 @@ import java.util.List; public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware { - @NotNull @Override - public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { + public FoldingDescriptor @NotNull [] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { // Initialize the group of folding regions that will expand/collapse together. FoldingGroup group = FoldingGroup.newGroup(SimpleAnnotator.SIMPLE_PREFIX_STR); // Initialize the list of folding regions diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java index 5abcf5415..aeade5c72 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -23,9 +23,8 @@ public class SimpleReference extends PsiReferenceBase implements Psi key = element.getText().substring(textRange.getStartOffset(), textRange.getEndOffset()); } - @NotNull @Override - public ResolveResult[] multiResolve(boolean incompleteCode) { + public ResolveResult @NotNull [] multiResolve(boolean incompleteCode) { Project project = myElement.getProject(); final List properties = SimpleUtil.findProperties(project, key); List results = new ArrayList<>(); @@ -42,9 +41,8 @@ public class SimpleReference extends PsiReferenceBase implements Psi return resolveResults.length == 1 ? resolveResults[0].getElement() : null; } - @NotNull @Override - public Object[] getVariants() { + public Object @NotNull [] getVariants() { Project project = myElement.getProject(); List properties = SimpleUtil.findProperties(project); List variants = new ArrayList<>(); diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java index d8704b64c..f27517b1b 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -17,10 +17,9 @@ public class SimpleReferenceContributor extends PsiReferenceContributor { public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), new PsiReferenceProvider() { - @NotNull @Override - public PsiReference[] getReferencesByElement(@NotNull PsiElement element, - @NotNull ProcessingContext context) { + public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, + @NotNull ProcessingContext context) { PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java index 73d1f2be2..35a6fa909 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -59,9 +59,8 @@ public class SimpleStructureViewElement implements StructureViewTreeElement, Sor return presentation != null ? presentation : new PresentationData(); } - @NotNull @Override - public TreeElement[] getChildren() { + public TreeElement @NotNull [] getChildren() { if (myElement instanceof SimpleFile) { List properties = PsiTreeUtil.getChildrenOfTypeAsList(myElement, SimpleProperty.class); List treeElements = new ArrayList<>(properties.size()); diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java index 6af1c5dc7..251c449cc 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java @@ -18,7 +18,7 @@ public class SimpleStructureViewModel extends StructureViewModelBase implements } @NotNull - public Sorter[] getSorters() { + public Sorter @NotNull [] getSorters() { return new Sorter[]{Sorter.ALPHA_SORTER}; } diff --git a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java index c37f7c283..5249cf9d4 100644 --- a/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java +++ b/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.intellij.sdk.language; @@ -41,22 +41,24 @@ public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase { return new SimpleLexerAdapter(); } - @NotNull @Override - public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { + public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) { if (tokenType.equals(SimpleTypes.SEPARATOR)) { return SEPARATOR_KEYS; - } else if (tokenType.equals(SimpleTypes.KEY)) { - return KEY_KEYS; - } else if (tokenType.equals(SimpleTypes.VALUE)) { - return VALUE_KEYS; - } else if (tokenType.equals(SimpleTypes.COMMENT)) { - return COMMENT_KEYS; - } else if (tokenType.equals(TokenType.BAD_CHARACTER)) { - return BAD_CHAR_KEYS; - } else { - return EMPTY_KEYS; } + if (tokenType.equals(SimpleTypes.KEY)) { + return KEY_KEYS; + } + if (tokenType.equals(SimpleTypes.VALUE)) { + return VALUE_KEYS; + } + if (tokenType.equals(SimpleTypes.COMMENT)) { + return COMMENT_KEYS; + } + if (tokenType.equals(TokenType.BAD_CHARACTER)) { + return BAD_CHAR_KEYS; + } + return EMPTY_KEYS; } }