From dc5ebd15c8d5e6d2007bb5374c815f950e4c42a4 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 6 May 2020 02:34:08 +0300 Subject: [PATCH] cleanup GitOrigin-RevId: 7a3bf3ae1ccca53ce39742c320ebcdcc788ab298 --- .../ex/GlobalInspectionContextBase.java | 2 +- .../impl/CustomSyntaxTableFileType.java | 2 + .../actions/AbstractLayoutCodeProcessor.java | 6 +-- .../impl/config/IntentionManagerImpl.java | 10 ++-- .../ex/GlobalInspectionContextImpl.java | 22 ++++---- .../openapi/fileTypes/UserFileType.java | 9 ++-- .../custom/impl/CustomFileTypeEditor.java | 1 + .../fileTypes/impl/AbstractFileType.java | 54 ++++++++----------- 8 files changed, 49 insertions(+), 57 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java index b588292db90d..6bfab7c627aa 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java @@ -369,7 +369,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G @Nullable String commandName, @Nullable Runnable postRunnable, final boolean modal) { - codeCleanup(scope, profile, commandName, postRunnable, modal, d -> true); + codeCleanup(scope, profile, commandName, postRunnable, modal, __ -> true); } public static void modalCodeCleanup(@NotNull Project project, @NotNull AnalysisScope scope, @Nullable Runnable runnable) { diff --git a/platform/core-impl/src/com/intellij/openapi/fileTypes/impl/CustomSyntaxTableFileType.java b/platform/core-impl/src/com/intellij/openapi/fileTypes/impl/CustomSyntaxTableFileType.java index 445f369131bb..393684bdfc4e 100644 --- a/platform/core-impl/src/com/intellij/openapi/fileTypes/impl/CustomSyntaxTableFileType.java +++ b/platform/core-impl/src/com/intellij/openapi/fileTypes/impl/CustomSyntaxTableFileType.java @@ -17,10 +17,12 @@ package com.intellij.openapi.fileTypes.impl; import com.intellij.ide.highlighter.custom.SyntaxTable; import com.intellij.openapi.fileTypes.FileType; +import org.jetbrains.annotations.NotNull; /** * Author: dmitrylomov */ public interface CustomSyntaxTableFileType extends FileType { + @NotNull SyntaxTable getSyntaxTable(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java index 725b5dd5ab99..dd153a97a3a5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java @@ -320,7 +320,7 @@ public abstract class AbstractLayoutCodeProcessor { } } - private static boolean canBeFormatted(PsiFile file) { + private static boolean canBeFormatted(@NotNull PsiFile file) { if (!file.isValid()) return false; if (LanguageFormatting.INSTANCE.forContext(file) == null) { return false; @@ -337,7 +337,7 @@ public abstract class AbstractLayoutCodeProcessor { new ReformatFilesTask(new EmptyProgressIndicator()).performFileProcessing(myFile); } - private List getAllProcessors() { + private @NotNull List getAllProcessors() { AbstractLayoutCodeProcessor current = this; List all = new ArrayList<>(); while (current != null) { @@ -451,7 +451,7 @@ public abstract class AbstractLayoutCodeProcessor { myStopFormatting = true; } - public boolean process() { + private boolean process() { myCountingIterator.processAll(file -> { updateIndicatorText(ApplicationBundle.message("bulk.reformat.prepare.progress.text"), ""); countingIteration(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java index 61561e2a4fee..8d69fd7bb578 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerImpl.java @@ -84,8 +84,8 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp @Override @NotNull - public List getStandardIntentionOptions(@NotNull final HighlightDisplayKey displayKey, - @NotNull final PsiElement context) { + public List getStandardIntentionOptions(@NotNull HighlightDisplayKey displayKey, + @NotNull PsiElement context) { checkForDuplicates(); List options = new ArrayList<>(9); options.add(new EditInspectionToolsSettingsAction(displayKey)); @@ -152,7 +152,7 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp @Override @NotNull - public LocalQuickFix convertToFix(@NotNull final IntentionAction action) { + public LocalQuickFix convertToFix(@NotNull IntentionAction action) { if (action instanceof LocalQuickFix) { return (LocalQuickFix)action; } @@ -170,8 +170,8 @@ public final class IntentionManagerImpl extends IntentionManager implements Disp } @Override - public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { - final PsiFile psiFile = descriptor.getPsiElement().getContainingFile(); + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + PsiFile psiFile = descriptor.getPsiElement().getContainingFile(); try { action.invoke(project, new LazyEditor(psiFile), psiFile); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index ad97b32dd1dd..c60e9c07fb8b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -745,23 +745,23 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx { Task task = modal ? new Task.Modal(getProject(), title, true) { @Override public void run(@NotNull ProgressIndicator indicator) { - cleanup(scope, profile, postRunnable, commandName, shouldApplyFix, indicator); + cleanup(scope, profile, postRunnable, commandName, indicator, shouldApplyFix); } } : new Task.Backgroundable(getProject(), title, true) { @Override public void run(@NotNull ProgressIndicator indicator) { - cleanup(scope, profile, postRunnable, commandName, shouldApplyFix, indicator); + cleanup(scope, profile, postRunnable, commandName, indicator, shouldApplyFix); } }; ProgressManager.getInstance().run(task); } - private void cleanup(final @NotNull AnalysisScope scope, + private void cleanup(@NotNull AnalysisScope scope, @NotNull InspectionProfile profile, - final @Nullable Runnable postRunnable, - final @Nullable String commandName, - @NotNull Predicate shouldApplyFix, - @NotNull ProgressIndicator progressIndicator) { + @Nullable Runnable postRunnable, + @Nullable String commandName, + @NotNull ProgressIndicator progressIndicator, + @NotNull Predicate shouldApplyFix) { setCurrentScope(scope); final int fileCount = scope.getFileCount(); progressIndicator.setIndeterminate(false); @@ -774,7 +774,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx { else { range = null; } - final Iterable inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> { + Iterable inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> { assert tools != null; return tools.getTool().isCleanupTool(); }); @@ -804,9 +804,9 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextEx { if (!lTools.isEmpty()) { try { - final LocalInspectionsPass pass = new LocalInspectionsPass(file, file.getViewProvider().getDocument(), range != null ? range.getStartOffset() : 0, - range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, - HighlightInfoProcessor.getEmpty(), true); + LocalInspectionsPass pass = new LocalInspectionsPass(file, file.getViewProvider().getDocument(), range != null ? range.getStartOffset() : 0, + range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, + HighlightInfoProcessor.getEmpty(), true); Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools); ApplicationManager.getApplication().runReadAction(runnable); diff --git a/platform/platform-api/src/com/intellij/openapi/fileTypes/UserFileType.java b/platform/platform-api/src/com/intellij/openapi/fileTypes/UserFileType.java index 401938303a74..ac0fab1330d0 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileTypes/UserFileType.java +++ b/platform/platform-api/src/com/intellij/openapi/fileTypes/UserFileType.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -public abstract class UserFileType implements FileType, Cloneable { +public abstract class UserFileType> implements FileType, Cloneable { @NotNull private String myName = ""; private String myDescription = ""; @@ -19,9 +19,10 @@ public abstract class UserFileType implements FileType, public abstract SettingsEditor getEditor(); @Override - public UserFileType clone() { + public UserFileType clone() { try { - return (UserFileType)super.clone(); + //noinspection unchecked + return (UserFileType)super.clone(); } catch (CloneNotSupportedException e) { return null; //Can't be @@ -81,7 +82,7 @@ public abstract class UserFileType implements FileType, return null; } - public void copyFrom(@NotNull UserFileType newType) { + public void copyFrom(@NotNull UserFileType newType) { myName = newType.getName(); myDescription = newType.getDescription(); } diff --git a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java index ce635843d9a1..d6b6a9c6f012 100644 --- a/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java +++ b/platform/platform-impl/src/com/intellij/ide/highlighter/custom/impl/CustomFileTypeEditor.java @@ -172,6 +172,7 @@ public class CustomFileTypeEditor extends SettingsEditor { return panel; } + @NotNull public SyntaxTable getSyntaxTable() { SyntaxTable syntaxTable = new SyntaxTable(); syntaxTable.setLineComment(myLineComment.getText()); diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/AbstractFileType.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/AbstractFileType.java index 74c42b44a365..4aed0ac1abec 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/AbstractFileType.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/AbstractFileType.java @@ -11,18 +11,15 @@ import com.intellij.openapi.options.ExternalizableScheme; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.util.ArrayUtilRt; import com.intellij.util.SmartList; import com.intellij.util.text.StringTokenizer; import org.jdom.Element; -import org.jdom.output.XMLOutputter; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -31,10 +28,11 @@ import java.util.Set; public class AbstractFileType extends UserFileType implements ExternalizableFileType, ExternalizableScheme, CustomSyntaxTableFileType, PlainTextLikeFileType { private static final String SEMICOLON = ";"; - protected SyntaxTable mySyntaxTable; + @NotNull + private SyntaxTable mySyntaxTable; private SyntaxTable myDefaultSyntaxTable; - protected Commenter myCommenter; - @NonNls public static final String ELEMENT_HIGHLIGHTING = "highlighting"; + private Commenter myCommenter; + @NonNls static final String ELEMENT_HIGHLIGHTING = "highlighting"; @NonNls private static final String ELEMENT_OPTIONS = "options"; @NonNls private static final String ELEMENT_OPTION = "option"; @NonNls private static final String ATTRIBUTE_VALUE = "value"; @@ -55,9 +53,9 @@ public class AbstractFileType extends UserFileType implements @NonNls private static final String ELEMENT_KEYWORDS3 = "keywords3"; @NonNls private static final String ELEMENT_KEYWORDS4 = "keywords4"; @NonNls private static final String ATTRIBUTE_NAME = "name"; - @NonNls public static final String ELEMENT_EXTENSION_MAP = "extensionMap"; + @NonNls static final String ELEMENT_EXTENSION_MAP = "extensionMap"; - public AbstractFileType(SyntaxTable syntaxTable) { + public AbstractFileType(@NotNull SyntaxTable syntaxTable) { mySyntaxTable = syntaxTable; } @@ -68,7 +66,7 @@ public class AbstractFileType extends UserFileType implements } @Override - public SyntaxTable getSyntaxTable() { + public @NotNull SyntaxTable getSyntaxTable() { return mySyntaxTable; } @@ -76,7 +74,7 @@ public class AbstractFileType extends UserFileType implements return myCommenter; } - public void setSyntaxTable(SyntaxTable syntaxTable) { + public void setSyntaxTable(@NotNull SyntaxTable syntaxTable) { mySyntaxTable = syntaxTable; } @@ -86,7 +84,7 @@ public class AbstractFileType extends UserFileType implements } @Override - public void copyFrom(@NotNull UserFileType newType) { + public void copyFrom(@NotNull UserFileType newType) { super.copyFrom(newType); if (newType instanceof AbstractFileType) { @@ -133,24 +131,24 @@ public class AbstractFileType extends UserFileType implements table.setNumPostfixChars(value); } else if (VALUE_LINE_COMMENT_AT_START.equals(name)) { - table.lineCommentOnlyAtStart = Boolean.valueOf(value).booleanValue(); + table.lineCommentOnlyAtStart = Boolean.parseBoolean(value); } else if (VALUE_HAS_BRACES.equals(name)) { - table.setHasBraces(Boolean.valueOf(value).booleanValue()); + table.setHasBraces(Boolean.parseBoolean(value)); } else if (VALUE_HAS_BRACKETS.equals(name)) { - table.setHasBrackets(Boolean.valueOf(value).booleanValue()); + table.setHasBrackets(Boolean.parseBoolean(value)); } else if (VALUE_HAS_PARENS.equals(name)) { - table.setHasParens(Boolean.valueOf(value).booleanValue()); + table.setHasParens(Boolean.parseBoolean(value)); } else if (VALUE_HAS_STRING_ESCAPES.equals(name)) { - table.setHasStringEscapes(Boolean.valueOf(value).booleanValue()); + table.setHasStringEscapes(Boolean.parseBoolean(value)); } } } else if (ELEMENT_KEYWORDS.equals(element.getName())) { - boolean ignoreCase = Boolean.valueOf(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE)).booleanValue(); + boolean ignoreCase = Boolean.parseBoolean(element.getAttributeValue(ATTRIBUTE_IGNORE_CASE)); table.setIgnoreCase(ignoreCase); loadKeywords(element, table.getKeywords1()); } @@ -165,21 +163,10 @@ public class AbstractFileType extends UserFileType implements } } - boolean DUMP_TABLE = false; - if (DUMP_TABLE) { - Element element = new Element("temp"); - writeTable(element, table); - XMLOutputter outputter = JDOMUtil.createOutputter("\n"); - try { - outputter.output((Element)element.getContent().get(0), System.out); - } - catch (IOException ignored) { - } - } return table; } - private static void loadKeywords(Element element, Set keywords) { + private static void loadKeywords(@NotNull Element element, @NotNull Set keywords) { String value = element.getAttributeValue(ELEMENT_KEYWORDS); if (value != null) { StringTokenizer tokenizer = new StringTokenizer(value, SEMICOLON); @@ -259,7 +246,7 @@ public class AbstractFileType extends UserFileType implements element.addContent(highlightingElement); } - private static void addElementOption(final Element optionsElement, final String valueHasParens, final boolean hasParens) { + private static void addElementOption(@NotNull Element optionsElement, @NotNull String valueHasParens, final boolean hasParens) { if (!hasParens) { return; } @@ -270,7 +257,7 @@ public class AbstractFileType extends UserFileType implements optionsElement.addContent(supportParens); } - private static Element writeKeywords(Set keywords, String tagName, Element highlightingElement) { + private static Element writeKeywords(@NotNull Set keywords, @NotNull String tagName, @NotNull Element highlightingElement) { if (keywords.isEmpty() && !ELEMENT_KEYWORDS.equals(tagName)) return null; Element keywordsElement = new Element(tagName); String[] strings = ArrayUtilRt.toStringArray(keywords); @@ -281,7 +268,8 @@ public class AbstractFileType extends UserFileType implements if (!keyword.contains(SEMICOLON)) { if (keywordsAttribute.length() != 0) keywordsAttribute.append(SEMICOLON); keywordsAttribute.append(keyword); - } else { + } + else { Element e = new Element(ELEMENT_KEYWORD); e.setAttribute(ATTRIBUTE_NAME, keyword); keywordsElement.addContent(e); @@ -363,7 +351,7 @@ public class AbstractFileType extends UserFileType implements return new CustomFileTypeEditor(); } - public void setCommenter(final Commenter commenter) { + public void setCommenter(@NotNull Commenter commenter) { myCommenter = commenter; } }