From 1f5d5a0b7641f08756d966c2808e46944ca5a0dc Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Sun, 30 Jul 2023 22:42:42 +0200 Subject: [PATCH] fix deprecations --- .../ErlangDialyzerExternalAnnotator.java | 24 ++++++------ .../inspection/ErlangInspectionBase.java | 4 +- .../ErlangIntroduceVariableHandler.java | 37 +++++++------------ 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/org/intellij/erlang/dialyzer/ErlangDialyzerExternalAnnotator.java b/src/org/intellij/erlang/dialyzer/ErlangDialyzerExternalAnnotator.java index 421af09f7..a85bc1206 100644 --- a/src/org/intellij/erlang/dialyzer/ErlangDialyzerExternalAnnotator.java +++ b/src/org/intellij/erlang/dialyzer/ErlangDialyzerExternalAnnotator.java @@ -130,17 +130,19 @@ public void apply(@NotNull PsiFile file, State annotationResult, @NotNull Annota TextRange problemRange = TextRange.create(offset, offset + width); String message = "Dialyzer: " + problem.myDescription; HighlightDisplayKey key = HighlightDisplayKey.find(ErlangDialyzerInspection.INSPECTION_SHORT_NAME); - holder - .newAnnotation(HighlightSeverity.WARNING, message) - .range(problemRange) - .withFix(new DisableInspectionToolAction(key) { - @NotNull - @Override - public String getName() { - return "Disable 'Dialyzer-based inspections'"; - } - }) - .create(); + if (key != null) { + holder + .newAnnotation(HighlightSeverity.WARNING, message) + .range(problemRange) + .withFix(new DisableInspectionToolAction(key) { + @NotNull + @Override + public String getName() { + return "Disable 'Dialyzer-based inspections'"; + } + }) + .create(); + } } } diff --git a/src/org/intellij/erlang/inspection/ErlangInspectionBase.java b/src/org/intellij/erlang/inspection/ErlangInspectionBase.java index aadb68766..79a7f9421 100644 --- a/src/org/intellij/erlang/inspection/ErlangInspectionBase.java +++ b/src/org/intellij/erlang/inspection/ErlangInspectionBase.java @@ -185,11 +185,11 @@ public PsiElement getContainer(PsiElement context) { @Override protected void createSuppression(@NotNull Project project, @NotNull PsiElement element, @NotNull PsiElement container) throws IncorrectOperationException { - PsiParserFacade parserFacade = PsiParserFacade.SERVICE.getInstance(project); + PsiParserFacade parserFacade = PsiParserFacade.getInstance(project); String text = SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + myID; PsiComment comment = parserFacade.createLineOrBlockCommentFromText(element.getContainingFile().getLanguage(), text); PsiElement where = container.getParent().addBefore(comment, container); - PsiElement spaceFromText = PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n"); + PsiElement spaceFromText = PsiParserFacade.getInstance(project).createWhiteSpaceFromText("\n"); where.getParent().addAfter(spaceFromText, where); } } diff --git a/src/org/intellij/erlang/refactoring/introduce/ErlangIntroduceVariableHandler.java b/src/org/intellij/erlang/refactoring/introduce/ErlangIntroduceVariableHandler.java index 398b93c34..81cf45ada 100644 --- a/src/org/intellij/erlang/refactoring/introduce/ErlangIntroduceVariableHandler.java +++ b/src/org/intellij/erlang/refactoring/introduce/ErlangIntroduceVariableHandler.java @@ -130,26 +130,17 @@ private void performActionOnElementOccurrences(@NotNull final Editor editor, @NotNull final ErlangExpression expression) { if (!editor.getSettings().isVariableInplaceRenameEnabled()) return; switch (myReplaceStrategy) { - case ASK: { - OccurrencesChooser.simpleChooser(editor).showChooser( - expression, - getOccurrences(expression), - new Pass() { - @Override - public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) { - performInplaceIntroduce(editor, expression, replaceChoice == OccurrencesChooser.ReplaceChoice.ALL); - } - }); - break; - } - case ALL: { - performInplaceIntroduce(editor, expression, true); - break; - } - case SINGLE: { - performInplaceIntroduce(editor, expression, false); - break; - } + case ASK -> OccurrencesChooser.simpleChooser(editor).showChooser( + expression, + getOccurrences(expression), + new Pass<>() { + @Override + public void pass(OccurrencesChooser.ReplaceChoice replaceChoice) { + performInplaceIntroduce(editor, expression, replaceChoice == OccurrencesChooser.ReplaceChoice.ALL); + } + }); + case ALL -> performInplaceIntroduce(editor, expression, true); + case SINGLE -> performInplaceIntroduce(editor, expression, false); } } @@ -209,7 +200,7 @@ private static void modifyDeclaration(@NotNull PsiElement declaration) { if (PsiTreeUtil.getParentOfType(declaration, ErlangArgumentDefinition.class) != null) return; PsiElement comma = ErlangElementFactory.createLeafFromText(declaration.getProject(), ",\n"); - PsiElement newLineNode = PsiParserFacade.SERVICE.getInstance(declaration.getProject()).createWhiteSpaceFromText("\n"); + PsiElement newLineNode = PsiParserFacade.getInstance(declaration.getProject()).createWhiteSpaceFromText("\n"); PsiElement parent = declaration.getParent(); PsiElement psiElement = parent.addAfter(comma, declaration); parent.addAfter(newLineNode, psiElement); @@ -220,7 +211,7 @@ private static PsiElement performReplace(@NotNull final String newName, @NotNull ErlangExpression initializer, @NotNull final List occurrences) { Project project = declaration.getProject(); - return WriteCommandAction.writeCommandAction(project, initializer.getContainingFile()).withName("Extract variable").compute(() -> { + return WriteCommandAction.writeCommandAction(project, initializer.getContainingFile()).withName("Extract Variable").compute(() -> { boolean alone = occurrences.size() == 1 && occurrences.get(0).getParent() instanceof ErlangClauseBody; PsiElement createdDeclaration = replaceLeftmostArgumentDefinition(declaration, occurrences); if (createdDeclaration == null) { @@ -348,7 +339,7 @@ private static List getOccurrences(@NotNull ErlangExpression express } @Override - public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) { + public void invoke(@NotNull Project project, @NotNull PsiElement @NotNull [] elements, DataContext dataContext) { } private static class ErlangInplaceVariableIntroducer extends InplaceVariableIntroducer {