Skip to content

Commit

Permalink
fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 30, 2023
1 parent 027b2cc commit 1f5d5a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/org/intellij/erlang/inspection/ErlangInspectionBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OccurrencesChooser.ReplaceChoice>() {
@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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -220,7 +211,7 @@ private static PsiElement performReplace(@NotNull final String newName,
@NotNull ErlangExpression initializer,
@NotNull final List<PsiElement> 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) {
Expand Down Expand Up @@ -348,7 +339,7 @@ private static List<PsiElement> 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<PsiElement> {
Expand Down

0 comments on commit 1f5d5a0

Please sign in to comment.