diff --git a/src/org/intellij/erlang/completion/ErlangKeywordsCompletionContributor.java b/src/org/intellij/erlang/completion/ErlangKeywordsCompletionContributor.java index c4d34aed7..b994735b1 100644 --- a/src/org/intellij/erlang/completion/ErlangKeywordsCompletionContributor.java +++ b/src/org/intellij/erlang/completion/ErlangKeywordsCompletionContributor.java @@ -32,7 +32,6 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.ProcessingContext; -import com.intellij.util.containers.ContainerUtil; import org.intellij.erlang.ErlangLanguage; import org.intellij.erlang.parser.ErlangLexer; import org.intellij.erlang.parser.ErlangParserUtil; @@ -102,9 +101,9 @@ private static LookupElement createKeywordLookupElement(@NotNull String keyword) boolean needBrackets = "export".equalsIgnoreCase(keyword) || "export_type".equalsIgnoreCase(keyword) || "optional_callbacks".equalsIgnoreCase(keyword); return PrioritizedLookupElement.withPriority(LookupElementBuilder.create(keyword) - .withInsertHandler(needHandler ? new ErlangKeywordInsertHandler(needQuotas, needBrackets) : null) - .withTailText(needHandler ? "()" : null) - .bold(), ErlangCompletionContributor.KEYWORD_PRIORITY); + .withInsertHandler(needHandler ? new ErlangKeywordInsertHandler(needQuotas, needBrackets) : null) + .withTailText(needHandler ? "()" : null) + .bold(), ErlangCompletionContributor.KEYWORD_PRIORITY); } private static class ErlangKeywordInsertHandler extends ParenthesesInsertHandler { @@ -135,7 +134,10 @@ public void handleInsert(@NotNull InsertionContext context, @NotNull LookupEleme if (insertBrackets()) doInsert(editor, document, "[", "]"); } - private static void doInsert(@NotNull Editor editor, @NotNull Document document, @NotNull String open, @NotNull String closed) { + private static void doInsert(@NotNull Editor editor, + @NotNull Document document, + @NotNull String open, + @NotNull String closed) { int offset = editor.getCaretModel().getOffset(); document.insertString(offset, open); document.insertString(offset + 1, closed); diff --git a/src/org/intellij/erlang/console/ErlangConsoleRunConfigurationForm.java b/src/org/intellij/erlang/console/ErlangConsoleRunConfigurationForm.java index 28b2eceea..ad5f69d07 100644 --- a/src/org/intellij/erlang/console/ErlangConsoleRunConfigurationForm.java +++ b/src/org/intellij/erlang/console/ErlangConsoleRunConfigurationForm.java @@ -36,7 +36,8 @@ public final class ErlangConsoleRunConfigurationForm extends SettingsEditor myModuleComboBox; - @Nullable private final Module myInitialModule; + @Nullable + private final Module myInitialModule; public ErlangConsoleRunConfigurationForm(@NotNull Project project, @Nullable Module module) { myInitialModule = module; @@ -81,9 +82,13 @@ protected void disposeEditor() { @NotNull private static SimpleListCellRenderer getListCellRendererWrapper() { - return new SimpleListCellRenderer() { + return new SimpleListCellRenderer<>() { @Override - public void customize(@NotNull JList list, @Nullable Module module, int index, boolean selected, boolean hasFocus) { + public void customize(@NotNull JList list, + @Nullable Module module, + int index, + boolean selected, + boolean hasFocus) { if (module != null) { setText(module.getName()); } diff --git a/src/org/intellij/erlang/editor/ErlangColorSettingsPage.java b/src/org/intellij/erlang/editor/ErlangColorSettingsPage.java index a7abc7f49..cb8790ecf 100644 --- a/src/org/intellij/erlang/editor/ErlangColorSettingsPage.java +++ b/src/org/intellij/erlang/editor/ErlangColorSettingsPage.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.util.HashMap; import java.util.Map; import static org.intellij.erlang.editor.ErlangSyntaxHighlighter.*; @@ -55,27 +54,25 @@ public class ErlangColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Guards", GUARD), new AttributesDescriptor("Callbacks", CALLBACK), new AttributesDescriptor("Specifications", SPEC), - }; + }; + + private static final Map ATTRIBUTES_KEY_MAP = Map.ofEntries( + Map.entry("a", ATOM), + Map.entry("d", DOC_TAG), + Map.entry("k", KEYWORD), + Map.entry("m", MACRO), + Map.entry("r", RECORDS), + Map.entry("f", FUNCTION), + Map.entry("t", TYPE), + Map.entry("bt", BUILT_IN_TYPE), + Map.entry("m_att", ATTRIBUTE), + Map.entry("c", FUNCTION_CALL), + Map.entry("mr", MODULE_REF), + Map.entry("g", GUARD), + Map.entry("s", SPEC), + Map.entry("cb", CALLBACK) + ); - private static final Map ATTRIBUTES_KEY_MAP = new HashMap<>(); - - static { - ATTRIBUTES_KEY_MAP.put("a", ATOM); - ATTRIBUTES_KEY_MAP.put("d", DOC_TAG); - ATTRIBUTES_KEY_MAP.put("k", KEYWORD); - ATTRIBUTES_KEY_MAP.put("m", MACRO); - ATTRIBUTES_KEY_MAP.put("r", RECORDS); - ATTRIBUTES_KEY_MAP.put("f", FUNCTION); - ATTRIBUTES_KEY_MAP.put("t", TYPE); - ATTRIBUTES_KEY_MAP.put("bt", BUILT_IN_TYPE); - ATTRIBUTES_KEY_MAP.put("m_att", ATTRIBUTE); - ATTRIBUTES_KEY_MAP.put("c", FUNCTION_CALL); - ATTRIBUTES_KEY_MAP.put("mr", MODULE_REF); - ATTRIBUTES_KEY_MAP.put("g", GUARD); - ATTRIBUTES_KEY_MAP.put("s", SPEC); - ATTRIBUTES_KEY_MAP.put("cb", CALLBACK); - } - @NotNull public String getDisplayName() { return "Erlang"; @@ -106,29 +103,29 @@ public String getDemoText() { %%% Module fact documentation -module(fact). -export([fac/1]). - + -record(state, {id, name}). - + -define(MACRO, macro_value). - + -type in() :: ok | hello . -type out() :: ok | {error, term()}. - + %% Factorial implementation %% @doc Documentation fac(0) -> 1; fac(N) when N > 0, is_integer(N) -> N * fac(N-1). - + string_sample(A) -> "string second line". - + update_state(State) -> State#state{id=10}. - + -spec simple(in())-> out().\s simple(ok) -> ok. - + use_macro() -> io:format(?MACRO). - + -callback start_service() -> {ok, pid()}.""" ; } diff --git a/src/org/intellij/erlang/editor/ErlangSyntaxHighlighterFactory.java b/src/org/intellij/erlang/editor/ErlangSyntaxHighlighterFactory.java index eb6049947..44b3af009 100755 --- a/src/org/intellij/erlang/editor/ErlangSyntaxHighlighterFactory.java +++ b/src/org/intellij/erlang/editor/ErlangSyntaxHighlighterFactory.java @@ -16,7 +16,6 @@ package org.intellij.erlang.editor; -import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory; import com.intellij.openapi.project.Project; diff --git a/src/org/intellij/erlang/eunit/ErlangUnitRunningState.java b/src/org/intellij/erlang/eunit/ErlangUnitRunningState.java index 5e994267e..afd99d67f 100644 --- a/src/org/intellij/erlang/eunit/ErlangUnitRunningState.java +++ b/src/org/intellij/erlang/eunit/ErlangUnitRunningState.java @@ -58,7 +58,8 @@ public List getCodePath() throws ExecutionException { try { List reporterModuleCodePath = Arrays.asList("-pa", createReporterModuleDirectory()); return ContainerUtil.concat(reporterModuleCodePath, super.getCodePath()); - } catch (IOException e) { + } + catch (IOException e) { throw new ExecutionException("Failed to setup eunit reports environment", e); } } @@ -143,14 +144,14 @@ else if (kind == ErlangUnitRunConfiguration.ErlangUnitRunConfigurationKind.FUNCT for (String function : e.getValue()) { boolean isGenerator = ErlangPsiImplUtil.isEunitTestGeneratorFunctionName(function); result.append(isGenerator ? "{generator, " : "") - .append("fun ").append(moduleName).append(':').append(function).append("/0") - .append(isGenerator ? "}" : "") - .append(", "); + .append("fun ").append(moduleName).append(':').append(function).append("/0") + .append(isGenerator ? "}" : "") + .append(", "); } result.setLength(result.length() - 2); result.append("]}, "); } - if (result.length() != 0) { + if (!result.isEmpty()) { result.setLength(result.length() - 2); } tests = result.toString(); diff --git a/src/org/intellij/erlang/eunit/generation/ErlangUnitTestMethodAction.java b/src/org/intellij/erlang/eunit/generation/ErlangUnitTestMethodAction.java index 9f5a49dc6..57bb2378b 100644 --- a/src/org/intellij/erlang/eunit/generation/ErlangUnitTestMethodAction.java +++ b/src/org/intellij/erlang/eunit/generation/ErlangUnitTestMethodAction.java @@ -36,7 +36,10 @@ import org.jetbrains.annotations.NotNull; public class ErlangUnitTestMethodAction extends CodeInsightAction implements CodeInsightActionHandler { - private static void insertTestFunction(@NotNull Project project, @NotNull Editor editor, String name, boolean needNewline) { + private static void insertTestFunction(@NotNull Project project, + @NotNull Editor editor, + String name, + boolean needNewline) { Template template = TemplateManager.getInstance(project).createTemplate("", ""); Expression nameExpr = new ConstantNode(name); Expression expected = new ConstantNode("expected"); @@ -75,11 +78,6 @@ public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull Ps insertTestFunction(project, editor, name, needNewline); } - @Override - public boolean startInWriteAction() { - return true; - } - @Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!(file instanceof ErlangFile)) return false; diff --git a/src/org/intellij/erlang/navigation/ErlangNavigationUtil.java b/src/org/intellij/erlang/navigation/ErlangNavigationUtil.java index 51a0caf4a..3afc934a9 100644 --- a/src/org/intellij/erlang/navigation/ErlangNavigationUtil.java +++ b/src/org/intellij/erlang/navigation/ErlangNavigationUtil.java @@ -42,7 +42,7 @@ private ErlangNavigationUtil() { @NotNull public static List getCallbackSpecs(@NotNull ErlangFunction function) { final String functionPresentation = ErlangPsiImplUtil.createFunctionPresentation(function); - return ContainerUtil.mapNotNull(((ErlangFile)function.getContainingFile()).getBehaviours(), behaviour -> { + return ContainerUtil.mapNotNull(((ErlangFile) function.getContainingFile()).getBehaviours(), behaviour -> { ErlangFile behaviourModule = ErlangPsiImplUtil.resolveToFile(behaviour.getModuleRef()); return behaviourModule != null ? behaviourModule.getCallbackByName(functionPresentation) : null; }); @@ -70,17 +70,15 @@ public String getLocationString() { return getContainingFile().getName(); } - @Nullable @Override - public Icon getIcon(boolean unused) { + public @NotNull Icon getIcon(boolean unused) { return ErlangIcons.CALLBACK; } }; } - @Nullable @Override - public Icon getIcon(int flags) { + public @NotNull Icon getIcon(int flags) { return ErlangIcons.CALLBACK; } }; diff --git a/src/org/intellij/erlang/quickfixes/ErlangFindIncludeQuickFix.java b/src/org/intellij/erlang/quickfixes/ErlangFindIncludeQuickFix.java index 7c9fa9abb..ec2a1f1b3 100644 --- a/src/org/intellij/erlang/quickfixes/ErlangFindIncludeQuickFix.java +++ b/src/org/intellij/erlang/quickfixes/ErlangFindIncludeQuickFix.java @@ -159,7 +159,7 @@ public int getDefaultOptionIndex() { @NotNull @Override public String getTitle() { - return "Multiple files found"; + return "Multiple Files Found"; } @Nullable @@ -169,7 +169,7 @@ public PopupStep onChosen(PsiFile o, boolean b) { fixUsingIncludeFile(problem, o); renameIncludeString(project, problem, setDirectHrlLink, includeString, includeFileName); FileContentUtilCore.reparseFiles(Collections.singletonList(problem.getContainingFile().getVirtualFile())); - }), "add facet action(find include quick fix)", null, problemEditor.getDocument()); + }), "Add Facet Action (Find Include Quick Fix)", null, problemEditor.getDocument()); return null; } @@ -228,13 +228,13 @@ private static void fixUsingIncludeFile(PsiElement problem, } /* - * returns file name from includeString - * eg: - * getFileName("pr285_helper/include/internal_communication.hrl") - * -> "internal_communications.hrl" - * getFileName("ecst_events.hrl") - * -> "ecst_events.hrl" - * */ + * returns file name from includeString + * eg: + * getFileName("pr285_helper/include/internal_communication.hrl") + * -> "internal_communications.hrl" + * getFileName("ecst_events.hrl") + * -> "ecst_events.hrl" + * */ private static String getFileName(String includeString) { int index = includeString.lastIndexOf(INCLUDE_STRING_PATH_SEPARATOR); return includeString.substring(index + 1); diff --git a/src/org/intellij/erlang/quickfixes/ErlangGenerateSpecFix.java b/src/org/intellij/erlang/quickfixes/ErlangGenerateSpecFix.java index 21d20b56f..40c7aea19 100644 --- a/src/org/intellij/erlang/quickfixes/ErlangGenerateSpecFix.java +++ b/src/org/intellij/erlang/quickfixes/ErlangGenerateSpecFix.java @@ -37,7 +37,6 @@ public class ErlangGenerateSpecFix extends ErlangQuickFixBase { public static final String NAME = "Generate function spec"; - private static final String ANY_TYPE_STRING = "any()"; @NotNull @Override @@ -60,6 +59,7 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri /** * Try and guess variable name used in the given expression, for spec argument naming purpose. + * * @return The guess or null */ private static @Nullable String guessArgumentName(ErlangCompositeElement expression) { @@ -72,7 +72,7 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri if (recordRef != null) { var RecordName = recordRef.getQAtom().getText(); - return RecordName.length() > 0 + return !RecordName.isEmpty() ? RecordName.substring(0, 1).toUpperCase() + RecordName.substring(1) : null; } diff --git a/src/org/intellij/erlang/quickfixes/ErlangIntroduceMacroQuickFix.java b/src/org/intellij/erlang/quickfixes/ErlangIntroduceMacroQuickFix.java index 1f0bed7f1..0c4246d48 100644 --- a/src/org/intellij/erlang/quickfixes/ErlangIntroduceMacroQuickFix.java +++ b/src/org/intellij/erlang/quickfixes/ErlangIntroduceMacroQuickFix.java @@ -25,7 +25,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiEditorUtil; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.psi.util.PsiUtilBase; import org.intellij.erlang.psi.ErlangFile; import org.intellij.erlang.psi.ErlangMacros; import org.intellij.erlang.psi.ErlangMacrosDefinition; diff --git a/src/org/intellij/erlang/quickfixes/ErlangRemoveDuplicateFunctionExportFix.java b/src/org/intellij/erlang/quickfixes/ErlangRemoveDuplicateFunctionExportFix.java index 4c9e053ef..ea1c3c53f 100644 --- a/src/org/intellij/erlang/quickfixes/ErlangRemoveDuplicateFunctionExportFix.java +++ b/src/org/intellij/erlang/quickfixes/ErlangRemoveDuplicateFunctionExportFix.java @@ -50,14 +50,16 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri StringBuilder newExport = new StringBuilder(); for (ErlangExportFunction ef : exportFunctions.getExportFunctionList()) { if (ef == function || !ef.getText().equals(function.getText())) { - if (newExport.length() > 0) + if (!newExport.isEmpty()) { newExport.append(", "); + } newExport.append(ef.getText()); } } - if (newExport.length() == 0) { - if (attribute.getNextSibling() instanceof PsiWhiteSpace) + if (newExport.isEmpty()) { + if (attribute.getNextSibling() instanceof PsiWhiteSpace) { attribute.getNextSibling().delete(); + } attribute.delete(); } else { diff --git a/src/org/intellij/erlang/roots/ErlangIncludeSourceRootEditHandler.java b/src/org/intellij/erlang/roots/ErlangIncludeSourceRootEditHandler.java index e3bbb1e98..bbc005ad7 100644 --- a/src/org/intellij/erlang/roots/ErlangIncludeSourceRootEditHandler.java +++ b/src/org/intellij/erlang/roots/ErlangIncludeSourceRootEditHandler.java @@ -60,7 +60,7 @@ public CustomShortcutSet getMarkRootShortcutSet() { @NotNull @Override public String getRootsGroupTitle() { - return "Include directories"; + return "Include Directories"; } @NotNull @@ -72,6 +72,6 @@ public Color getRootsGroupColor() { @NotNull @Override public String getUnmarkRootButtonText() { - return "Unmark include directory"; + return "Unmark Include Directory"; } }